Files
inter-hub/Web/View/Widgets/New.hs
Bernd Worsch 32bb003f3b feat(P6/T04): WidgetAdapterSpecsController, registry, widget adapter integration
CRUD for WidgetAdapterSpec (index, show, new/create, edit/update — status+notes only
after creation). Widget new/edit forms expose optional adapter_spec_id select.
Widget show page renders adapter badge with link to spec. Widgets controller
fetches adapter spec for show action.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-29 21:14:57 +00:00

70 lines
2.0 KiB
Haskell

module Web.View.Widgets.New where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
data NewView = NewView
{ widget :: !Widget
, hubs :: ![Hub]
, adapterSpecs :: ![WidgetAdapterSpec]
}
instance View NewView where
html NewView { .. } = [hsx|
<div class="max-w-lg">
<h1 class="text-2xl font-semibold mb-6">Register Widget</h1>
{renderForm widget hubs adapterSpecs}
</div>
|]
renderForm :: Widget -> [Hub] -> [WidgetAdapterSpec] -> Html
renderForm widget hubs adapterSpecs = formFor widget [hsx|
{textField #name}
{selectField #widgetType widgetTypeOptions}
{selectField #hubId (hubOptions hubs)}
{textField #capabilityRef}
{textField #viewContext}
{selectField #policyScope policyScopeOptions}
{selectField #status statusOptions}
<div>
<label class="ihp-form-label">Adapter Spec (optional leave blank for native IHP widget)</label>
<select name="adapterSpecId" class="ihp-form-field">
<option value=""> Native IHP widget </option>
{forEach adapterSpecs (\s -> [hsx|
<option value={tshow s.id}>{s.name} ({s.framework} v{s.version})</option>
|])}
</select>
</div>
{submitButton}
|]
hubOptions :: [Hub] -> [(Text, Id Hub)]
hubOptions hubs = map (\h -> (h.name, h.id)) hubs
widgetTypeOptions :: [(Text, Text)]
widgetTypeOptions =
[ ("Chart", "chart")
, ("Form", "form")
, ("Table", "table")
, ("Action", "action")
, ("Panel", "panel")
, ("Navigation", "nav")
, ("Other", "other")
]
policyScopeOptions :: [(Text, Text)]
policyScopeOptions =
[ ("Internal", "internal")
, ("Hub", "hub")
, ("Public", "public")
]
statusOptions :: [(Text, Text)]
statusOptions =
[ ("Active", "active")
, ("Deprecated", "deprecated")
, ("Draft", "draft")
]