fix(uns): guard import save + comma-limitation hint + reset-on-open (review)

This commit is contained in:
Joseph Doherty
2026-06-08 14:00:26 -04:00
parent 7db9a24403
commit 983d30cb15
2 changed files with 8 additions and 3 deletions
@@ -30,6 +30,7 @@
<textarea class="form-control form-control-sm mono" rows="12" <textarea class="form-control form-control-sm mono" rows="12"
@bind="_csv" @bind:event="oninput" disabled="@_busy" @bind="_csv" @bind:event="oninput" disabled="@_busy"
placeholder="Name,MachineCode,UnsLineId,DriverInstanceId,ZTag,SAPID,Manufacturer,Model&#10;mixer-01,MX_001,LINE-1,drv-modbus-01,ZT-12345,SAP-9876,Siemens,SIMATIC-1500"></textarea> placeholder="Name,MachineCode,UnsLineId,DriverInstanceId,ZTag,SAPID,Manufacturer,Model&#10;mixer-01,MX_001,LINE-1,drv-modbus-01,ZT-12345,SAP-9876,Siemens,SIMATIC-1500"></textarea>
<div class="form-text">Simple comma-separated values only — fields containing commas are not supported.</div>
@if (!string.IsNullOrWhiteSpace(_parseError)) @if (!string.IsNullOrWhiteSpace(_parseError))
{ {
@@ -91,16 +92,18 @@
private bool _busy; private bool _busy;
private string? _parseError; private string? _parseError;
private EquipmentImportResult? _result; private EquipmentImportResult? _result;
private bool _wasVisible;
protected override void OnParametersSet() protected override void OnParametersSet()
{ {
// Reset the working state each time the host (re)opens the modal. // Reset only on the false→true transition so that re-renders while open don't wipe state.
if (!Visible) if (Visible && !_wasVisible)
{ {
_csv = ""; _csv = "";
_parseError = null; _parseError = null;
_result = null; _result = null;
} }
_wasVisible = Visible;
} }
private async Task ImportAsync() private async Task ImportAsync()
@@ -154,6 +157,7 @@
var rows = new List<EquipmentInput>(); var rows = new List<EquipmentInput>();
for (var lineIdx = 1; lineIdx < lines.Length; lineIdx++) for (var lineIdx = 1; lineIdx < lines.Length; lineIdx++)
{ {
// NOTE: simple comma split — no RFC4180 quoting; values with commas are not supported.
var parts = lines[lineIdx].Split(',').Select(c => c.Trim()).ToArray(); var parts = lines[lineIdx].Split(',').Select(c => c.Trim()).ToArray();
if (parts.Length < RequiredColumns.Length) if (parts.Length < RequiredColumns.Length)
{ {
@@ -575,7 +575,8 @@ public sealed class UnsTreeService(IDbContextFactory<OtOpcUaConfigDbContext> dbF
inserted++; inserted++;
} }
await db.SaveChangesAsync(ct); if (inserted > 0)
await db.SaveChangesAsync(ct);
return new EquipmentImportResult(inserted, skipped, errors); return new EquipmentImportResult(inserted, skipped, errors);
} }