Skip to content

Fixed stale state issue in ResourceEditor after saving #530

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

Merged
merged 1 commit into from
Jul 24, 2025

Conversation

JBBianchi
Copy link
Member

Many thanks for submitting your Pull Request ❤️!

What this PR does / why we need it:
Ensure resource editor reflects latest resource state.

Closes #523

Special notes for reviewers:

Additional information (if needed):

@JBBianchi JBBianchi requested a review from cdavernas July 24, 2025 09:57
@JBBianchi JBBianchi self-assigned this Jul 24, 2025
@JBBianchi JBBianchi added type: bug Something isn't working priority: high Indicates a high priority issue app: dashboard Concerns the Dashboard UI weight: 1 An issue that has a very low development impact type: fix labels Jul 24, 2025
@JBBianchi JBBianchi force-pushed the fix-523-update-resource-editor-state branch from a27e584 to 0881f78 Compare July 24, 2025 10:11
@cdavernas cdavernas requested a review from Copilot July 24, 2025 10:37
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a stale state issue in the ResourceEditor component by ensuring proper state synchronization after save operations. The changes focus on improving the state management flow and preventing race conditions when updating the UI after resource modifications.

  • Modified OnStateChanged method to accept optional patch parameter for triggering state updates without patches
  • Updated resource editor opening methods to use proper async/await pattern with duplicate ShowAsync calls
  • Enhanced ResourceEditor state subscription handling and removed manual StateHasChanged calls in favor of centralized state management

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
StatefulComponent.cs Made patch parameter optional in OnStateChanged method to allow state refresh without modifications
View.razor Updated OnShowResourceEditorAsync to use async/await pattern with duplicate ShowAsync calls
ResourceManagementComponent.cs Applied same async/await pattern changes as View.razor for consistency
ResourceEditor.razor Improved state subscription handling and replaced manual StateHasChanged calls with centralized OnStateChanged

var parameters = new Dictionary<string, object>
{
{ nameof(ResourceEditor<Namespace>.Resource), resource! },
{ nameof(ResourceEditor<Namespace>.IsCluster), true }
};
string actionType = resource == null ? "creation" : "edition";
return this.EditorOffCanvas.ShowAsync<ResourceEditor<Namespace>>(title: typeof(Namespace).Name + " " + actionType, parameters: parameters);
await this.EditorOffCanvas.ShowAsync<ResourceEditor<Namespace>>(title: typeof(Namespace).Name + " " + actionType);
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate ShowAsync call detected. Line 107 calls ShowAsync without parameters, then line 108 calls it again with parameters. The first call on line 107 should be removed as it serves no purpose and may cause unexpected behavior.

Suggested change
await this.EditorOffCanvas.ShowAsync<ResourceEditor<Namespace>>(title: typeof(Namespace).Name + " " + actionType);

Copilot uses AI. Check for mistakes.

var parameters = new Dictionary<string, object>
{
{ nameof(ResourceEditor<TResource>.Resource), resource! }
};
string actionType = resource == null ? "creation" : "edition";
return this.EditorOffCanvas.ShowAsync<ResourceEditor<TResource>>(title: typeof(TResource).Name + " " + actionType, parameters: parameters);
await this.EditorOffCanvas.ShowAsync<ResourceEditor<TResource>>(title: typeof(TResource).Name + " " + actionType);
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate ShowAsync call detected. Line 247 calls ShowAsync without parameters, then line 248 calls it again with parameters. The first call on line 247 should be removed as it serves no purpose and may cause unexpected behavior.

Suggested change
await this.EditorOffCanvas.ShowAsync<ResourceEditor<TResource>>(title: typeof(TResource).Name + " " + actionType);

Copilot uses AI. Check for mistakes.

@@ -125,9 +125,9 @@
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync().ConfigureAwait(false);
this.Store.IsSaving.Subscribe(saving => this.OnStateChanged(cmp => this.OnSavingChanged(saving)), token: this.CancellationTokenSource.Token);
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra space in lambda parameter 'cmp =>' should be 'cmp =>' for consistency with other lambda expressions in the code.

Suggested change
this.Store.IsSaving.Subscribe(saving => this.OnStateChanged(cmp => this.OnSavingChanged(saving)), token: this.CancellationTokenSource.Token);
this.Store.IsSaving.Subscribe(saving => this.OnStateChanged(cmp => this.OnSavingChanged(saving)), token: this.CancellationTokenSource.Token);

Copilot uses AI. Check for mistakes.

@JBBianchi JBBianchi merged commit b20f4de into main Jul 24, 2025
2 checks passed
@JBBianchi JBBianchi deleted the fix-523-update-resource-editor-state branch July 24, 2025 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app: dashboard Concerns the Dashboard UI priority: high Indicates a high priority issue type: bug Something isn't working type: fix weight: 1 An issue that has a very low development impact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating a new operator doesn't reset the editor state
1 participant