From a20d3fae6fed85a67e72b2bbd4d37d8d6f3cea2f Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 30 Dec 2022 05:31:32 +0100 Subject: [PATCH] feat: add a All Static Inputs module to the flow editor --- .../lib/components/InputTransformForm.svelte | 162 ++++++++++-------- frontend/src/lib/components/Popover.svelte | 2 +- frontend/src/lib/components/SchemaForm.svelte | 88 +++++----- .../src/lib/components/TemplateEditor.svelte | 2 +- .../flows/content/FlowConstants.svelte | 68 ++++++++ .../flows/content/FlowEditorPanel.svelte | 3 + .../flows/content/FlowModuleHeader.svelte | 8 +- .../flows/header/FlowPreviewButtons.svelte | 3 +- .../flows/map/FlowConstantsItem.svelte | 22 +++ .../flows/map/FlowInputsItem.svelte | 3 +- .../flows/map/FlowModuleSchemaMap.svelte | 13 +- .../flows/map/FlowSettingsItem.svelte | 4 +- 12 files changed, 247 insertions(+), 131 deletions(-) create mode 100644 frontend/src/lib/components/flows/content/FlowConstants.svelte create mode 100644 frontend/src/lib/components/flows/map/FlowConstantsItem.svelte diff --git a/frontend/src/lib/components/InputTransformForm.svelte b/frontend/src/lib/components/InputTransformForm.svelte index c236372d9a..a089b1b530 100644 --- a/frontend/src/lib/components/InputTransformForm.svelte +++ b/frontend/src/lib/components/InputTransformForm.svelte @@ -27,7 +27,7 @@ export let pickForField: string | undefined = undefined export let variableEditor: VariableEditor | undefined = undefined export let itemPicker: ItemPicker | undefined = undefined - export let noVariablePicker = false + export let noDynamicToggle = false let monaco: SimpleEditor | undefined = undefined let monacoTemplate: TemplateEditor | undefined = undefined @@ -113,7 +113,7 @@ const { focusProp, propPickerConfig } = getContext('PropPickerWrapper') - $: isStaticTemplate(inputCat) && propertyType == 'static' && setPropertyType(arg.value) + $: isStaticTemplate(inputCat) && propertyType == 'static' && setPropertyType(arg?.value) const openBracket = '${' const closeBracket = '}' @@ -141,75 +141,83 @@ {/if} -
- { - const staticTemplate = isStaticTemplate(inputCat) - if (e.detail === 'javascript') { - if (arg.expr == undefined) { - arg.expr = getDefaultExpr( - argName, - previousModuleId, - staticTemplate - ? `\`${arg.value ?? ''}\`` - : arg.value - ? JSON.stringify(arg.value, null, 4) - : '' - ) - } - - arg.value = undefined - propertyType = 'javascript' - arg.type = 'javascript' - } else { - if (staticTemplate) { - arg.value = codeToStaticTemplate(arg.expr) - setPropertyType(arg.value) + {#if !noDynamicToggle} +
+ { + const staticTemplate = isStaticTemplate(inputCat) + if (e.detail === 'javascript') { + if (arg.expr == undefined) { + arg.expr = getDefaultExpr( + argName, + previousModuleId, + staticTemplate + ? `\`${arg?.value ?? ''}\`` + : arg.value + ? JSON.stringify(arg?.value, null, 4) + : '' + ) + } + if (arg) { + arg.value = undefined + } + propertyType = 'javascript' + arg.type = 'javascript' } else { - arg.type = 'static' - arg.value = undefined - arg.expr = undefined + if (staticTemplate) { + if (arg) { + arg.value = codeToStaticTemplate(arg.expr) + } + setPropertyType(arg?.value) + } else { + if (arg) { + arg.type = 'static' + arg.value = undefined + arg.expr = undefined + } + } + propertyType = 'static' } - propertyType = 'static' - } - }} - > - {#if isStaticTemplate(inputCat)} - - {'${} '}Templatable   Write javascript expressions between "{openBracket}" and "{closeBracket}". You may - refer to contextual objects like 'flow_input', or 'result' or functions like - 'resource' and 'variable' - - {:else} - Static - {/if} - - - Dynamic (JS) - - - -
+ {#if isStaticTemplate(inputCat)} + + {'${} '}Templatable   Write javascript expressions between "{openBracket}" and "{closeBracket}". You may + refer to contextual objects like 'flow_input', or 'result' or functions like + 'resource' and 'variable' + + {:else} + Static + {/if} + + + Dynamic (JS) + +
+ +
+ {/if} +
{/if} - {#if isStaticTemplate(inputCat) && propertyType == 'static'} -
- + {#if isStaticTemplate(inputCat) && propertyType == 'static' && !noDynamicToggle} +
+ {#if arg} + + {/if}
{:else if propertyType === undefined || propertyType == 'static'}
diff --git a/frontend/src/lib/components/SchemaForm.svelte b/frontend/src/lib/components/SchemaForm.svelte index 7d11e26a1b..3337c1780f 100644 --- a/frontend/src/lib/components/SchemaForm.svelte +++ b/frontend/src/lib/components/SchemaForm.svelte @@ -26,6 +26,8 @@ export let compact = false export let password: string | undefined = undefined export let noVariablePicker = false + export let filter: string[] | undefined = undefined + export let noDynamicToggle = false let clazz: string = '' export { clazz as class } @@ -56,48 +58,50 @@
{#if Object.keys(schema?.properties ?? {}).length > 0} {#each Object.keys(schema?.properties ?? {}) as argName, i (argName)} -
- {#if inputTransform} - - {:else if typeof args == 'object'} - - {:else} - Expected argument to be an object, got {JSON.stringify(args)} instead - {/if} -
+ {#if !filter || filter.includes(argName)} +
+ {#if inputTransform} + + {:else if typeof args == 'object'} + + {:else} + Expected argument to be an object, got {JSON.stringify(args)} instead + {/if} +
+ {/if} {/each} {:else if !shouldHideNoInputs}
No inputs
diff --git a/frontend/src/lib/components/TemplateEditor.svelte b/frontend/src/lib/components/TemplateEditor.svelte index 1e25091ed8..493e4a5f10 100644 --- a/frontend/src/lib/components/TemplateEditor.svelte +++ b/frontend/src/lib/components/TemplateEditor.svelte @@ -423,7 +423,7 @@ lineNumbers: 'off', fontSize, suggestOnTriggerCharacters: true, - lineDecorationsWidth: 20 + lineDecorationsWidth: 24 }) const stdLib = { content: libStdContent, filePath: 'es5.d.ts' } diff --git a/frontend/src/lib/components/flows/content/FlowConstants.svelte b/frontend/src/lib/components/flows/content/FlowConstants.svelte new file mode 100644 index 0000000000..12ccf88fa0 --- /dev/null +++ b/frontend/src/lib/components/flows/content/FlowConstants.svelte @@ -0,0 +1,68 @@ + + +
+ +
+ This page centralizes the static inputs of every steps. It is akin to a file containing all + constants. Modifying a value here modify it in the step input directly. It is especially + useful when forking a flow to get an overview of all the variables to parametrize that are + not exposed directly as flow inputs. + {#each steps as [args, filter, m] (m.id)} + {#if filter.length > 0} +
+

{m.summary || m.value['path'] || 'Inline script'} + {m.id} +

+ + +
+ {/if} + {/each} +
+
+
diff --git a/frontend/src/lib/components/flows/content/FlowEditorPanel.svelte b/frontend/src/lib/components/flows/content/FlowEditorPanel.svelte index d6bc942499..f7b1ef1ee0 100644 --- a/frontend/src/lib/components/flows/content/FlowEditorPanel.svelte +++ b/frontend/src/lib/components/flows/content/FlowEditorPanel.svelte @@ -7,6 +7,7 @@ import FlowInput from './FlowInput.svelte' import FlowFailureModule from './FlowFailureModule.svelte' import { flowStore } from '../flowStore' + import FlowConstants from './FlowConstants.svelte' export let initialPath: string @@ -17,6 +18,8 @@ {:else if $selectedId === 'inputs'} +{:else if $selectedId === 'constants'} + {:else if $selectedId === 'failure'} {:else} diff --git a/frontend/src/lib/components/flows/content/FlowModuleHeader.svelte b/frontend/src/lib/components/flows/content/FlowModuleHeader.svelte index f43eb9e4c7..c74b67959b 100644 --- a/frontend/src/lib/components/flows/content/FlowModuleHeader.svelte +++ b/frontend/src/lib/components/flows/content/FlowModuleHeader.svelte @@ -20,7 +20,7 @@
{#if module.value.type === 'script' || module.value.type === 'rawscript'} Retries Early stop/break Suspend + import type { FlowEditorContext } from '../types' + import { getContext } from 'svelte' + import Icon from 'svelte-awesome' + import { faDollarSign } from '@fortawesome/free-solid-svg-icons' + import { classNames } from '$lib/utils' + + const { select, selectedId } = getContext('FlowEditorContext') + + $: settingsClass = classNames( + 'border w-full rounded-sm p-2 bg-white border-gray-400 text-sm cursor-pointer flex items-center', + $selectedId == 'constants' ? 'outline outline-offset-1 outline-2 outline-slate-900' : '' + ) + + + +
select('constants')} class={settingsClass}> + + + All Static Inputs + +
diff --git a/frontend/src/lib/components/flows/map/FlowInputsItem.svelte b/frontend/src/lib/components/flows/map/FlowInputsItem.svelte index 950c7d40a2..c9e753199d 100644 --- a/frontend/src/lib/components/flows/map/FlowInputsItem.svelte +++ b/frontend/src/lib/components/flows/map/FlowInputsItem.svelte @@ -3,14 +3,13 @@ import { getContext } from 'svelte' import FlowModuleSchemaItem from './FlowModuleSchemaItem.svelte' import Icon from 'svelte-awesome' - import { faFlagCheckered, faPen } from '@fortawesome/free-solid-svg-icons' + import { faFlagCheckered } from '@fortawesome/free-solid-svg-icons' const { select, selectedId } = getContext('FlowEditorContext') select('inputs')} - isFirst hasLine selected={$selectedId === 'inputs'} bold diff --git a/frontend/src/lib/components/flows/map/FlowModuleSchemaMap.svelte b/frontend/src/lib/components/flows/map/FlowModuleSchemaMap.svelte index fb4178bb41..a1bf0af859 100644 --- a/frontend/src/lib/components/flows/map/FlowModuleSchemaMap.svelte +++ b/frontend/src/lib/components/flows/map/FlowModuleSchemaMap.svelte @@ -19,6 +19,10 @@ import FlowInputsItem from './FlowInputsItem.svelte' import InsertModuleButton from './InsertModuleButton.svelte' import { slide } from 'svelte/transition' + import FlowModuleSchemaItem from './FlowModuleSchemaItem.svelte' + import { Icon } from 'svelte-awesome' + import { faDollarSign } from '@fortawesome/free-solid-svg-icons' + import FlowConstantsItem from './FlowConstantsItem.svelte' export let root: boolean = false export let modules: FlowModule[] | undefined @@ -102,12 +106,17 @@
{#if root}
+
+ +
{/if} -
    +
      {#if root}
    • diff --git a/frontend/src/lib/components/flows/map/FlowSettingsItem.svelte b/frontend/src/lib/components/flows/map/FlowSettingsItem.svelte index efbc739c33..bf34b88fd0 100644 --- a/frontend/src/lib/components/flows/map/FlowSettingsItem.svelte +++ b/frontend/src/lib/components/flows/map/FlowSettingsItem.svelte @@ -2,12 +2,12 @@ import type { FlowEditorContext } from '../types' import { getContext } from 'svelte' import Icon from 'svelte-awesome' - import { faCalendarAlt, faSliders } from '@fortawesome/free-solid-svg-icons' + import { faSliders } from '@fortawesome/free-solid-svg-icons' import { classNames } from '$lib/utils' import { Badge } from '$lib/components/common' import { flowStore } from '../flowStore' - const { select, selectedId, schedule } = getContext('FlowEditorContext') + const { select, selectedId } = getContext('FlowEditorContext') $: settingsClass = classNames( 'border w-full rounded-sm p-2 bg-white border-gray-400 text-sm cursor-pointer flex items-center',