module Web.View.HubCapabilityManifests.Index where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
import Web.Routes ()
import Data.Aeson (Value(..))
import qualified Data.Vector as V
data IndexView = IndexView
{ manifests :: ![HubCapabilityManifest]
, hubs :: ![Hub]
}
instance View IndexView where
html IndexView { .. } = [hsx|
Hub Capability Manifests
Extension registrations for domain and shared hubs
New Manifest
| Hub |
Status |
Widget Types |
Event Types |
Categories |
Scopes |
Activated |
|
{forEach manifests (renderRow hubs)}
|]
renderRow :: [Hub] -> HubCapabilityManifest -> Html
renderRow hubs m = [hsx|
| {hubName hubs m.hubId} |
{statusBadge m.status} |
{jsonCount m.declaredWidgetTypes} |
{jsonCount m.declaredEventTypes} |
{jsonCount m.declaredAnnotationCategories} |
{jsonCount m.declaredPolicyScopes} |
{maybe "—" show m.activatedAt} |
View
|
|]
hubName :: [Hub] -> Id Hub -> Text
hubName hubs i = maybe "Unknown" (.name) (find (\h -> h.id == i) hubs)
statusBadge :: Text -> Html
statusBadge "active" = [hsx|active|]
statusBadge "draft" = [hsx|draft|]
statusBadge "retired" = [hsx|retired|]
statusBadge s = [hsx|{s}|]
jsonCount :: Value -> Text
jsonCount (Array v) | V.null v = "0"
| otherwise = tshow (V.length v)
jsonCount _ = "0"