Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ParameterGroupName to ParameterEditor; fixes #720 #728

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion COMET.Web.Common.Test/COMET.Web.Common.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="bunit.web" Version="1.26.64" />
<PackageReference Include="bunit.web" Version="1.36.0" />
<PackageReference Include="DevExpress.Blazor" Version="23.2.9" />
<PackageReference Include="Moq" Version="4.20.72" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion COMET.Web.Common.Tests/COMET.Web.Common.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="bunit" Version="1.26.64" />
<PackageReference Include="bunit" Version="1.36.0" />
<PackageReference Include="DotNetSeleniumExtras.WaitHelpers" Version="3.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Moq" Version="4.20.72" />
Expand Down
4 changes: 2 additions & 2 deletions COMET.Web.Common/COMET.Web.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<ItemGroup>
<PackageReference Include="AsyncEnumerator" Version="4.0.2" />
<PackageReference Include="Blazored.FluentValidation" Version="2.2.0" />
<PackageReference Include="CDP4ServicesDal-CE" Version="27.4.0" />
<PackageReference Include="CDP4Web-CE" Version="27.4.0" />
<PackageReference Include="CDP4ServicesDal-CE" Version="27.4.1" />
<PackageReference Include="CDP4Web-CE" Version="27.4.1" />
<PackageReference Include="DevExpress.Blazor" Version="23.2.9" />
<PackageReference Include="FluentResults" Version="3.16.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.10" />
Expand Down
2 changes: 1 addition & 1 deletion COMETwebapp.Tests/COMETwebapp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="bunit" Version="1.26.64" />
<PackageReference Include="bunit" Version="1.36.0" />
<PackageReference Include="DotNetSeleniumExtras.WaitHelpers" Version="3.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Moq" Version="4.20.72" />
Expand Down
25 changes: 13 additions & 12 deletions COMETwebapp.Tests/Pages/ModelDashboard/ModelDashboardTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,28 @@ public async Task VerifyIterationSelection()
public void VerifyIterationPreselection()
{
this.openedIterations.AddRange(new List<Iteration> { this.firstIteration });

this.context.RenderComponent<ModelDashboard>(parameters =>
{
parameters.Add(p => p.IterationId, this.firstIteration.Iid.ToShortGuid());
});

var navigation = this.context.Services.GetService<NavigationManager>();
var navigationManager = this.context.Services.GetRequiredService<NavigationManager>();
var testUri = $"/ModelDashboard?IterationId={this.firstIteration.Iid.ToShortGuid()}";

// Act: Navigate to the URI and render the component
navigationManager.NavigateTo(testUri);
this.context.RenderComponent<ModelDashboard>();

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<ModelDashboard>(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<ModelDashboard>();

Assert.That(this.viewModel.SelectedThing, Is.EqualTo(this.firstIteration));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,27 @@ public void VerifyIterationPreselection()
{
this.openedIterations.AddRange(new List<Iteration> { this.firstIteration });

this.context.RenderComponent<ParameterEditor>(parameters => { parameters.Add(p => p.IterationId, this.firstIteration.Iid.ToShortGuid()); });
var navigationManager = this.context.Services.GetRequiredService<NavigationManager>();
var testUri = $"/ParameterEditor?IterationId={this.firstIteration.Iid.ToShortGuid()}";

var navigation = this.context.Services.GetService<NavigationManager>();
// Act: Navigate to the URI and render the component
navigationManager.NavigateTo(testUri);
this.context.RenderComponent<ParameterEditor>();

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<ParameterEditor>(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<ParameterEditor>();

Assert.That(this.viewModel.SelectedThing, Is.EqualTo(this.firstIteration));
}
Expand Down
17 changes: 12 additions & 5 deletions COMETwebapp.Tests/Pages/Viewer/ViewerTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,27 @@ public void VerifyIterationPreselection()
{
this.openedIterations.AddRange(new List<Iteration> { this.firstIteration });

this.context.RenderComponent<Viewer>(parameters => { parameters.Add(p => p.IterationId, this.firstIteration.Iid.ToShortGuid()); });
var navigationManager = this.context.Services.GetRequiredService<NavigationManager>();
var testUri = $"/Viewer?IterationId={this.firstIteration.Iid.ToShortGuid()}";

var navigation = this.context.Services.GetService<NavigationManager>();
// Act: Navigate to the URI and render the component
navigationManager.NavigateTo(testUri);
this.context.RenderComponent<Viewer>();

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<Viewer>(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<Viewer>();

Assert.That(this.viewModel.SelectedThing, Is.EqualTo(this.firstIteration));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -111,6 +127,7 @@ public void Setup()
Owner = this.domain,
ParameterType = parameterType,
Scale = scale,
Group = this.parameterGroup,
ValueSet =
{
new ParameterValueSet()
Expand All @@ -130,6 +147,7 @@ public void Setup()
ParameterType = parameterType,
Scale = scale,
Owner = this.domain,
Group = this.parameterGroup2,
ValueSet =
{
new ParameterValueSet()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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}"));
});
}

Expand Down
4 changes: 4 additions & 0 deletions COMETwebapp/COMETwebapp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@
</Content>
</ItemGroup>

<ItemGroup>
<Folder Include="logs\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

@if (this.ViewModel.IsOnEditMode)
{
var parameters = new Dictionary<string, object>()

Check warning on line 30 in COMETwebapp/Components/ParameterEditor/ParameterTable.razor

View workflow job for this annotation

GitHub Actions / Build

Remove these redundant parentheses. (https://rules.sonarsource.com/csharp/RSPEC-3235)

Check warning on line 30 in COMETwebapp/Components/ParameterEditor/ParameterTable.razor

View workflow job for this annotation

GitHub Actions / Build

Remove these redundant parentheses. (https://rules.sonarsource.com/csharp/RSPEC-3235)
{
{"ViewModel", this.ViewModel.HaveComponentParameterTypeEditorViewModel},
{"IsOnEditMode", true},
Expand All @@ -37,7 +37,7 @@
var headerText = string.Empty;
var isCloseButtonAvailable = true;

switch (this.ViewModel.HaveComponentParameterTypeEditorViewModel)

Check warning on line 40 in COMETwebapp/Components/ParameterEditor/ParameterTable.razor

View workflow job for this annotation

GitHub Actions / Build

Replace this 'switch' statement with 'if' statements to increase readability. (https://rules.sonarsource.com/csharp/RSPEC-1301)

Check warning on line 40 in COMETwebapp/Components/ParameterEditor/ParameterTable.razor

View workflow job for this annotation

GitHub Actions / Build

Add a 'default' clause to this 'switch' statement. (https://rules.sonarsource.com/csharp/RSPEC-131)
{
case CompoundParameterTypeEditorViewModel:
{
Expand Down Expand Up @@ -109,6 +109,7 @@
</DxGridDataColumn>
<DxGridDataColumn FieldName="@nameof(ParameterBaseRowViewModel.ModelCode)" Caption="@("Model Code")" AllowGroup="false" AllowSort="true" />
<DxGridDataColumn FieldName="@nameof(ParameterBaseRowViewModel.OwnerName)" Caption="@("Owner")" AllowGroup="false" AllowSort="true" />
<DxGridDataColumn FieldName="@nameof(ParameterBaseRowViewModel.ParameterGroupPath)" Caption="@("Parameter Group Path")" AllowGroup="false" AllowSort="true" />
</Columns>
</DxGrid>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@

this.ParameterSwitchKindSelectorViewModel = new ParameterSwitchKindSelectorViewModel(this.Switch, this.IsReadOnly)
{
OnUpdate = new EventCallbackFactory().Create(this, this.UpdateParameterValueSwitch)

Check warning on line 76 in COMETwebapp/ViewModels/Components/ParameterEditor/ParameterBaseRowViewModel.cs

View workflow job for this annotation

GitHub Actions / Build

Make sure the use of 'this' doesn't expose partially-constructed instances of this class in multi-threaded environments. (https://rules.sonarsource.com/csharp/RSPEC-3366)
};

this.ParameterTypeEditorSelectorViewModel = new ParameterTypeEditorSelectorViewModel(this.ParameterType, this.ValueSet, this.IsReadOnly, messageBus)
{
ParameterValueChanged = new EventCallbackFactory().Create<(IValueSet,int)>(this, this.OnParameterValueChanged)

Check warning on line 81 in COMETwebapp/ViewModels/Components/ParameterEditor/ParameterBaseRowViewModel.cs

View workflow job for this annotation

GitHub Actions / Build

Make sure the use of 'this' doesn't expose partially-constructed instances of this class in multi-threaded environments. (https://rules.sonarsource.com/csharp/RSPEC-3366)
};

this.Disposables.Add(this.WhenAnyValue(x => x.ParameterSwitchKindSelectorViewModel.SwitchValue)
Expand All @@ -89,7 +89,7 @@
/// Initializes this row view model properties
/// </summary>
/// <param name="isReadOnly">Value asserting if this row view model should be readonly or not</param>
private void InitializesProperties(bool isReadOnly)

Check warning on line 92 in COMETwebapp/ViewModels/Components/ParameterEditor/ParameterBaseRowViewModel.cs

View workflow job for this annotation

GitHub Actions / Build

The Cyclomatic Complexity of this method is 11 which is greater than 10 authorized. (https://rules.sonarsource.com/csharp/RSPEC-1541)
{
this.IsReadOnly = isReadOnly;
this.ParameterName = this.Parameter.ParameterType is not null ? this.Parameter.ParameterType.Name : string.Empty;
Expand All @@ -112,6 +112,36 @@
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.CalculateParameterGroupData();
}

/// <summary>
/// Calculate and set the values of <see cref="ParameterGroup"/> parameters
/// </summary>
private void CalculateParameterGroupData()
lxatstariongroup marked this conversation as resolved.
Show resolved Hide resolved
{
var parameterGroupPath = string.Empty;

if (this.Parameter.Group != null)
{
var group = this.Parameter.Group;
parameterGroupPath = this.Parameter.Group.Name;

while (true)
{
if (group.ContainingGroup != null)
{
parameterGroupPath = $"{group.ContainingGroup.Name} => {parameterGroupPath}";
group = group.ContainingGroup;
}
else
{
break;

Check warning on line 139 in COMETwebapp/ViewModels/Components/ParameterEditor/ParameterBaseRowViewModel.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor the code in order to remove this break statement. (https://rules.sonarsource.com/csharp/RSPEC-1227)
}
}
}

this.ParameterGroupPath = parameterGroupPath;
}

/// <summary>
Expand Down Expand Up @@ -168,6 +198,11 @@
/// </summary>
public string OwnerName { get; private set; }

/// <summary>
/// Gets the <see cref="ParameterGroup" /> name
/// </summary>
public string ParameterGroupPath { get; private set; }

/// <summary>
/// Gets the switch for the published value
/// </summary>
Expand Down Expand Up @@ -214,7 +249,7 @@
/// </summary>
/// <param name="value">The updated <see cref="IValueSet"/> with the index</param>
/// <returns>an asynchronous operation</returns>
private async Task OnParameterValueChanged((IValueSet valueSet, int _) value)

Check warning on line 252 in COMETwebapp/ViewModels/Components/ParameterEditor/ParameterBaseRowViewModel.cs

View workflow job for this annotation

GitHub Actions / Build

Add the 'Async' suffix to the name of this method. (https://rules.sonarsource.com/csharp/RSPEC-4261)
{
if (!this.IsReadOnly && value.valueSet is ParameterValueSetBase parameterValueSetBase)
{
Expand All @@ -239,7 +274,7 @@
/// Update the <see cref="ParameterSwitchKind" />
/// </summary>
/// <returns></returns>
private async Task UpdateParameterValueSwitch()

Check warning on line 277 in COMETwebapp/ViewModels/Components/ParameterEditor/ParameterBaseRowViewModel.cs

View workflow job for this annotation

GitHub Actions / Build

Add the 'Async' suffix to the name of this method. (https://rules.sonarsource.com/csharp/RSPEC-4261)
{
if (!this.IsReadOnly && this.ParameterSwitchKindSelectorViewModel.SwitchValue != this.ValueSet.ValueSwitch && this.ValueSet is ParameterValueSetBase parameterValueSetBase)
{
Expand Down
Loading