fix(adminui): stale-open guards, validation summaries, key-delete confirm, error boundary (#604)

Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
This commit is contained in:
Joseph Doherty
2026-10-08 06:55:23 -04:00
parent 3baa332d6b
commit d3bca7afd4
12 changed files with 504 additions and 13 deletions
@@ -85,20 +85,26 @@
private int _rowCount;
private string? _groupFilter;
// Bumped on every open and close so a superseded build can't install its CSV under another device's modal.
private int _openGeneration;
protected override async Task OnParametersSetAsync()
{
if (Visible && !_built)
{
_built = true;
await BuildAsync();
await BuildAsync(++_openGeneration);
}
else if (!Visible)
{
_built = false;
_openGeneration++;
}
}
private async Task BuildAsync()
private bool IsStale(int generation) => generation != _openGeneration || !Visible;
private async Task BuildAsync(int generation)
{
_loading = true;
_error = null;
@@ -110,6 +116,7 @@
if (!string.IsNullOrEmpty(TagGroupId))
{
var ctx = await ExportReader.ResolveGroupContextAsync(TagGroupId!);
if (IsStale(generation)) { return; }
if (ctx is { } c)
{
_groupFilter = c.GroupPath;
@@ -127,6 +134,7 @@
}
var tags = await ExportReader.ReadDeviceTagsAsync(deviceId);
if (IsStale(generation)) { return; }
// When exporting a single group, keep only that group's subtree (its path + descendants).
if (!string.IsNullOrEmpty(_groupFilter))
@@ -147,11 +155,11 @@
}
catch (Exception ex)
{
_error = ex.Message;
if (!IsStale(generation)) { _error = ex.Message; }
}
finally
{
_loading = false;
if (!IsStale(generation)) { _loading = false; }
}
}
@@ -164,6 +172,7 @@
private async Task Close()
{
_built = false;
_openGeneration++;
_csv = "";
_dataUri = "";
Visible = false;
@@ -191,6 +191,11 @@
private bool _committing;
private bool _resolved;
// Bumped on every open and every close; an async continuation compares its captured value after each
// await so a superseded open can never write its target under a different device's displayed modal
// (same idiom as RawBrowseModal / RawManualTagEntryModal).
private int _openGeneration;
private string _effectiveDeviceId = "";
private string? _groupPrefix;
@@ -209,17 +214,21 @@
{
if (Visible && !_resolved)
{
await ResolveTargetAsync();
_resolved = true;
var generation = ++_openGeneration;
await ResolveTargetAsync(generation);
}
else if (!Visible)
{
_resolved = false;
_openGeneration++;
}
}
private bool IsStale(int generation) => generation != _openGeneration || !Visible;
// Resolve the effective device id + the group-path prefix once per open.
private async Task ResolveTargetAsync()
private async Task ResolveTargetAsync(int generation)
{
_effectiveDeviceId = DeviceId;
_groupPrefix = null;
@@ -227,6 +236,7 @@
if (!string.IsNullOrEmpty(TagGroupId))
{
var ctx = await ExportReader.ResolveGroupContextAsync(TagGroupId!);
if (IsStale(generation)) { return; }
if (ctx is { } c)
{
_groupPrefix = c.GroupPath;
@@ -244,12 +254,14 @@
_commitErrors = new();
_removed.Clear();
_parsing = true;
var generation = _openGeneration;
try
{
using var stream = e.File.OpenReadStream(maxAllowedSize: 16 * 1024 * 1024);
using var reader = new StreamReader(stream);
var text = await reader.ReadToEndAsync();
if (IsStale(generation)) { return; }
_result = RawTagCsvMapper.Parse(DriverType, text, _groupPrefix);
_fatal = _result.FatalError;
}
@@ -283,6 +295,8 @@
_committing = true;
_commitErrors = new();
var generation = _openGeneration;
var targetDeviceId = _effectiveDeviceId;
try
{
var rows = _result.Rows
@@ -290,7 +304,8 @@
.Select(r => r.ImportRow!)
.ToList();
var outcome = await Svc.ImportTagsAsync(_effectiveDeviceId, rows);
var outcome = await Svc.ImportTagsAsync(targetDeviceId, rows);
if (IsStale(generation)) { return; }
if (outcome.Errors.Count > 0)
{
_commitErrors = outcome.Errors.ToList();
@@ -315,6 +330,7 @@
Reset();
Visible = false;
_resolved = false;
_openGeneration++;
await VisibleChanged.InvokeAsync(false);
}
}