refactor(ui): prioritize permitted operational views and touch topology

This commit is contained in:
Joseph Doherty
2026-11-13 19:24:12 -05:00
parent 0c41b613ac
commit 9dbfe7bcaf
70 changed files with 13050 additions and 96 deletions
@@ -1,5 +1,6 @@
@page "/"
@attribute [Authorize]
@using ZB.MOM.WW.ScadaBridge.Security
@using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories
@using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Security
@inject ISiteRepository SiteRepository
@@ -19,55 +20,38 @@
</AuthorizeView>
</div>
@* KPI row *@
<div class="row g-3 mb-4">
<div class="col-lg-3 col-md-6 col-12">
<div class="card h-100" role="region" aria-label="Sites configured">
<div class="card-body text-center">
<div class="fs-2 fw-bold" role="status" aria-live="polite">@CountText(_sites)</div>
@if (_sites.Failed)
{
<button type="button" class="btn btn-sm btn-outline-secondary" disabled="@_sites.Loading" @onclick="LoadSites">Retry Sites configured</button>
}
<div class="text-muted small">Sites configured</div>
</div>
</div>
<div class="agg-grid dashboard-facts" aria-label="Configuration facts">
<div class="agg-card" role="region" aria-label="Sites configured">
<div class="agg-label">Sites configured</div>
<div class="agg-value" role="status" aria-live="polite">@CountText(_sites)</div>
@if (_sites.Failed)
{
<button type="button" class="btn btn-sm btn-outline-secondary mt-2" disabled="@_sites.Loading" @onclick="LoadSites">Retry Sites configured</button>
}
</div>
<div class="col-lg-3 col-md-6 col-12">
<div class="card h-100" role="region" aria-label="Data connections configured">
<div class="card-body text-center">
<div class="fs-2 fw-bold" role="status" aria-live="polite">@CountText(_connections)</div>
@if (_connections.Failed)
{
<button type="button" class="btn btn-sm btn-outline-secondary" disabled="@_connections.Loading" @onclick="LoadConnections">Retry Data connections configured</button>
}
<div class="text-muted small">Data connections configured</div>
</div>
</div>
<div class="agg-card" role="region" aria-label="Data connections configured">
<div class="agg-label">Data connections configured</div>
<div class="agg-value" role="status" aria-live="polite">@CountText(_connections)</div>
@if (_connections.Failed)
{
<button type="button" class="btn btn-sm btn-outline-secondary mt-2" disabled="@_connections.Loading" @onclick="LoadConnections">Retry Data connections configured</button>
}
</div>
<div class="col-lg-3 col-md-6 col-12">
<div class="card h-100" role="region" aria-label="Templates">
<div class="card-body text-center">
<div class="fs-2 fw-bold" role="status" aria-live="polite">@CountText(_templates)</div>
@if (_templates.Failed)
{
<button type="button" class="btn btn-sm btn-outline-secondary" disabled="@_templates.Loading" @onclick="LoadTemplates">Retry Templates</button>
}
<div class="text-muted small">Templates</div>
</div>
</div>
<div class="agg-card" role="region" aria-label="Templates">
<div class="agg-label">Templates</div>
<div class="agg-value" role="status" aria-live="polite">@CountText(_templates)</div>
@if (_templates.Failed)
{
<button type="button" class="btn btn-sm btn-outline-secondary mt-2" disabled="@_templates.Loading" @onclick="LoadTemplates">Retry Templates</button>
}
</div>
<div class="col-lg-3 col-md-6 col-12">
<div class="card h-100" role="region" aria-label="API keys">
<div class="card-body text-center">
<div class="fs-2 fw-bold" role="status" aria-live="polite">@CountText(_apiKeys)</div>
@if (_apiKeys.Failed)
{
<button type="button" class="btn btn-sm btn-outline-secondary" disabled="@_apiKeys.Loading" @onclick="LoadApiKeys">Retry API keys</button>
}
<div class="text-muted small">API keys</div>
</div>
</div>
<div class="agg-card" role="region" aria-label="API keys">
<div class="agg-label">API keys</div>
<div class="agg-value" role="status" aria-live="polite">@CountText(_apiKeys)</div>
@if (_apiKeys.Failed)
{
<button type="button" class="btn btn-sm btn-outline-secondary mt-2" disabled="@_apiKeys.Loading" @onclick="LoadApiKeys">Retry API keys</button>
}
</div>
</div>
@@ -85,6 +69,7 @@
</div>
</a>
</div>
<AuthorizeView Policy="@AuthorizationPolicies.OperationalAudit" Context="shortcutContext">
<div class="col-lg-4 col-md-6 col-12">
<a class="card h-100 text-decoration-none text-reset" href="/audit/configuration">
<div class="card-body">
@@ -96,6 +81,8 @@
</div>
</a>
</div>
</AuthorizeView>
<AuthorizeView Policy="@AuthorizationPolicies.RequireDesign" Context="shortcutContext">
<div class="col-lg-4 col-md-6 col-12">
<a class="card h-100 text-decoration-none text-reset" href="/design/templates">
<div class="card-body">
@@ -107,6 +94,7 @@
</div>
</a>
</div>
</AuthorizeView>
</div>
</div>
@@ -29,7 +29,7 @@
@inject IServiceScopeFactory ScopeFactory
@implements IDisposable
<div class="container-fluid mt-3">
<div class="container-fluid mt-3 topology-page">
<ToastNotification @ref="_toast" />
<CreateAreaDialog @bind-IsVisible="_showCreateAreaDialog"
@@ -111,7 +111,7 @@
@_allAreas.Count loaded area(s) · @_allInstances.Count loaded instance(s) across @_sites.Count site(s). Expand a branch and load its instances (50 per page).
</div>
<div style="max-height: calc(100vh - 240px); overflow-y: auto; padding: 4px;">
<div class="topology-tree" role="region" aria-label="Loaded topology">
<TreeView @ref="_tree" TItem="TopoNode" Items="_treeRoots"
ChildrenSelector="n => n.Children"
HasChildrenSelector="n => n.Children.Count > 0"
@@ -30,6 +30,16 @@
</div>
</div>
@if (_siteStates.Count > 0)
{
<section aria-label="Site observations" class="agg-grid health-facts">
<div class="agg-card"><div class="agg-label">Sites online</div><div class="agg-value">@_siteStates.Values.Count(s => s.IsOnline)</div></div>
<div class="agg-card @(_siteStates.Values.Any(s => !s.IsOnline) ? "alert" : "")"><div class="agg-label">Sites offline</div><div class="agg-value">@_siteStates.Values.Count(s => !s.IsOnline)</div></div>
<div class="agg-card @(_siteStates.Values.Any(SiteHasReportIntervalErrors) ? "caution" : "")"><div class="agg-label">Sites with errors in last report interval</div><div class="agg-value">@_siteStates.Values.Count(SiteHasReportIntervalErrors)</div></div>
<div class="agg-card"><div class="agg-label">Sites with unknown metrics</div><div class="agg-value">@_siteStates.Values.Count(s => s.LatestReport is null)</div></div>
</section>
}
@* Headline KPI groups. Each is a self-contained panel, so each gets its own card
boundary — the same treatment the Site Health Trends group below already uses,
including tiles-that-are-cards nested in a card body (Trends does exactly that
@@ -112,8 +122,8 @@
reuses the site keys already loaded into _siteStates; the window toggle
drives the time range. Both re-query independently. *@
<div class="card mb-3" data-test="site-health-trends">
<div class="card-header d-flex justify-content-between align-items-center py-2">
<div class="d-flex align-items-center">
<div class="card-header d-flex flex-wrap gap-2 justify-content-between align-items-center py-2">
<div class="d-flex flex-wrap gap-2 align-items-center">
<h6 class="text-muted mb-0 me-3">Site Health Trends</h6>
@if (_trendSiteKeys.Count > 0)
{
@@ -198,50 +208,13 @@
}
else
{
@* Overview cards — the fourth headline tile row, so it takes the same card
boundary as the three above it. It was also the only tile row on the page
with no heading at all; it now carries one for the same reason. *@
<div class="card mb-3">
<div class="card-body pb-0">
<div class="d-flex justify-content-between align-items-center mb-2">
<h6 class="text-muted mb-0">Sites</h6>
</div>
<div class="row g-3 mb-3">
<div class="col-lg-4 col-md-6 col-12">
<div class="card border-success h-100">
<div class="card-body text-center">
<h3 class="mb-0 text-success">@_siteStates.Values.Count(s => s.IsOnline)</h3>
<small class="text-muted">Sites Online</small>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 col-12">
<div class="card border-danger h-100">
<div class="card-body text-center">
<h3 class="mb-0 text-danger">@_siteStates.Values.Count(s => !s.IsOnline)</h3>
<small class="text-muted">Sites Offline</small>
</div>
</div>
</div>
<div class="col-lg-4 col-md-6 col-12">
<div class="card border-warning h-100">
<div class="card-body text-center">
<h3 class="mb-0 text-warning">@_siteStates.Values.Count(SiteHasActiveErrors)</h3>
<small class="text-muted">Sites with active errors</small>
</div>
</div>
</div>
</div>
</div>
</div>
@* Per-site detail cards — central cluster pinned to the top, then sites alphabetically *@
@foreach (var (siteId, state) in _siteStates.OrderBy(s => s.Key == CentralHealthReportLoop.CentralSiteId ? 0 : 1).ThenBy(s => s.Key))
@* Actionable observations first; display name and site id provide stable tie-breakers. *@
@foreach (var (siteId, state) in _siteStates.OrderBy(s => SiteAttentionOrder(s.Value)).ThenBy(s => GetSiteName(s.Key), StringComparer.OrdinalIgnoreCase).ThenBy(s => s.Key, StringComparer.Ordinal))
{
var isCentral = siteId == CentralHealthReportLoop.CentralSiteId;
var siteName = isCentral ? "Central Cluster" : GetSiteName(siteId);
var detailsCollapseId = $"site-details-{siteId}";
<div class="card mb-3">
<div class="card mb-3" data-site-id="@siteId">
<div class="card-header d-flex justify-content-between align-items-center py-2">
@* Display name and machine id are two different things and are read
for two different reasons, so they get two lines: chips + name on
@@ -258,6 +231,10 @@
<span class="badge bg-danger" aria-label="State: Offline">@OfflineGlyph Offline</span>
}
<strong class="fs-5">@siteName</strong>
@if (state.LatestReport is null)
{
<span class="badge bg-secondary">Metrics unknown</span>
}
@if (state.IsOnline && state.IsMetricsStale)
{
<span class="badge bg-warning text-dark"
@@ -751,7 +728,7 @@
private bool _localDbBacklogAvailable = true;
private string? _localDbBacklogError;
private static bool SiteHasActiveErrors(SiteHealthState state)
private static bool SiteHasReportIntervalErrors(SiteHealthState state)
{
var report = state.LatestReport;
if (report == null) return false;
@@ -760,6 +737,13 @@
|| report.DeadLetterCount > 0;
}
// Liveness remains the aggregator's observation. Missing metrics are not a healthy reading;
// report counters describe one collection interval, not an ongoing or cumulative fault.
private int SiteAttentionOrder(SiteHealthState state) => !state.IsOnline ? 0
: state.IsMetricsStale || IsLocalDbBacklogSustained(state) || IsStartupReconcilerMissing(state)
|| HasSecretMirrorFailures(state) || HasAuditRejectedRows(state) || SiteHasReportIntervalErrors(state) ? 1
: state.LatestReport is null ? 2 : 3;
protected override async Task OnInitializedAsync()
{
// Load site names for display
@@ -160,3 +160,13 @@ li[role="treeitem"]:focus-visible > .tv-row {
.tv-row .tv-kebab .show {
opacity: 1;
}
/* Touch retains the same tree callbacks/roving focus with practical hit regions.
Fine pointers retain the existing compact rows. */
@media (pointer: coarse) {
.tv-row { min-height: 44px; }
.tv-row .tv-toggle { min-width: 44px; min-height: 44px; }
.tv-row .tv-content { min-height: 44px; }
.tv-row .tv-content button { min-width: 44px; min-height: 44px; }
.tv-row .tv-kebab { opacity: 1; }
}
@@ -214,3 +214,30 @@
.text-primary { color: var(--accent-deep) !important; }
.text-secondary { color: var(--ink-soft) !important; }
.text-muted, .text-body-secondary, .text-body-tertiary { color: var(--ink-faint) !important; }
/* Host-specific four-fact composition; shared aggregate tokens and geometry own each fact. */
.dashboard-facts, .health-facts { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .dashboard-facts, .health-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 420px) { .dashboard-facts, .health-facts { grid-template-columns: minmax(0, 1fr); } }
/* Topology follows document flow on small/short screens; no guessed header subtraction.
On roomy desktop screens the page/toolbar/tree share the actual available height. */
.topology-page { display: flex; flex-direction: column; min-width: 0; }
.topology-tree { min-width: 0; padding: 4px; }
@media (min-width: 992px) and (min-height: 640px) {
.app-shell > main.page:has(.topology-page) {
display: flex;
flex-direction: column;
height: 100vh;
height: 100dvh;
min-height: 0;
}
.topology-page { flex: 1; min-height: 0; padding-bottom: 1rem; }
.topology-tree { flex: 1; min-height: 12rem; overflow-y: auto; }
}
@media (pointer: coarse) {
.topology-page button, .topology-page summary, .topology-page input[type="text"] {
min-height: 44px;
}
.topology-page input[type="checkbox"] { min-width: 24px; min-height: 24px; }
}