Skip to content

Commit

Permalink
feat(Dashboard): added capability to replay a workflow with the same …
Browse files Browse the repository at this point in the history
…input

Signed-off-by: Jean-Baptiste Bianchi <jb.bianchi@neuroglia.io>
  • Loading branch information
JBBianchi committed Oct 23, 2024
1 parent c6b75bb commit e8ca80c
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public async Task OnCopyToClipboard()
try
{
await this.JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", text);
this.ToastService.Notify(new(ToastType.Success, "Definition copied to the clipboard!"));
this.ToastService.Notify(new(ToastType.Success, "Copied to the clipboard!"));
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public async Task OnCopyToClipboard()
try
{
await this.JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", text);
this.ToastService.Notify(new(ToastType.Success, "Definition copied to the clipboard!"));
this.ToastService.Notify(new(ToastType.Success, "Copied to the clipboard!"));
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
try
{
await this.JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", text);
this.ToastService.Notify(new(ToastType.Success, "Definition copied to the clipboard!"));
this.ToastService.Notify(new(ToastType.Success, "Copied to the clipboard!"));
}
catch (Exception ex)

Check warning on line 261 in src/dashboard/Synapse.Dashboard/Components/ResourceEditor/ResourceEditor.razor

View workflow job for this annotation

GitHub Actions / build (8.0.x)

The variable 'ex' is declared but never used

Check warning on line 261 in src/dashboard/Synapse.Dashboard/Components/ResourceEditor/ResourceEditor.razor

View workflow job for this annotation

GitHub Actions / build (8.0.x)

The variable 'ex' is declared but never used
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@inject MonacoInterop MonacoInterop
@inject IJsonSerializer Serializer

<MonacoEditor OnTextChanged="OnTextChanged" ModelName="@modelName" />
<MonacoEditor OnTextChanged="OnTextChanged" ModelName="@modelName" Document="input" />
<div class="text-center">
<Button Outline="true" Color="ButtonColor.Primary" class="m-auto mt-3" @onclick="async (_) => await OnStart()">
<Icon Name="IconName.Play" />
Expand All @@ -30,8 +30,10 @@
@code {
string payload = string.Empty;
string modelName = string.Empty;
EquatableDictionary<string, object>? input;

[Parameter] public WorkflowDefinition? WorkflowDefinition { get; set; }
[Parameter] public EquatableDictionary<string, object>? Input { get; set; }
[Parameter] public EventCallback<string> OnCreate { get; set; }

void OnTextChanged(string value)
Expand All @@ -50,12 +52,15 @@
protected override async Task OnParametersSetAsync()
{
await base.OnParametersSetAsync();
if (this.WorkflowDefinition?.Input?.Schema?.Document != null)
if (Input != input)
{
modelName = this.WorkflowDefinition.Document.Name + "-" + this.WorkflowDefinition.Document.Version;
await this.MonacoInterop.AddValidationSchemaAsync(this.Serializer.SerializeToText(this.WorkflowDefinition.Input.Schema.Document), $"https://synapse.io/schemas/{modelName}.json", $"{modelName}*").ConfigureAwait(false);
}

input = Input;
}
if (WorkflowDefinition?.Input?.Schema?.Document != null)
{
modelName = WorkflowDefinition.Document.Name + "-" + WorkflowDefinition.Document.Version;
await MonacoInterop.AddValidationSchemaAsync(Serializer.SerializeToText(WorkflowDefinition.Input.Schema.Document), $"https://synapse.io/schemas/{modelName}.json", $"{modelName}*").ConfigureAwait(false);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@
</ul>
</div>
break;
case "Replay":
<button class="btn btn-sm text-primary" @onclick="async _ => await OnReplayClickedAsync(instance)" @onclick:stopPropagation="true"><Icon Name="IconName.ArrowClockwise" /></button>
break;
case "Delete":
<button class="btn btn-sm text-danger" @onclick="async _ => await OnDeleteClickedAsync(instance)" @onclick:stopPropagation="true"><Icon Name="IconName.Trash" /></button>
break;
Expand Down Expand Up @@ -204,6 +207,7 @@
[Parameter] public EventCallback<WorkflowInstance> OnShowDetails { get; set; }
[Parameter] public EventCallback<string?> OnToggleSelected { get; set; }
[Parameter] public EventCallback<WorkflowInstance> OnDelete { get; set; }
[Parameter] public EventCallback<WorkflowInstance> OnReplay { get; set; }
[Parameter] public EventCallback OnDeleteSelected { get; set; }

IEnumerable<string> knownColumns = [
Expand All @@ -217,6 +221,7 @@
"Duration",
"Operator",
"Actions",
"Replay",
"Delete"
];

Expand Down Expand Up @@ -391,7 +396,7 @@
}

/// <summary>
/// Handles the clikc on the delete button
/// Handles the click on the delete button
/// </summary>
/// <param name="instance"></param>
/// <returns></returns>
Expand All @@ -402,4 +407,17 @@
await this.OnDelete.InvokeAsync(instance);
}
}

/// <summary>
/// Handles the click on the replay button
/// </summary>
/// <param name="instance"></param>
/// <returns></returns>
protected async Task OnReplayClickedAsync(WorkflowInstance instance)
{
if (this.OnReplay.HasDelegate)
{
await this.OnReplay.InvokeAsync(instance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,10 @@ async Task SetTextEditorValueAsync()
{
return;
}
await this.TextEditor.SetValue(document);
try
{
await this.TextEditor.SetValue(document);
await Task.Delay(10);
await this.TextEditor.Trigger("", "editor.action.formatDocument");
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,10 @@ async Task SetTextEditorValueAsync()
{
return;
}
await this.TextEditor.SetValue(document);
try
{
await this.TextEditor.SetValue(document);
await Task.Delay(10);
await this.TextEditor.Trigger("", "editor.action.formatDocument");
}
catch (Exception ex)
Expand All @@ -357,6 +358,7 @@ async Task SetTextEditorValueAsync()
public async Task OnDidChangeModelContent(ModelContentChangedEvent e)
{
if (this.TextEditor == null) return;

var document = await this.TextEditor.GetValue();
this.Reduce(state => state with
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public async Task OnCopyToClipboard()
try
{
await this.JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", text);
this.ToastService.Notify(new(ToastType.Success, "Definition copied to the clipboard!"));
this.ToastService.Notify(new(ToastType.Success, "Copied to the clipboard!"));
}
catch (Exception ex)
{
Expand All @@ -322,13 +322,14 @@ public async Task OnCopyToClipboard()
/// Displays the modal used to provide the new workflow input
/// </summary>
/// <returns>A awaitable task</returns>
public async Task OnShowCreateInstanceAsync(WorkflowDefinition workflowDefinition)
public async Task OnShowCreateInstanceAsync(WorkflowDefinition workflowDefinition, EquatableDictionary<string, object>? input = null)
{
if (this.Modal != null)
{
var parameters = new Dictionary<string, object>
{
{ nameof(WorkflowInstanceCreation.WorkflowDefinition), workflowDefinition },
{ nameof(WorkflowInstanceCreation.Input), input! },
{ nameof(WorkflowInstanceCreation.OnCreate), EventCallback.Factory.Create<string>(this, CreateInstanceAsync) }
};
await this.Modal.ShowAsync<WorkflowInstanceCreation>(title: "Start a new worklfow", parameters: parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
OnSearchInput="Store.SetSearchTerm"
OnShowDetails="OnShowInstanceDetails"
OnDelete="OnDeleteWorkflowInstanceAsync"
OnReplay="async instance => await Store.OnShowCreateInstanceAsync(workflowDefinition, instance.Spec?.Input)"
OnToggleSelected="Store.ToggleResourceSelection"
OnDeleteSelected="OnDeleteSelectedResourcesAsync" />
<Button Outline="true" Color="ButtonColor.Primary" @onclick="async _ => await Store.OnShowCreateInstanceAsync(workflowDefinition)" class="w-100 mt-3">
Expand Down Expand Up @@ -126,6 +127,7 @@
"Status",
"Start Time",
"End Time",
"Replay",
"Delete"
];

Expand Down

0 comments on commit e8ca80c

Please sign in to comment.