From 6fd4c2b0b5f4fe2ab9bb9afed12ea64890991fed Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Mon, 23 Nov 2026 20:59:32 -0500 Subject: [PATCH] feat(grpc-data): H2 AdminUI HistoryRead checkbox, history limit fields, X0 banner Connection/export/mapping editors offer HistoryRead (DataOperationAuthoring, never ahead of the validator) and the HistoryTimeoutMilliseconds / MaxConcurrentHistoryReads / MaxHistoryValuesPerPage / MaxHistoryResponseBytes / MaxHistoryAssemblyBytesPerRequest fields; an informational banner shows while a post-v1 bit is ticked (plan 4.3). --- .../Clusters/ClusterDataConnections.razor | 15 ++++- .../DataConnections/DataOperationAuthoring.cs | 25 ++++++++ .../GrpcDataHistoryEditorTests.cs | 63 +++++++++++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/DataConnections/DataOperationAuthoring.cs create mode 100644 tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/DataConnections/GrpcDataHistoryEditorTests.cs diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor index c44e28d8e..732e33d83 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor +++ b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/Clusters/ClusterDataConnections.razor @@ -73,6 +73,7 @@ else
Reference only; never enter a key or secret value.
Consumer nodes@foreach (var n in Nodes) { }
@Operations(c.AllowedOperations, v => c.AllowedOperations = v) +
Each remote HistoryRead call is bounded by the caller's remaining deadline and this.
@Actions(c, c.DataConnectionRowId != Guid.Empty) @@ -86,6 +87,9 @@ else @Operations(e.AllowedOperations, v => e.AllowedOperations = v) + + +
Larger answers are sent in bounded chunks.
@Actions(e, e.DataExportRowId != Guid.Empty) } @@ -103,6 +107,7 @@ else
Consumer nodes@foreach (var n in Nodes) { }
@Operations(m.AllowedOperations, v => m.AllowedOperations = v) +
@Actions(m, m.RemoteNamespaceMappingRowId != Guid.Empty) } @@ -226,10 +231,16 @@ else private RenderFragment Operations(DataOperations current, Action set) => builder => { builder.OpenElement(0, "fieldset"); builder.OpenElement(1, "legend"); builder.AddAttribute(2, "class", "fs-6"); builder.AddContent(3, "Allowed operations"); builder.CloseElement(); - foreach (var bit in new[] { DataOperations.Browse, DataOperations.Metadata, DataOperations.Read, DataOperations.Subscribe, DataOperations.Write }) + foreach (var bit in DataOperationAuthoring.AuthorableOperations) { builder.OpenElement(4, "label"); builder.AddAttribute(5, "class", "me-3"); builder.OpenElement(6, "input"); builder.AddAttribute(7, "type", "checkbox"); builder.AddAttribute(8, "checked", current.HasFlag(bit)); - builder.AddAttribute(9, "onchange", EventCallback.Factory.Create(this, args => set((bool)args.Value! ? current | bit : current & ~bit))); builder.CloseElement(); builder.AddContent(10, " " + bit); builder.CloseElement(); + builder.AddAttribute(9, "onchange", EventCallback.Factory.Create(this, args => set((bool)args.Value! ? current | bit : current & ~bit))); builder.CloseElement(); builder.AddContent(10, " " + DataOperationAuthoring.Label(bit)); builder.CloseElement(); + } + if (DataOperationAuthoring.FeatureBitBanner(current) is { } banner) + { + // Plan §4.3: the X0-everywhere rule is procedural, so the editor reminds whenever a post-v1 bit is ticked. + builder.OpenElement(11, "div"); builder.AddAttribute(12, "class", "notice mt-2"); builder.AddAttribute(13, "role", "note"); + builder.AddContent(14, banner); builder.CloseElement(); } builder.CloseElement(); }; diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/DataConnections/DataOperationAuthoring.cs b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/DataConnections/DataOperationAuthoring.cs new file mode 100644 index 000000000..df10c753e --- /dev/null +++ b/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/DataConnections/DataOperationAuthoring.cs @@ -0,0 +1,25 @@ +using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections; + +namespace ZB.MOM.WW.OtOpcUa.AdminUI.DataConnections; + +/// +/// The operation checkboxes the data-connection editors offer, and the mixed-version banner (plan §4.3). The set +/// grows with the authoring validator, never ahead of it: H2 adds . +/// +public static class DataOperationAuthoring +{ + /// The operation bits an operator can tick, in display order. + public static IReadOnlyList AuthorableOperations { get; } = + [DataOperations.Browse, DataOperations.Metadata, DataOperations.Read, DataOperations.Subscribe, DataOperations.Write, DataOperations.HistoryRead]; + + /// The checkbox label of a bit. + public static string Label(DataOperations operation) => operation == DataOperations.HistoryRead ? "HistoryRead" : operation.ToString(); + + /// + /// The informational banner shown while a post-v1 feature bit is ticked: ConfigDb records no node build, so the + /// "every node is on X0" rule is a deploy-checklist step the editor can only remind about. Null when only v1 bits are set. + /// + public static string? FeatureBitBanner(DataOperations operations) => (operations & ~DataOperationSets.V1) == 0 ? null + : "Every node of both clusters must run X0+ before authoring this: a pre-X0 node rejects the whole data-connection " + + "snapshot when a row carries an operation bit it does not know. Nothing checks this automatically."; +} diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/DataConnections/GrpcDataHistoryEditorTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/DataConnections/GrpcDataHistoryEditorTests.cs new file mode 100644 index 000000000..daf4f86ad --- /dev/null +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/DataConnections/GrpcDataHistoryEditorTests.cs @@ -0,0 +1,63 @@ +using Shouldly; +using Xunit; +using ZB.MOM.WW.OtOpcUa.AdminUI.DataConnections; +using ZB.MOM.WW.OtOpcUa.Configuration.Validation; +using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections; + +namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.DataConnections; + +/// H2 editor models: the HistoryRead checkbox, the history limits' defaults and the mixed-version banner. +[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "H2")] +public sealed class GrpcDataHistoryEditorTests +{ + [Fact] + public void HistoryRead_is_authorable_and_new_drafts_do_not_grant_it() + { + DataOperationAuthoring.AuthorableOperations.ShouldContain(DataOperations.HistoryRead); + DataOperationAuthoring.AuthorableOperations.ShouldNotContain(DataOperations.AlarmSubscribe, "A2 bits stay unauthorable"); + // Every authorable bit is one the validator accepts — the editor never gets ahead of authoring. + var all = DataOperationAuthoring.AuthorableOperations.Aggregate(DataOperations.None, (a, b) => a | b); + (all & ~DataOperationSets.Understood).ShouldBe(DataOperations.None); + new DataConnectionEditorModel().Value.AllowedOperations.HasFlag(DataOperations.HistoryRead).ShouldBeFalse(); + new RemoteMappingEditorModel().Value.AllowedOperations.HasFlag(DataOperations.HistoryRead).ShouldBeFalse(); + DataOperationAuthoring.Label(DataOperations.HistoryRead).ShouldBe("HistoryRead"); + } + + [Fact] + public void New_drafts_carry_the_plans_history_limits() + { + new DataConnectionEditorModel().Value.HistoryTimeoutMilliseconds.ShouldBe(30000); + new RemoteMappingEditorModel().Value.MaxHistoryAssemblyBytesPerRequest.ShouldBe(16 * 1024 * 1024); + } + + [Fact] + public void The_banner_shows_only_while_a_post_v1_bit_is_ticked() + { + DataOperationAuthoring.FeatureBitBanner(DataOperationSets.V1).ShouldBeNull(); + var banner = DataOperationAuthoring.FeatureBitBanner(DataOperations.Read | DataOperations.HistoryRead).ShouldNotBeNull(); + banner.ShouldContain("every node of both clusters must run X0+ before authoring this", Case.Insensitive); + } + + [Fact] + public void A_HistoryRead_draft_validates_and_a_zero_limit_does_not() + { + var draft = GrpcDataEditorValidationTestsAccess.ValidSnapshot(DataOperations.Read | DataOperations.HistoryRead); + DataConnectionValidator.Validate(draft).ShouldNotContain(x => x.Code.EndsWith("OperationsInvalid", StringComparison.Ordinal)); + draft.DataConnections[0].HistoryTimeoutMilliseconds = 0; + DataConnectionValidator.Validate(draft).ShouldContain(x => x.Code == "DataConnectionLimitInvalid"); + } +} + +/// A minimal valid draft for the editor tests. +internal static class GrpcDataEditorValidationTestsAccess +{ + public static DraftSnapshot ValidSnapshot(DataOperations operations) => new() + { + GenerationId = 1, ClusterId = "MAIN", + DataConnections = [new() { DataConnectionId = "peer", ClusterId = "MAIN", Revision = 1, Enabled = true, AllowedOperations = operations, + ConsumerNodeIds = [], EligibleTargetNodeIds = [], Endpoints = ["https://peer.example"] }], + DataExports = [new() { DataExportId = "export", ClusterId = "MAIN", Enabled = true, AllowedOperations = operations, PrincipalId = "p", Revision = 1 }], + RemoteNamespaceMappings = [new() { RemoteNamespaceMappingId = "mount", ClusterId = "MAIN", DataConnectionId = "peer", Enabled = true, + AllowedOperations = operations, ConsumerNodeIds = [], Revision = 1 }], + }; +}