Skip to content

Commit

Permalink
feat(Dashboard): enabled custom functions and service accounts edition
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Baptiste Bianchi <[email protected]>
  • Loading branch information
JBBianchi committed Oct 21, 2024
1 parent 1eda1a4 commit 25693f3
Show file tree
Hide file tree
Showing 13 changed files with 1,140 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public static class Breadcrumbs
/// </summary>
public static BreadcrumbItem[] Correlations = [new("Correlations", "/correlations")];
/// <summary>
/// Holds the breadcrumb items for <see cref="ServiceAccount"/> related routes
/// </summary>
public static BreadcrumbItem[] ServiceAccounts = [new("Service Accounts", "/service-accounts")];
/// <summary>
/// Holds the breadcrumb items for about related routes
/// </summary>
public static BreadcrumbItem[] About = [new("About", "/about")];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
@*
Copyright © 2024-Present The Synapse Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*@

@namespace Synapse.Dashboard.Components

@if (resource != null)
{

<div class="container-fluid">
<div class="row">
<table class="table mb-3">
<tbody>
<tr>
<td>API Version</td>
<td>@resource.ApiVersion</td>
</tr>
<tr>
<td>Kind</td>
<td>@resource.Kind</td>
</tr>
<tr>
<td>Name</td>
<td>@resource.GetName()</td>
</tr>
@if (resource.IsNamespaced() == true)
{
<tr>
<td>Namespace</td>
<td>@resource.GetNamespace()</td>
</tr>
}
<tr>
<td>Creation Time</td>
<td>@resource.Metadata.CreationTimestamp?.ToString("R")</td>
</tr>
<tr>
<td>Generation</td>
<td>@resource.Metadata.Generation</td>
</tr>
@if (resource.Metadata.Labels?.Any() == true)
{
<tr>
<td>Labels</td>
<td>
@foreach (var label in resource.Metadata.Labels)
{
<span class="badge bg-primary text-dark m-1">@label.Key: @label.Value</span>
}
</td>
</tr>
}
<tr>
<td>Latest version</td>
<td>@resource.Spec.Versions.GetLatestVersion()</td>
</tr>
<tr>
<td colspan="2">
Latest definition
<br />
<MonacoEditor Document="resource.Spec.Versions.GetLatest()" IsReadOnly="true" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
}

@code {

CustomFunction? resource;
/// <summary>
/// Gets/sets the resource to display details about
/// </summary>
[Parameter] public CustomFunction? Resource { get; set; }

/// <inheritdoc/>
protected override Task OnParametersSetAsync()
{
if(this.resource != this.Resource)
{
this.resource = this.Resource;
}
return base.OnParametersSetAsync();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void SetNamespace(string? @namespace)
/// Lists all available <see cref="Namespace"/>s
/// </summary>
/// <returns>A new awaitable <see cref="Task"/></returns>
public virtual async Task ListNamespaceAsync()
public virtual async Task ListNamespacesAsync()
{
var namespaceList = new EquatableList<Namespace>(await (await this.ApiClient.Namespaces.ListAsync().ConfigureAwait(false)).OrderBy(ns => ns.GetQualifiedName()).ToListAsync().ConfigureAwait(false));
this.Reduce(s => s with
Expand All @@ -85,7 +85,7 @@ public override async Task DeleteResourceAsync(TResource resource)
/// <inheritdoc/>
public override async Task InitializeAsync()
{
await this.ListNamespaceAsync().ConfigureAwait(false);
await this.ListNamespacesAsync().ConfigureAwait(false);
await base.InitializeAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class ResourceManagementComponent<TComponent, TStore, TState, TR
/// Gets/sets the service used for JS interop
/// </summary>
[Inject]
protected JSInterop jsInterop { get; set; } = default!;
protected JSInterop JsInterop { get; set; } = default!;

/// <summary>
/// Gets the service used to serialize/deserialize objects to/from JSON
Expand Down Expand Up @@ -118,15 +118,15 @@ protected override async Task OnInitializedAsync()
if (selectedResourceNames.Count == 0)
{
await this.jsInterop.SetCheckboxStateAsync(this.CheckboxAll.Value, CheckboxState.Unchecked);
await this.JsInterop.SetCheckboxStateAsync(this.CheckboxAll.Value, CheckboxState.Unchecked);
}
else if (selectedResourceNames.Count == (resources?.Count ?? 0))
{
await this.jsInterop.SetCheckboxStateAsync(this.CheckboxAll.Value, CheckboxState.Checked);
await this.JsInterop.SetCheckboxStateAsync(this.CheckboxAll.Value, CheckboxState.Checked);
}
else
{
await this.jsInterop.SetCheckboxStateAsync(this.CheckboxAll.Value, CheckboxState.Indeterminate);
await this.JsInterop.SetCheckboxStateAsync(this.CheckboxAll.Value, CheckboxState.Indeterminate);
}
}
}, cancellationToken: this.CancellationTokenSource.Token);
Expand Down Expand Up @@ -222,12 +222,12 @@ protected async Task OnDeleteSelectedResourcesAsync()
/// Opens the targeted <see cref="Resource"/>'s details
/// </summary>
/// <param name="resource">The <see cref="Resource"/> to show the details for</param>
protected Task OnShowResourceDetailsAsync(TResource resource)
protected virtual Task OnShowResourceDetailsAsync(TResource resource)
{
if (this.DetailsOffCanvas == null) return Task.CompletedTask;
var parameters = new Dictionary<string, object>
{
{ nameof(ResourceEditor<TResource>.Resource), resource }
{ nameof(ResourceDetails<TResource>.Resource), resource }
};
return this.DetailsOffCanvas.ShowAsync<ResourceDetails<TResource>>(title: typeof(TResource).Name + " details", parameters: parameters);
}
Expand Down
7 changes: 6 additions & 1 deletion src/dashboard/Synapse.Dashboard/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</li>
<li class="nav-item">
<div class="dropdown">
<button class="btn nav-link dropdown-toggle @(IsActive("correlators", NavLinkMatch.Prefix) || IsActive("operators", NavLinkMatch.Prefix) ? "active" : "")" type="button" id="servicesDropdownButton" data-bs-toggle="dropdown" aria-expanded="false">
<button class="btn nav-link dropdown-toggle @(IsActive("correlators", NavLinkMatch.Prefix) || IsActive("operators", NavLinkMatch.Prefix) || IsActive("service-accounts", NavLinkMatch.Prefix) ? "active" : "")" type="button" id="servicesDropdownButton" data-bs-toggle="dropdown" aria-expanded="false">
<span class="btn-label">Services</span>
</button>
<ul class="dropdown-menu" aria-labelledby="servicesDropdownButton">
Expand All @@ -75,6 +75,11 @@
<span class="btn-label">Operators</span>
</NavLink>
</li>
<li>
<NavLink class="nav-link" href="service-accounts" Match="NavLinkMatch.All">
<span class="btn-label">Serivce Accounts</span>
</NavLink>
</li>
</ul>
</div>
</li>
Expand Down
106 changes: 106 additions & 0 deletions src/dashboard/Synapse.Dashboard/Pages/Functions/Create/State.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright © 2024-Present The Synapse Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"),
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Semver;
using ServerlessWorkflow.Sdk.Models;
using Synapse.Resources;

namespace Synapse.Dashboard.Pages.Functions.Create;

/// <summary>
/// The <see cref="State{TState}"/> of the workflow editor
/// </summary>
[Feature]
public record CreateFunctionViewState
{
/// <summary>
/// Gets a <see cref="EquatableList{T}"/> that contains all <see cref="Neuroglia.Data.Infrastructure.ResourceOriented.Namespace"/>s
/// </summary>
public EquatableList<Namespace>? Namespaces { get; set; }

/// <summary>
/// Gets/sets the <see cref="CustomFunction"/>'s namespace
/// </summary>
public string? Namespace { get; set; }

/// <summary>
/// Gets/sets the <see cref="CustomFunction"/>'s name
/// </summary>
public string? Name { get; set; }

/// <summary>
/// Gets/sets the <see cref="CustomFunction"/>'s namespace, when the user is creating one
/// </summary>
public string? ChosenNamespace { get; set; }

/// <summary>
/// Gets/sets the <see cref="CustomFunction"/>'s name, when the user is creating one
/// </summary>
public string? ChosenName { get; set; }

/// <summary>
/// Gets/sets the function text representation
/// </summary>
public SemVersion Version { get; set; } = new SemVersion(1, 0, 0);

/// <summary>
/// Gets/sets the definition of the workflow to create
/// </summary>
public TaskDefinition? Function { get; set; } = null;

/// <summary>
/// Gets/sets the function text representation
/// </summary>
public string? FunctionText { get; set; }

/// <summary>
/// Gets/sets a boolean indicating whether or not the state is being loaded
/// </summary>
public bool Loading { get; set; } = false;

/// <summary>
/// Defines if the function is being updated
/// </summary>
public bool Updating { get; set; } = false;

/// <summary>
/// Defines if the function is being saved
/// </summary>
public bool Saving { get; set; } = false;

/// <summary>
/// Gets/sets the <see cref="ProblemDetails"/> type that occurred when trying to save the resource, if any
/// </summary>
public Uri? ProblemType { get; set; } = null;

/// <summary>
/// Gets/sets the <see cref="ProblemDetails"/> title that occurred when trying to save the resource, if any
/// </summary>
public string ProblemTitle { get; set; } = string.Empty;

/// <summary>
/// Gets/sets the <see cref="ProblemDetails"/> details that occurred when trying to save the resource, if any
/// </summary>
public string ProblemDetail { get; set; } = string.Empty;

/// <summary>
/// Gets/sets the <see cref="ProblemDetails"/> status that occurred when trying to save the resource, if any
/// </summary>
public int ProblemStatus { get; set; } = 0;

/// <summary>
/// Gets/sets the list of <see cref="ProblemDetails"/> errors that occurred when trying to save the resource, if any
/// </summary>
public IDictionary<string, string[]> ProblemErrors { get; set; } = new Dictionary<string, string[]>();

}
Loading

0 comments on commit 25693f3

Please sign in to comment.