Harden Hosts driver-controls dialog lifecycle and reflow

This commit is contained in:
Joseph Doherty
2026-11-14 01:18:22 -05:00
parent aa919ceef2
commit fc4053f0c9
63 changed files with 1574 additions and 42 deletions
@@ -295,6 +295,7 @@ else
Reconnect/Restart buttons on DriverOperator. *@
<button type="button"
class="btn btn-sm btn-outline-secondary"
aria-label="@($"Controls for {d.Name ?? d.DriverInstanceId} ({d.DriverInstanceId})")"
@onclick="() => OpenControls(d.DriverInstanceId)"
title="Show live status, resilience and driver controls">
Controls
@@ -309,47 +310,34 @@ else
</section>
}
@* Controls dialog (#546, reworked from an inline expander row — the full-width panel inside the
table made an already-dense page unreadable). Only one dialog at a time; the id survives the
5 s RebuildDriverGroups because it is held on the component, and the row is re-resolved from
the CURRENT groups each render so the header/Enabled always track live state. A driver that
vanishes from the snapshot (undeployed) closes the dialog by rendering nothing.
Enabled participates in the panel's key on purpose. The panel decides whether to subscribe
ONCE, in OnInitializedAsync (`if (!Enabled) return;`), and has no OnParametersSet hook — so a
live config edit that flips Enabled (surfaced by the 5 s LoadConfigAsync refresh) would
re-render the panel's "Disabled — not deployed" markup while its two store subscriptions and
its staleness timer stayed wired underneath. Keying on the flag recycles the component:
the old instance is disposed (unsubscribing both stores, draining both timers) and a fresh
one mounts against the new value. Closing the dialog disposes the panel the same way. *@
@if (FindControlsDriver() is var (cg, cd) && cd is not null && cg is not null)
{
<div class="modal-backdrop fade show" style="display:block"></div>
<div class="modal fade show" tabindex="-1" role="dialog" style="display:block">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
@(cd.Name ?? cd.DriverInstanceId)
<span class="mono small text-muted ms-2">@cd.DriverInstanceId</span>
<span class="chip chip-idle ms-2">@cg.ClusterId</span>
</h5>
<button type="button" class="btn-close" aria-label="Close" @onclick="CloseControls"></button>
</div>
<div class="modal-body">
<DriverStatusPanel @key="@($"detail-{cd.DriverInstanceId}-{cd.Enabled}")"
DriverInstanceId="@cd.DriverInstanceId"
ClusterId="@cg.ClusterId"
Enabled="@cd.Enabled" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" @onclick="CloseControls">Close</button>
</div>
</div>
</div>
</div>
}
}
@* The identity survives ordinary health/config refreshes, but a changed driver/Enabled context
retires both the control panel and its callbacks. Only this outer dialog owns focus trapping;
the panel's restart confirmation remains an inline group. *@
@{
var (cg, cd) = FindControlsDriver();
var controlsPresentation = PrepareControls(cg, cd);
var controlsIdentity = _controlsIdentity;
}
@if (cd is not null && cg is not null)
{
<ModalFrame Visible="true" Title="Driver controls" DialogClass="modal-lg modal-dialog-scrollable text-break"
Description="@($"{cd.Name ?? cd.DriverInstanceId} · Driver {cd.DriverInstanceId} · Cluster {cg.ClusterId}")"
Target="@controlsPresentation" Busy="@_controlsBusy" OnClose="() => CloseControls(controlsPresentation)">
<ChildContent>
<DriverStatusPanel @key="@($"detail-{controlsPresentation}-{cd.DriverInstanceId}-{cd.Enabled}")"
DriverInstanceId="@cd.DriverInstanceId"
ClusterId="@cg.ClusterId"
Enabled="@cd.Enabled"
BusyChanged="busy => ControlsBusyChanged(controlsPresentation, controlsIdentity, busy)" />
</ChildContent>
<Footer>
<button type="button" class="btn btn-outline-secondary" data-initial-focus="true" disabled="@_controlsBusy" @onclick="() => CloseControls(controlsPresentation)">Close</button>
</Footer>
</ModalFrame>
}
</PageErrorBoundary>
@code {
@@ -378,6 +366,9 @@ else
// the row records, so it survives the 5 s timer's RebuildDriverGroups — which replaces every
// HostsDriverRow instance and would otherwise close a dialog an operator just opened.
private string? _controlsDriverId;
private long _controlsGeneration;
private object? _controlsIdentity;
private bool _controlsBusy;
// Overlap guard: a tick whose config load outruns the 5 s interval must not stack behind the
// next one. A manual Refresh landing on top of an in-flight tick is a no-op by the same guard.
@@ -539,9 +530,42 @@ else
=> _driverGroups = HostsDriverView.Build(DriverStore.GetAll(), _nodes, _instances);
// Open/close the Controls dialog. Ids are globally unique, so no cluster qualifier is needed.
private void OpenControls(string driverInstanceId) => _controlsDriverId = driverInstanceId;
private void OpenControls(string driverInstanceId)
{
if (_disposed || _controlsBusy) return;
++_controlsGeneration;
_controlsDriverId = driverInstanceId;
_controlsIdentity = null;
_controlsBusy = false;
}
private void CloseControls() => _controlsDriverId = null;
private long PrepareControls(HostsClusterGroup? group, HostsDriverRow? driver)
{
object? identity = driver is null || group is null ? null : (driver.DriverInstanceId, driver.Enabled, group.ClusterId);
if (!Equals(_controlsIdentity, identity))
{
_controlsIdentity = identity;
++_controlsGeneration;
_controlsBusy = false;
}
// A vanished driver closes permanently; its later reappearance cannot reopen an old request.
if (driver is null) _controlsDriverId = null;
return _controlsGeneration;
}
private void ControlsBusyChanged(long generation, object? identity, bool busy)
{
if (_disposed || generation != _controlsGeneration || _controlsDriverId is null || !Equals(identity, _controlsIdentity)) return;
_controlsBusy = busy;
}
private void CloseControls(long generation)
{
if (_disposed || generation != _controlsGeneration || _controlsBusy) return;
_controlsDriverId = null;
_controlsIdentity = null;
++_controlsGeneration;
}
// Resolve the open dialog's driver from the CURRENT groups (the row records are replaced on
// every rebuild, so the dialog must never cache one). Null row ⇒ the driver vanished from the