fix(admin-ui): recover root loads and clarify loaded-tree filtering

This commit is contained in:
Joseph Doherty
2026-11-13 23:32:11 -05:00
parent 7c888d1dca
commit c6fe9c46e0
27 changed files with 1241 additions and 19 deletions
@@ -8,6 +8,7 @@
@using ZB.MOM.WW.OtOpcUa.AdminUI.Uns
@using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Raw
@inject IRawTreeService Svc
@implements IDisposable
@* Peer of GlobalUns (/uns) for the v3 Raw project tree — the cluster-rooted
Enterprise → Cluster → Folder → Driver → Device → TagGroup → Tag hierarchy.
@@ -33,17 +34,21 @@
@if (_loading)
{
<div style="padding:1rem" class="text-muted">
<span class="spinner-border spinner-border-sm me-1"></span>Loading…
<div style="padding:1rem" class="text-muted" role="status">
<span class="spinner-border spinner-border-sm me-1" aria-hidden="true"></span>Loading Raw tree…
</div>
}
else if (_loadError is not null)
{
<div style="padding:1rem" class="text-danger">@_loadError</div>
<div class="p-3">
<p role="alert">The Raw tree could not be loaded. Retry to read the current roots.</p>
<DiagnosticDetails Summary="Raw loading details" Text="@_loadError" />
<button type="button" class="btn btn-outline-secondary mt-2" data-testid="tree-retry" @ref="_retryControl" @onclick="RetryAsync">Retry loading Raw tree</button>
</div>
}
else if (_roots.Count == 0)
{
<div style="padding:1rem" class="text-muted">No clusters yet.</div>
<div class="p-3"><p class="text-muted mb-2">No clusters yet.</p><a href="/clusters/new">Create a cluster</a></div>
}
else
{
@@ -59,11 +64,39 @@
private bool _loading = true;
private string? _loadError;
protected override async Task OnInitializedAsync()
private ElementReference _retryControl;
private bool _restoreRetryFocus;
private async Task RetryAsync()
{
await LoadRootsAsync();
if (!_disposed && _loadError is not null) { _restoreRetryFocus = true; }
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (_restoreRetryFocus && !_disposed)
{
_restoreRetryFocus = false;
await _retryControl.FocusAsync();
}
}
private readonly CancellationTokenSource _readLifetime = new();
private bool _readPending;
private bool _disposed;
protected override Task OnInitializedAsync() => LoadRootsAsync();
private async Task LoadRootsAsync()
{
if (_disposed || _readPending) { return; }
_readPending = true;
_loading = true;
_loadError = null;
try
{
_roots = await Svc.LoadRootsAsync();
var roots = await Svc.LoadRootsAsync(_readLifetime.Token);
if (_disposed) { return; }
_roots = roots;
// Auto-expand the Enterprise roots so the Cluster level (which owns the lazy plumbing) is
// visible on load, mirroring GlobalUns.ExpandStructural. Enterprise children (clusters) are
// eagerly materialised by LoadRootsAsync, so this needs no lazy fetch; clusters stay
@@ -71,13 +104,22 @@
foreach (var enterprise in _roots)
enterprise.Expanded = true;
}
catch (OperationCanceledException) when (_disposed) { }
catch (Exception ex)
{
_loadError = $"Failed to load the Raw tree: {ex.Message}";
if (!_disposed) { _loadError = ex.Message; }
}
finally
{
_loading = false;
_readPending = false;
if (!_disposed) { _loading = false; }
}
}
public void Dispose()
{
_disposed = true;
_readLifetime.Cancel();
_readLifetime.Dispose();
}
}
@@ -5,6 +5,7 @@
@using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Uns
@inject IUnsTreeService Svc
@inject NavigationManager Nav
@implements IDisposable
<PageErrorBoundary>
<PageTitle>UNS · OtOpcUa</PageTitle>
@@ -20,30 +21,44 @@
<h2 class="m-0" style="font:inherit">Unified namespace</h2>
<div class="d-flex align-items-center gap-2 flex-wrap">
<div><label class="form-label small mb-1" for="@_filterId">Filter loaded UNS names</label>
<input id="@_filterId" type="text" class="form-control form-control-sm" style="max-width:240px"
<input @ref="_filterControl" aria-describedby="@(_filterId + "-hint")" id="@_filterId" type="text" class="form-control form-control-sm" style="max-width:240px"
placeholder="Filter by name (substring)…"
@bind="_filter" @bind:event="oninput" /></div>
@bind="_filter" @bind:event="oninput" disabled="@(_loading || _loadError is not null)" />
@if (!string.IsNullOrWhiteSpace(_filter))
{
<button type="button" class="btn btn-outline-secondary btn-sm mt-1" @onclick="ClearFilterAsync">Clear filter</button>
}</div>
<div class="btn-group btn-group-sm" role="group">
<button type="button" class="btn btn-outline-secondary btn-sm" @onclick="ExpandAll">Expand all</button>
<button type="button" class="btn btn-outline-secondary btn-sm" @onclick="CollapseAll">Collapse all</button>
<button type="button" class="btn btn-outline-secondary btn-sm" @onclick="ExpandAll" disabled="@(_loading || _loadError is not null)">Expand all</button>
<button type="button" class="btn btn-outline-secondary btn-sm" @onclick="CollapseAll" disabled="@(_loading || _loadError is not null)">Collapse all</button>
</div>
<button type="button" class="btn btn-outline-primary btn-sm" @onclick="OpenImportModal">Import equipment CSV</button>
</div>
</div>
<p id="@(_filterId + "-hint")" class="small text-muted px-3 pt-2 mb-0">Filters loaded names only. Unloaded tag contents are not searched.</p>
@if (_loading)
{
<div style="padding:1rem" class="text-muted">
<span class="spinner-border spinner-border-sm me-1"></span>Loading…
<div style="padding:1rem" class="text-muted" role="status">
<span class="spinner-border spinner-border-sm me-1" aria-hidden="true"></span>Loading UNS tree…
</div>
}
else if (_loadError is not null)
{
<div class="p-3">
<p role="alert">The UNS tree could not be loaded. Retry to read the current structure.</p>
<DiagnosticDetails Summary="UNS loading details" Text="@_loadError" />
<button type="button" class="btn btn-outline-secondary mt-2" data-testid="tree-retry" @ref="_retryControl" @onclick="RetryAsync">Retry loading UNS tree</button>
</div>
}
else if (_roots.Count == 0)
{
<div style="padding:1rem" class="text-muted">No clusters yet.</div>
<div class="p-3"><p class="text-muted mb-2">No clusters yet.</p><a href="/clusters/new">Create a cluster</a></div>
}
else
{
<div style="padding:.5rem 1rem">
<div style="padding:.5rem 1rem;max-width:100%;overflow:auto" tabindex="0" role="region" aria-label="Loaded UNS tree">
<UnsTree Roots="_roots" Filter="@_filter"
OnToggleExpand="ToggleAsync"
OnAddChild="HandleAddChild"
@@ -148,10 +163,64 @@
.Select(n => (n.EntityId!, n.DisplayName))
.ToList();
protected override async Task OnInitializedAsync()
private ElementReference _filterControl;
private string? _loadError;
private ElementReference _retryControl;
private bool _restoreRetryFocus;
private async Task RetryAsync()
{
_roots = await Svc.LoadStructureAsync();
_loading = false;
await LoadStructureAsync();
if (!_disposed && _loadError is not null) { _restoreRetryFocus = true; }
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (_restoreRetryFocus && !_disposed)
{
_restoreRetryFocus = false;
await _retryControl.FocusAsync();
}
}
private readonly CancellationTokenSource _readLifetime = new();
private bool _readPending;
private bool _disposed;
protected override Task OnInitializedAsync() => LoadStructureAsync();
private async Task LoadStructureAsync()
{
if (_disposed || _readPending) { return; }
_readPending = true;
_loading = true;
_loadError = null;
try
{
var roots = await Svc.LoadStructureAsync(_readLifetime.Token);
if (!_disposed) { _roots = roots; }
}
catch (OperationCanceledException) when (_disposed) { }
catch (Exception ex)
{
if (!_disposed) { _loadError = ex.Message; }
}
finally
{
_readPending = false;
if (!_disposed) { _loading = false; }
}
}
private async Task ClearFilterAsync()
{
_filter = null;
await _filterControl.FocusAsync();
}
public void Dispose()
{
_disposed = true;
_readLifetime.Cancel();
_readLifetime.Dispose();
}
/// <summary>Returns the <c>(Id, Display)</c> area options inside a single cluster, for the line picker.</summary>
@@ -4,6 +4,10 @@
Children and raises callbacks; the host page owns expansion + lazy loading. *@
@using ZB.MOM.WW.OtOpcUa.AdminUI.Uns
@if (Roots.Count > 0 && HasFilter && !Roots.Any(r => VisibleUnder(r, false)))
{
<p role="status" class="mb-0">No loaded names match this filter. Clear the filter to show the loaded structure.</p>
}
@foreach (var root in Roots.Where(r => VisibleUnder(r, false)))
{
@RenderNode(root, 0, false)