Skip to content

Commit

Permalink
changes to solve two tabs from same panel bug
Browse files Browse the repository at this point in the history
TODO
- Investigate viewmodel not reacting in side panel
  • Loading branch information
joao4all committed Jul 30, 2024
1 parent e061a80 commit 8dc1816
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 31 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
31 changes: 2 additions & 29 deletions COMETwebapp/Components/ParameterEditor/ParameterTable.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ public partial class ParameterTable
[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 @@ -86,35 +81,13 @@ protected override void OnInitialized()
this.Disposables.Add(this.WhenAnyValue(x => x.ViewModel.IsOnEditMode)
.SubscribeAsync(_ => this.InvokeAsync(this.StateHasChanged)));

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()
.AutoRefresh()
.Sort(this.comparer)
.Bind(out this.sortedCollection)
.Subscribe(_ => this.InvokeAsync(this.StateHasChanged)));

this.ViewModelHashCode = this.ViewModel.GetHashCode();
this.closeEditor = new EventCallbackFactory().Create(this, () => { this.ViewModel.IsOnEditMode = false; });
}

/// <summary>
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>
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; }
}
}

0 comments on commit 8dc1816

Please sign in to comment.