module Web.View.HubRoutingRules.Index where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
import Web.Routes ()
data IndexView = IndexView
{ rules :: ![HubRoutingRule]
, hubs :: ![Hub]
}
instance View IndexView where
html IndexView { .. } = [hsx|
{renderRulesList rules hubs}
|]
renderRulesList :: [HubRoutingRule] -> [Hub] -> Html
renderRulesList [] _ = [hsx|No routing rules configured yet.
|]
renderRulesList rules hubs = [hsx|
| Source → Target |
Match Category |
Match Widget Type |
Priority |
Status |
|
{forEach rules (renderRoutingRuleRow hubs)}
|]
renderRoutingRuleRow :: [Hub] -> HubRoutingRule -> Html
renderRoutingRuleRow hubs r =
let hubName hid = maybe (show hid) (.name) (find (\h -> h.id == hid) hubs)
in [hsx|
|
{hubName r.sourceHubId} → {hubName r.targetHubId}
|
{fromMaybe "any" r.matchCategory} |
{fromMaybe "any" r.matchWidgetType} |
{show r.priority} |
" text-xs px-2 py-0.5 rounded font-medium"}>
{r.status}
|
View
{renderRuleToggle r}
|
|]
renderRuleToggle :: HubRoutingRule -> Html
renderRuleToggle r
| r.status == "inactive" = [hsx|Activate|]
| otherwise = [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"