Skip to content

Commit 595d5ed

Browse files
committed
feat(Dashboard): added operator filtering in workflows
Signed-off-by: Jean-Baptiste Bianchi <[email protected]>
1 parent aad8c3b commit 595d5ed

File tree

21 files changed

+454
-73
lines changed

21 files changed

+454
-73
lines changed

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
}
3737
}
3838
</div>
39-
<Button Color="ButtonColor.Primary" Outline="true" Disabled="updating || saving" Loading="saving" @onclick="async _ => await Store.SubmitResourceAsync()">
39+
<Button Color="ButtonColor.Primary" Outline="true" Disabled="isUpdating || isSaving" Loading="isSaving" @onclick="async _ => await Store.SubmitResourceAsync()">
4040
@if (resource?.Metadata?.Generation == null || resource?.Metadata?.Generation == 0)
4141
{
4242
<span>Create</span>
@@ -57,6 +57,12 @@
5757
/// </summary>
5858
[Parameter] public TResource? Resource { get; set; }
5959

60+
bool isCluster = false;
61+
/// <summary>
62+
/// Gets/sets a boolean indicating the resource is a cluster
63+
/// </summary>
64+
[Parameter] public bool IsCluster { get; set; } = false;
65+
6066
/// <summary>
6167
/// The reference of the <see cref="StandaloneCodeEditor" />
6268
/// </summary>
@@ -80,12 +86,12 @@
8086
/// <summary>
8187
/// A boolean indicating if the text editor is being updated
8288
/// </summary>
83-
private bool updating = false;
89+
private bool isUpdating = false;
8490

8591
/// <summary>
8692
/// A boolean indicating if the resource is being saved
8793
/// </summary>
88-
private bool saving = false;
94+
private bool isSaving = false;
8995

9096
/// <summary>
9197
/// The <see cref="ProblemDetails"/> that occurred when trying to save the resource, if any
@@ -97,8 +103,8 @@
97103
{
98104
await base.OnInitializedAsync().ConfigureAwait(false);
99105
this.Store.Resource.Subscribe(resource => this.OnStateChanged(cmp => cmp.resource = resource), token: this.CancellationTokenSource.Token);
100-
this.Store.Updating.Subscribe(updating => this.OnStateChanged(cmp => cmp.updating = updating), token: this.CancellationTokenSource.Token);
101-
this.Store.Saving.Subscribe(OnSavingChanged, token: this.CancellationTokenSource.Token);
106+
this.Store.IsUpdating.Subscribe(updating => this.OnStateChanged(cmp => cmp.isUpdating = updating), token: this.CancellationTokenSource.Token);
107+
this.Store.IsSaving.Subscribe(OnSavingChanged, token: this.CancellationTokenSource.Token);
102108
this.Store.ProblemDetails.Subscribe(problemDetails => this.OnStateChanged(cmp => cmp.problemDetails = problemDetails), token: this.CancellationTokenSource.Token);
103109
this.textEditorInput
104110
.Throttle(TimeSpan.FromMilliseconds(300))
@@ -119,6 +125,11 @@
119125
this.resource = this.Resource; // should happen in this.Store.Resource.Subscribe but prevents possible race when multiple params are set
120126
this.Store.SetResource(this.Resource);
121127
}
128+
if (this.isCluster != this.IsCluster)
129+
{
130+
this.isCluster = this.IsCluster;
131+
this.Store.SetIsCluster(this.IsCluster);
132+
}
122133
return base.OnParametersSetAsync();
123134
}
124135

@@ -128,7 +139,7 @@
128139
/// <param name="saving">Whenever the resource is in a saving state</param>
129140
private void OnSavingChanged(bool saving)
130141
{
131-
this.saving = saving;
142+
this.isSaving = saving;
132143
if (this.textBasedEditor != null) this.textBasedEditor.UpdateOptions(new EditorUpdateOptions() { ReadOnly = saving });
133144
this.StateHasChanged();
134145
}
@@ -161,7 +172,7 @@
161172
/// <returns>A <see cref="Task"/></returns>
162173
private async Task OnTextBasedValueChanged(ModelContentChangedEvent e)
163174
{
164-
if (!this.updating && this.textBasedEditor != null && this.textEditorInput != null)
175+
if (!this.isUpdating && this.textBasedEditor != null && this.textEditorInput != null)
165176
{
166177
var text = await this.textBasedEditor.GetValue();
167178
this.textEditorInput.OnNext(text);

src/dashboard/Synapse.Dashboard/Components/ResourceEditor/State.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,20 @@ public record ResourceEditorState<TResource>
3535
/// </summary>
3636
public string TextEditorValue { get; set; } = string.Empty;
3737

38+
/// <summary>
39+
/// Gets/sets a boolean indicating if the resource is a cluster
40+
/// </summary>
41+
public bool IsCluster { get; set; } = false;
42+
3843
/// <summary>
3944
/// Gets/sets a boolean indicating if the text editor is being updated
4045
/// </summary>
41-
public bool Updating { get; set; } = false;
46+
public bool IsUpdating { get; set; } = false;
4247

4348
/// <summary>
4449
/// Gets/sets a boolean indicating if the resource is being saved
4550
/// </summary>
46-
public bool Saving { get; set; } = false;
51+
public bool IsSaving { get; set; } = false;
4752

4853
/// <summary>
4954
/// Gets/sets the <see cref="ProblemDetails"/> type that occurred when trying to save the resource, if any

src/dashboard/Synapse.Dashboard/Components/ResourceEditor/Store.cs

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
using Neuroglia.Data;
1616
using Neuroglia.Serialization.Yaml;
1717
using Synapse.Api.Client.Services;
18-
using System.Reactive.Linq;
1918

2019
namespace Synapse.Dashboard.Components.ResourceEditorStateManagement;
2120

@@ -50,14 +49,19 @@ public class ResourceEditorStore<TResource>(ISynapseApiClient apiClient, IMonaco
5049
public IObservable<string> TextEditorValue => this.Select(state => state.TextEditorValue).DistinctUntilChanged();
5150

5251
/// <summary>
53-
/// Gets an <see cref="IObservable{T}"/> used to observe <see cref="ResourceEditorState{TResource}.Updating"/> changes
52+
/// Gets an <see cref="IObservable{T}"/> used to observe <see cref="ResourceEditorState{TResource}.IsCluster"/> changes
5453
/// </summary>
55-
public IObservable<bool> Updating => this.Select(state => state.Updating).DistinctUntilChanged();
54+
public IObservable<bool> IsCluster => this.Select(state => state.IsCluster).DistinctUntilChanged();
5655

5756
/// <summary>
58-
/// Gets an <see cref="IObservable{T}"/> used to observe <see cref="ResourceEditorState{TResource}.Saving"/> changes
57+
/// Gets an <see cref="IObservable{T}"/> used to observe <see cref="ResourceEditorState{TResource}.IsUpdating"/> changes
5958
/// </summary>
60-
public IObservable<bool> Saving => this.Select(state => state.Saving).DistinctUntilChanged();
59+
public IObservable<bool> IsUpdating => this.Select(state => state.IsUpdating).DistinctUntilChanged();
60+
61+
/// <summary>
62+
/// Gets an <see cref="IObservable{T}"/> used to observe <see cref="ResourceEditorState{TResource}.IsSaving"/> changes
63+
/// </summary>
64+
public IObservable<bool> IsSaving => this.Select(state => state.IsSaving).DistinctUntilChanged();
6165

6266
/// <summary>
6367
/// Gets an <see cref="IObservable{T}"/> used to observe <see cref="ResourceEditorState{TResource}.ProblemType"/> changes
@@ -166,26 +170,38 @@ public void SetEditorValue(string textEditorValue)
166170
}
167171

168172
/// <summary>
169-
/// Sets the state's <see cref="ResourceEditorState{TResource}.Updating"/>
173+
/// Sets the state's <see cref="ResourceEditorState{TResource}.IsUpdating"/>
174+
/// </summary>
175+
/// <param name="isUpdating">The new <see cref="ResourceEditorState{TResource}.IsUpdating"/> value</param>
176+
public void SetUpdating(bool isUpdating)
177+
{
178+
this.Reduce(state => state with
179+
{
180+
IsUpdating = isUpdating
181+
});
182+
}
183+
184+
/// <summary>
185+
/// Sets the state's <see cref="ResourceEditorState{TResource}.IsCluster"/>
170186
/// </summary>
171-
/// <param name="updating">The new <see cref="ResourceEditorState{TResource}.Updating"/> value</param>
172-
public void SetUpdating(bool updating)
187+
/// <param name="isCluster">The new <see cref="ResourceEditorState{TResource}.IsCluster"/> value</param>
188+
public void SetIsCluster(bool isCluster)
173189
{
174190
this.Reduce(state => state with
175191
{
176-
Updating = updating
192+
IsCluster = isCluster
177193
});
178194
}
179195

180196
/// <summary>
181-
/// Sets the state's <see cref="ResourceEditorState{TResource}.Saving"/>
197+
/// Sets the state's <see cref="ResourceEditorState{TResource}.IsSaving"/>
182198
/// </summary>
183-
/// <param name="saving">The new <see cref="ResourceEditorState{TResource}.Saving"/> value</param>
184-
public void SetSaving(bool saving)
199+
/// <param name="isSaving">The new <see cref="ResourceEditorState{TResource}.IsSaving"/> value</param>
200+
public void SetSaving(bool isSaving)
185201
{
186202
this.Reduce(state => state with
187203
{
188-
Saving = saving
204+
IsSaving = isSaving
189205
});
190206
}
191207

@@ -258,7 +274,11 @@ public async Task CreateResourceAsync()
258274
try
259275
{
260276
resource = jsonSerializer.Deserialize<TResource>(textEditorValue);
261-
resource = await apiClient.ManageNamespaced<TResource>().CreateAsync(resource!, this.CancellationTokenSource.Token);
277+
var isCluster = this.Get(state => state.IsCluster);
278+
resource = await (!isCluster ?
279+
apiClient.ManageNamespaced<TResource>().CreateAsync(resource!, this.CancellationTokenSource.Token) :
280+
apiClient.ManageCluster<TResource>().CreateAsync(resource!, this.CancellationTokenSource.Token)
281+
);
262282
this.SetResource(resource);
263283
}
264284
catch (ProblemDetailsException ex)
@@ -294,7 +314,11 @@ public async Task UpdateResourceAsync()
294314
var resourcePatch = new Patch(PatchType.JsonPatch, jsonPatch);
295315
try
296316
{
297-
resource = await apiClient.ManageNamespaced<TResource>().PatchAsync(resource.GetName(), resource.GetNamespace()!, resourcePatch, null, this.CancellationTokenSource.Token);
317+
var isCluster = this.Get(state => state.IsCluster);
318+
resource = await (!isCluster ?
319+
apiClient.ManageNamespaced<TResource>().PatchAsync(resource.GetName(), resource.GetNamespace()!, resourcePatch, null, this.CancellationTokenSource.Token) :
320+
apiClient.ManageCluster<TResource>().PatchAsync(resource.GetName(), resourcePatch, null, this.CancellationTokenSource.Token)
321+
);
298322
this.SetResource(resource);
299323
}
300324
catch(ProblemDetailsException ex)

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,38 @@ public override async Task DeleteResourceAsync(TResource resource)
3636
await this.ApiClient.ManageCluster<TResource>().DeleteAsync(resource.GetName()).ConfigureAwait(false);
3737
}
3838

39+
/// <inheritdoc/>
40+
public override async Task GetResourceDefinitionAsync()
41+
{
42+
var resourceDefinition = await this.ApiClient.ManageCluster<TResource>().GetDefinitionAsync().ConfigureAwait(false);
43+
this.Reduce(s => s with
44+
{
45+
Definition = resourceDefinition
46+
});
47+
}
48+
49+
/// <inheritdoc/>
50+
public override async Task ListResourcesAsync(ResourcesFilter? filter = null)
51+
{
52+
try
53+
{
54+
this.Reduce(state => state with
55+
{
56+
Loading = true,
57+
});
58+
var resourceList = new EquatableList<TResource>(await (await this.ApiClient.ManageCluster<TResource>().ListAsync(filter?.LabelSelectors).ConfigureAwait(false)).OrderBy(r => r.Metadata.CreationTimestamp).ToListAsync().ConfigureAwait(false));
59+
this.Reduce(s => s with
60+
{
61+
Resources = resourceList,
62+
Loading = false
63+
});
64+
}
65+
catch (Exception ex)
66+
{
67+
Console.WriteLine(ex.ToString());
68+
// todo: implement proper error handling
69+
}
70+
}
71+
72+
3973
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ public record NamespacedResourceManagementComponentState<TResource>
2323
{
2424

2525
/// <summary>
26-
/// Gets a <see cref="List{T}"/> that contains all cached <see cref="Neuroglia.Data.Infrastructure.ResourceOriented.Namespace"/>s
26+
/// Gets a <see cref="EquatableList{T}"/> that contains all <see cref="Neuroglia.Data.Infrastructure.ResourceOriented.Namespace"/>s
2727
/// </summary>
2828
public EquatableList<Namespace>? Namespaces { get; set; }
2929

3030
/// <summary>
31-
/// Gets the <see cref="Neuroglia.Data.Infrastructure.ResourceOriented.Namespace"/>, if any, the (namespaced) resources to list belong to
31+
/// Gets the <see cref="Neuroglia.Data.Infrastructure.ResourceOriented.Namespace"/> the (namespaced) resources to list belong to, if any
3232
/// </summary>
3333
public string? Namespace { get; set; }
3434

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ protected Task OnShowResourceDetailsAsync(TResource resource)
227227
if (this.DetailsOffCanvas == null) return Task.CompletedTask;
228228
var parameters = new Dictionary<string, object>
229229
{
230-
{ "Resource", resource }
230+
{ nameof(ResourceEditor<TResource>.Resource), resource }
231231
};
232232
return this.DetailsOffCanvas.ShowAsync<ResourceDetails<TResource>>(title: typeof(TResource).Name + " details", parameters: parameters);
233233
}
@@ -236,12 +236,12 @@ protected 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 Task OnShowResourceEditorAsync(TResource? resource = null)
239+
protected virtual Task OnShowResourceEditorAsync(TResource? resource = null)
240240
{
241241
if (this.EditorOffCanvas == null) return Task.CompletedTask;
242242
var parameters = new Dictionary<string, object>
243243
{
244-
{ "Resource", resource! }
244+
{ nameof(ResourceEditor<TResource>.Resource), resource! }
245245
};
246246
string actionType = resource == null ? "creation" : "edition";
247247
return this.EditorOffCanvas.ShowAsync<ResourceEditor<TResource>>(title: typeof(TResource).Name + " " + actionType, parameters: parameters);

0 commit comments

Comments
 (0)