diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelList.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelList.svelte index 59cf1981cd..43c189fe4a 100644 --- a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelList.svelte +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanelList.svelte @@ -2,11 +2,11 @@ import { Badge } from '$lib/components/common' import { classNames } from '$lib/utils' import { getContext } from 'svelte' - import type { AppComponent, AppEditorContext } from '../../types' + import type { AppEditorContext } from '../../types' import PanelSection from '../settingsPanel/common/PanelSection.svelte' + import { getAppScripts } from './utils' export let selectedScriptComponentId: string | undefined = undefined - const { app, selectedComponent, lazyGrid } = getContext('AppEditorContext') function selectInlineScript(id: string) { @@ -16,63 +16,7 @@ } } - $: runnablesByName = $lazyGrid.reduce((acc, gridComponent) => { - const component: AppComponent = gridComponent.data - - if (component.type === 'tablecomponent') { - component.actionButtons.forEach((actionButton) => { - if (actionButton.componentInput?.type === 'runnable') { - if (actionButton.componentInput.runnable?.type === 'runnableByName') { - acc.push({ - name: actionButton.componentInput.runnable.name, - id: actionButton.id - }) - } - } - }) - } - - const componentInput = component.componentInput - - if (componentInput?.type === 'runnable') { - if (componentInput.runnable?.type === 'runnableByName') { - acc.push({ - name: componentInput.runnable.name, - id: gridComponent.id - }) - } - } - return acc - }, [] as { name: string; id: string }[]) - - $: runnablesByPath = $lazyGrid.reduce((acc, gridComponent) => { - const component: AppComponent = gridComponent.data - - if (component.type === 'tablecomponent') { - component.actionButtons.forEach((actionButton) => { - if (actionButton.componentInput?.type === 'runnable') { - if (actionButton.componentInput.runnable?.type === 'runnableByPath') { - acc.push({ - name: actionButton.componentInput.runnable.path, - id: actionButton.id - }) - } - } - }) - } - - const componentInput = component.componentInput - - if (componentInput?.type === 'runnable') { - if (componentInput.runnable?.type === 'runnableByPath') { - acc.push({ - name: componentInput.runnable.path, - id: gridComponent.id - }) - } - } - return acc - }, [] as { name: string; id: string }[]) + $: runnables = getAppScripts($lazyGrid) // When seleced component changes, update selectedScriptComponentId $: { @@ -85,9 +29,9 @@
- {#if runnablesByName.length > 0} + {#if runnables.inline.length > 0}
- {#each runnablesByName as { name, id }, index (index)} + {#each runnables.inline as { name, id }, index (index)}
No inline scripts
{/if}
- +
- {#if runnablesByPath.length > 0} + {#if runnables.imported.length > 0}
- {#each runnablesByPath as { name, id }, index (index)} + {#each runnables.imported as { name, id }, index (index)}
{ + const component: AppComponent = gridComponent.data + const componentInput = component.componentInput + + if (component.type === 'tablecomponent') { + component.actionButtons.forEach((actionButton) => { + if (actionButton.componentInput?.type !== 'runnable') { return } + processRunnable( + actionButton.componentInput.runnable, + actionButton.id, + acc + ) + }) + } + if (componentInput?.type === 'runnable') { + processRunnable( + componentInput.runnable, + gridComponent.id, + acc + ) + } + + return acc + }, {inline: [], imported: []} as AppScriptsList) +} + +function processRunnable(runnable: Runnable, id: string, list: AppScriptsList) { + if(runnable?.type === undefined) { return } + const type: keyof AppScriptsList = runnable.type === 'runnableByPath' ? 'imported' : 'inline' + list[type].push({ + name: runnable[runnable.type === 'runnableByPath' ? 'path' : 'name'], + id + }) +} \ No newline at end of file