Skip to content

Commit

Permalink
Fix #689 2 tabs of same view: Filtering is identical (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
joao4all authored Jul 31, 2024
1 parent f4341b2 commit 41ec4d3
Show file tree
Hide file tree
Showing 21 changed files with 156 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
// limitations under the License.
------------------------------------------------------------------------------->
<CascadingValue Value="this.CurrentThing">
<DynamicComponent Type="this.ApplicationBaseType" Parameters="this.parameters"/>
<DynamicComponent Type="this.ApplicationBaseType" Parameters="this.parameters" @key="this.Id"/>
</CascadingValue>
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public partial class DynamicApplicationBase
[Parameter]
public Thing CurrentThing { get; set; }

/// <summary>
/// Gets or sets the component's id
/// </summary>
[Parameter]
public object Id { get; set; }

/// <summary>
/// Gets the <see cref="Dictionary{TKey,TValue}"/> of parameters that have to be passed to the <see cref="DynamicComponent"/>
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class ParameterEditorTestFixture
private Mock<ISession> session;
private Iteration firstIteration;
private Iteration secondIteration;
private ICDPMessageBus messageBus;
private CDPMessageBus messageBus;

[SetUp]
public void Setup()
Expand Down Expand Up @@ -123,21 +123,31 @@ public void Setup()
mockConfigurationService.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration());
this.messageBus = new CDPMessageBus();

var parameterTableViewModel = new Mock<IParameterTableViewModel>();
parameterTableViewModel.Setup(x => x.Rows).Returns(new SourceList<ParameterBaseRowViewModel>());

var parameterEditorBodyViewModel = new Mock<IParameterEditorBodyViewModel>();
parameterEditorBodyViewModel.Setup(x => x.OptionSelector).Returns(new Mock<IOptionSelectorViewModel>().Object);
parameterEditorBodyViewModel.Setup(x => x.BatchParameterEditorViewModel).Returns(new Mock<IBatchParameterEditorViewModel>().Object);
parameterEditorBodyViewModel.Setup(x => x.ParameterTypeSelector).Returns(new Mock<IParameterTypeSelectorViewModel>().Object);
parameterEditorBodyViewModel.Setup(x => x.ElementSelector).Returns(new Mock<IElementBaseSelectorViewModel>().Object);
parameterEditorBodyViewModel.Setup(x => x.ParameterTableViewModel).Returns(parameterTableViewModel.Object);

var configurationService = new Mock<IStringTableService>();
configurationService.Setup(x => x.GetText(It.IsAny<string>())).Returns("something");

this.context.ConfigureDevExpressBlazor();
this.context.Services.AddSingleton(this.viewModel);
this.context.Services.AddSingleton(this.sessionService.Object);
this.context.Services.AddSingleton(mockConfigurationService.Object);
this.context.Services.AddSingleton(parameterEditorBodyViewModel.Object);
this.context.Services.AddSingleton(parameterTableViewModel.Object);
this.context.Services.AddSingleton(configurationService.Object);
this.context.Services.AddSingleton<ICDPMessageBus>(this.messageBus);
this.context.Services.AddSingleton<IOpenModelViewModel, OpenModelViewModel>();
this.context.Services.AddSingleton<IParameterEditorBodyViewModel, ParameterEditorBodyViewModel>();
this.context.Services.AddSingleton<IBatchParameterEditorViewModel, BatchParameterEditorViewModel>();
this.context.Services.AddSingleton<ISubscriptionService, SubscriptionService>();
this.context.Services.AddSingleton<IParameterTableViewModel, ParameterTableViewModel>();
this.context.Services.AddSingleton<INotificationService, NotificationService>();
this.context.Services.AddSingleton(mockConfigurationService.Object);
this.context.Services.AddSingleton(this.messageBus);

var configurationService = new Mock<IStringTableService>();
configurationService.Setup(x => x.GetText(It.IsAny<string>())).Returns("something");
this.context.Services.AddSingleton(configurationService.Object);
}

[TearDown]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,33 +242,13 @@ public async Task VerifyApplyFilters()
await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);

this.viewModel.ElementSelector.SelectedElementBase = this.viewModel.ElementSelector.AvailableElements.First();
await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);

this.tableViewModel.Verify(x => x.ApplyFilters(this.iteration.DefaultOption, this.viewModel.ElementSelector.SelectedElementBase, null, true), Times.Once);

this.viewModel.ElementSelector.SelectedElementBase = null;
await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);

this.viewModel.ParameterTypeSelector.SelectedParameterType = this.viewModel.ParameterTypeSelector.AvailableParameterTypes.First();
await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);

this.tableViewModel.Verify(x => x.ApplyFilters(this.iteration.DefaultOption,
null, this.viewModel.ParameterTypeSelector.SelectedParameterType, true), Times.Once);

this.viewModel.ParameterTypeSelector.SelectedParameterType = null;
await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);

this.viewModel.OptionSelector.SelectedOption = this.viewModel.CurrentThing.Option.Last();
await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);

this.tableViewModel.Verify(x => x.ApplyFilters(this.iteration.Option.Last(),
null, null, true), Times.Once);

this.viewModel.IsOwnedParameters = false;
await TaskHelper.WaitWhileAsync(() => this.viewModel.IsLoading);

this.tableViewModel.Verify(x => x.ApplyFilters(this.iteration.Option.Last(),
null, null, false), Times.Once);
this.viewModel.ApplyFilters();

this.tableViewModel.Verify(x => x.ApplyFilters(It.IsAny<Option>(), It.IsAny<ElementBase>(), It.IsAny<ParameterType>(), It.IsAny<bool>()), Times.AtLeastOnce);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
</div>
</div>
</div>
</LoadingComponent>
</LoadingComponent>
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ private void UpdateUrl(string pageName = WebAppConstantValues.ModelDashboardPage
additionalParameters[QueryKeys.ParameterKey] = this.ViewModel.ParameterTypeSelector.SelectedParameterType.Iid.ToShortGuid();
}

this.ViewModel.UpdateDashboards();
this.UpdateUrlWithParameters(additionalParameters, pageName);
}

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

@inherits COMET.Web.Common.Components.Applications.SingleIterationApplicationBase<COMETwebapp.ViewModels.Components.ParameterEditor.IParameterEditorBodyViewModel>

<LoadingComponent IsVisible="@(this.ViewModel.IsLoading || this.ViewModel.BatchParameterEditorViewModel.IsLoading)">
<LoadingComponent IsVisible="@(this.ViewModel.IsLoading)">
<div id="@WebAppConstantValues.ParameterEditorPage.QueryPageBodyName()" class="container-fluid">
<div class="row ">
<div class="col">
Expand Down Expand Up @@ -60,4 +60,4 @@ Copyright (c) 2024 Starion Group S.A.
<ParameterTable ViewModel="this.ViewModel.ParameterTableViewModel"/>
</div>
</div>
</LoadingComponent>
</LoadingComponent>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ protected override void OnViewModelAssigned()
{
base.OnViewModelAssigned();

this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.OptionSelector.SelectedOption,
this.Disposables.Add(this.WhenAnyValue(
x => x.ViewModel.OptionSelector.SelectedOption,
x => x.ViewModel.ParameterTypeSelector.SelectedParameterType,
x => x.ViewModel.ElementSelector.SelectedElementBase,
x => x.ViewModel.IsOwnedParameters)
Expand Down Expand Up @@ -99,6 +100,7 @@ private void UpdateUrl()
additionalParameters["owned"] = this.ViewModel.IsOwnedParameters.ToString();
}

this.ViewModel.ApplyFilters();
this.UpdateUrlWithParameters(additionalParameters, WebAppConstantValues.ParameterEditorPage);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<DxGrid @ref="this.Grid"
CssClass="default-grid"
ShowAllRows="true"
Data="@this.sortedCollection"
Data="@(this.sortedCollection)"
SelectionMode="GridSelectionMode.Single"
AllowSelectRowByClick="false"
ShowFilterRow="true"
Expand Down
30 changes: 15 additions & 15 deletions COMETwebapp/Components/ParameterEditor/ParameterTable.razor.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ParameterTable.cs" company="Starion Group S.A.">
// Copyright (c) 2023-2024 Starion Group S.A.
// <copyright file="ParameterTable.razor.cs" company="Starion Group S.A.">
// Copyright (c) 2024 Starion Group S.A.
//
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine
// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua
//
// This file is part of CDP4-COMET WEB Community Edition
// The CDP4-COMET WEB Community Edition is the Starion Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
// This file is part of COMET WEB Community Edition
// The COMET WEB Community Edition is the Starion Group Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C.
//
// The CDP4-COMET WEB Community Edition is free software; you can redistribute it and/or
// The COMET WEB Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The CDP4-COMET WEB Community Edition is distributed in the hope that it will be useful,
// The COMET WEB Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
Expand All @@ -26,8 +26,7 @@ namespace COMETwebapp.Components.ParameterEditor
{
using System.Collections.ObjectModel;

using CDP4Common.EngineeringModelData;
using CDP4Common.SiteDirectoryData;
using COMET.Web.Common.Extensions;

using COMETwebapp.Comparer;
using COMETwebapp.ViewModels.Components.ParameterEditor;
Expand All @@ -46,14 +45,14 @@ namespace COMETwebapp.Components.ParameterEditor
public partial class ParameterTable
{
/// <summary>
/// <see cref="EventCallback" /> to close the popup editor
/// The <see cref="ParameterBaseRowViewModelComparer" />
/// </summary>
private EventCallback closeEditor;
private readonly ParameterBaseRowViewModelComparer comparer = new();

/// <summary>
/// The <see cref="ParameterBaseRowViewModelComparer" />
/// <see cref="EventCallback" /> to close the popup editor
/// </summary>
private ParameterBaseRowViewModelComparer comparer = new();
private EventCallback closeEditor;

/// <summary>
/// The sorted collection of <see cref="ParameterBaseRowViewModel" />
Expand All @@ -80,9 +79,10 @@ protected override void OnInitialized()
base.OnInitialized();

this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.IsOnEditMode)
.Subscribe(_ => this.InvokeAsync(this.StateHasChanged)));
.SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));

this.Disposables.Add(this.ViewModel.Rows.Connect()
.AutoRefresh()
.Sort(this.comparer)
.Bind(out this.sortedCollection)
.Subscribe(_ => this.InvokeAsync(this.StateHasChanged)));
Expand All @@ -93,7 +93,7 @@ protected override void OnInitialized()
/// <summary>
/// Customizes the table rows
/// </summary>
/// <param name="e">The <see cref="GridCustomizeElementEventArgs"/></param>
/// <param name="e">The <see cref="GridCustomizeElementEventArgs" /></param>
private void OnCustomizeElement(GridCustomizeElementEventArgs e)
{
if (e.ElementType == GridElementType.DataRow)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ private void UpdateUrl()
additionalParameters[QueryKeys.ParameterKey] = this.ViewModel.ParameterTypeSelector.SelectedParameterType.Iid.ToShortGuid();
}

this.ViewModel.UpdateTables();
this.UpdateUrlWithParameters(additionalParameters, WebAppConstantValues.SubscriptionDashboardPage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private void UpdateUrl()
additionalParameters[QueryKeys.OptionKey] = this.ViewModel.OptionSelector.SelectedOption.Iid.ToShortGuid();
}

this.ViewModel.ApplyFilters();
this.UpdateUrlWithParameters(additionalParameters, WebAppConstantValues.SystemRepresentationPage);
}
}
Expand Down
3 changes: 2 additions & 1 deletion COMETwebapp/Components/Tabs/TabsPanelComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
<div class="template-container" id="tabs-page-content">
<DynamicApplicationBase ViewModel="this.Panel.CurrentTab.ApplicationBaseViewModel"
ApplicationBaseType="this.Panel.CurrentTab.ComponentType"
CurrentThing="this.Panel.CurrentTab.ObjectOfInterest as Thing"/>
CurrentThing="this.Panel.CurrentTab.ObjectOfInterest as Thing"
Id="@(this.Panel.CurrentTab.Id)"/>
</div>
}
</div>
1 change: 1 addition & 0 deletions COMETwebapp/Components/Viewer/ViewerBody.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ private void UpdateUrl()
additionalParameters["option"] = this.ViewModel.OptionSelector.SelectedOption.Iid.ToShortGuid();
}

this.ViewModel.InitializeViewModel();
this.UpdateUrlWithParameters(additionalParameters, WebAppConstantValues.ViewerPage);
}
}
Expand Down
6 changes: 6 additions & 0 deletions COMETwebapp/Model/TabbedApplicationInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public TabbedApplicationInformation(IApplicationBaseViewModel applicationBaseVie
this.ApplicationBaseViewModel = applicationBaseViewModel;
this.ComponentType = componentType;
this.ObjectOfInterest = objectOfInterest;
this.Id = Guid.NewGuid();
}

/// <summary>
Expand All @@ -58,5 +59,10 @@ public TabbedApplicationInformation(IApplicationBaseViewModel applicationBaseVie
/// Gets the object of interest
/// </summary>
public object ObjectOfInterest { get; }

/// <summary>
/// Gets the tab's id
/// </summary>
public Guid Id { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,10 @@ public interface IModelDashboardBodyViewModel : ISingleIterationApplicationBaseV
/// Gets the <see cref="IElementDashboardViewModel" />
/// </summary>
IElementDashboardViewModel ElementDashboard { get; }

/// <summary>
/// Update the dashboard view models properties
/// </summary>
void UpdateDashboards();
}
}
Loading

0 comments on commit 41ec4d3

Please sign in to comment.