module Web.View.HubCapabilityManifests.Edit where import Web.Types import Generated.Types import IHP.Prelude import IHP.ViewPrelude import Data.Aeson (Value(..), encode, decode) import qualified Data.Vector as V 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.

{if manifest.status /= "draft" then [hsx|
This manifest is {manifest.status} and is read-only. Retire it first to create a new draft amendment.
|] else [hsx||]}

Manifest Details

{(textareaField #capabilityDescription) { fieldClass = "w-full border border-gray-300 rounded px-3 py-2 text-sm" }}
{(textField #contact) { fieldClass = "w-full border border-gray-300 rounded px-3 py-2 text-sm" }}
{typeArraySection "Declared Widget Types" "declaredWidgetTypes" manifest.declaredWidgetTypes widgetTypeEntries} {typeArraySection "Declared Event Types" "declaredEventTypes" manifest.declaredEventTypes eventTypeEntries} {typeArraySection2 "Declared Annotation Categories" "declaredAnnotationCategories" manifest.declaredAnnotationCategories categoryEntries} {typeArraySection3 "Declared Policy Scopes" "declaredPolicyScopes" manifest.declaredPolicyScopes policyScopeEntries}
{if manifest.status == "draft" then [hsx| Save & Activate |] else [hsx||]}
|] -- | Render a JSON array text area with available registry options shown below. typeArraySection :: Text -> Text -> Value -> [WidgetTypeRegistry] -> Html typeArraySection title fieldName val entries = [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: {intercalate ", " (map (.name) entries)}

|] typeArraySection2 :: Text -> Text -> Value -> [AnnotationCategoryRegistry] -> Html typeArraySection2 title fieldName val entries = [hsx|

{title}

JSON array of annotation category names.

Registered: {intercalate ", " (map (.name) entries)}

|] typeArraySection3 :: Text -> Text -> Value -> [PolicyScopeRegistry] -> Html typeArraySection3 title fieldName val entries = [hsx|

{title}

JSON array of policy scope names.

Registered: {intercalate ", " (map (.name) entries)}

|] valueText :: Value -> Text valueText v = cs (BL.unpack (encode v)) intercalate :: Text -> [Text] -> Text intercalate _ [] = "" intercalate _ [x] = x intercalate sep (x:xs) = x <> sep <> intercalate sep xs