Skip to content

Commit

Permalink
Feat #596 [Parameter Editor] Allow parameter filtering by category an…
Browse files Browse the repository at this point in the history
…d domains of expertise in batch update (#713)
  • Loading branch information
joao4all authored Jul 31, 2024
1 parent 41ec4d3 commit b421907
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<DxComboBox Data="@(this.ViewModel.AvailableDomainsOfExpertise)"
@bind-Value="@(this.ViewModel.SelectedDomainOfExpertise)"
FilteringMode="DataGridFilteringMode.Contains"
ClearButtonDisplayMode="DataEditorClearButtonDisplayMode.Never"
ClearButtonDisplayMode="@(this.ViewModel.AllowNullSelection ? DataEditorClearButtonDisplayMode.Auto : DataEditorClearButtonDisplayMode.Never)"
NullText="Select a Domain Of Expertise"
AllowUserInput="true"
CssClass="@(this.CssClass)">
Expand All @@ -48,6 +48,10 @@
@(domainOfExpertise.GetSelectorNameAndShortname())
</div>
}
else
{
<span class="text-secondary">@("Select a Domain Of Expertise")</span>
}
</EditBoxTemplate>
</DxComboBox>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class DomainOfExpertiseSelectorViewModel : BelongsToIterationSelectorView
/// Creates a new instance of <see cref="DomainOfExpertiseSelectorViewModel" />
/// </summary>
/// <param name="sessionService">The <see cref="ISessionService" /></param>
/// <param name="messageBus">The <see cref="ICDPMessageBus"/></param>
/// <param name="messageBus">The <see cref="ICDPMessageBus" /></param>
public DomainOfExpertiseSelectorViewModel(ISessionService sessionService, ICDPMessageBus messageBus)
{
this.SessionService = sessionService;
Expand All @@ -62,7 +62,12 @@ public DomainOfExpertiseSelectorViewModel(ISessionService sessionService, ICDPMe
}

/// <summary>
/// Gets or sets the callback that is executed when the <see cref="SelectedDomainOfExpertise"/> property has changed
/// Gets or sets the condition to check if a null selection can be allowed
/// </summary>
public bool AllowNullSelection { get; set; }

/// <summary>
/// Gets or sets the callback that is executed when the <see cref="SelectedDomainOfExpertise" /> property has changed
/// </summary>
public EventCallback<DomainOfExpertise> OnSelectedDomainOfExpertiseChange { get; set; }

Expand Down Expand Up @@ -91,11 +96,11 @@ public DomainOfExpertise SelectedDomainOfExpertise
}

/// <summary>
/// Sets the <see cref="SelectedDomainOfExpertise"/> property or resets its value
/// Sets the <see cref="SelectedDomainOfExpertise" /> property or resets its value
/// </summary>
/// <param name="reset">The condition to check if the value should be reset</param>
/// <param name="domainOfExpertise">The <see cref="DomainOfExpertise"/> to be set</param>
/// <returns>A <see cref="Task"/></returns>
/// <param name="domainOfExpertise">The <see cref="DomainOfExpertise" /> to be set</param>
/// <returns>A <see cref="Task" /></returns>
public async Task SetSelectedDomainOfExpertiseOrReset(bool reset, DomainOfExpertise domainOfExpertise = null)
{
switch (reset)
Expand Down Expand Up @@ -124,7 +129,7 @@ protected override void UpdateProperties()
/// <summary>
/// Method executed when an iteration domain has changed
/// </summary>
/// <param name="domainChangedEvent">The <see cref="DomainChangedEvent"/> data</param>
/// <param name="domainChangedEvent">The <see cref="DomainChangedEvent" /> data</param>
private void OnDomainChanged(DomainChangedEvent domainChangedEvent)
{
if (domainChangedEvent.Iteration.Iid == this.CurrentIteration?.Iid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,26 @@ public interface IDomainOfExpertiseSelectorViewModel : IBelongsToIterationSelect
ISessionService SessionService { get; }

/// <summary>
/// Gets the <see cref="DomainOfExpertise" /> from the current <see cref="Iteration"/>
/// Gets the <see cref="DomainOfExpertise" /> from the current <see cref="Iteration" />
/// </summary>
DomainOfExpertise CurrentIterationDomain { get; set; }

/// <summary>
/// Gets or sets the callback that is executed when the <see cref="SelectedDomainOfExpertise"/> property has changed
/// Gets or sets the callback that is executed when the <see cref="SelectedDomainOfExpertise" /> property has changed
/// </summary>
EventCallback<DomainOfExpertise> OnSelectedDomainOfExpertiseChange { get; set; }

/// <summary>
/// Sets the <see cref="SelectedDomainOfExpertise"/> property or resets its value
/// Gets or sets the condition to check if a null selection can be allowed
/// </summary>
bool AllowNullSelection { get; set; }

/// <summary>
/// Sets the <see cref="SelectedDomainOfExpertise" /> property or resets its value
/// </summary>
/// <param name="reset">The condition to check if the value should be reset</param>
/// <param name="domainOfExpertise">The <see cref="DomainOfExpertise"/> to be set</param>
/// <returns>A <see cref="Task"/></returns>
/// <param name="domainOfExpertise">The <see cref="DomainOfExpertise" /> to be set</param>
/// <returns>A <see cref="Task" /></returns>
Task SetSelectedDomainOfExpertiseOrReset(bool reset, DomainOfExpertise domainOfExpertise = null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void SetUp()
var parameterTypeEditorSelectorViewModel = new Mock<IParameterTypeEditorSelectorViewModel>();
var finiteStateSelectorViewModel = new Mock<IFiniteStateSelectorViewModel>();
var optionSelectorViewModel = new Mock<IOptionSelectorViewModel>();
var domainOfExpertiseSelectorViewModel = new Mock<IDomainOfExpertiseSelectorViewModel>();
var confirmCancelPopupViewModel = new Mock<IConfirmCancelPopupViewModel>();

var parameter = new Parameter
Expand Down Expand Up @@ -100,6 +101,7 @@ public void SetUp()
this.viewModel.Setup(x => x.ParameterTypeSelectorViewModel).Returns(parameterTypeSelectorViewModel.Object);
this.viewModel.Setup(x => x.FiniteStateSelectorViewModel).Returns(finiteStateSelectorViewModel.Object);
this.viewModel.Setup(x => x.OptionSelectorViewModel).Returns(optionSelectorViewModel.Object);
this.viewModel.Setup(x => x.DomainOfExpertiseSelectorViewModel).Returns(domainOfExpertiseSelectorViewModel.Object);
this.viewModel.Setup(x => x.ParameterTypeEditorSelectorViewModel).Returns(parameterTypeEditorSelectorViewModel.Object);

this.renderer = this.context.RenderComponent<BatchParameterEditor>(parameters => { parameters.Add(p => p.ViewModel, this.viewModel.Object); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ public class BatchParameterEditorViewModelTestFixture
private Mock<ILogger<BatchParameterEditorViewModel>> loggerMock;
private Iteration iteration;
private CDPMessageBus messageBus;
private static readonly ValueArray<string> defaultValueArray = new(["-"]);
private static readonly ValueArray<string> DefaultValueArray = new(["-"]);

[SetUp]
public void Setup()
{
this.sessionService = new Mock<ISessionService>();
this.sessionService.Setup(x => x.GetSiteDirectory()).Returns(new SiteDirectory());

this.loggerMock = new Mock<ILogger<BatchParameterEditorViewModel>>();
this.messageBus = new CDPMessageBus();

this.viewModel = new BatchParameterEditorViewModel(this.sessionService.Object, this.messageBus, this.loggerMock.Object);

var domain = new DomainOfExpertise();
Expand All @@ -66,7 +69,11 @@ public void Setup()
{
Iid = Guid.NewGuid(),
Name = "mass",
ShortName = "m"
ShortName = "m",
Category =
{
new Category()
}
};

var scale = new RatioScale
Expand All @@ -86,28 +93,28 @@ public void Setup()
new ParameterValueSet
{
Iid = Guid.NewGuid(),
Manual = defaultValueArray,
Published = defaultValueArray,
Manual = DefaultValueArray,
Published = DefaultValueArray,
ValueSwitch = ParameterSwitchKind.MANUAL,
ActualOption = new Option()
},
new ParameterValueSet
{
Iid = Guid.NewGuid(),
Manual = defaultValueArray,
Published = defaultValueArray,
Manual = DefaultValueArray,
Published = DefaultValueArray,
ValueSwitch = ParameterSwitchKind.MANUAL,
ActualState = new ActualFiniteState { Container = new ActualFiniteStateList() }
},
new ParameterValueSet
{
Iid = Guid.NewGuid(),
Manual = defaultValueArray,
Published = defaultValueArray,
Manual = DefaultValueArray,
Published = DefaultValueArray,
ValueSwitch = ParameterSwitchKind.MANUAL,
ActualState = new ActualFiniteState { Container = new ActualFiniteStateList() },
ActualOption = new Option()
},
}
}
};

Expand Down Expand Up @@ -173,11 +180,17 @@ public void VerifyOpenAndFiltering()
Assert.That(this.viewModel.ParameterTypeSelectorViewModel.SelectedParameterType, Is.Null);
Assert.That(this.viewModel.OptionSelectorViewModel.SelectedOption, Is.Null);
Assert.That(this.viewModel.FiniteStateSelectorViewModel.SelectedActualFiniteState, Is.Null);
Assert.That(this.viewModel.DomainOfExpertiseSelectorViewModel.SelectedDomainOfExpertise, Is.Null);
Assert.That(this.viewModel.SelectedCategory, Is.Null);
Assert.That(this.viewModel.SelectedValueSetsRowsToUpdate, Has.Count.EqualTo(0));
Assert.That(this.viewModel.IsVisible, Is.EqualTo(true));
Assert.That(this.viewModel.Rows.Items.Count(), Is.EqualTo(0));
});

this.viewModel.SelectedCategory = new Category();
Assert.That(this.viewModel.Rows.Items.Count(), Is.EqualTo(0));

this.viewModel.SelectedCategory = null;
var firstTopElementParameter = this.iteration.TopElement.Parameter[0];
this.viewModel.ParameterTypeSelectorViewModel.SelectedParameterType = firstTopElementParameter.ParameterType;
Assert.That(this.viewModel.Rows.Items.Count(), Is.EqualTo(3));
Expand All @@ -187,6 +200,12 @@ public void VerifyOpenAndFiltering()

this.viewModel.FiniteStateSelectorViewModel.SelectedActualFiniteState = firstTopElementParameter.ValueSet[1].ActualState;
Assert.That(this.viewModel.Rows.Items.Count(), Is.EqualTo(1));

this.viewModel.DomainOfExpertiseSelectorViewModel.SelectedDomainOfExpertise = firstTopElementParameter.Owner;
Assert.That(this.viewModel.Rows.Items.Count(), Is.EqualTo(1));

this.viewModel.SelectedCategory = new Category();
Assert.That(this.viewModel.Rows.Items.Count(), Is.EqualTo(0));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Copyright (c) 2024 Starion Group S.A.

@if (this.ViewModel.ParameterTypeSelectorViewModel.SelectedParameterType != null)
{
<div class="row pt-2">
<div class="row pt-3">
<div class="col">
<OptionSelector ViewModel="this.ViewModel.OptionSelectorViewModel"/>
</div>
Expand All @@ -47,6 +47,23 @@ Copyright (c) 2024 Starion Group S.A.
</div>
</div>

<div class="row pt-3">
<div class="col">
<h6>Filter on Category:</h6>
<DxComboBox Data="@this.ViewModel.AvailableCategories"
AllowUserInput="true"
@bind-Value="@this.ViewModel.SelectedCategory"
FilteringMode="DataGridFilteringMode.Contains"
TextFieldName="@nameof(Category.Name)"
ClearButtonDisplayMode="@(DataEditorClearButtonDisplayMode.Auto)"
NullText="Select a Category" />
</div>
<div class="col">
<DomainOfExpertiseSelector ViewModel="@(this.ViewModel.DomainOfExpertiseSelectorViewModel)"
DisplayText="Filter on Domain Of Expertise:"/>
</div>
</div>

<div class="row pt-3">
<h6>Select a value:</h6>
<ParameterTypeEditorSelector BindValueMode="BindValueMode.OnDelayedInput"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ protected override void OnInitialized()
this.Disposables.Add(this.WhenAnyValue(
x => x.ViewModel.ParameterTypeSelectorViewModel.SelectedParameterType,
x => x.ViewModel.OptionSelectorViewModel.SelectedOption,
x => x.ViewModel.FiniteStateSelectorViewModel.SelectedActualFiniteState)
x => x.ViewModel.FiniteStateSelectorViewModel.SelectedActualFiniteState,
x => x.ViewModel.SelectedCategory,
x => x.ViewModel.DomainOfExpertiseSelectorViewModel.SelectedDomainOfExpertise)
.SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));
}

/// <summary>
/// Gets the group check value based on the given <see cref="ViewModel"/>
/// Gets the group check value based on the given <see cref="ViewModel" />
/// </summary>
/// <param name="context">The column group context</param>
/// <returns>The check box value</returns>
Expand Down Expand Up @@ -106,9 +108,9 @@ private void GroupCheckBox_CheckedChanged(bool? value, GridDataColumnGroupRowTem
}

/// <summary>
/// Gets the <see cref="ParameterValueSetBaseRowViewModel"/>s from the selected element name group
/// Gets the <see cref="ParameterValueSetBaseRowViewModel" />s from the selected element name group
/// </summary>
/// <param name="context">The <see cref="GridDataColumnGroupRowTemplateContext"/></param>
/// <param name="context">The <see cref="GridDataColumnGroupRowTemplateContext" /></param>
/// <returns>A collection of data items contained in the given group</returns>
private IEnumerable<object> GetGroupDataItems(GridDataColumnGroupRowTemplateContext context)
{
Expand Down
Loading

0 comments on commit b421907

Please sign in to comment.