feat(overview): add optional attention filter and explicit sweep zone
This commit is contained in:
@@ -71,19 +71,51 @@ else
|
||||
</div>
|
||||
</div>
|
||||
|
||||
var visibleCount = _snapshot.Applications.Sum(application => VisibleInstances(application, now).Count);
|
||||
<div class="d-flex align-items-center flex-wrap gap-2 mb-2">
|
||||
<div class="form-check mb-0">
|
||||
<input id="overview-needs-attention" @ref="_attentionFilterRef" class="form-check-input" type="checkbox"
|
||||
data-testid="attention-filter" aria-describedby="attention-help"
|
||||
@bind="_attentionOnly" @bind:after="OnAttentionFilterChanged" />
|
||||
<label class="form-check-label" for="overview-needs-attention">Needs attention</label>
|
||||
</div>
|
||||
@if (_attentionOnly)
|
||||
{
|
||||
<TechButton Variant="ButtonVariant.Secondary" Size="ButtonSize.Small"
|
||||
data-testid="attention-clear" @onclick="ClearAttentionFilter">Clear filter</TechButton>
|
||||
}
|
||||
<span class="page-meta" data-testid="attention-summary">Showing @visibleCount of @_instances.Count instances</span>
|
||||
</div>
|
||||
<p id="attention-help" class="filter-hint">Includes stale readings and leader disagreement. Fleet totals above include every instance.</p>
|
||||
@if (_instances.Count(instance => instance.Status is null) is var pending && pending > 0)
|
||||
{
|
||||
<p class="filter-hint" data-testid="attention-pending"><span class="s-idle">@pending pending observation@(pending == 1 ? "" : "s") · not yet classified</span></p>
|
||||
}
|
||||
<span class="visually-hidden" role="status" data-testid="attention-outcome">@_filterOutcome</span>
|
||||
@if (_attentionOnly && visibleCount == 0)
|
||||
{
|
||||
<div class="notice info" data-testid="attention-empty">
|
||||
No matching instances in this attention view. Clear the filter to see healthy and pending observations.
|
||||
</div>
|
||||
}
|
||||
|
||||
@foreach (var application in _snapshot.Applications)
|
||||
{
|
||||
<section class="app-section rise" id="@MainLayout.Slug(application.Name)" data-testid="application">
|
||||
var visibleInstances = VisibleInstances(application, now);
|
||||
if (_attentionOnly && visibleInstances.Count == 0) { continue; }
|
||||
<section @key="application.Name" class="app-section rise" id="@MainLayout.Slug(application.Name)" data-testid="application">
|
||||
<div class="app-head">
|
||||
<h2>@application.Name</h2>
|
||||
<StatusPill State="RollupState(application, now)">@RollupLabel(application, now)</StatusPill>
|
||||
<span class="spacer"></span>
|
||||
<span class="app-meta">@AppMeta(application)</span>
|
||||
<span class="app-meta">@AppMeta(application)@(_attentionOnly ? $" · showing {visibleInstances.Count}" : null)</span>
|
||||
</div>
|
||||
|
||||
@foreach (var group in Layout(application))
|
||||
{
|
||||
<div class="group">
|
||||
var visibleGroup = group.Where(instance => MatchesAttention(application, instance, now)).ToList();
|
||||
if (_attentionOnly && visibleGroup.Count == 0) { continue; }
|
||||
<div @key="group.Key" class="group">
|
||||
@if (group.Key is { } groupName)
|
||||
{
|
||||
var state = application.GroupFor(groupName);
|
||||
@@ -105,13 +137,13 @@ else
|
||||
Split brain · @string.Join(" vs ", state.ReportedLeaders)
|
||||
</StatusPill>
|
||||
}
|
||||
<span class="group-meta">@GroupMeta(group, now)</span>
|
||||
<span class="group-meta">@GroupMeta(group, now)@(_attentionOnly ? $" · showing {visibleGroup.Count}" : null)</span>
|
||||
</div>
|
||||
}
|
||||
<div class="card-grid">
|
||||
@foreach (var instance in group)
|
||||
@foreach (var instance in visibleGroup)
|
||||
{
|
||||
<InstanceCard Instance="instance"
|
||||
<InstanceCard @key="(instance.Application, instance.Instance)" Instance="instance"
|
||||
Now="now"
|
||||
IsLeader="IsLeader(application, instance)" />
|
||||
}
|
||||
@@ -134,6 +166,10 @@ else
|
||||
private IReadOnlyList<InstanceSnapshot> _instances = [];
|
||||
private bool _paused;
|
||||
private string _viewOutcome = string.Empty;
|
||||
private bool _attentionOnly;
|
||||
private string _filterOutcome = string.Empty;
|
||||
private bool _focusAttentionFilter;
|
||||
private ElementReference _attentionFilterRef;
|
||||
private ITimer? _timer;
|
||||
|
||||
protected override void OnInitialized()
|
||||
@@ -143,7 +179,7 @@ else
|
||||
_timer = Time.CreateTimer(_ => InvokeAsync(StateHasChanged), null, UiTick, UiTick);
|
||||
}
|
||||
|
||||
private void OnSnapshotChanged(OverviewSnapshot snapshot)
|
||||
private void OnSnapshotChanged(OverviewSnapshot _)
|
||||
{
|
||||
// Pause stops ADOPTING new snapshots; the poller keeps sweeping. That is what makes the
|
||||
// pause useful — the frozen view then visibly ages into Stale, so a paused dashboard can
|
||||
@@ -153,7 +189,10 @@ else
|
||||
|
||||
InvokeAsync(() =>
|
||||
{
|
||||
Adopt(snapshot);
|
||||
// A publication can queue before Pause/Resume. Read the latest cache here,
|
||||
// rather than replaying an older event after Resume adopted a newer snapshot.
|
||||
if (_paused) return;
|
||||
Adopt(Store.Current);
|
||||
StateHasChanged();
|
||||
});
|
||||
}
|
||||
@@ -175,6 +214,38 @@ else
|
||||
Adopt(Store.Current);
|
||||
}
|
||||
|
||||
private bool MatchesAttention(ApplicationSnapshot application, InstanceSnapshot instance, DateTimeOffset now) =>
|
||||
!_attentionOnly || instance.IsStale(now)
|
||||
|| instance.Status is InstanceStatus.Down or InstanceStatus.Degraded or InstanceStatus.Unreachable
|
||||
|| (instance.Group is { } group && application.GroupFor(group)?.Disagreement == true);
|
||||
|
||||
private List<InstanceSnapshot> VisibleInstances(ApplicationSnapshot application, DateTimeOffset now) =>
|
||||
application.Instances.Where(instance => MatchesAttention(application, instance, now)).ToList();
|
||||
|
||||
private void OnAttentionFilterChanged()
|
||||
{
|
||||
var now = Time.GetUtcNow();
|
||||
var visible = _snapshot.Applications.Sum(application => VisibleInstances(application, now).Count);
|
||||
_filterOutcome = _attentionOnly
|
||||
? $"Attention view enabled. Showing {visible} of {_instances.Count} instances."
|
||||
: $"Showing all {_instances.Count} instances.";
|
||||
}
|
||||
|
||||
private void ClearAttentionFilter()
|
||||
{
|
||||
_attentionOnly = false;
|
||||
OnAttentionFilterChanged();
|
||||
_focusAttentionFilter = true;
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (!_focusAttentionFilter) return;
|
||||
_focusAttentionFilter = false;
|
||||
try { await _attentionFilterRef.FocusAsync(); }
|
||||
catch (Microsoft.JSInterop.JSDisconnectedException) { }
|
||||
}
|
||||
|
||||
private int Count(DateTimeOffset now, InstanceStatus status) =>
|
||||
_instances.Count(i => i.Status == status && !i.IsStale(now));
|
||||
|
||||
@@ -186,9 +257,9 @@ else
|
||||
{
|
||||
var generated = _snapshot.GeneratedUtc == default
|
||||
? "never"
|
||||
: _snapshot.GeneratedUtc.ToLocalTime().ToString("HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
|
||||
: _snapshot.GeneratedUtc.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss 'UTC'", System.Globalization.CultureInfo.InvariantCulture);
|
||||
|
||||
return $"last sweep {generated} · {_instances.Count} instances";
|
||||
return $"last sweep {generated} · {_instances.Count} instance{(_instances.Count == 1 ? "" : "s")}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -130,3 +130,6 @@ details.checks summary:hover { color: var(--ink); }
|
||||
.check-row { grid-template-columns: 8px minmax(0, 1fr) auto; }
|
||||
.check-desc { grid-column: 2 / -1; }
|
||||
}
|
||||
|
||||
.filter-hint { margin: 0 0 .75rem; font-size: .8rem; color: var(--ink-soft); }
|
||||
.page-head .page-meta { min-width: 0; overflow-wrap: anywhere; }
|
||||
|
||||
Reference in New Issue
Block a user