Improve admin field names and generation-safe dialog lifecycle

This commit is contained in:
Joseph Doherty
2026-11-13 21:15:58 -05:00
parent 06b1743051
commit 169149f1eb
82 changed files with 15839 additions and 73 deletions
@@ -3,32 +3,23 @@
call and surfaces any UnsMutationResult.Error (a blocked delete names its blocker) via a follow-up
message. Markup mirrors the other /raw modal shells. *@
@if (Visible)
{
<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" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">@Title</h5>
<button type="button" class="btn-close" aria-label="Close" @onclick="Cancel"></button>
</div>
<div class="modal-body">
<p class="mb-0">@Message</p>
</div>
<div class="modal-footer">
<div class="btn-group" role="group">
<button type="button" class="btn btn-outline-secondary" @onclick="Cancel" disabled="@_busy">Cancel</button>
<button type="button" class="btn btn-danger" @onclick="Confirm" disabled="@_busy">
@if (_busy) { <span class="spinner-border spinner-border-sm me-1"></span> }
@ConfirmLabel
</button>
</div>
</div>
</div>
</div>
</div>
@implements IDisposable
@{
var presentation = _generation;
var confirmAction = OnConfirm;
}
<ModalFrame Visible="@Visible" Title="@Title" Description="@Message" Target="@presentation" Busy="@_busy" OnClose="() => Cancel(presentation)">
<Footer>
<div class="btn-group" role="group">
<button type="button" class="btn btn-outline-secondary" data-initial-focus="true" @onclick="() => Cancel(presentation)" disabled="@_busy">Cancel</button>
<button type="button" class="btn btn-danger" @onclick="() => Confirm(presentation, confirmAction)" disabled="@_busy">
@if (_busy) { <span class="spinner-border spinner-border-sm me-1" aria-hidden="true"></span> }
@ConfirmLabel
</button>
</div>
</Footer>
</ModalFrame>
@code {
/// <summary>Whether the dialog is shown (supports <c>@bind-Visible</c>).</summary>
@@ -49,27 +40,61 @@
/// <summary>Raised when the operator confirms. The dialog awaits it, then self-closes.</summary>
[Parameter] public EventCallback OnConfirm { get; set; }
private bool _busy;
/// <summary>Optional nonconfidential row identity when different targets share the same title/message.</summary>
[Parameter] public object? Target { get; set; }
private async Task Confirm()
private bool _busy;
private bool _disposed;
private bool _lastVisible;
private string? _lastTitle;
private string? _lastMessage;
private object? _lastTarget;
private long _generation;
protected override void OnParametersSet()
{
if (_disposed) return;
if (_lastVisible == Visible && string.Equals(_lastTitle, Title, StringComparison.Ordinal)
&& string.Equals(_lastMessage, Message, StringComparison.Ordinal) && Equals(_lastTarget, Target)) return;
_lastVisible = Visible;
_lastTitle = Title;
_lastMessage = Message;
_lastTarget = Target;
++_generation;
_busy = false; // Another target's already-dispatched operation continues independently.
}
private async Task Confirm(long generation, EventCallback action)
{
if (_disposed || !Visible || generation != _generation || _busy) return;
_busy = true;
try
{
await OnConfirm.InvokeAsync();
await action.InvokeAsync();
}
finally
{
_busy = false;
if (generation == _generation) _busy = false;
}
await Close();
if (generation == _generation) await Close(generation);
}
private Task Cancel() => Close();
private Task Cancel(long generation) => !_disposed && generation == _generation && !_busy ? Close(generation) : Task.CompletedTask;
private async Task Close()
private async Task Close(long generation)
{
if (_disposed || !Visible || generation != _generation) return;
Visible = false;
_lastVisible = false;
++_generation; // Invalidate this render's controls even before a parent parameter pass.
await VisibleChanged.InvokeAsync(false);
}
/// <summary>Invalidates old UI callbacks without cancelling an already-dispatched caller operation.</summary>
public void Dispose()
{
if (_disposed) return;
_disposed = true;
++_generation;
}
}
@@ -63,6 +63,7 @@
NodeName="@_msgNodeName" OnClose="CloseMessage" />
@code {
private readonly string _labelScope = "raw-control-" + Guid.NewGuid().ToString("N") + "-";
/// <summary>The top-level Raw nodes to render (the enterprise roots from <c>LoadRootsAsync</c>).</summary>
[Parameter, EditorRequired] public IReadOnlyList<RawNode> Roots { get; set; } = default!;
@@ -189,7 +190,7 @@
break;
default:
<div @key="row.Key" class="small py-1" style="@($"padding-left:{row.Depth * 18}px")">
<button type="button" class="btn btn-sm btn-link p-0" @onclick="@(() => ShowMore(row.Node))">
<button type="button" class="btn btn-sm btn-link p-0" aria-label="@($"Show {Math.Min(row.Remaining, RawTreeRows.DefaultPageSize)} more ({row.Remaining} not shown) under {row.Node.DisplayName}")" @onclick="@(() => ShowMore(row.Node))">
Show @Math.Min(row.Remaining, RawTreeRows.DefaultPageSize) more
(@row.Remaining not shown)
</button>
@@ -211,7 +212,8 @@
@if (hasExpander)
{
<button type="button" class="btn btn-sm btn-link p-0 tree-twist"
@onclick="@(() => ToggleAsync(node))">
aria-label="@($"{(node.Expanded ? "Collapse" : "Expand")} {node.DisplayName}")" aria-expanded="@(node.Expanded ? "true" : "false")"
aria-busy="@(node.Loading ? "true" : null)" @onclick="@(() => ToggleAsync(node))">
@(node.Expanded ? "▼" : "▶")
</button>
}
@@ -222,7 +224,7 @@
@if (items.Count > 0)
{
<ContextMenu Items="items" ShowEllipsis="true">
<ContextMenu Items="items" ShowEllipsis="true" TriggerLabel="@($"More actions for {node.DisplayName}")">
@RenderRowBody(node, muted)
</ContextMenu>
}
@@ -239,12 +241,12 @@
<span class="d-inline-flex align-items-center gap-1">
@if (PickerMode && node.Kind == RawNodeKind.Tag)
{
<input type="checkbox" class="form-check-input me-1"
checked="@IsTagSelected(node)"
<input type="checkbox" class="form-check-input me-1" aria-labelledby="@(_labelScope + Convert.ToHexString(System.Text.Encoding.UTF8.GetBytes(node.Key)))"
title="@($"{node.Kind} {node.Key}")" checked="@IsTagSelected(node)"
@onchange="@(e => ToggleTagSelection(node, e.Value is true))" />
}
<span aria-hidden="true">@KindIcon(node.Kind)</span>
<span class="mono small @(muted ? "text-muted" : "")">@node.DisplayName</span>
<span id="@(_labelScope + Convert.ToHexString(System.Text.Encoding.UTF8.GetBytes(node.Key)))" class="mono small @(muted ? "text-muted" : "")">@node.DisplayName</span>
@if (muted)
{
<span class="chip chip-idle ms-1" style="font-size:0.65rem">disabled</span>