From 0fbd5209fcec414808d1da10d5490f09bebdf41a Mon Sep 17 00:00:00 2001 From: Faton Ramadani Date: Thu, 4 Aug 2022 20:14:32 +0200 Subject: [PATCH] Fix previous results in Flow preview (#332) --- .../src/lib/components/FlowBuilder.svelte | 133 +++++++++--------- frontend/src/lib/components/ModuleStep.svelte | 14 +- .../src/lib/components/flows/flowStore.ts | 1 + frontend/src/lib/components/flows/utils.ts | 12 +- 4 files changed, 81 insertions(+), 79 deletions(-) diff --git a/frontend/src/lib/components/FlowBuilder.svelte b/frontend/src/lib/components/FlowBuilder.svelte index 8b549c5dff..5ccd468b19 100644 --- a/frontend/src/lib/components/FlowBuilder.svelte +++ b/frontend/src/lib/components/FlowBuilder.svelte @@ -2,7 +2,7 @@ import { goto } from '$app/navigation' import { page } from '$app/stores' import { FlowService, ScheduleService, type Flow } from '$lib/gen' - import { clearPreviewResults, workspaceStore } from '$lib/stores' + import { clearPreviewResults, previewResults, workspaceStore } from '$lib/stores' import { encodeState, formatCron, @@ -18,7 +18,7 @@ import FlowEditor from './FlowEditor.svelte' import FlowPreviewContent from './FlowPreviewContent.svelte' import { flowStore, mode } from './flows/flowStore' - import { flowToMode } from './flows/utils' + import { flowToMode, jobsToResults } from './flows/utils' import ScriptSchema from './ScriptSchema.svelte' @@ -134,72 +134,70 @@
-
- -
- - - - - - - - -
- {#if step == 1} - - - {:else} - - {/if} -
-
-
- - {#if initialPath && initialPath != $flowStore?.path} {initialPath} → {/if} - {$flowStore?.path} - -
- - - - {#if $flowStore} - {#if step === 1} - - {:else if step === 2} - + +
+ + + + + + + + +
+ {#if step == 1} + + + {:else} + {/if} - {:else} -

Loading

- {/if} +
+
+ + {#if initialPath && initialPath != $flowStore?.path} {initialPath} → {/if} + {$flowStore?.path} + +
+ + + + {#if $flowStore} + {#if step === 1} + + {:else if step === 2} + + {/if} + {:else} +

Loading

+ {/if}
diff --git a/frontend/src/lib/components/ModuleStep.svelte b/frontend/src/lib/components/ModuleStep.svelte index ef993ef6a2..297b4a73b1 100644 --- a/frontend/src/lib/components/ModuleStep.svelte +++ b/frontend/src/lib/components/ModuleStep.svelte @@ -19,7 +19,7 @@ schemasStore, type FlowMode } from './flows/flowStore' - import { getPickableProperties } from './flows/utils' + import { getPickableProperties, jobsToResults } from './flows/utils' import SchemaForm from './SchemaForm.svelte' import Tooltip from './Tooltip.svelte' @@ -43,16 +43,6 @@ i === 0 ? schemaToTsType($flowStore?.schema) : objectToTsType($previewResults[i]) ) - function toResults(jobs: any) { - return jobs.map((job) => { - if (job.result) { - return job.result - } else if (Array.isArray(job)) { - return toResults(job) - } - }) - } - const isTrigger = mode === 'pull' && i === 0 @@ -157,7 +147,7 @@ {mode} schemas={$schemasStore} on:change={(e) => { - previewResults.set(toResults(e.detail)) + previewResults.set(jobsToResults(e.detail)) }} /> diff --git a/frontend/src/lib/components/flows/flowStore.ts b/frontend/src/lib/components/flows/flowStore.ts index 39ba2bff04..53d42c0043 100644 --- a/frontend/src/lib/components/flows/flowStore.ts +++ b/frontend/src/lib/components/flows/flowStore.ts @@ -71,6 +71,7 @@ export const isCopyFirstStepSchemaDisabled = derived(flowStore, (flow: Flow | un if (flow) { const modules = flow.value.modules const [firstModule] = modules + return ( modules.length === 0 || (firstModule.value.type === 'script' && firstModule.value.path === '') ) diff --git a/frontend/src/lib/components/flows/utils.ts b/frontend/src/lib/components/flows/utils.ts index d3ac8ccc97..fd440e2bd1 100644 --- a/frontend/src/lib/components/flows/utils.ts +++ b/frontend/src/lib/components/flows/utils.ts @@ -1,5 +1,5 @@ import type { Schema } from '$lib/common' -import type { Flow, FlowModule, FlowModuleValue, InputTransform, RawScript } from '$lib/gen' +import type { Flow, FlowModule, FlowModuleValue, InputTransform, Job, RawScript } from '$lib/gen' import { inferArgs } from '$lib/infer' import { loadSchema } from '$lib/scripts' import { emptySchema, getScriptByPath, schemaToObject } from '$lib/utils' @@ -208,3 +208,13 @@ export function getPickableProperties( return pickableProperties } + +export function jobsToResults(jobs: Job[]) { + return jobs.map((job) => { + if ('result' in job) { + return job.result + } else if (Array.isArray(job)) { + return jobsToResults(job) + } + }) +}