From bb61cef0e56bf7fa7f8a5f91dabd590afd5db791 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 29 Mar 2023 01:05:12 +0200 Subject: [PATCH] fix(backend): add a refresh button to workspace script/hub --- .../InlineScriptEditorPanel.svelte | 127 ++++++++++++------ 1 file changed, 84 insertions(+), 43 deletions(-) diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditorPanel.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditorPanel.svelte index 01aabef491..da6bda4f67 100644 --- a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditorPanel.svelte +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditorPanel.svelte @@ -5,10 +5,16 @@ import FlowPathViewer from '$lib/components/flows/content/FlowPathViewer.svelte' import { inferArgs } from '$lib/infer' import { workspaceStore } from '$lib/stores' - import { emptySchema, getScriptByPath } from '$lib/utils' - import { faCodeBranch, faExternalLinkAlt, faEye, faPen } from '@fortawesome/free-solid-svg-icons' + import { emptySchema, getScriptByPath, sendUserToast } from '$lib/utils' + import { + faCodeBranch, + faExternalLinkAlt, + faEye, + faPen, + faRefresh + } from '@fortawesome/free-solid-svg-icons' import type { AppInput, RunnableByPath } from '../../inputType' - import { clearResultAppInput } from '../../utils' + import { clearResultAppInput, loadSchema, schemaToInputsSpec } from '../../utils' import EmptyInlineScript from './EmptyInlineScript.svelte' import InlineScriptEditor from './InlineScriptEditor.svelte' import { computeFields } from './utils' @@ -22,7 +28,7 @@ export let id: string export let transformer: boolean - const { app } = getContext('AppViewerContext') + const { app, stateId } = getContext('AppViewerContext') async function fork(path: string) { let { content, language, schema } = await getScriptByPath(path) @@ -60,13 +66,25 @@ } } + async function refreshFlow(x: RunnableByPath) { + const schema = (await loadSchema($workspaceStore ?? '', x.path, 'flow')) ?? emptySchema() + x.schema = schema + if (componentInput?.type == 'runnable') { + componentInput.fields = schemaToInputsSpec(schema, defaultUserInput) + } + componentInput = componentInput + console.log('refreshFlow', componentInput) + } $: if ( componentInput && componentInput.type == 'runnable' && - componentInput?.runnable?.type === 'runnableByPath' && - componentInput.runnable.runType == 'script' + componentInput?.runnable?.type === 'runnableByPath' ) { - refreshScript(componentInput.runnable) + if (componentInput.runnable.runType == 'script') { + refreshScript(componentInput.runnable) + } else if (componentInput.runnable.runType == 'flow') { + refreshFlow(componentInput.runnable) + } } function deleteInlineScript() { @@ -153,42 +171,65 @@ {/if} -
- {#if componentInput.runnable.runType == 'script' || componentInput.runnable.runType == 'hubscript'} - - {:else if componentInput.runnable.runType == 'flow'} -
- - - -
- - {:else} - Unrecognized runType {componentInput.runnable.runType} - {/if} +
+ {#key $stateId} + {#if componentInput.runnable.runType == 'script' || componentInput.runnable.runType == 'hubscript'} + + {:else if componentInput.runnable.runType == 'flow'} +
+ + + + +
+ + {:else} + Unrecognized runType {componentInput.runnable.runType} + {/if} + {/key}
{/if}