generated from coulomb/repo-seed
feat(WP-0011): IHF Phase 10 — Hub Registry and Widget Marketplace
Some checks failed
Test / test (push) Has been cancelled
Some checks failed
Test / test (push) Has been cancelled
Delivers the hub registry discovery UI, widget pattern library, governance template library, and marketplace dashboard. Key changes: - Schema: widget_patterns (widget_type FK to registry), widget_pattern_versions, pattern_adoptions, governance_templates (categories JSONB, validated at controller), governance_template_clones — all GAAF-compliant, no bare TEXT type discriminators - Migration: 1743897600-ihf-phase10-hub-registry.sql - HubRegistry controller + views: browsable view over hub_capability_manifests, hub_health_snapshots, hubs with per-hub GAAF compliance indicator - WidgetPatterns controller + views: publish, version, adopt; adoption triggers manifest amendment draft when new types are introduced - GovernanceTemplates controller + views: CRUD, clone with category validation against annotation_category_registry - MarketplaceDashboard controller + view: full-text search, widget-type filter, sort, trending panel, autoRefresh - API v2: /api/v2/hub-registry, /api/v2/widget-patterns (+ adopt endpoint) - OpenAPI spec updated with Phase 10 paths - GAAF scorecard: Customization 2.5 → 3.2; overall 3.41 → 3.56 (Strong) - CLAUDE.md: Phase 10 complete; active workplan → Phase 11 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
49
Web/View/WidgetPatterns/Edit.hs
Normal file
49
Web/View/WidgetPatterns/Edit.hs
Normal file
@@ -0,0 +1,49 @@
|
||||
module Web.View.WidgetPatterns.Edit where
|
||||
|
||||
import Web.Types
|
||||
import Generated.Types
|
||||
import IHP.Prelude
|
||||
import IHP.ViewPrelude
|
||||
|
||||
data EditView = EditView
|
||||
{ pattern :: !WidgetPattern
|
||||
, hubs :: ![Hub]
|
||||
, widgetTypes :: ![(Text, Text)]
|
||||
}
|
||||
|
||||
instance View EditView where
|
||||
html EditView { .. } = [hsx|
|
||||
<div class="mb-4">
|
||||
<a href={ShowWidgetPatternAction { widgetPatternId = pattern.id }}
|
||||
class="text-sm text-gray-500 hover:text-gray-700">
|
||||
← Pattern
|
||||
</a>
|
||||
</div>
|
||||
<h1 class="text-2xl font-semibold mb-6">Edit Pattern</h1>
|
||||
|
||||
<form method="POST" action={UpdateWidgetPatternAction { widgetPatternId = pattern.id }}>
|
||||
{csrfTokenFormField}
|
||||
<div class="space-y-4 max-w-lg">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Name</label>
|
||||
<input type="text" name="name" value={pattern.name}
|
||||
class="w-full border border-gray-300 rounded px-3 py-2 text-sm" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Widget Type</label>
|
||||
<p class="font-mono text-sm text-gray-600">{pattern.widgetType}</p>
|
||||
<p class="text-xs text-gray-400">Widget type cannot be changed after creation.</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Description</label>
|
||||
<textarea name="description" rows="3"
|
||||
class="w-full border border-gray-300 rounded px-3 py-2 text-sm"
|
||||
>{fromMaybe "" pattern.description}</textarea>
|
||||
</div>
|
||||
<button type="submit"
|
||||
class="text-sm bg-indigo-600 text-white px-4 py-2 rounded hover:bg-indigo-700">
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|]
|
||||
57
Web/View/WidgetPatterns/Index.hs
Normal file
57
Web/View/WidgetPatterns/Index.hs
Normal file
@@ -0,0 +1,57 @@
|
||||
module Web.View.WidgetPatterns.Index where
|
||||
|
||||
import Web.Types
|
||||
import Generated.Types
|
||||
import IHP.Prelude
|
||||
import IHP.ViewPrelude
|
||||
|
||||
-- Row: WidgetPattern fields + adopter_count + latest_version
|
||||
type PatternIndexRow = (WidgetPattern, Int, Maybe Int)
|
||||
|
||||
data IndexView = IndexView
|
||||
{ patterns :: ![PatternIndexRow]
|
||||
}
|
||||
|
||||
instance View IndexView where
|
||||
html IndexView { .. } = [hsx|
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
<h1 class="text-2xl font-semibold">Widget Pattern Library</h1>
|
||||
<p class="text-sm text-gray-500 mt-1">Published reusable widget patterns.</p>
|
||||
</div>
|
||||
<a href={NewWidgetPatternAction}
|
||||
class="text-sm bg-indigo-600 text-white px-3 py-1.5 rounded hover:bg-indigo-700">
|
||||
New Pattern
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3">
|
||||
{forEach patterns renderPatternRow}
|
||||
{if null patterns
|
||||
then [hsx|<p class="text-sm text-gray-400">No published patterns yet.</p>|]
|
||||
else mempty}
|
||||
</div>
|
||||
|]
|
||||
|
||||
renderPatternRow :: PatternIndexRow -> Html
|
||||
renderPatternRow (pattern, adopterCount, mVersion) = [hsx|
|
||||
<div class="bg-white rounded-lg border border-gray-200 p-4 hover:border-indigo-200">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-3">
|
||||
<a href={ShowWidgetPatternAction { widgetPatternId = pattern.id }}
|
||||
class="font-medium text-indigo-700 hover:underline">
|
||||
{pattern.name}
|
||||
</a>
|
||||
<span class="font-mono text-xs text-gray-400">{pattern.widgetType}</span>
|
||||
{if pattern.isCrossHub
|
||||
then [hsx|<span class="px-2 py-0.5 rounded text-xs bg-purple-100 text-purple-700">cross-hub</span>|]
|
||||
else mempty}
|
||||
</div>
|
||||
<div class="flex items-center gap-3 text-xs text-gray-500">
|
||||
<span>{tshow adopterCount} adopters</span>
|
||||
{maybe mempty (\v -> [hsx|<span class="font-mono">v{tshow v}</span>|]) mVersion}
|
||||
</div>
|
||||
</div>
|
||||
{maybe mempty (\d -> [hsx|<p class="text-xs text-gray-500 mt-1">{d}</p>|]) pattern.description}
|
||||
</div>
|
||||
|]
|
||||
64
Web/View/WidgetPatterns/New.hs
Normal file
64
Web/View/WidgetPatterns/New.hs
Normal file
@@ -0,0 +1,64 @@
|
||||
module Web.View.WidgetPatterns.New where
|
||||
|
||||
import Web.Types
|
||||
import Generated.Types
|
||||
import IHP.Prelude
|
||||
import IHP.ViewPrelude
|
||||
|
||||
data NewView = NewView
|
||||
{ pattern :: !WidgetPattern
|
||||
, hubs :: ![Hub]
|
||||
, widgetTypes :: ![(Text, Text)] -- (name, label)
|
||||
}
|
||||
|
||||
instance View NewView where
|
||||
html NewView { .. } = [hsx|
|
||||
<div class="mb-4">
|
||||
<a href={WidgetPatternsAction} class="text-sm text-gray-500 hover:text-gray-700">
|
||||
← Widget Patterns
|
||||
</a>
|
||||
</div>
|
||||
<h1 class="text-2xl font-semibold mb-6">New Widget Pattern</h1>
|
||||
|
||||
{renderForm pattern hubs widgetTypes}
|
||||
|]
|
||||
|
||||
renderForm :: WidgetPattern -> [Hub] -> [(Text, Text)] -> Html
|
||||
renderForm pattern hubs widgetTypes = [hsx|
|
||||
<form method="POST" action={CreateWidgetPatternAction}>
|
||||
{csrfTokenFormField}
|
||||
<div class="space-y-4 max-w-lg">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Name</label>
|
||||
<input type="text" name="name" value={pattern.name}
|
||||
class="w-full border border-gray-300 rounded px-3 py-2 text-sm" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Hub</label>
|
||||
<select name="hubId" class="w-full border border-gray-300 rounded px-3 py-2 text-sm">
|
||||
{forEach hubs (\h -> [hsx|
|
||||
<option value={tshow h.id}>{h.name}</option>
|
||||
|])}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Widget Type</label>
|
||||
<select name="widgetType" class="w-full border border-gray-300 rounded px-3 py-2 text-sm font-mono">
|
||||
{forEach widgetTypes (\(n, l) -> [hsx|
|
||||
<option value={n}>{l} ({n})</option>
|
||||
|])}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Description</label>
|
||||
<textarea name="description" rows="3"
|
||||
class="w-full border border-gray-300 rounded px-3 py-2 text-sm"
|
||||
>{fromMaybe "" pattern.description}</textarea>
|
||||
</div>
|
||||
<button type="submit"
|
||||
class="text-sm bg-indigo-600 text-white px-4 py-2 rounded hover:bg-indigo-700">
|
||||
Create Pattern
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|]
|
||||
146
Web/View/WidgetPatterns/Show.hs
Normal file
146
Web/View/WidgetPatterns/Show.hs
Normal file
@@ -0,0 +1,146 @@
|
||||
module Web.View.WidgetPatterns.Show where
|
||||
|
||||
import Web.Types
|
||||
import Generated.Types
|
||||
import IHP.Prelude
|
||||
import IHP.ViewPrelude
|
||||
import Data.Aeson (encode)
|
||||
import qualified Data.ByteString.Lazy.Char8 as BL
|
||||
|
||||
data ShowView = ShowView
|
||||
{ pattern :: !WidgetPattern
|
||||
, hub :: !Hub
|
||||
, versions :: ![WidgetPatternVersion]
|
||||
, adopterCount :: !Int
|
||||
, anonCount :: !Int
|
||||
, meanFriction :: !(Maybe Double)
|
||||
, outcomeCount :: !Int
|
||||
}
|
||||
|
||||
instance View ShowView where
|
||||
html ShowView { .. } = [hsx|
|
||||
<div class="mb-4">
|
||||
<a href={WidgetPatternsAction} class="text-sm text-gray-500 hover:text-gray-700">
|
||||
← Widget Patterns
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-3 mb-2">
|
||||
<h1 class="text-2xl font-semibold">{pattern.name}</h1>
|
||||
<span class="font-mono text-sm text-gray-400">{pattern.widgetType}</span>
|
||||
{if pattern.isCrossHub
|
||||
then [hsx|<span class="px-2 py-0.5 rounded text-xs bg-purple-100 text-purple-700">cross-hub</span>|]
|
||||
else mempty}
|
||||
{if pattern.isPublished
|
||||
then [hsx|<span class="px-2 py-0.5 rounded text-xs bg-green-100 text-green-800">published</span>|]
|
||||
else [hsx|<span class="px-2 py-0.5 rounded text-xs bg-amber-100 text-amber-800">draft</span>|]}
|
||||
</div>
|
||||
|
||||
<p class="text-sm text-gray-500 mb-1">Hub: {hub.name}</p>
|
||||
<p class="text-sm text-gray-500 mb-4">{tshow adopterCount} adopters</p>
|
||||
|
||||
{maybe mempty (\d -> [hsx|<p class="text-sm text-gray-600 mb-4">{d}</p>|]) pattern.description}
|
||||
|
||||
{aggregatePanel adopterCount anonCount meanFriction outcomeCount}
|
||||
|
||||
<div class="flex gap-2 mb-6">
|
||||
{if not pattern.isPublished
|
||||
then [hsx|
|
||||
<a href={EditWidgetPatternAction { widgetPatternId = pattern.id }}
|
||||
class="text-sm border border-gray-300 text-gray-700 px-3 py-1.5 rounded hover:bg-gray-50">
|
||||
Edit
|
||||
</a>
|
||||
<a href={PublishWidgetPatternAction { widgetPatternId = pattern.id }}
|
||||
class="text-sm bg-green-600 text-white px-3 py-1.5 rounded hover:bg-green-700">
|
||||
Publish
|
||||
</a>
|
||||
|]
|
||||
else [hsx|
|
||||
<a href={AdoptPatternAction { widgetPatternId = pattern.id }}
|
||||
class="text-sm bg-indigo-600 text-white px-3 py-1.5 rounded hover:bg-indigo-700">
|
||||
Adopt Pattern
|
||||
</a>
|
||||
|]}
|
||||
</div>
|
||||
|
||||
<h2 class="text-lg font-semibold mb-3">Version History</h2>
|
||||
{if null versions
|
||||
then [hsx|<p class="text-sm text-gray-400 mb-6">No versions published yet.</p>|]
|
||||
else [hsx|
|
||||
<div class="space-y-3 mb-6">
|
||||
{forEach versions renderVersionRow}
|
||||
</div>
|
||||
|]}
|
||||
|
||||
{if pattern.isPublished
|
||||
then [hsx|
|
||||
<div class="border-t border-gray-200 pt-4">
|
||||
<h2 class="text-base font-semibold mb-3">Publish New Version</h2>
|
||||
<form method="POST" action={PublishNewVersionAction { widgetPatternId = pattern.id }}>
|
||||
{csrfTokenFormField}
|
||||
<div class="mb-3">
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">
|
||||
Definition (JSON)
|
||||
</label>
|
||||
<textarea name="definition" rows="4"
|
||||
class="w-full border border-gray-300 rounded px-3 py-2 text-sm font-mono"
|
||||
placeholder='{"key": "value"}'></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Changelog</label>
|
||||
<input type="text" name="changelog"
|
||||
class="w-full border border-gray-300 rounded px-3 py-2 text-sm"
|
||||
placeholder="What changed in this version?" />
|
||||
</div>
|
||||
<button type="submit"
|
||||
class="text-sm bg-indigo-600 text-white px-3 py-1.5 rounded hover:bg-indigo-700">
|
||||
Publish Version
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|]
|
||||
else mempty}
|
||||
|]
|
||||
|
||||
-- | Aggregate friction/outcome panel (T07)
|
||||
aggregatePanel :: Int -> Int -> Maybe Double -> Int -> Html
|
||||
aggregatePanel adopterCount anonCount meanFriction outcomeCount = [hsx|
|
||||
<div class="bg-gray-50 rounded border border-gray-200 p-4 mb-6">
|
||||
<h3 class="text-sm font-semibold text-gray-700 mb-3">Adoption Metrics</h3>
|
||||
<div class="grid grid-cols-3 gap-4">
|
||||
<div>
|
||||
<p class="text-xs text-gray-500">Total Adopters</p>
|
||||
<p class="text-lg font-semibold">{tshow adopterCount}</p>
|
||||
{if anonCount > 0
|
||||
then [hsx|<p class="text-xs text-gray-400">{tshow anonCount} opted out of aggregate feedback</p>|]
|
||||
else mempty}
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-xs text-gray-500">Mean Friction Score</p>
|
||||
<p class="text-lg font-semibold">
|
||||
{maybe "—" (\f -> tshow (round f :: Int)) meanFriction}
|
||||
</p>
|
||||
<p class="text-xs text-gray-400">non-anonymous adopters</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-xs text-gray-500">Outcome Signals</p>
|
||||
<p class="text-lg font-semibold">{tshow outcomeCount}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|]
|
||||
|
||||
renderVersionRow :: WidgetPatternVersion -> Html
|
||||
renderVersionRow v = [hsx|
|
||||
<div class="bg-white rounded border border-gray-200 p-3">
|
||||
<div class="flex items-center justify-between mb-1">
|
||||
<span class="font-mono text-sm font-medium">v{tshow v.versionNumber}</span>
|
||||
<span class="text-xs text-gray-400">{tshow v.publishedAt}</span>
|
||||
</div>
|
||||
{maybe mempty (\c -> [hsx|<p class="text-xs text-gray-600">{c}</p>|]) v.changelog}
|
||||
<details class="mt-2">
|
||||
<summary class="text-xs text-gray-400 cursor-pointer">Definition</summary>
|
||||
<pre class="text-xs text-gray-600 mt-1 overflow-x-auto">{cs (BL.unpack (encode v.definition)) :: Text}</pre>
|
||||
</details>
|
||||
</div>
|
||||
|]
|
||||
Reference in New Issue
Block a user