module Web.View.HubCapabilityManifests.Edit where import Web.Types import Generated.Types import IHP.Prelude import IHP.ViewPrelude import Web.Routes () import Data.Aeson (Value(..), encode, decode) import qualified Data.ByteString.Lazy.Char8 as BL data EditView = EditView { manifest :: !HubCapabilityManifest , hub :: !Hub , widgetTypeEntries :: ![WidgetTypeRegistry] , eventTypeEntries :: ![EventTypeRegistry] , categoryEntries :: ![AnnotationCategoryRegistry] , policyScopeEntries :: ![PolicyScopeRegistry] } instance View EditView where html EditView { .. } = [hsx|
← {hub.name} Manifest

Edit Capability Manifest — {hub.name}

Declare the type names this hub owns. After saving, activate the manifest to register them.

{renderReadOnlyWarning manifest}

Manifest Details

{typeArraySection "Declared Widget Types" "declaredWidgetTypes" manifest.declaredWidgetTypes (map (.name) widgetTypeEntries)} {typeArraySection "Declared Event Types" "declaredEventTypes" manifest.declaredEventTypes (map (.name) eventTypeEntries)} {typeArraySection "Declared Annotation Categories" "declaredAnnotationCategories" manifest.declaredAnnotationCategories (map (.name) categoryEntries)} {typeArraySection "Declared Policy Scopes" "declaredPolicyScopes" manifest.declaredPolicyScopes (map (.name) policyScopeEntries)}
{if manifest.status == "draft" then renderActivateLink manifest.id else mempty}
|] renderActivateLink :: Id HubCapabilityManifest -> Html renderActivateLink mid = [hsx| Save & Activate |] -- | Render a JSON array text area with available registry options shown below. typeArraySection :: Text -> Text -> Value -> [Text] -> Html typeArraySection title fieldName val names = [hsx|

{title}

JSON array of type names to declare ownership of. Names that don't yet exist in the registry will be created on activation.

Registered: {joinNames names}

|] renderReadOnlyWarning :: HubCapabilityManifest -> Html renderReadOnlyWarning manifest | manifest.status /= "draft" = [hsx|
This manifest is {manifest.status} and is read-only. Retire it first to create a new draft amendment.
|] | otherwise = mempty valueText :: Value -> Text valueText v = cs (BL.unpack (encode v)) joinNames :: [Text] -> Text joinNames [] = "" joinNames [x] = x joinNames (x:xs) = x <> ", " <> joinNames xs