diff --git a/frontend/src/lib/components/apps/components/helpers/HiddenComponent.svelte b/frontend/src/lib/components/apps/components/helpers/HiddenComponent.svelte index 8b39e68b09..21c3b35073 100644 --- a/frontend/src/lib/components/apps/components/helpers/HiddenComponent.svelte +++ b/frontend/src/lib/components/apps/components/helpers/HiddenComponent.svelte @@ -1,27 +1,17 @@ -{#if inlineScript} +{#if runnable && (runnable.type == 'runnableByPath' || (runnable.type == 'runnableByName' && runnable.inlineScript != undefined))} diff --git a/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte b/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte index 181d4a4a4f..a916b1524b 100644 --- a/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte +++ b/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte @@ -35,6 +35,7 @@ export let recomputeOnInputChanged: boolean = true export let loading = false export let refreshOnStart: boolean = false + export let recomputableByRefreshButton: boolean const { worldStore, @@ -346,7 +347,7 @@ } $runnableComponents[id] = { - autoRefresh: autoRefresh, + autoRefresh: autoRefresh && recomputableByRefreshButton, refreshOnStart: refreshOnStart, cb: cancellableRun } diff --git a/frontend/src/lib/components/apps/components/helpers/RunnableWrapper.svelte b/frontend/src/lib/components/apps/components/helpers/RunnableWrapper.svelte index e594f6ac20..537a391064 100644 --- a/frontend/src/lib/components/apps/components/helpers/RunnableWrapper.svelte +++ b/frontend/src/lib/components/apps/components/helpers/RunnableWrapper.svelte @@ -124,9 +124,8 @@ bind:result runnable={componentInput.runnable} transformer={componentInput.transformer} - autoRefresh={componentInput.autoRefresh === undefined - ? autoRefresh - : componentInput.autoRefresh} + {autoRefresh} + recomputableByRefreshButton={componentInput.autoRefresh ?? true} bind:recomputeOnInputChanged={componentInput.recomputeOnInputChanged} {id} {extraQueryParams} diff --git a/frontend/src/lib/components/apps/editor/AppEditor.svelte b/frontend/src/lib/components/apps/editor/AppEditor.svelte index f8db3d6229..ab1d422e07 100644 --- a/frontend/src/lib/components/apps/editor/AppEditor.svelte +++ b/frontend/src/lib/components/apps/editor/AppEditor.svelte @@ -44,6 +44,7 @@ import SettingsPanel from './SettingsPanel.svelte' import { secondaryMenu, SecondaryMenu } from './settingsPanel/secondaryMenu' import Popover from '../../Popover.svelte' + import { migrateApp } from '../utils' export let app: App export let path: string @@ -52,6 +53,8 @@ export let summary: string export let fromHub: boolean = false + migrateApp(app) + const appStore = writable(app) const selectedComponent = writable(undefined) const mode = writable(initialMode) diff --git a/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte b/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte index 3c5bf19e4e..8c8dd7a4df 100644 --- a/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte +++ b/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte @@ -34,6 +34,7 @@ AppInput, ConnectedAppInput, RowAppInput, + Runnable, StaticAppInput, UserAppInput } from '../inputType' @@ -120,7 +121,7 @@ ) } async function computeTriggerables() { - const allTriggers = await Promise.all( + const allTriggers = (await Promise.all( allItems($app.grid, $app.subgrids) .flatMap((x) => { let c = x.data as AppComponent @@ -132,27 +133,32 @@ }) .map(async (input) => { if (input?.type == 'runnable') { - const staticInputs = collectStaticFields(input.fields) - if (input.runnable?.type == 'runnableByName') { - let hex = await hash(input.runnable.inlineScript?.content) - return [`rawscript/${hex}`, staticInputs] - } else if (input.runnable?.type == 'runnableByPath') { - let prefix = - input.runnable.runType !== 'hubscript' ? input.runnable.runType : 'script' - return [`${prefix}/${input.runnable.path}`, staticInputs] - } + return await processRunnable(input.runnable, input.fields) } - return [] }) .concat( Object.values($app.hiddenInlineScripts ?? {}).map(async (v) => { - let hex = await hash(v.inlineScript?.content) - const staticInputs = collectStaticFields(v.fields) - return [`rawscript/${hex}`, staticInputs] + return await processRunnable(v, v.fields) }) ) + )) as ([string, Record] | undefined)[] + policy.triggerables = Object.fromEntries( + allTriggers.filter(Boolean) as [string, Record][] ) - policy.triggerables = Object.fromEntries(allTriggers.filter((x) => x.length > 0)) + } + + async function processRunnable( + runnable: Runnable, + fields: Record + ): Promise<[string, Record] | undefined> { + const staticInputs = collectStaticFields(fields) + if (runnable?.type == 'runnableByName') { + let hex = await hash(runnable.inlineScript?.content) + return [`rawscript/${hex}`, staticInputs] + } else if (runnable?.type == 'runnableByPath') { + let prefix = runnable.runType !== 'hubscript' ? runnable.runType : 'script' + return [`${prefix}/${runnable.path}`, staticInputs] + } } async function createApp(path: string) { await computeTriggerables() @@ -496,7 +502,13 @@ - (jobsDrawerOpen = false)} tooltip="Look at latests runs to spot potential bugs." documentationLink="https://docs.windmill.dev/docs/apps/app_toolbar#debug-runs"> + (jobsDrawerOpen = false)} + tooltip="Look at latests runs to spot potential bugs." + documentationLink="https://docs.windmill.dev/docs/apps/app_toolbar#debug-runs" + > diff --git a/frontend/src/lib/components/apps/editor/AppPreview.svelte b/frontend/src/lib/components/apps/editor/AppPreview.svelte index 5d03b70185..bf94614011 100644 --- a/frontend/src/lib/components/apps/editor/AppPreview.svelte +++ b/frontend/src/lib/components/apps/editor/AppPreview.svelte @@ -21,6 +21,7 @@ import { HiddenComponent } from '../components' import { deepEqual } from 'fast-equals' import { dfs } from './appUtils' + import { migrateApp } from '../utils' export let app: App export let appPath: string @@ -33,6 +34,8 @@ export let noBackend: boolean = false export let isLocked = false + migrateApp(app) + const appStore = writable(app) const selectedComponent = writable(undefined) const mode = writable('preview') @@ -163,17 +166,9 @@ {#if app.hiddenInlineScripts} - {#each app.hiddenInlineScripts as script, index} - {#if script} - + {#each app.hiddenInlineScripts as runnable, index} + {#if runnable} + {/if} {/each} {/if} diff --git a/frontend/src/lib/components/apps/editor/GridEditor.svelte b/frontend/src/lib/components/apps/editor/GridEditor.svelte index f3ef9e0f47..b50aa542c3 100644 --- a/frontend/src/lib/components/apps/editor/GridEditor.svelte +++ b/frontend/src/lib/components/apps/editor/GridEditor.svelte @@ -127,16 +127,9 @@ {#if $app.hiddenInlineScripts} - {#each $app.hiddenInlineScripts as script, index} - {#if script} - + {#each $app.hiddenInlineScripts as runnable, index} + {#if runnable} + {/if} {/each} {/if} diff --git a/frontend/src/lib/components/apps/editor/SettingsPanel.svelte b/frontend/src/lib/components/apps/editor/SettingsPanel.svelte index 2a4d84444a..563fc7e2f7 100644 --- a/frontend/src/lib/components/apps/editor/SettingsPanel.svelte +++ b/frontend/src/lib/components/apps/editor/SettingsPanel.svelte @@ -52,22 +52,6 @@ return undefined } - - $: { - if (hiddenInlineScript && hiddenInlineScript?.script.recomputeOnInputChanged === undefined) { - hiddenInlineScript.script.recomputeOnInputChanged = true - } - - //TODO: remove after migration is done - if ( - hiddenInlineScript && - hiddenInlineScript?.script.doNotRecomputeOnInputChanged != undefined - ) { - hiddenInlineScript.script.recomputeOnInputChanged = - !hiddenInlineScript.script.doNotRecomputeOnInputChanged - hiddenInlineScript.script.doNotRecomputeOnInputChanged = undefined - } - } {#if componentSettings} @@ -97,7 +81,7 @@ {/key} {:else if hiddenInlineScript} diff --git a/frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptsOutput.svelte b/frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptsOutput.svelte index 7a138ccb09..1015ca8b9c 100644 --- a/frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptsOutput.svelte +++ b/frontend/src/lib/components/apps/editor/contextPanel/components/BackgroundScriptsOutput.svelte @@ -7,5 +7,7 @@ {#each $app.hiddenInlineScripts as action, index} - + {#if !action.hidden} + + {/if} {/each} diff --git a/frontend/src/lib/components/apps/editor/contextPanel/components/OutputHeader.svelte b/frontend/src/lib/components/apps/editor/contextPanel/components/OutputHeader.svelte index c7a5ebb62a..62c84b1488 100644 --- a/frontend/src/lib/components/apps/editor/contextPanel/components/OutputHeader.svelte +++ b/frontend/src/lib/components/apps/editor/contextPanel/components/OutputHeader.svelte @@ -28,7 +28,8 @@ $search != '' && ($hasResult[id] || Object.entries($hasResult).some(([key, value]) => value && subids.includes(key))) - $: open = $allIdsInPath.includes(id) || $manuallyOpened[id] || inSearch + $: open = + $allIdsInPath.includes(id) || id == $selectedComponent?.[0] || $manuallyOpened[id] || inSearch const hoverColor = { blue: 'hover:bg-blue-100 hover:text-blue-500', @@ -76,12 +77,7 @@ }) $app.hiddenInlineScripts.forEach((x) => { - console.log('process', x.name, id) - processRunnable(from, to, { - name: x.name, - inlineScript: x.inlineScript, - type: 'runnableByName' - }) + processRunnable(from, to, x) }) } propagateRename(id, newId) diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/EmptyInlineScript.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/EmptyInlineScript.svelte index 334c00ce5b..a33fe2e484 100644 --- a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/EmptyInlineScript.svelte +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/EmptyInlineScript.svelte @@ -16,9 +16,11 @@ import { defaultCode } from '../component' import InlineScriptList from '../settingsPanel/mainInput/InlineScriptList.svelte' import WorkspaceScriptList from '../settingsPanel/mainInput/WorkspaceScriptList.svelte' + import RunnableSelector from '../settingsPanel/mainInput/RunnableSelector.svelte' export let name: string export let componentType: string | undefined = undefined + export let showScriptPicker = false let tab = 'inlinescripts' let filter: string = '' @@ -140,9 +142,12 @@
-
-
Choose a language:
+
+
Choose a language
+ {#if showScriptPicker} + + {/if} +
@@ -181,7 +187,7 @@ {/each}
-
Typescript templates
+
Typescript templates
| undefined = undefined {#if inlineScript} @@ -163,50 +162,7 @@
- {#if $runnableComponents[id] != undefined} - {#if !runLoading} - - {:else} - - {/if} - {/if} + diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditorPanel.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditorPanel.svelte index 67ebe528a0..c157938fda 100644 --- a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditorPanel.svelte +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptEditorPanel.svelte @@ -1,26 +1,12 @@ - - - - - + async function fork(runnable: Runnable) { + if (componentInput?.type == 'runnable') { + componentInput.runnable = runnable + } + } + {#if transformer} {#if componentInput?.type == 'runnable' && componentInput.transformer} @@ -147,97 +73,20 @@ componentInput?.runnable?.type === 'runnableByName' ) { componentInput.runnable.inlineScript = e.detail + componentInput.autoRefresh = true + componentInput.recomputeOnInputChanged = true $app = $app } }} /> {/if} {:else if componentInput?.runnable?.type === 'runnableByPath' && componentInput?.runnable?.path} -
- {#if componentInput.runnable.runType == 'script' || componentInput.runnable.runType == 'hubscript'} -
- -
- {/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} -
-
+ fork(e.detail)} + bind:runnable={componentInput.runnable} + bind:fields={componentInput.fields} + on:delete + {id} + /> {/if} {/if} diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptHiddenRunnable.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptHiddenRunnable.svelte new file mode 100644 index 0000000000..01e4972ab2 --- /dev/null +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptHiddenRunnable.svelte @@ -0,0 +1,59 @@ + + +{#if runnable?.type === 'runnableByName' && runnable.inlineScript} + +{:else if runnable?.type == 'runnableByPath'} + fork(e.detail)} + on:delete + {id} + /> +{:else} + onPick(e.detail)} + name={runnable.name} + on:delete + showScriptPicker + on:new={(e) => { + runnable = { + type: 'runnableByName', + inlineScript: e.detail, + name: runnable.name, + fields: {}, + autoRefresh: true, + recomputeOnInputChanged: true + } + }} + /> +{/if} diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptRunnableByPath.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptRunnableByPath.svelte new file mode 100644 index 0000000000..3dbf2b74d7 --- /dev/null +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptRunnableByPath.svelte @@ -0,0 +1,174 @@ + + + + + + + + +
+
+ + + + + + {#if runnable.runType == 'flow'} + + + + {/if} +
+
+ {#key $stateId} + {#if runnable.runType == 'script' || runnable.runType == 'hubscript'} +
+ +
+ {:else if runnable.runType == 'flow'} + + {:else} + Unrecognized runType {runnable.runType} + {/if} + {/key} +
+
diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanel.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanel.svelte index ea378e49d4..5767c60607 100644 --- a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanel.svelte +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanel.svelte @@ -5,9 +5,9 @@ import { Pane, Splitpanes } from 'svelte-splitpanes' import InlineScriptsPanelList from './InlineScriptsPanelList.svelte' import InlineScriptEditor from './InlineScriptEditor.svelte' - import EmptyInlineScript from './EmptyInlineScript.svelte' import InlineScriptsPanelWithTable from './InlineScriptsPanelWithTable.svelte' import { findGridItem } from '../appUtils' + import InlineScriptHiddenRunnable from './InlineScriptHiddenRunnable.svelte' const { app, runnableComponents } = getContext('AppViewerContext') const { selectedComponentInEditor } = getContext('AppEditorContext') @@ -18,12 +18,17 @@ $app.hiddenInlineScripts.splice(index, 1) $app.hiddenInlineScripts = [...$app.hiddenInlineScripts] } else { - $app.hiddenInlineScripts[index].hidden = true - $app.hiddenInlineScripts[index].inlineScript = undefined - $app.hiddenInlineScripts[index].name = `Background Script ${index}` + $app.hiddenInlineScripts[index] = { + hidden: true, + inlineScript: undefined, + name: `Background Script ${index}`, + fields: {}, + type: 'runnableByName' + } $app.hiddenInlineScripts = $app.hiddenInlineScripts } + $selectedComponentInEditor = undefined delete $runnableComponents[`bg_${index}`] } @@ -70,27 +75,12 @@ {/key} {:else if hiddenInlineScript > -1} {#key hiddenInlineScript} - {#if $app.hiddenInlineScripts?.[hiddenInlineScript]?.inlineScript} - deleteBackgroundScript(hiddenInlineScript)} id={`bg_${hiddenInlineScript}`} - bind:inlineScript={$app.hiddenInlineScripts[hiddenInlineScript].inlineScript} - bind:name={$app.hiddenInlineScripts[hiddenInlineScript].name} - bind:fields={$app.hiddenInlineScripts[hiddenInlineScript].fields} - syncFields - on:delete={() => deleteBackgroundScript(hiddenInlineScript)} - /> - {:else} - deleteBackgroundScript(hiddenInlineScript)} - on:new={(e) => { - if ($app.hiddenInlineScripts[hiddenInlineScript]) { - $app.hiddenInlineScripts[hiddenInlineScript].inlineScript = e.detail - } - }} - /> - {/if} - {/key} + bind:runnable={$app.hiddenInlineScripts[hiddenInlineScript]} + />{/if}{/key} {:else}
No script found at id {$selectedComponentInEditor} diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelList.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelList.svelte index c0da8e8ea4..77630ff1af 100644 --- a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelList.svelte +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelList.svelte @@ -23,11 +23,15 @@ $: runnables = getAppScripts($app.grid, $app.subgrids) // When selected component changes, update selectedScriptComponentId - $: if ( - $selectedComponent != $selectedComponentInEditor && - !$selectedComponentInEditor?.includes('_transformer') - ) { - $selectedComponentInEditor = $selectedComponent?.[0] + $: $selectedComponent && handleSelectedComponent() + + function handleSelectedComponent() { + if ( + $selectedComponent != $selectedComponentInEditor && + !$selectedComponentInEditor?.includes('_transformer') + ) { + $selectedComponentInEditor = $selectedComponent?.[0] + } } function createBackgroundScript() { @@ -57,7 +61,7 @@ name: newScriptPath, inlineScript: undefined, autoRefresh: true, - + type: 'runnableByName', fields: {} }) $app.hiddenInlineScripts = $app.hiddenInlineScripts diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/RunButton.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/RunButton.svelte new file mode 100644 index 0000000000..84101e686c --- /dev/null +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/RunButton.svelte @@ -0,0 +1,59 @@ + + +{#if $runnableComponents[id] != undefined} + {#if !runLoading} + + {:else} + + {/if} +{/if} diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/InputsSpecsEditor.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/InputsSpecsEditor.svelte index 930debf6ab..06c9d5cf41 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/InputsSpecsEditor.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/InputsSpecsEditor.svelte @@ -6,18 +6,20 @@ export let id: string export let inputSpecs: RichConfigurations - export let inputSpecsConfiguration: RichConfigurations = inputSpecs + export let inputSpecsConfiguration: RichConfigurations | undefined = undefined export let userInputEnabled: boolean = false export let shouldCapitalize: boolean = true export let rowColumns = false export let resourceOnly = false export let displayType = false + + $: finalInputSpecsConfiguration = inputSpecsConfiguration ?? inputSpecs {#if inputSpecs}
- {#each Object.keys(inputSpecsConfiguration) as k} - {#if inputSpecsConfiguration[k]?.type == 'oneOf'} + {#each Object.keys(finalInputSpecsConfiguration) as k} + {#if finalInputSpecsConfiguration[k]?.type == 'oneOf'} {:else} - {@const meta = inputSpecsConfiguration?.[k]} + {@const meta = finalInputSpecsConfiguration?.[k]} - import type { ResultAppInput } from '$lib/components/apps/inputType' + import type { ResultAppInput, Runnable, StaticAppInput } from '$lib/components/apps/inputType' import { isScriptByNameDefined, isScriptByPathDefined } from '$lib/components/apps/utils' + import { getContext } from 'svelte' import type { AppComponent } from '../../component' import RunnableSelector from '../mainInput/RunnableSelector.svelte' import SelectedRunnable from '../SelectedRunnable.svelte' + import type { AppEditorContext } from '$lib/components/apps/types' export let appInput: ResultAppInput export let defaultUserInput = false export let appComponent: AppComponent + + const { selectedComponentInEditor } = getContext('AppEditorContext') + + function onPick({ + runnable, + fields + }: { + runnable: Runnable + fields: Record + }) { + if (appInput.type === 'runnable') { + appInput = { ...appInput, runnable, fields } + $selectedComponentInEditor = appComponent.id + } else { + console.warn('Cannot pick runnable for non-runnable input') + } + } {#if isScriptByPathDefined(appInput) || isScriptByNameDefined(appInput)} {:else if appInput !== undefined} - + onPick(e.detail)} /> {/if} diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/mainInput/RunnableSelector.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/mainInput/RunnableSelector.svelte index eff4155323..9ebe6a8891 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/mainInput/RunnableSelector.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/mainInput/RunnableSelector.svelte @@ -4,27 +4,32 @@ import PickHubScript from '$lib/components/flows/pickers/PickHubScript.svelte' import { Building, Globe2 } from 'lucide-svelte' import InlineScriptList from './InlineScriptList.svelte' - import type { ResultAppInput } from '$lib/components/apps/inputType' + import type { Runnable, StaticAppInput } from '$lib/components/apps/inputType' import WorkspaceScriptList from './WorkspaceScriptList.svelte' import WorkspaceFlowList from './WorkspaceFlowList.svelte' - import type { AppEditorContext, AppViewerContext } from '$lib/components/apps/types' - import { getContext } from 'svelte' + import type { AppViewerContext } from '$lib/components/apps/types' + import { createEventDispatcher, getContext } from 'svelte' import type { Schema } from '$lib/common' import { getAllScriptNames, loadSchema, schemaToInputsSpec } from '$lib/components/apps/utils' import { emptySchema } from '$lib/utils' type Tab = 'hubscripts' | 'workspacescripts' | 'workspaceflows' | 'inlinescripts' - export let appInput: ResultAppInput export let defaultUserInput = false - export let id: string + export let hideCreateScript = false let tab: Tab = 'inlinescripts' let filter: string = '' let picker: Drawer const { app, workspace } = getContext('AppViewerContext') - const { selectedComponentInEditor } = getContext('AppEditorContext') + + const dispatch = createEventDispatcher<{ + pick: { + runnable: Runnable + fields: Record + } + }>() async function loadSchemaFromTriggerable( path: string, @@ -34,48 +39,49 @@ } async function pickScript(path: string) { - if (appInput.type === 'runnable') { - const schema = await loadSchemaFromTriggerable(path, 'script') - const fields = schemaToInputsSpec(schema, defaultUserInput) - appInput.runnable = { - type: 'runnableByPath', - path, - runType: 'script', - schema - } - appInput.fields = fields - $selectedComponentInEditor = id - } + const schema = await loadSchemaFromTriggerable(path, 'script') + const fields = schemaToInputsSpec(schema, defaultUserInput) + const runnable = { + type: 'runnableByPath', + path, + runType: 'script', + schema + } as const + + dispatch('pick', { + runnable, + fields + }) } async function pickFlow(path: string) { - if (appInput.type === 'runnable') { - const schema = await loadSchemaFromTriggerable(path, 'flow') - const fields = schemaToInputsSpec(schema, defaultUserInput) - appInput.runnable = { - type: 'runnableByPath', - path, - runType: 'flow', - schema - } - appInput.fields = fields - $selectedComponentInEditor = id - } + const schema = await loadSchemaFromTriggerable(path, 'flow') + const fields = schemaToInputsSpec(schema, defaultUserInput) + const runnable = { + type: 'runnableByPath', + path, + runType: 'flow', + schema + } as const + dispatch('pick', { + runnable, + fields + }) } async function pickHubScript(path: string) { - if (appInput.type === 'runnable') { - const schema = await loadSchemaFromTriggerable(path, 'hubscript') - const fields = schemaToInputsSpec(schema, defaultUserInput) - appInput.runnable = { - type: 'runnableByPath', - path, - runType: 'hubscript', - schema - } - appInput.fields = fields - $selectedComponentInEditor = id - } + const schema = await loadSchemaFromTriggerable(path, 'hubscript') + const fields = schemaToInputsSpec(schema, defaultUserInput) + const runnable = { + type: 'runnableByPath', + path, + runType: 'hubscript', + schema + } as const + dispatch('pick', { + runnable, + fields + }) } function pickInlineScript(name: string) { @@ -83,20 +89,20 @@ (script) => script.name === name ) const unusedInlineScript = $app.unusedInlineScripts?.[unusedInlineScriptIndex] - if (appInput.type === 'runnable' && unusedInlineScript?.inlineScript) { - appInput.runnable = { + dispatch('pick', { + runnable: { type: 'runnableByName', name, inlineScript: unusedInlineScript.inlineScript - } + }, + fields: {} + }) - $app.unusedInlineScripts.splice(unusedInlineScriptIndex, 1) - } - $selectedComponentInEditor = id - $app = $app + $app.unusedInlineScripts.splice(unusedInlineScriptIndex, 1) + $app.unusedInlineScripts = $app.unusedInlineScripts } - function createScript(): string { + function createScript() { let index = 0 let newScriptPath = `Inline Script ${index}` @@ -107,16 +113,14 @@ newScriptPath = `Inline Script ${++index}` } - appInput.runnable = { - type: 'runnableByName', - name: newScriptPath, - inlineScript: undefined - } - - appInput = appInput - $selectedComponentInEditor = id - - return newScriptPath + dispatch('pick', { + runnable: { + type: 'runnableByName', + name: newScriptPath, + inlineScript: undefined + }, + fields: {} + }) } @@ -175,16 +179,18 @@
- + {#if !hideCreateScript} + + {/if}