From a200985bbdb785f0b9079128fd6998da8130aa7e Mon Sep 17 00:00:00 2001 From: Alexander van Delft <56023674+lxatstariongroup@users.noreply.github.com> Date: Fri, 6 Dec 2024 11:30:15 +0100 Subject: [PATCH] Add ParameterGroupName to ParameterEditor; fixes #720 * Add ParameterGroupName to ParameterEditor * Show complete group hierarchy path instead of only main group * Ugrade Bunit becuse of transitive vulnerability and bump CDP4-COMET-SDK to 27.4.1 * Refactor due to SQ issue * Rename method according to review --- .../COMET.Web.Common.Test.csproj | 2 +- .../COMET.Web.Common.Tests.csproj | 2 +- COMET.Web.Common/COMET.Web.Common.csproj | 4 +-- COMETwebapp.Tests/COMETwebapp.Tests.csproj | 2 +- .../ModelDashboardTestFixture.cs | 25 ++++++++------- .../ParameterEditorTestFixture.cs | 17 +++++++--- .../Pages/Viewer/ViewerTestFixture.cs | 17 +++++++--- .../ParameterTableViewModelTestFixture.cs | 22 ++++++++++++- COMETwebapp/COMETwebapp.csproj | 4 +++ .../ParameterEditor/ParameterTable.razor | 1 + .../ParameterBaseRowViewModel.cs | 32 +++++++++++++++++++ 11 files changed, 100 insertions(+), 28 deletions(-) diff --git a/COMET.Web.Common.Test/COMET.Web.Common.Test.csproj b/COMET.Web.Common.Test/COMET.Web.Common.Test.csproj index d2ae6fbe..8088b80e 100644 --- a/COMET.Web.Common.Test/COMET.Web.Common.Test.csproj +++ b/COMET.Web.Common.Test/COMET.Web.Common.Test.csproj @@ -28,7 +28,7 @@ - + diff --git a/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj b/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj index 8c64447d..b616db34 100644 --- a/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj +++ b/COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj @@ -46,7 +46,7 @@ - + diff --git a/COMET.Web.Common/COMET.Web.Common.csproj b/COMET.Web.Common/COMET.Web.Common.csproj index 36303baf..4eb65777 100644 --- a/COMET.Web.Common/COMET.Web.Common.csproj +++ b/COMET.Web.Common/COMET.Web.Common.csproj @@ -31,8 +31,8 @@ - - + + diff --git a/COMETwebapp.Tests/COMETwebapp.Tests.csproj b/COMETwebapp.Tests/COMETwebapp.Tests.csproj index f90bfa7f..2b4f74df 100644 --- a/COMETwebapp.Tests/COMETwebapp.Tests.csproj +++ b/COMETwebapp.Tests/COMETwebapp.Tests.csproj @@ -15,7 +15,7 @@ - + diff --git a/COMETwebapp.Tests/Pages/ModelDashboard/ModelDashboardTestFixture.cs b/COMETwebapp.Tests/Pages/ModelDashboard/ModelDashboardTestFixture.cs index 64b692c1..283dbab0 100644 --- a/COMETwebapp.Tests/Pages/ModelDashboard/ModelDashboardTestFixture.cs +++ b/COMETwebapp.Tests/Pages/ModelDashboard/ModelDashboardTestFixture.cs @@ -172,27 +172,28 @@ public async Task VerifyIterationSelection() public void VerifyIterationPreselection() { this.openedIterations.AddRange(new List { this.firstIteration }); - - this.context.RenderComponent(parameters => - { - parameters.Add(p => p.IterationId, this.firstIteration.Iid.ToShortGuid()); - }); - var navigation = this.context.Services.GetService(); + var navigationManager = this.context.Services.GetRequiredService(); + var testUri = $"/ModelDashboard?IterationId={this.firstIteration.Iid.ToShortGuid()}"; + + // Act: Navigate to the URI and render the component + navigationManager.NavigateTo(testUri); + this.context.RenderComponent(); Assert.Multiple(() => { Assert.That(this.viewModel.SelectedThing, Is.EqualTo(this.firstIteration)); - Assert.That(navigation.Uri.Contains("server"), Is.True); - Assert.That(navigation.Uri.Contains(this.firstIteration.Iid.ToShortGuid()), Is.True); + Assert.That(navigationManager.Uri.Contains("server"), Is.True); + Assert.That(navigationManager.Uri.Contains(this.firstIteration.Iid.ToShortGuid()), Is.True); }); this.viewModel.SelectedThing = null; - this.context.RenderComponent(parameters => - { - parameters.Add(p => p.IterationId, this.secondIteration.Iid.ToShortGuid()); - }); + testUri = $"/ModelDashboard?IterationId={this.secondIteration.Iid.ToShortGuid()}"; + + // Act: Navigate to the URI and render the component + navigationManager.NavigateTo(testUri); + this.context.RenderComponent(); Assert.That(this.viewModel.SelectedThing, Is.EqualTo(this.firstIteration)); } diff --git a/COMETwebapp.Tests/Pages/ParameterEditor/ParameterEditorTestFixture.cs b/COMETwebapp.Tests/Pages/ParameterEditor/ParameterEditorTestFixture.cs index e01a4656..625085f9 100644 --- a/COMETwebapp.Tests/Pages/ParameterEditor/ParameterEditorTestFixture.cs +++ b/COMETwebapp.Tests/Pages/ParameterEditor/ParameterEditorTestFixture.cs @@ -162,20 +162,27 @@ public void VerifyIterationPreselection() { this.openedIterations.AddRange(new List { this.firstIteration }); - this.context.RenderComponent(parameters => { parameters.Add(p => p.IterationId, this.firstIteration.Iid.ToShortGuid()); }); + var navigationManager = this.context.Services.GetRequiredService(); + var testUri = $"/ParameterEditor?IterationId={this.firstIteration.Iid.ToShortGuid()}"; - var navigation = this.context.Services.GetService(); + // Act: Navigate to the URI and render the component + navigationManager.NavigateTo(testUri); + this.context.RenderComponent(); Assert.Multiple(() => { Assert.That(this.viewModel.SelectedThing, Is.EqualTo(this.firstIteration)); - Assert.That(navigation.Uri.Contains("server"), Is.True); - Assert.That(navigation.Uri.Contains(this.firstIteration.Iid.ToShortGuid()), Is.True); + Assert.That(navigationManager.Uri.Contains("server"), Is.True); + Assert.That(navigationManager.Uri.Contains(this.firstIteration.Iid.ToShortGuid()), Is.True); }); this.viewModel.SelectedThing = null; - this.context.RenderComponent(parameters => { parameters.Add(p => p.IterationId, this.secondIteration.Iid.ToShortGuid()); }); + testUri = $"/ParameterEditor?IterationId={this.secondIteration.Iid.ToShortGuid()}"; + + // Act: Navigate to the URI and render the component + navigationManager.NavigateTo(testUri); + this.context.RenderComponent(); Assert.That(this.viewModel.SelectedThing, Is.EqualTo(this.firstIteration)); } diff --git a/COMETwebapp.Tests/Pages/Viewer/ViewerTestFixture.cs b/COMETwebapp.Tests/Pages/Viewer/ViewerTestFixture.cs index 54fb6dba..b0969c62 100644 --- a/COMETwebapp.Tests/Pages/Viewer/ViewerTestFixture.cs +++ b/COMETwebapp.Tests/Pages/Viewer/ViewerTestFixture.cs @@ -151,20 +151,27 @@ public void VerifyIterationPreselection() { this.openedIterations.AddRange(new List { this.firstIteration }); - this.context.RenderComponent(parameters => { parameters.Add(p => p.IterationId, this.firstIteration.Iid.ToShortGuid()); }); + var navigationManager = this.context.Services.GetRequiredService(); + var testUri = $"/Viewer?IterationId={this.firstIteration.Iid.ToShortGuid()}"; - var navigation = this.context.Services.GetService(); + // Act: Navigate to the URI and render the component + navigationManager.NavigateTo(testUri); + this.context.RenderComponent(); Assert.Multiple(() => { Assert.That(this.viewModel.SelectedThing, Is.EqualTo(this.firstIteration)); - Assert.That(navigation.Uri.Contains("server"), Is.True); - Assert.That(navigation.Uri.Contains(this.firstIteration.Iid.ToShortGuid()), Is.True); + Assert.That(navigationManager.Uri.Contains("server"), Is.True); + Assert.That(navigationManager.Uri.Contains(this.firstIteration.Iid.ToShortGuid()), Is.True); }); this.viewModel.SelectedThing = null; - this.context.RenderComponent(parameters => { parameters.Add(p => p.IterationId, this.secondIteration.Iid.ToShortGuid()); }); + testUri = $"/Viewer?IterationId={this.secondIteration.Iid.ToShortGuid()}"; + + // Act: Navigate to the URI and render the component + navigationManager.NavigateTo(testUri); + this.context.RenderComponent(); Assert.That(this.viewModel.SelectedThing, Is.EqualTo(this.firstIteration)); } diff --git a/COMETwebapp.Tests/ViewModels/Components/ParameterEditor/ParameterTableViewModelTestFixture.cs b/COMETwebapp.Tests/ViewModels/Components/ParameterEditor/ParameterTableViewModelTestFixture.cs index 6e5d12ca..d01f2122 100644 --- a/COMETwebapp.Tests/ViewModels/Components/ParameterEditor/ParameterTableViewModelTestFixture.cs +++ b/COMETwebapp.Tests/ViewModels/Components/ParameterEditor/ParameterTableViewModelTestFixture.cs @@ -50,6 +50,8 @@ public class ParameterTableViewModelTestFixture private Iteration iteration; private Option option; private CDPMessageBus messageBus; + private ParameterGroup parameterGroup; + private ParameterGroup parameterGroup2; [SetUp] public void Setup() @@ -86,12 +88,26 @@ public void Setup() ShortName = "kg" }; + this.parameterGroup = new ParameterGroup() + { + Iid = Guid.NewGuid(), + Name = "ParameterGroup 1" + }; + + this.parameterGroup2 = new ParameterGroup() + { + Iid = Guid.NewGuid(), + Name = "ParameterGroup 2", + ContainingGroup = this.parameterGroup + }; + var parameter1 = new Parameter() { Iid = Guid.NewGuid(), Owner = this.domain, ParameterType = parameterType, Scale = scale, + Group = this.parameterGroup, ValueSet = { new ParameterValueSet() @@ -111,6 +127,7 @@ public void Setup() Owner = this.domain, ParameterType = parameterType, Scale = scale, + Group = this.parameterGroup, ValueSet = { new ParameterValueSet() @@ -130,6 +147,7 @@ public void Setup() ParameterType = parameterType, Scale = scale, Owner = this.domain, + Group = this.parameterGroup2, ValueSet = { new ParameterValueSet() @@ -166,7 +184,8 @@ public void Setup() { Iid = Guid.NewGuid(), Name = "Container", - Parameter = { parameter3 } + Parameter = { parameter3 }, + ParameterGroup = { this.parameterGroup, this.parameterGroup2 } }; var elementDefinition = new ElementDefinition() @@ -228,6 +247,7 @@ public void VerifyParameterRowProperties() Assert.That(parameterRow.ParameterName, Is.EqualTo("mass")); Assert.That(parameterRow.Option, Is.Empty); Assert.That(parameterRow.State, Is.Empty); + Assert.That(parameterRow.ParameterGroupPath, Is.EqualTo($"{this.parameterGroup.Name} => {this.parameterGroup2.Name}")); }); } diff --git a/COMETwebapp/COMETwebapp.csproj b/COMETwebapp/COMETwebapp.csproj index 389eb9ac..2aa81597 100644 --- a/COMETwebapp/COMETwebapp.csproj +++ b/COMETwebapp/COMETwebapp.csproj @@ -38,4 +38,8 @@ + + + + diff --git a/COMETwebapp/Components/ParameterEditor/ParameterTable.razor b/COMETwebapp/Components/ParameterEditor/ParameterTable.razor index a53f0250..57dbf694 100644 --- a/COMETwebapp/Components/ParameterEditor/ParameterTable.razor +++ b/COMETwebapp/Components/ParameterEditor/ParameterTable.razor @@ -109,6 +109,7 @@ + diff --git a/COMETwebapp/ViewModels/Components/ParameterEditor/ParameterBaseRowViewModel.cs b/COMETwebapp/ViewModels/Components/ParameterEditor/ParameterBaseRowViewModel.cs index 52acc332..be572157 100644 --- a/COMETwebapp/ViewModels/Components/ParameterEditor/ParameterBaseRowViewModel.cs +++ b/COMETwebapp/ViewModels/Components/ParameterEditor/ParameterBaseRowViewModel.cs @@ -112,6 +112,33 @@ private void InitializesProperties(bool isReadOnly) this.Option = this.ValueSet.ActualOption is not null ? this.ValueSet.ActualOption?.Name : string.Empty; this.State = this.ValueSet.ActualState is not null ? this.ValueSet.ActualState.Name : string.Empty; this.Switch = this.ValueSet.ValueSwitch; + this.CalculateParameterGroupPath(); + } + + /// + /// Calculate and set the values of parameters + /// + private void CalculateParameterGroupPath() + { + var parameterGroupPath = string.Empty; + + if (this.Parameter.Group != null) + { + var group = this.Parameter.Group; + parameterGroupPath = this.Parameter.Group.Name; + + while (group != null) + { + if (group.ContainingGroup != null) + { + parameterGroupPath = $"{group.ContainingGroup.Name} => {parameterGroupPath}"; + } + + group = group.ContainingGroup; + } + } + + this.ParameterGroupPath = parameterGroupPath; } /// @@ -168,6 +195,11 @@ public bool IsPublishable /// public string OwnerName { get; private set; } + /// + /// Gets the name + /// + public string ParameterGroupPath { get; private set; } + /// /// Gets the switch for the published value ///