Skip to content

Commit

Permalink
update to include sortedcollection attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
joao4all committed Jul 30, 2024
1 parent 2987f53 commit e061a80
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
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.ViewModel.Rows.Items.Order(this.comparer)"
Data="@(this.sortedCollection)"
SelectionMode="GridSelectionMode.Single"
AllowSelectRowByClick="false"
ShowFilterRow="true"
Expand Down
48 changes: 45 additions & 3 deletions COMETwebapp/Components/ParameterEditor/ParameterTable.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@

namespace COMETwebapp.Components.ParameterEditor
{
using System.Collections.ObjectModel;

using COMET.Web.Common.Extensions;

using COMETwebapp.Comparer;
using COMETwebapp.ViewModels.Components.ParameterEditor;

using DevExpress.Blazor;

using DynamicData;

using Microsoft.AspNetCore.Components;

using ReactiveUI;
Expand All @@ -40,22 +44,32 @@ namespace COMETwebapp.Components.ParameterEditor
/// </summary>
public partial class ParameterTable
{
/// <summary>
/// The <see cref="ParameterBaseRowViewModelComparer" />
/// </summary>
private readonly ParameterBaseRowViewModelComparer comparer = new();

/// <summary>
/// <see cref="EventCallback" /> to close the popup editor
/// </summary>
private EventCallback closeEditor;

/// <summary>
/// The <see cref="ParameterBaseRowViewModelComparer" />
/// The sorted collection of <see cref="ParameterBaseRowViewModel" />
/// </summary>
private readonly ParameterBaseRowViewModelComparer comparer = new();
private ReadOnlyObservableCollection<ParameterBaseRowViewModel> sortedCollection;

/// <summary>
/// Gets or sets the <see cref="IParameterTableViewModel" />
/// </summary>
[Parameter]
public IParameterTableViewModel ViewModel { get; set; }

/// <summary>
/// Gets the current view model hash code to compare with new ones
/// </summary>
public int ViewModelHashCode { get; set; }

/// <summary>
/// Gets or sets the grid control that is being customized.
/// </summary>
Expand All @@ -75,6 +89,34 @@ protected override void OnInitialized()
this.closeEditor = new EventCallbackFactory().Create(this, () => { this.ViewModel.IsOnEditMode = false; });
}

/// <summary>
/// Method invoked when the component has received parameters from its parent in
/// the render tree, and the incoming values have been assigned to properties.
/// </summary>
protected override void OnParametersSet()
{
base.OnParametersSet();

if (this.ViewModel.GetHashCode() == this.ViewModelHashCode)
{
return;
}

if (this.ViewModelHashCode != 0)
{
var latestViewModelRowsSubscription = this.Disposables.Last();
latestViewModelRowsSubscription.Dispose();
this.Disposables.Remove(latestViewModelRowsSubscription);
}

this.Disposables.Add(this.ViewModel.Rows.Connect()
.Sort(this.comparer)
.Bind(out this.sortedCollection)
.Subscribe(_ => this.InvokeAsync(this.StateHasChanged)));

this.ViewModelHashCode = this.ViewModel.GetHashCode();
}

/// <summary>
/// Customizes the table rows
/// </summary>
Expand All @@ -94,7 +136,7 @@ private void OnCustomizeElement(GridCustomizeElementEventArgs e)
if (e.ElementType == GridElementType.GroupCell)
{
var elementBaseName = (string)e.Grid.GetRowValue(e.VisibleIndex, nameof(ParameterBaseRowViewModel.ElementBaseName));
var isPublishableParameterInGroup = this.ViewModel.Rows.Items.Any(x => x.IsPublishable && x.ElementBaseName == elementBaseName);
var isPublishableParameterInGroup = this.sortedCollection.Any(x => x.IsPublishable && x.ElementBaseName == elementBaseName);

if (isPublishableParameterInGroup)
{
Expand Down

0 comments on commit e061a80

Please sign in to comment.