fix(adminui): Monaco text syncs on demand, diagnostics are sequenced, Problems list (D1)
R04:P1 - the editor no longer ships its full text JS->.NET on every keystroke. It reports at blur, and ScriptEdit / the VirtualTag modal read the authoritative value with MonacoEditor.GetValueAsync at Save (validation runs after the pull). The Blazor hub's MaximumReceiveMessageSize is raised from 32 KB to 1 MB. The JS refuses a value that would not fit instead of sending an oversize frame, and Save surfaces that refusal rather than persisting stale source. R04:P9 - diagnostics carry a generation counter and an AbortController. Every edit aborts the in-flight request, and only the response for the current text is applied. R04:S2 - the always-empty inlay-hints provider, endpoint, service method and contracts are removed. R04:S3 - MarkersChanged is typed (DiagnosticMarker) and feeds a new ScriptProblemsList. Clicking a problem calls RevealLineAsync. Markers cross to .NET only when a list subscribes. Refs #745 Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
@using System.Text
|
||||
@using ZB.MOM.WW.OtOpcUa.Configuration
|
||||
@using ZB.MOM.WW.OtOpcUa.Configuration.Entities
|
||||
@using ZB.MOM.WW.OtOpcUa.AdminUI.ScriptAnalysis
|
||||
@inject IDbContextFactory<OtOpcUaConfigDbContext> DbFactory
|
||||
@inject NavigationManager Nav
|
||||
|
||||
@@ -30,7 +31,9 @@ else if (!IsNew && _existing is null)
|
||||
}
|
||||
else
|
||||
{
|
||||
<EditForm Model="_form" OnValidSubmit="SubmitAsync" FormName="scriptEdit">
|
||||
@* OnSubmit (not OnValidSubmit): the editor text is pulled from Monaco FIRST, then validated — the bound
|
||||
SourceCode is only refreshed at blur, so validating before the pull could judge stale text. *@
|
||||
<EditForm Model="_form" OnSubmit="SubmitAsync" FormName="scriptEdit">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary class="alert alert-danger py-2 px-3" />
|
||||
<section class="panel rise">
|
||||
@@ -57,7 +60,9 @@ else
|
||||
<section class="panel rise mt-3">
|
||||
<div class="panel-head">Source</div>
|
||||
<div style="padding:1rem">
|
||||
<MonacoEditor @bind-Value="_form.SourceCode" Height="420px" />
|
||||
<MonacoEditor @ref="_editor" @bind-Value="_form.SourceCode" Height="420px"
|
||||
MarkersChanged="OnMarkersChanged" />
|
||||
<ScriptProblemsList Markers="_markers" OnSelect="RevealProblemAsync" />
|
||||
<div class="form-text">SHA-256 hash is computed automatically on save.</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -84,6 +89,13 @@ else
|
||||
private bool _loaded;
|
||||
private bool _busy;
|
||||
private string? _error;
|
||||
private MonacoEditor? _editor;
|
||||
private IReadOnlyList<DiagnosticMarker> _markers = Array.Empty<DiagnosticMarker>();
|
||||
|
||||
private void OnMarkersChanged(IReadOnlyList<DiagnosticMarker> markers) => _markers = markers;
|
||||
|
||||
private Task RevealProblemAsync(DiagnosticMarker m)
|
||||
=> _editor is null ? Task.CompletedTask : _editor.RevealLineAsync(m.StartLineNumber, m.StartColumn);
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
@@ -105,11 +117,21 @@ else
|
||||
_loaded = true;
|
||||
}
|
||||
|
||||
private async Task SubmitAsync()
|
||||
private async Task SubmitAsync(EditContext editContext)
|
||||
{
|
||||
_busy = true; _error = null;
|
||||
try
|
||||
{
|
||||
// The editor reports its text only at blur, so read the authoritative current value now. A read
|
||||
// failure (e.g. the script is too large to send) aborts the save rather than persisting stale source.
|
||||
if (_editor is not null)
|
||||
{
|
||||
var read = await _editor.GetValueAsync();
|
||||
if (!read.Ok) { _error = $"Not saved: {read.Error}"; return; }
|
||||
_form.SourceCode = read.Value!;
|
||||
}
|
||||
if (!editContext.Validate()) return;
|
||||
|
||||
var sourceHash = HashSource(_form.SourceCode);
|
||||
await using var db = await DbFactory.CreateDbContextAsync();
|
||||
if (IsNew)
|
||||
|
||||
Reference in New Issue
Block a user