module Web.View.HubRegistry.Index where import Web.Types import Web.Types (HubRegistryRow(..), GaafStatus(..), gaafStatus) 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 { registryRows :: ![HubRegistryRow] } instance View IndexView where html IndexView { .. } = [hsx|

Hub Registry

All registered hubs with capability manifests and health status.

Marketplace
{forEach registryRows renderRow} {if null registryRows then noHubsMsg else mempty}
|] noHubsMsg :: Html noHubsMsg = [hsx|

No hubs registered yet.

|] renderRow :: HubRegistryRow -> Html renderRow row@HubRegistryRow { hub, mManifest, mLatestSnapshot } = let gs = gaafStatus mManifest wCount = maybe 0 (jsonArrayLen . (.declaredWidgetTypes)) mManifest eCount = maybe 0 (jsonArrayLen . (.declaredEventTypes)) mManifest cCount = maybe 0 (jsonArrayLen . (.declaredAnnotationCategories)) mManifest score = fmap (.healthScore) mLatestSnapshot in [hsx|
{hub.name} {hub.hubKind} {gaafBadge gs}
{maybe mempty healthScoreBadge score} {tshow wCount} widget types {tshow eCount} event types {tshow cCount} categories

{hub.domain}

|] gaafBadge :: GaafStatus -> Html gaafBadge GaafCompliant = [hsx|GAAF compliant|] gaafBadge GaafDraftOnly = [hsx|draft manifest|] gaafBadge GaafNoManifest = [hsx|no manifest|] healthScoreBadge :: Int -> Html healthScoreBadge s = let cls :: Text cls = if s >= 80 then "bg-green-100 text-green-800" else if s >= 50 then "bg-amber-100 text-amber-800" else "bg-red-100 text-red-700" in [hsx| cls}>health {tshow s}|] jsonArrayLen :: Value -> Int jsonArrayLen (Array v) = V.length v jsonArrayLen _ = 0