generated from coulomb/repo-seed
feat(P3): IHF Phase 3 complete — Governance and Decision Linkage
Implements the full governance layer: - Schema: requirements, decision_records, policy_references, implementation_change_references; requirement_candidates gets requirement_id back-reference - RequirementsController (index/show; promotion-only create) - DecisionRecordsController (CRUD + policy/impl ref management) - GovernanceDashboardAction on HubsController (AutoRefresh) - PromoteToRequirementAction + LinkToDecisionAction on candidates - Outcome immutability enforced at controller level (fill excludes outcome) - Full six-outcome vocabulary with Tailwind color roles - Integration tests for all Phase 3 paths - FrontController: registers Phase 2 missing controllers + all Phase 3 - SCOPE.md + docs/phase3-summary.md updated Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
206
Web/View/Hubs/GovernanceDashboard.hs
Normal file
206
Web/View/Hubs/GovernanceDashboard.hs
Normal file
@@ -0,0 +1,206 @@
|
||||
module Web.View.Hubs.GovernanceDashboard where
|
||||
|
||||
import Web.Types
|
||||
import Generated.Types
|
||||
import IHP.Prelude
|
||||
import IHP.ViewPrelude
|
||||
|
||||
data GovernanceDashboardView = GovernanceDashboardView
|
||||
{ hub :: !Hub
|
||||
, widgets :: ![Widget]
|
||||
, allCandidates :: ![RequirementCandidate]
|
||||
, allRequirements :: ![Requirement]
|
||||
, recentDecisions :: ![DecisionRecord]
|
||||
, allDecisions :: ![DecisionRecord]
|
||||
, allAnnotations :: ![Annotation]
|
||||
}
|
||||
|
||||
instance View GovernanceDashboardView where
|
||||
html GovernanceDashboardView { .. } = [hsx|
|
||||
<div class="mb-6 flex items-center justify-between">
|
||||
<div>
|
||||
<div class="flex items-center gap-2 text-sm text-gray-500 mb-1">
|
||||
<a href={HubsAction} class="hover:text-gray-700">Hubs</a>
|
||||
<span>/</span>
|
||||
<a href={ShowHubAction { hubId = hub.id }} class="hover:text-gray-700">{hub.name}</a>
|
||||
<span>/</span>
|
||||
<span>Governance</span>
|
||||
</div>
|
||||
<h1 class="text-2xl font-semibold">Governance Dashboard — {hub.name}</h1>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<a href={TriageDashboardAction { hubId = hub.id }}
|
||||
class="text-sm border border-gray-300 px-3 py-1.5 rounded hover:bg-gray-50">
|
||||
Triage Dashboard
|
||||
</a>
|
||||
<a href={ShowHubAction { hubId = hub.id }}
|
||||
class="text-sm border border-gray-300 px-3 py-1.5 rounded hover:bg-gray-50">
|
||||
Hub Overview
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- KPI row: decision outcomes -->
|
||||
<div class="grid grid-cols-3 gap-4 mb-6 sm:grid-cols-6">
|
||||
{forEach outcomeList (\o -> renderKpiCard o (countOutcome allDecisions o))}
|
||||
</div>
|
||||
|
||||
<!-- Open requirements awaiting decision -->
|
||||
<div class="bg-white rounded-lg border border-gray-200 px-6 py-5 mb-6">
|
||||
<h2 class="text-sm font-semibold text-gray-700 mb-3">
|
||||
Open Requirements Awaiting Decision
|
||||
<span class="ml-2 text-xs font-normal text-gray-400">
|
||||
({show (length awaitingDecision)} pending)
|
||||
</span>
|
||||
</h2>
|
||||
{if null awaitingDecision
|
||||
then [hsx|<p class="text-sm text-gray-400">All requirements have linked decisions.</p>|]
|
||||
else forEach awaitingDecision renderAwaitingReq}
|
||||
</div>
|
||||
|
||||
<!-- Recent decisions -->
|
||||
<div class="bg-white rounded-lg border border-gray-200 px-6 py-5 mb-6">
|
||||
<h2 class="text-sm font-semibold text-gray-700 mb-3">Recent Decisions</h2>
|
||||
{if null recentDecisions
|
||||
then [hsx|<p class="text-sm text-gray-400">No decisions recorded yet.</p>|]
|
||||
else [hsx|
|
||||
<table class="w-full text-sm">
|
||||
<thead class="border-b border-gray-100">
|
||||
<tr>
|
||||
<th class="text-left py-2 text-xs font-medium text-gray-500">Title</th>
|
||||
<th class="text-left py-2 text-xs font-medium text-gray-500">Outcome</th>
|
||||
<th class="text-left py-2 text-xs font-medium text-gray-500">Source Widget</th>
|
||||
<th class="text-left py-2 text-xs font-medium text-gray-500">Decided At</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-50">
|
||||
{forEach recentDecisions (renderDecisionRow allRequirements allCandidates widgets)}
|
||||
</tbody>
|
||||
</table>
|
||||
|]}
|
||||
</div>
|
||||
|
||||
<!-- Traceability coverage per widget -->
|
||||
<div class="bg-white rounded-lg border border-gray-200 px-6 py-5">
|
||||
<h2 class="text-sm font-semibold text-gray-700 mb-3">Traceability Coverage</h2>
|
||||
<table class="w-full text-sm">
|
||||
<thead class="border-b border-gray-100">
|
||||
<tr>
|
||||
<th class="text-left py-2 text-xs font-medium text-gray-500">Widget</th>
|
||||
<th class="text-center py-2 text-xs font-medium text-gray-500">Annotation</th>
|
||||
<th class="text-center py-2 text-xs font-medium text-gray-500">Candidate</th>
|
||||
<th class="text-center py-2 text-xs font-medium text-gray-500">Decision</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-50">
|
||||
{forEach widgets (renderCoverageRow allAnnotations allCandidates allRequirements allDecisions)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|]
|
||||
where
|
||||
awaitingDecision = filter (isAwaitingDecision allDecisions) allRequirements
|
||||
|
||||
outcomeList :: [Text]
|
||||
outcomeList = ["accepted", "rejected", "deferred", "split", "merged", "reframed"]
|
||||
|
||||
countOutcome :: [DecisionRecord] -> Text -> Int
|
||||
countOutcome decisions o = length (filter (\d -> d.outcome == o) decisions)
|
||||
|
||||
renderKpiCard :: Text -> Int -> Html
|
||||
renderKpiCard outcome count = [hsx|
|
||||
<div class={kpiCardClass outcome <> " rounded-lg px-4 py-3 text-center"}>
|
||||
<div class="text-2xl font-bold">{show count}</div>
|
||||
<div class="text-xs mt-0.5 opacity-75">{outcome}</div>
|
||||
</div>
|
||||
|]
|
||||
|
||||
kpiCardClass :: Text -> Text
|
||||
kpiCardClass "accepted" = "bg-green-50 text-green-800"
|
||||
kpiCardClass "rejected" = "bg-red-50 text-red-800"
|
||||
kpiCardClass "deferred" = "bg-gray-50 text-gray-700"
|
||||
kpiCardClass "split" = "bg-purple-50 text-purple-800"
|
||||
kpiCardClass "merged" = "bg-indigo-50 text-indigo-800"
|
||||
kpiCardClass "reframed" = "bg-orange-50 text-orange-800"
|
||||
kpiCardClass _ = "bg-gray-50 text-gray-700"
|
||||
|
||||
isAwaitingDecision :: [DecisionRecord] -> Requirement -> Bool
|
||||
isAwaitingDecision decisions req =
|
||||
not (any (\d -> d.requirementId == Just req.id) decisions)
|
||||
|
||||
renderAwaitingReq :: Requirement -> Html
|
||||
renderAwaitingReq req = [hsx|
|
||||
<div class="flex items-center justify-between py-2 border-b border-gray-50 last:border-0">
|
||||
<a href={ShowRequirementAction { requirementId = req.id }}
|
||||
class="text-sm text-indigo-600 hover:text-indigo-800">{req.title}</a>
|
||||
<span class="text-xs text-gray-400">{show req.createdAt}</span>
|
||||
</div>
|
||||
|]
|
||||
|
||||
renderDecisionRow :: [Requirement] -> [RequirementCandidate] -> [Widget] -> DecisionRecord -> Html
|
||||
renderDecisionRow reqs candidates widgets dr = [hsx|
|
||||
<tr>
|
||||
<td class="py-2 pr-4">
|
||||
<a href={ShowDecisionRecordAction { decisionRecordId = dr.id }}
|
||||
class="text-indigo-600 hover:text-indigo-800">{dr.title}</a>
|
||||
</td>
|
||||
<td class="py-2 pr-4">
|
||||
<span class={outcomeClass dr.outcome <> " text-xs px-2 py-0.5 rounded font-medium"}>
|
||||
{dr.outcome}
|
||||
</span>
|
||||
</td>
|
||||
<td class="py-2 pr-4 text-gray-600 text-xs">
|
||||
{originWidget dr reqs candidates widgets}
|
||||
</td>
|
||||
<td class="py-2 text-gray-400 text-xs">{show dr.decidedAt}</td>
|
||||
</tr>
|
||||
|]
|
||||
|
||||
-- Trace decision → requirement → candidate → widget name
|
||||
originWidget :: DecisionRecord -> [Requirement] -> [RequirementCandidate] -> [Widget] -> Text
|
||||
originWidget dr reqs candidates widgets =
|
||||
case dr.requirementId >>= \rid -> find (\r -> r.id == rid) reqs of
|
||||
Just req ->
|
||||
case find (\c -> c.id == req.sourceCandidateId) candidates of
|
||||
Just c ->
|
||||
case find (\w -> w.id == c.sourceWidgetId) widgets of
|
||||
Just w -> w.name
|
||||
Nothing -> "—"
|
||||
Nothing -> "—"
|
||||
Nothing ->
|
||||
case dr.candidateId >>= \cid -> find (\c -> c.id == cid) candidates of
|
||||
Just c ->
|
||||
case find (\w -> w.id == c.sourceWidgetId) widgets of
|
||||
Just w -> w.name
|
||||
Nothing -> "—"
|
||||
Nothing -> "—"
|
||||
|
||||
renderCoverageRow :: [Annotation] -> [RequirementCandidate] -> [Requirement] -> [DecisionRecord] -> Widget -> Html
|
||||
renderCoverageRow annotations candidates requirements decisions w = [hsx|
|
||||
<tr>
|
||||
<td class="py-2 pr-4 text-sm text-gray-700">{w.name}</td>
|
||||
<td class="py-2 text-center">{coverageMark hasAnnotation}</td>
|
||||
<td class="py-2 text-center">{coverageMark hasCandidate}</td>
|
||||
<td class="py-2 text-center">{coverageMark hasDecision}</td>
|
||||
</tr>
|
||||
|]
|
||||
where
|
||||
hasAnnotation = any (\a -> a.widgetId == w.id) annotations
|
||||
widgetCandidates = filter (\c -> c.sourceWidgetId == w.id) candidates
|
||||
hasCandidate = not (null widgetCandidates)
|
||||
candidateIds = map (.id) widgetCandidates
|
||||
widgetReqIds = map (.id) (filter (\r -> r.sourceCandidateId `elem` candidateIds) requirements)
|
||||
hasDecision = any (\d -> d.requirementId `elem` map Just widgetReqIds) decisions
|
||||
|
||||
coverageMark :: Bool -> Html
|
||||
coverageMark True = [hsx|<span class="text-green-600 font-bold">✓</span>|]
|
||||
coverageMark False = [hsx|<span class="text-gray-300">✗</span>|]
|
||||
|
||||
outcomeClass :: Text -> Text
|
||||
outcomeClass "accepted" = "bg-green-100 text-green-800"
|
||||
outcomeClass "rejected" = "bg-red-100 text-red-800"
|
||||
outcomeClass "deferred" = "bg-gray-100 text-gray-600"
|
||||
outcomeClass "split" = "bg-purple-100 text-purple-800"
|
||||
outcomeClass "merged" = "bg-indigo-100 text-indigo-800"
|
||||
outcomeClass "reframed" = "bg-orange-100 text-orange-800"
|
||||
outcomeClass _ = "bg-gray-100 text-gray-600"
|
||||
@@ -33,6 +33,10 @@ instance View ShowView where
|
||||
class="text-sm border border-indigo-300 text-indigo-700 px-3 py-1.5 rounded hover:bg-indigo-50">
|
||||
Triage Dashboard
|
||||
</a>
|
||||
<a href={GovernanceDashboardAction { hubId = hub.id }}
|
||||
class="text-sm border border-purple-300 text-purple-700 px-3 py-1.5 rounded hover:bg-purple-50">
|
||||
Governance Dashboard
|
||||
</a>
|
||||
<a href={EditHubAction { hubId = hub.id }}
|
||||
class="text-sm border border-gray-300 px-3 py-1.5 rounded hover:bg-gray-50">
|
||||
Edit
|
||||
|
||||
Reference in New Issue
Block a user