module Web.View.HubRoutingRules.Index where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
data IndexView = IndexView
{ rules :: ![HubRoutingRule]
, hubs :: ![Hub]
}
instance View IndexView where
html IndexView { .. } = [hsx|
{if null rules
then [hsx|No routing rules configured yet.
|]
else [hsx|
| Source → Target |
Match Category |
Match Widget Type |
Priority |
Status |
|
{forEach rules renderRow}
|]}
|]
where
hubName hid = maybe (show hid) (.name) (find (\h -> h.id == hid) hubs)
renderRow :: HubRoutingRule -> Html
renderRow r = [hsx|
|
{hubName r.sourceHubId} → {hubName r.targetHubId}
|
{maybe "any" id r.matchCategory} |
{maybe "any" id r.matchWidgetType} |
{show r.priority} |
" text-xs px-2 py-0.5 rounded font-medium"}>
{r.status}
|
View
{if r.status == "inactive"
then [hsx|Activate|]
else [hsx|Deactivate|]}
|
|]
statusBadge :: Text -> Text
statusBadge s = case s of
"active" -> "bg-green-100 text-green-700"
"inactive" -> "bg-gray-100 text-gray-500"
_ -> "bg-gray-100 text-gray-600"