Files
inter-hub/Web/View/FederatedGovernance/Dashboard.hs
Bernd Worsch 9265ca2d9c feat(P8): IHF Phase 8 complete — Federated Hub Maturity
Implements the final phase of the IHF v0.1 specification:

- WidgetOwnership: delegated ownership registry (local/delegated/global),
  append-only audit artefacts, ownership badge on widget show page
- HubRoutingRule + RoutingEngine: priority-ordered inter-hub routing engine;
  null-inclusive category/widget-type matching; RouteNowAction for manual
  re-evaluation; RoutedCandidates view per hub
- FederatedPolicyOverlay: draft → active → retired lifecycle; activated
  overlays are immutable (same pattern as Phase 6 contracts); policy
  compliance dashboard with decision coverage metrics
- StewardshipRole: named governance roles per hub; point-in-time revocation
  pattern; hub and ops-board integration
- ArchiveRecord + is_archived: soft-delete on widgets; lineage inspector
  traces full traceability chain (Widget → Events → Annotations → Candidates
  → Requirements → Decisions → Deployments → Signals + ArchiveRecord)
- FederatedGovernanceDashboard: 5-panel autoRefresh org-wide governance view
  (ownership coverage, routing activity, policy compliance, stewardship
  coverage, archive activity)

Schema: widget_ownerships, hub_routing_rules, federated_policy_overlays,
stewardship_roles, archive_records; ALTER widgets ADD is_archived;
ALTER requirement_candidates ADD routed_to_hub_id

Migration: 1743638400-ihf-phase8-federated-hub-maturity.sql
Tests: Phase 8 integration tests appended to Test/Integration.hs
Docs: docs/phase8-summary.md; SCOPE.md updated to Phase 8 complete

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-29 22:53:01 +00:00

230 lines
12 KiB
Haskell

module Web.View.FederatedGovernance.Dashboard where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
import qualified Data.List as List
data FederatedGovernanceDashboardView = FederatedGovernanceDashboardView
{ hubs :: ![Hub]
, widgets :: ![Widget]
, ownerships :: ![WidgetOwnership]
, rules :: ![HubRoutingRule]
, routedCandidates :: ![RequirementCandidate]
, overlays :: ![FederatedPolicyOverlay]
, allDecisions :: ![DecisionRecord]
, allPolicies :: ![PolicyReference]
, stewards :: ![StewardshipRole]
, recentArchives :: ![ArchiveRecord]
}
instance View FederatedGovernanceDashboardView where
html FederatedGovernanceDashboardView { .. } = [hsx|
<div class="flex items-center justify-between mb-6">
<h1 class="text-2xl font-semibold">Federated Governance</h1>
<a href={PolicyComplianceDashboardAction}
class="text-sm text-indigo-600 hover:underline">Policy Compliance </a>
</div>
<div class="grid grid-cols-1 gap-6 lg:grid-cols-2">
{panel1Ownership}
{panel2Routing}
{panel3PolicyCompliance}
{panel4Stewardship}
{panel5Archive}
</div>
|]
where
-- ── Panel 1: Ownership coverage ──────────────────────────────────
totalWidgets = length widgets
ownedWidgetIds = List.nub (map (.widgetId) ownerships)
ownedCount = length ownedWidgetIds
localCount = length (filter (\o -> o.ownershipType == "local") ownerships)
delegatedCount = length (filter (\o -> o.ownershipType == "delegated") ownerships)
globalCount = length (filter (\o -> o.ownershipType == "global") ownerships)
ownershipPct :: Int
ownershipPct = if totalWidgets == 0 then 0 else (ownedCount * 100) `div` totalWidgets
panel1Ownership = [hsx|
<div class="bg-white rounded-lg border border-gray-200 p-5">
<div class="flex items-center justify-between mb-4">
<h2 class="font-medium text-gray-800">Ownership Coverage</h2>
<a href={WidgetOwnershipsAction}
class="text-xs text-blue-600 hover:underline">View all </a>
</div>
<div class="flex gap-6 mb-4">
<div class="text-center">
<div class="text-3xl font-bold text-gray-900">{show ownedCount}</div>
<div class="text-xs text-gray-500">of {show totalWidgets} widgets owned</div>
</div>
<div class="text-center">
<div class="text-3xl font-bold text-indigo-600">{show ownershipPct}%</div>
<div class="text-xs text-gray-500">coverage</div>
</div>
</div>
<div class="flex gap-3 text-xs">
<span class="bg-gray-100 text-gray-700 px-2 py-1 rounded">
local: {show localCount}
</span>
<span class="bg-blue-100 text-blue-700 px-2 py-1 rounded">
delegated: {show delegatedCount}
</span>
<span class="bg-purple-100 text-purple-700 px-2 py-1 rounded">
global: {show globalCount}
</span>
</div>
</div>
|]
-- ── Panel 2: Routing activity ─────────────────────────────────────
activeRulesCount = length rules
routedCount = length routedCandidates
hubName hid = maybe (show hid) (.name) (find (\h -> h.id == hid) hubs)
panel2Routing = [hsx|
<div class="bg-white rounded-lg border border-gray-200 p-5">
<div class="flex items-center justify-between mb-4">
<h2 class="font-medium text-gray-800">Routing Activity</h2>
<a href={HubRoutingRulesAction}
class="text-xs text-blue-600 hover:underline">Rules </a>
</div>
<div class="flex gap-6 mb-4">
<div class="text-center">
<div class="text-3xl font-bold text-gray-900">{show activeRulesCount}</div>
<div class="text-xs text-gray-500">active rules</div>
</div>
<div class="text-center">
<div class="text-3xl font-bold text-green-600">{show routedCount}</div>
<div class="text-xs text-gray-500">routed (30 days)</div>
</div>
</div>
{if null rules
then [hsx|<p class="text-xs text-gray-400">No active routing rules.</p>|]
else [hsx|
<div class="space-y-1">
{forEach (take 5 rules) renderRuleRow}
</div>
|]}
</div>
|]
renderRuleRow :: HubRoutingRule -> Html
renderRuleRow r = [hsx|
<div class="flex items-center gap-2 text-xs text-gray-600">
<span class="font-medium">{hubName r.sourceHubId}</span>
<span class="text-gray-400"></span>
<span class="font-medium">{hubName r.targetHubId}</span>
{maybe mempty (\c -> [hsx|<span class="text-gray-400">({c})</span>|]) r.matchCategory}
</div>
|]
-- ── Panel 3: Policy compliance ────────────────────────────────────
activeOverlaysCount = length overlays
decisionIdsWithPolicy = List.nub $ map (.requirementId) allPolicies
coveredDecisions = length $ filter (\d -> Just d.id `elem` decisionIdsWithPolicy) allDecisions
totalDecisions = length allDecisions
policyPct :: Int
policyPct = if totalDecisions == 0 then 0
else (coveredDecisions * 100) `div` totalDecisions
panel3PolicyCompliance = [hsx|
<div class="bg-white rounded-lg border border-gray-200 p-5">
<div class="flex items-center justify-between mb-4">
<h2 class="font-medium text-gray-800">Policy Compliance</h2>
<a href={PolicyComplianceDashboardAction}
class="text-xs text-blue-600 hover:underline">Dashboard </a>
</div>
<div class="flex gap-6 mb-4">
<div class="text-center">
<div class="text-3xl font-bold text-gray-900">{show activeOverlaysCount}</div>
<div class="text-xs text-gray-500">active overlays</div>
</div>
<div class="text-center">
<div class="text-3xl font-bold text-indigo-600">{show policyPct}%</div>
<div class="text-xs text-gray-500">decision coverage</div>
</div>
</div>
{if null overlays
then [hsx|<p class="text-xs text-gray-400">No active policy overlays.</p>|]
else [hsx|
<div class="space-y-1">
{forEach overlays \o -> [hsx|
<div class="text-xs text-gray-600 truncate">{o.title}</div>
|]}
</div>
|]}
</div>
|]
-- ── Panel 4: Stewardship coverage ─────────────────────────────────
hubsWithStewards = List.nub (map (.hubId) stewards)
stewardedCount = length hubsWithStewards
totalHubs = length hubs
hubsWithNoSteward = filter (\h -> h.id `notElem` hubsWithStewards) hubs
panel4Stewardship = [hsx|
<div class="bg-white rounded-lg border border-gray-200 p-5">
<div class="flex items-center justify-between mb-4">
<h2 class="font-medium text-gray-800">Stewardship Coverage</h2>
<a href={StewardshipRolesAction}
class="text-xs text-blue-600 hover:underline">Roles </a>
</div>
<div class="flex gap-6 mb-4">
<div class="text-center">
<div class="text-3xl font-bold text-gray-900">{show stewardedCount}</div>
<div class="text-xs text-gray-500">of {show totalHubs} hubs stewarded</div>
</div>
<div class="text-center">
<div class="text-3xl font-bold text-amber-600">{show (length hubsWithNoSteward)}</div>
<div class="text-xs text-gray-500">hubs unassigned</div>
</div>
</div>
{if null hubsWithNoSteward
then [hsx|<p class="text-xs text-green-600">All hubs have active stewards.</p>|]
else [hsx|
<div>
<p class="text-xs text-gray-500 mb-1">Hubs without stewards:</p>
<div class="flex flex-wrap gap-1">
{forEach hubsWithNoSteward \h -> [hsx|
<span class="text-xs bg-amber-100 text-amber-700 px-2 py-0.5 rounded">
{h.name}
</span>
|]}
</div>
</div>
|]}
</div>
|]
-- ── Panel 5: Archive activity ─────────────────────────────────────
archiveByType = List.sortBy (\a b -> compare (fst a) (fst b))
$ map (\grp -> (fst (head grp), length grp))
$ List.groupBy (\a b -> a.subjectType == b.subjectType)
$ List.sortBy (\a b -> compare a.subjectType b.subjectType) recentArchives
panel5Archive = [hsx|
<div class="bg-white rounded-lg border border-gray-200 p-5 lg:col-span-2">
<div class="flex items-center justify-between mb-4">
<h2 class="font-medium text-gray-800">Archive Activity (90 days)</h2>
<a href={ArchiveRecordsAction}
class="text-xs text-blue-600 hover:underline">All records </a>
</div>
{if null recentArchives
then [hsx|<p class="text-sm text-gray-400">No artifacts archived in the last 90 days.</p>|]
else [hsx|
<div class="flex items-center gap-3 mb-2">
<div class="text-3xl font-bold text-gray-900">{show (length recentArchives)}</div>
<div class="text-xs text-gray-500">total archived artifacts</div>
</div>
<div class="flex flex-wrap gap-2">
{forEach archiveByType \(typ, cnt) -> [hsx|
<span class="text-sm bg-amber-50 border border-amber-200 text-amber-800 px-3 py-1 rounded">
{typ}: {show cnt}
</span>
|]}
</div>
|]}
</div>
|]