fix(admin-ui): harden simple modal field and pending lifecycles

This commit is contained in:
Joseph Doherty
2026-11-13 22:07:54 -05:00
parent b990ebe3ea
commit c086f97757
44 changed files with 3424 additions and 276 deletions
@@ -1,53 +1,35 @@
@* Driver-type picker for the /raw "New driver" action: pick a driver type + name, then the caller
creates a minimal driver (CreateDriverAsync with "{}") and the operator configures it afterwards via
the Configure-driver modal. Name is inline-validated as a RawPath segment. Markup mirrors the other
/raw modal shells. *@
@using ZB.MOM.WW.OtOpcUa.Commons.Types
@using ZB.MOM.WW.OtOpcUa.Core.Abstractions
@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">New driver</h5>
<button type="button" class="btn-close" aria-label="Close" @onclick="Cancel"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="form-label" for="raw-drv-type">Driver type</label>
<select id="raw-drv-type" class="form-select form-select-sm" @bind="_type">
@foreach (var t in Types)
{
<option value="@t.Value">@t.Label</option>
}
</select>
</div>
<div class="mb-1">
<label class="form-label" for="raw-drv-name">Name</label>
<input id="raw-drv-name" class="form-control form-control-sm mono"
@bind="_name" @bind:event="oninput" placeholder="line3-modbus" />
<div class="form-text">A RawPath segment — no '/', no leading or trailing spaces.</div>
</div>
@if (_error is not null)
{
<div class="text-danger small mt-1">@_error</div>
}
</div>
<div class="modal-footer">
<div class="btn-group" role="group">
<button type="button" class="btn btn-outline-secondary" @onclick="Cancel">Cancel</button>
<button type="button" class="btn btn-primary" @onclick="Submit">Create</button>
</div>
</div>
</div>
</div>
</div>
@implements IDisposable
@{
var presentation = _generation;
var submitAction = OnSubmit;
var closeAction = VisibleChanged;
}
<ModalFrame Visible="@Visible" Title="New driver" Target="@presentation" Busy="@_busy" OnClose="() => Cancel(presentation, closeAction)">
<ChildContent>
<fieldset disabled="@_busy">
<div class="mb-3"><label class="form-label" for='@FieldId("raw-drv-type")'>Driver type</label>
<select id='@FieldId("raw-drv-type")' class="form-select form-select-sm" @bind="_type">
@foreach (var t in Types) { <option value="@t.Value">@t.Label</option> }
</select></div>
<label class="form-label" for='@FieldId("raw-drv-name")'>Name</label>
<input id='@FieldId("raw-drv-name")' class="form-control form-control-sm mono" @bind="_name" @bind:event="oninput"
aria-describedby='@FieldIds("name-hint", "name-error")' aria-invalid="@(_error is null ? null : "true")" placeholder="line3-modbus" />
<div id='@FieldId("name-hint")' class="form-text">A RawPath segment — no '/', no leading or trailing spaces.</div>
<div id='@FieldId("name-error")' class="text-danger small mt-1" role="alert">@_error</div>
</fieldset>
</ChildContent>
<Footer>
<div class="btn-group" role="group">
<button type="button" class="btn btn-outline-secondary" data-initial-focus="true" disabled="@_busy" @onclick="() => Cancel(presentation, closeAction)">Cancel</button>
<button type="button" class="btn btn-primary" disabled="@_busy" @onclick="() => Submit(presentation, submitAction, closeAction)">Create</button>
</div>
</Footer>
</ModalFrame>
@code {
/// <summary>Whether the dialog is shown (supports <c>@bind-Visible</c>).</summary>
[Parameter] public bool Visible { get; set; }
@@ -57,6 +39,9 @@
/// <summary>Raised with the chosen driver type + name when the operator confirms; the dialog self-closes after.</summary>
[Parameter] public EventCallback<(string DriverType, string Name)> OnSubmit { get; set; }
/// <summary>Optional nonconfidential identity when successive targets share the same displayed values.</summary>
[Parameter] public object? Target { get; set; }
// Label → DriverType value. Galaxy's factory registers as "GalaxyMxGateway". Guarded against
// DriverTypeNames by RawDriverTypeDialogParityTests, which reads this field by reflection.
private static readonly (string Label, string Value)[] Types =
@@ -76,35 +61,53 @@
("Heidenhain", DriverTypeNames.Heidenhain),
];
private readonly string _fieldScope = "ot-simple-" + Guid.NewGuid().ToString("N");
private string FieldId(string suffix) => _fieldScope + "-" + suffix;
private string FieldIds(params string[] suffixes) => string.Join(" ", suffixes.Select(FieldId));
private string _type = DriverTypeNames.Modbus;
private string _name = "";
private string? _error;
private bool _open; // seed once per open; preserve edits across unrelated re-renders
private bool _busy, _disposed, _lastVisible;
private object? _lastTarget;
private long _generation;
protected override void OnParametersSet()
{
if (!Visible) { _open = false; return; }
if (_open) { return; }
_open = true;
object? identity = Target;
if (_disposed || (_lastVisible == Visible && Equals(_lastTarget, identity))) return;
_lastVisible = Visible;
_lastTarget = identity;
++_generation;
if (!Visible) return;
_type = DriverTypeNames.Modbus;
_name = "";
_error = null;
}
private async Task Submit()
private async Task Submit(long generation, EventCallback<(string DriverType, string Name)> action, EventCallback<bool> closeAction)
{
if (!Current(generation) || _busy) return;
var err = RawPaths.ValidateSegment(_name);
if (err is not null) { _error = err; return; }
await OnSubmit.InvokeAsync((_type, _name));
await Close();
var submitted = (_type, _name);
_busy = true;
try { await action.InvokeAsync(submitted); }
finally { _busy = false; }
if (Current(generation)) await Close(generation, closeAction);
}
private Task Cancel() => Close();
private async Task Close()
private bool Current(long generation) => !_disposed && Visible && generation == _generation;
private Task Cancel(long generation, EventCallback<bool> closeAction) => Current(generation) && !_busy ? Close(generation, closeAction) : Task.CompletedTask;
private async Task Close(long generation, EventCallback<bool> closeAction)
{
if (!Current(generation)) return;
Visible = false;
_open = false;
await VisibleChanged.InvokeAsync(false);
_lastVisible = false;
++_generation;
await closeAction.InvokeAsync(false);
}
/// <summary>Invalidates UI callbacks without cancelling a dispatched caller operation.</summary>
public void Dispose() { _disposed = true; ++_generation; }
}
@@ -1,43 +1,31 @@
@* Reusable name-input dialog for the /raw create + rename operations (New folder / New tag-group /
New group / Rename folder-driver-device-tag-group). Inline-validates the input as a RawPath segment
(RawPaths.ValidateSegment) before raising OnSubmit; a valid submit self-closes the dialog and the
caller runs the create/rename service call + surfaces any server-side error/warnings. Markup mirrors
the other /raw modal shells (RawStubModal). *@
@using ZB.MOM.WW.OtOpcUa.Commons.Types
@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">
<label class="form-label" for="raw-name-input">Name</label>
<input id="raw-name-input" class="form-control form-control-sm mono"
@bind="_value" @bind:event="oninput" @onkeydown="OnKeyDown"
placeholder="segment-name" />
<div class="form-text">A RawPath segment — no '/', no leading or trailing spaces.</div>
@if (_error is not null)
{
<div class="text-danger small mt-1">@_error</div>
}
</div>
<div class="modal-footer">
<div class="btn-group" role="group">
<button type="button" class="btn btn-outline-secondary" @onclick="Cancel">Cancel</button>
<button type="button" class="btn btn-primary" @onclick="Submit">OK</button>
</div>
</div>
</div>
</div>
</div>
@implements IDisposable
@{
var presentation = _generation;
var submitAction = OnSubmit;
var closeAction = VisibleChanged;
}
<ModalFrame Visible="@Visible" Title="@Title" Target="@presentation" Busy="@_busy" OnClose="() => Cancel(presentation, closeAction)">
<ChildContent>
<fieldset disabled="@_busy">
<label class="form-label" for='@FieldId("raw-name-input")'>Name</label>
<input id='@FieldId("raw-name-input")' class="form-control form-control-sm mono" @bind="_value" @bind:event="oninput" @onkeydown="e => OnKeyDown(e, presentation, submitAction, closeAction)"
aria-describedby='@FieldIds("name-hint", "name-error")' aria-invalid="@(_error is null ? null : "true")" placeholder="segment-name" />
<div id='@FieldId("name-hint")' class="form-text">A RawPath segment — no '/', no leading or trailing spaces.</div>
<div id='@FieldId("name-error")' class="text-danger small mt-1" role="alert">@_error</div>
</fieldset>
</ChildContent>
<Footer>
<div class="btn-group" role="group">
<button type="button" class="btn btn-outline-secondary" data-initial-focus="true" disabled="@_busy" @onclick="() => Cancel(presentation, closeAction)">Cancel</button>
<button type="button" class="btn btn-primary" disabled="@_busy" @onclick="() => Submit(presentation, submitAction, closeAction)">OK</button>
</div>
</Footer>
</ModalFrame>
@code {
/// <summary>Whether the dialog is shown (supports <c>@bind-Visible</c>).</summary>
[Parameter] public bool Visible { get; set; }
@@ -53,38 +41,55 @@
/// <summary>Raised with the validated name when the operator confirms. The dialog self-closes after.</summary>
[Parameter] public EventCallback<string> OnSubmit { get; set; }
/// <summary>Optional nonconfidential identity when successive targets share the same displayed values.</summary>
[Parameter] public object? Target { get; set; }
private readonly string _fieldScope = "ot-simple-" + Guid.NewGuid().ToString("N");
private string FieldId(string suffix) => _fieldScope + "-" + suffix;
private string FieldIds(params string[] suffixes) => string.Join(" ", suffixes.Select(FieldId));
private string _value = "";
private string? _error;
private bool _open; // seed the input once per open; preserve typing across unrelated re-renders
private bool _busy, _disposed, _lastVisible;
private object? _lastTarget;
private long _generation;
protected override void OnParametersSet()
{
if (!Visible) { _open = false; return; }
if (_open) { return; }
_open = true;
object? identity = (Target, Title, Value);
if (_disposed || (_lastVisible == Visible && Equals(_lastTarget, identity))) return;
_lastVisible = Visible;
_lastTarget = identity;
++_generation;
if (!Visible) return;
_value = Value ?? "";
_error = null;
}
private async Task Submit()
private async Task Submit(long generation, EventCallback<string> action, EventCallback<bool> closeAction)
{
if (!Current(generation) || _busy) return;
var err = RawPaths.ValidateSegment(_value);
if (err is not null) { _error = err; return; }
await OnSubmit.InvokeAsync(_value);
await Close();
var submitted = _value;
_busy = true;
try { await action.InvokeAsync(submitted); }
finally { _busy = false; }
if (Current(generation)) await Close(generation, closeAction);
}
private async Task OnKeyDown(KeyboardEventArgs e)
{
if (e.Key == "Enter") { await Submit(); }
}
private Task Cancel() => Close();
private async Task Close()
private bool Current(long generation) => !_disposed && Visible && generation == _generation;
private Task Cancel(long generation, EventCallback<bool> closeAction) => Current(generation) && !_busy ? Close(generation, closeAction) : Task.CompletedTask;
private async Task Close(long generation, EventCallback<bool> closeAction)
{
if (!Current(generation)) return;
Visible = false;
_open = false;
await VisibleChanged.InvokeAsync(false);
_lastVisible = false;
++_generation;
await closeAction.InvokeAsync(false);
}
private Task OnKeyDown(KeyboardEventArgs e, long generation, EventCallback<string> action, EventCallback<bool> closeAction) => e.Key == "Enter" ? Submit(generation, action, closeAction) : Task.CompletedTask;
/// <summary>Invalidates UI callbacks without cancelling a dispatched caller operation.</summary>
public void Dispose() { _disposed = true; ++_generation; }
}
@@ -1,37 +1,14 @@
@* Placeholder modal for the /raw context-menu actions whose real dialogs
(Configure / Device / TagModal / CSV import-export / Browse device / Rename)
land in later Batch-2 waves (B/C). This wave wires every menu action to a
named handler that opens this "coming soon" placeholder, so the tree + lazy
expansion + menus can be live-verified without the real modals existing yet.
Wave B/C replaces each handler body with the real modal invocation and can
then delete this component. Markup mirrors the GlobalUns delete-confirm modal. *@
@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="OnClose"></button>
</div>
<div class="modal-body">
<p>@Message</p>
@if (!string.IsNullOrWhiteSpace(NodeName))
{
<p class="text-muted small mb-0">Target: <span class="mono">@NodeName</span></p>
}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" @onclick="OnClose">Close</button>
</div>
</div>
</div>
</div>
}
@implements IDisposable
@{ var presentation = _generation; var closeAction = OnClose; }
<ModalFrame Visible="@Visible" Title="@Title" Description="@Message" Target="@presentation" Busy="@_closing" OnClose="() => Close(presentation, closeAction)">
<ChildContent>
@if (!string.IsNullOrWhiteSpace(NodeName))
{ <p class="text-muted small mb-0">Target: <span class="mono">@NodeName</span></p> }
</ChildContent>
<Footer><button type="button" class="btn btn-outline-secondary" data-initial-focus="true" disabled="@_closing" @onclick="() => Close(presentation, closeAction)">Close</button></Footer>
</ModalFrame>
@code {
/// <summary>Whether the placeholder is shown.</summary>
[Parameter] public bool Visible { get; set; }
@@ -46,4 +23,25 @@
/// <summary>Raised when the placeholder is dismissed.</summary>
[Parameter] public EventCallback OnClose { get; set; }
/// <summary>Optional nonconfidential identity for successive messages with identical captions.</summary>
[Parameter] public object? Target { get; set; }
private bool _lastVisible, _disposed, _closing;
private object? _lastTarget;
private long _generation;
protected override void OnParametersSet()
{
object identity = (Target, Title, Message, NodeName);
if (_lastVisible == Visible && Equals(_lastTarget, identity)) return;
_lastVisible = Visible; _lastTarget = identity; ++_generation;
}
private async Task Close(long generation, EventCallback action)
{
if (_disposed || !Visible || generation != _generation || _closing) return;
_closing = true;
try { await action.InvokeAsync(); }
finally { _closing = false; }
}
/// <summary>Invalidates old presentation callbacks.</summary>
public void Dispose() { _disposed = true; ++_generation; }
}