From 483509284a645e8e25930f4f8452f3370c1e8cde Mon Sep 17 00:00:00 2001 From: JBBianchi Date: Tue, 25 Jun 2024 17:40:02 +0200 Subject: [PATCH] fix(Dashboard): fixed "latest" version handling in workflow details view Signed-off-by: Jean-Baptiste Bianchi --- .../Synapse.Cli/Sample/workflow-fake-2.yaml | 165 ++++++++++++++++++ src/cli/Synapse.Cli/Sample/workflow-fake.yaml | 165 ++++++++++++++++++ .../Pages/Workflows/Details/Store.cs | 20 ++- .../Pages/Workflows/Details/View.razor | 16 +- 4 files changed, 356 insertions(+), 10 deletions(-) create mode 100644 src/cli/Synapse.Cli/Sample/workflow-fake-2.yaml create mode 100644 src/cli/Synapse.Cli/Sample/workflow-fake.yaml diff --git a/src/cli/Synapse.Cli/Sample/workflow-fake-2.yaml b/src/cli/Synapse.Cli/Sample/workflow-fake-2.yaml new file mode 100644 index 000000000..aba12175b --- /dev/null +++ b/src/cli/Synapse.Cli/Sample/workflow-fake-2.yaml @@ -0,0 +1,165 @@ +document: + dsl: '0.10' + namespace: default + name: fake-name + version: '0.2.0' + title: Fake Title + summary: Fake MD summary + tags: + fakeTagName: fakeTagValue +use: + authentications: + fakeBasic: + basic: + username: fake-user + password: fake-password + fakeBearer: + bearer: + token: fake-token + fakeOAuth2: + oauth2: + authority: https://fake-authority.com/ + grant: client_credentials + client: + id: fake-client-id + secret: fake-client-secret + extensions: + fakeLoggingExtension: + extend: all + when: fake-expression + before: + - fake-http-call: + call: http + with: + method: post + uri: https://fake.log.collector.com + body: + message: ${ "Executing task '\($task.reference)'..." } + after: + - fake-http-call: + call: http + with: + method: post + uri: https://fake.log.collector.com + body: + message: ${ "Executed task '\($task.reference)'..." } + functions: + fakeFunction1: + call: http + with: + method: post + uri: https://test.com + fakeFunction2: + run: + shell: + command: echo "Hello, World!" + secrets: + - fake-secret +do: +- todo-1: + call: http + with: + method: get + uri: https://unit-tests.serverlessworkflow.io +- todo-2: + emit: + event: + with: + type: io.serverlessworkflow.unit-tests.fake.event.type.v1 +- todo-3: + for: + each: color + in: .colors + at: index + do: + - fake-http-call: + set: + processed: .processed + [$color] +- todo-4: + listen: + to: + any: + - with: + foo: bar + - with: + foo: bar + bar: baz +- todo-5: + raise: + error: + type: fake-error-type + title: fake-error-title + status: "400" +- todo-6: + run: + container: + image: fake-image:latest + command: fake command --arg1 arg1 + environment: + ASPNET_ENVIRONMENT: Development +- todo-7: + run: + shell: + command: fake command --arg1 arg1 + arguments: + - --arg2 arg2 + environment: + ASPNET_ENVIRONMENT: Development +- todo-8: + run: + script: + language: js + code: console.log("Hello, World!") +- todo-9: + run: + workflow: + namespace: default + name: fake-workflow + version: '1.0.0' + input: + foo: bar +- todo-10: + set: + foo: bar + bar: + baz: foo +- todo-11: + switch: + - case-1: + when: fake-condition + then: continue + - case-2: + when: another-fake-condition + then: exit + - default: + then: end +- todo-12: + try: + - setFoo: + set: + foo: bar + catch: {} +- todo-13: + wait: + minutes: 5 +- todo-14: + do: + - todo-14-1: + call: http + with: + method: get + uri: https://unit-tests.serverlessworkflow.io + - todo-14-2: + emit: + event: + with: + type: io.serverlessworkflow.unit-tests.fake.event.type.v1 + - todo-14-3: + for: + each: color + in: .colors + at: index + do: + - setProcessed: + set: + processed: .processed + [$color] \ No newline at end of file diff --git a/src/cli/Synapse.Cli/Sample/workflow-fake.yaml b/src/cli/Synapse.Cli/Sample/workflow-fake.yaml new file mode 100644 index 000000000..68b2255ee --- /dev/null +++ b/src/cli/Synapse.Cli/Sample/workflow-fake.yaml @@ -0,0 +1,165 @@ +document: + dsl: '0.10' + namespace: default + name: fake-name + version: '0.1.0' + title: Fake Title + summary: Fake MD summary + tags: + fakeTagName: fakeTagValue +use: + authentications: + fakeBasic: + basic: + username: fake-user + password: fake-password + fakeBearer: + bearer: + token: fake-token + fakeOAuth2: + oauth2: + authority: https://fake-authority.com/ + grant: client_credentials + client: + id: fake-client-id + secret: fake-client-secret + extensions: + fakeLoggingExtension: + extend: all + when: fake-expression + before: + - fake-http-call: + call: http + with: + method: post + uri: https://fake.log.collector.com + body: + message: ${ "Executing task '\($task.reference)'..." } + after: + - fake-http-call: + call: http + with: + method: post + uri: https://fake.log.collector.com + body: + message: ${ "Executed task '\($task.reference)'..." } + functions: + fakeFunction1: + call: http + with: + method: post + uri: https://test.com + fakeFunction2: + run: + shell: + command: echo "Hello, World!" + secrets: + - fake-secret +do: +- todo-1: + call: http + with: + method: get + uri: https://unit-tests.serverlessworkflow.io +- todo-2: + emit: + event: + with: + type: io.serverlessworkflow.unit-tests.fake.event.type.v1 +- todo-3: + for: + each: color + in: .colors + at: index + do: + - fake-http-call: + set: + processed: .processed + [$color] +- todo-4: + listen: + to: + any: + - with: + foo: bar + - with: + foo: bar + bar: baz +- todo-5: + raise: + error: + type: fake-error-type + title: fake-error-title + status: "400" +- todo-6: + run: + container: + image: fake-image:latest + command: fake command --arg1 arg1 + environment: + ASPNET_ENVIRONMENT: Development +- todo-7: + run: + shell: + command: fake command --arg1 arg1 + arguments: + - --arg2 arg2 + environment: + ASPNET_ENVIRONMENT: Development +- todo-8: + run: + script: + language: js + code: console.log("Hello, World!") +- todo-9: + run: + workflow: + namespace: default + name: fake-workflow + version: '1.0.0' + input: + foo: bar +- todo-10: + set: + foo: bar + bar: + baz: foo +- todo-11: + switch: + - case-1: + when: fake-condition + then: continue + - case-2: + when: another-fake-condition + then: exit + - default: + then: end +- todo-12: + try: + - setFoo: + set: + foo: bar + catch: {} +- todo-13: + wait: + minutes: 5 +- todo-14: + do: + - todo-14-1: + call: http + with: + method: get + uri: https://unit-tests.serverlessworkflow.io + - todo-14-2: + emit: + event: + with: + type: io.serverlessworkflow.unit-tests.fake.event.type.v1 + - todo-14-3: + for: + each: color + in: .colors + at: index + do: + - setProcessed: + set: + processed: .processed + [$color] \ No newline at end of file diff --git a/src/dashboard/Synapse.Dashboard/Pages/Workflows/Details/Store.cs b/src/dashboard/Synapse.Dashboard/Pages/Workflows/Details/Store.cs index afc2589fb..53289442f 100644 --- a/src/dashboard/Synapse.Dashboard/Pages/Workflows/Details/Store.cs +++ b/src/dashboard/Synapse.Dashboard/Pages/Workflows/Details/Store.cs @@ -69,13 +69,24 @@ IYamlSerializer yamlSerializer /// Gets an exposing the /// public IObservable WorkflowDefinition => Observable.CombineLatest( - this.Workflow.Where(wf => wf != null), + this.Workflow, this.WorkflowDefinitionVersion, (workflow, version) => { - return string.IsNullOrWhiteSpace(version) - ? workflow!.Spec.Versions.GetLatest() - : workflow!.Spec.Versions.Get(version); + if (workflow == null) + { + return null; + } + if (string.IsNullOrWhiteSpace(version)) + { + var latest = workflow.Spec.Versions.GetLatest()?.Document.Version; + if (!string.IsNullOrWhiteSpace(latest)) + { + this.SetWorkflowDefinitionVersion(latest); + } + return null; + } + return workflow.Spec.Versions.Get(version); } ); @@ -99,6 +110,7 @@ public void SetWorkflowDefinitionName(string? workflowDefinitionName) { this.Reduce(state => state with { + Workflow = null, WorkflowDefinitionName = workflowDefinitionName }); var ns = this.Get(state => state.Namespace); diff --git a/src/dashboard/Synapse.Dashboard/Pages/Workflows/Details/View.razor b/src/dashboard/Synapse.Dashboard/Pages/Workflows/Details/View.razor index f0447be30..8e1c147fa 100644 --- a/src/dashboard/Synapse.Dashboard/Pages/Workflows/Details/View.razor +++ b/src/dashboard/Synapse.Dashboard/Pages/Workflows/Details/View.razor @@ -45,7 +45,9 @@ @if (workflowDefinition == null) { - +
+ +
} else { @@ -58,7 +60,9 @@ @if (workflowDefinition == null) { - +
+ +
} else { @@ -82,10 +86,10 @@ WorkflowDefinition workflowDefinition = null!; readonly IEnumerable columns = [ "Name", - "Namespace", - "Status", - "Started At", - "Ended At" + "Namespace", + "Status", + "Started At", + "Ended At" ]; [Parameter] public new string? Namespace { get; set; }