Skip to content

Commit b20f4de

Browse files
authored
Merge pull request #530 from serverlessworkflow/fix-523-update-resource-editor-state
Fixed stale state issue in ResourceEditor after saving
2 parents 4787c0b + 0881f78 commit b20f4de

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

src/dashboard/Synapse.Dashboard/Components/ResourceEditor/ResourceEditor.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@
125125
protected override async Task OnInitializedAsync()
126126
{
127127
await base.OnInitializedAsync().ConfigureAwait(false);
128+
this.Store.IsSaving.Subscribe(saving => this.OnStateChanged(cmp => this.OnSavingChanged(saving)), token: this.CancellationTokenSource.Token);
128129
this.Store.Resource.Subscribe(resource => this.OnStateChanged(cmp => cmp.resource = resource), token: this.CancellationTokenSource.Token);
129130
this.Store.IsUpdating.Subscribe(updating => this.OnStateChanged(cmp => cmp.isUpdating = updating), token: this.CancellationTokenSource.Token);
130-
this.Store.IsSaving.Subscribe(OnSavingChanged, token: this.CancellationTokenSource.Token);
131131
this.Store.ProblemDetails.Subscribe(problemDetails => this.OnStateChanged(cmp => cmp.problemDetails = problemDetails), token: this.CancellationTokenSource.Token);
132132
this.textEditorInput
133133
.Throttle(TimeSpan.FromMilliseconds(300))
@@ -148,6 +148,7 @@
148148
{
149149
this.resource = this.Resource; // should happen in this.Store.Resource.Subscribe but prevents possible race when multiple params are set
150150
this.Store.SetResource(this.Resource);
151+
this.Store.SetProblemDetails(null);
151152
}
152153
if (this.isCluster != this.IsCluster)
153154
{
@@ -178,7 +179,6 @@
178179
{
179180
this.isSaving = saving;
180181
if (this.textBasedEditor != null) this.textBasedEditor.UpdateOptions(new EditorUpdateOptions() { ReadOnly = saving });
181-
this.StateHasChanged();
182182
}
183183

184184
/// <summary>
@@ -199,7 +199,7 @@
199199
await this.SetTextEditorValueAsync();
200200
await this.SetTextBasedEditorLanguageAsync();
201201
}
202-
this.StateHasChanged();
202+
this.OnStateChanged();
203203
}
204204

205205
/// <summary>

src/dashboard/Synapse.Dashboard/Components/ResourceManagement/ResourceManagementComponent.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,16 @@ protected virtual Task OnShowResourceDetailsAsync(TResource resource)
236236
/// Opens the targeted <see cref="Resource"/>'s edition
237237
/// </summary>
238238
/// <param name="resource">The <see cref="Resource"/> to edit</param>
239-
protected virtual Task OnShowResourceEditorAsync(TResource? resource = null)
239+
protected virtual async Task OnShowResourceEditorAsync(TResource? resource = null)
240240
{
241-
if (this.EditorOffCanvas == null) return Task.CompletedTask;
241+
if (this.EditorOffCanvas == null) return;
242242
var parameters = new Dictionary<string, object>
243243
{
244244
{ nameof(ResourceEditor<TResource>.Resource), resource! }
245245
};
246246
string actionType = resource == null ? "creation" : "edition";
247-
return this.EditorOffCanvas.ShowAsync<ResourceEditor<TResource>>(title: typeof(TResource).Name + " " + actionType, parameters: parameters);
247+
await this.EditorOffCanvas.ShowAsync<ResourceEditor<TResource>>(title: typeof(TResource).Name + " " + actionType);
248+
await this.EditorOffCanvas.ShowAsync<ResourceEditor<TResource>>(title: typeof(TResource).Name + " " + actionType, parameters: parameters);
248249
}
249250

250251
}

src/dashboard/Synapse.Dashboard/Pages/Namespaces/List/View.razor

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,16 @@
9595
/// Opens the targeted <see cref="Resource"/>'s edition
9696
/// </summary>
9797
/// <param name="resource">The <see cref="Resource"/> to edit</param>
98-
protected override Task OnShowResourceEditorAsync(Namespace? resource = null)
98+
protected override async Task OnShowResourceEditorAsync(Namespace? resource = null)
9999
{
100-
if (this.EditorOffCanvas == null) return Task.CompletedTask;
100+
if (this.EditorOffCanvas == null) return;
101101
var parameters = new Dictionary<string, object>
102102
{
103103
{ nameof(ResourceEditor<Namespace>.Resource), resource! },
104104
{ nameof(ResourceEditor<Namespace>.IsCluster), true }
105105
};
106106
string actionType = resource == null ? "creation" : "edition";
107-
return this.EditorOffCanvas.ShowAsync<ResourceEditor<Namespace>>(title: typeof(Namespace).Name + " " + actionType, parameters: parameters);
107+
await this.EditorOffCanvas.ShowAsync<ResourceEditor<Namespace>>(title: typeof(Namespace).Name + " " + actionType);
108+
await this.EditorOffCanvas.ShowAsync<ResourceEditor<Namespace>>(title: typeof(Namespace).Name + " " + actionType, parameters: parameters);
108109
}
109110
}

src/dashboard/Synapse.Dashboard/StatefulComponent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ protected override async Task OnInitializedAsync()
6161
/// Patches the component fields after a change
6262
/// </summary>
6363
/// <param name="patch">The patch to apply</param>
64-
protected void OnStateChanged(Action<TComponent> patch)
64+
protected void OnStateChanged(Action<TComponent>? patch = null)
6565
{
66-
patch((TComponent)this);
66+
if (patch != null) patch((TComponent)this);
6767
this.shouldRender = true;
6868
this.StateHasChanged();
6969
}

0 commit comments

Comments
 (0)