diff --git a/frontend/src/lib/components/LogViewer.svelte b/frontend/src/lib/components/LogViewer.svelte index 94de0fd437..38fa2c953a 100644 --- a/frontend/src/lib/components/LogViewer.svelte +++ b/frontend/src/lib/components/LogViewer.svelte @@ -45,14 +45,15 @@ - {#if duration} + {#if isLoading} + + {:else if duration} took {duration}ms {/if} -
{#if content}{content}{:else if isLoading}
-				
-			{:else}No logs are available yet{/if}
{#if content}{content}{:else if !isLoading}No logs are available yet{/if} diff --git a/frontend/src/lib/components/ModulePreview.svelte b/frontend/src/lib/components/ModulePreview.svelte index bde44acf54..c31fd94c94 100644 --- a/frontend/src/lib/components/ModulePreview.svelte +++ b/frontend/src/lib/components/ModulePreview.svelte @@ -11,7 +11,6 @@ import { flowStateStore } from './flows/flowState' import { flowStore } from './flows/flowStore' import { workspaceStore } from '$lib/stores' - import { Icon } from 'svelte-awesome' import { Loader2 } from 'lucide-svelte' export let mod: FlowModule diff --git a/frontend/src/lib/components/ScriptEditor.svelte b/frontend/src/lib/components/ScriptEditor.svelte index 25fbef7246..6c5736dd0c 100644 --- a/frontend/src/lib/components/ScriptEditor.svelte +++ b/frontend/src/lib/components/ScriptEditor.svelte @@ -140,91 +140,93 @@ {/if} - - -
{ - inferSchema(code) - }} - > - { - inferSchema(e.detail) + + + +
{ + inferSchema(code) }} - cmdEnterAction={async () => { - await inferSchema(code) - runTest() - }} - formatAction={async () => { - await inferSchema(code) - try { - localStorage.setItem(path ?? 'last_save', code) - } catch (e) { - console.error('Could not save last_save to local storage', e) - } - lastSave = code - }} - class="flex flex-1 h-full !overflow-visible" - lang={scriptLangToEditorLang(lang)} - automaticLayout={true} - {fixedOverflowWidgets} - /> -
-
- -
-
- {#if testIsLoading} - - {:else} - - {/if} + > + { + inferSchema(e.detail) + }} + cmdEnterAction={async () => { + await inferSchema(code) + runTest() + }} + formatAction={async () => { + await inferSchema(code) + try { + localStorage.setItem(path ?? 'last_save', code) + } catch (e) { + console.error('Could not save last_save to local storage', e) + } + lastSave = code + }} + class="flex flex-1 h-full !overflow-visible" + lang={scriptLangToEditorLang(lang)} + automaticLayout={true} + {fixedOverflowWidgets} + />
- - -
-
- + + +
+
+ {#if testIsLoading} + + {:else} + + {/if} +
+ + +
+
+ +
-
-
- - - - -
- + + + + + +
+
+
diff --git a/frontend/src/lib/components/TestJobLoader.svelte b/frontend/src/lib/components/TestJobLoader.svelte index 59f37ec6ef..397e8a24f8 100644 --- a/frontend/src/lib/components/TestJobLoader.svelte +++ b/frontend/src/lib/components/TestJobLoader.svelte @@ -4,11 +4,6 @@ import { onDestroy } from 'svelte' import type { Preview } from '$lib/gen/models/Preview' import { createEventDispatcher } from 'svelte' - import { - setIntervalAsync, - clearIntervalAsync, - type SetIntervalAsyncTimer - } from 'set-interval-async' export let isLoading = false export let job: Job | undefined = undefined @@ -18,7 +13,6 @@ const dispatch = createEventDispatcher() $: workspace = workspaceOverride ?? $workspaceStore - let intervalId: SetIntervalAsyncTimer | undefined = undefined let syncIteration: number = 0 let errorIteration = 0 @@ -26,19 +20,32 @@ let ITERATIONS_BEFORE_SLOW_REFRESH = 10 let ITERATIONS_BEFORE_SUPER_SLOW_REFRESH = 100 - let stopCurrentIteration = false + let lastStartedAt: number = Date.now() + let currentId: string | undefined = undefined + + $: isLoading = currentId !== undefined export async function abstractRun(fn: () => Promise) { try { - await clearCurrentJob() isLoading = true + clearCurrentJob() + const startedAt = Date.now() const testId = await fn() - if (testId) { - await watchJob(testId) + + if (lastStartedAt < startedAt) { + lastStartedAt = startedAt + if (testId) { + try { + await watchJob(testId) + } catch { + if (currentId === testId) { + currentId = undefined + } + } + } } return testId } catch (err) { - isLoading = false throw err } } @@ -89,108 +96,102 @@ } export async function cancelJob() { - try { - await JobService.cancelQueuedJob({ - workspace: $workspaceStore ?? '', - id: job?.id ?? '', - requestBody: {} - }) - } catch (err) { - console.error(err) + const id = currentId + if (id) { + currentId = undefined + try { + await JobService.cancelQueuedJob({ + workspace: $workspaceStore ?? '', + id, + requestBody: {} + }) + } catch (err) { + console.error(err) + } } - isLoading = false - console.log('cancelled') + console.debug('cancelled') } export async function clearCurrentJob() { - if (intervalId) { - const interval = intervalId - intervalId = undefined - stopCurrentIteration = true - if (isLoading && job) { - try { - await JobService.cancelQueuedJob({ - workspace: workspace!, - id: job.id, - requestBody: {} - }) - } catch {} - } - await clearIntervalAsync(interval) + if (currentId) { + console.debug('clear') + job = undefined + await cancelJob() } - stopCurrentIteration = false - job = undefined - isLoading = false } export async function watchJob(testId: string) { syncIteration = 0 errorIteration = 0 + currentId = testId + job = undefined const isCompleted = await loadTestJob(testId) if (!isCompleted) { - isLoading = true - intervalId = setIntervalAsync(async () => { - await syncer(testId) + setTimeout(() => { + syncer(testId) }, 50) } } async function loadTestJob(id: string): Promise { let isCompleted = false - try { - if (job && `running` in job) { - let previewJobUpdates = await JobService.getJobUpdates({ - workspace: workspace!, - id, - running: job.running, - logOffset: job.logs?.length ? job.logs?.length + 1 : 0 - }) + if (currentId === id) { + try { + if (job && `running` in job) { + let previewJobUpdates = await JobService.getJobUpdates({ + workspace: workspace!, + id, + running: job.running, + logOffset: job.logs?.length ? job.logs?.length + 1 : 0 + }) - if (previewJobUpdates.new_logs) { - job.logs = (job?.logs ?? '').concat(previewJobUpdates.new_logs) - } - if ((previewJobUpdates.running ?? false) || (previewJobUpdates.completed ?? false)) { + if (previewJobUpdates.new_logs) { + job.logs = (job?.logs ?? '').concat(previewJobUpdates.new_logs) + } + if ((previewJobUpdates.running ?? false) || (previewJobUpdates.completed ?? false)) { + job = await JobService.getJob({ workspace: workspace!, id }) + } + } else { job = await JobService.getJob({ workspace: workspace!, id }) } - } else { - job = await JobService.getJob({ workspace: workspace!, id }) - } - job = await JobService.getJob({ workspace: workspace ?? '', id }) - if (job?.type === 'CompletedJob') { - //only CompletedJob has success property - isCompleted = true - intervalId && clearIntervalAsync(intervalId!) - if (isLoading) { - dispatch('done', job) - isLoading = false + if (job?.type === 'CompletedJob') { + //only CompletedJob has success property + isCompleted = true + if (currentId === id) { + dispatch('done', job) + currentId = undefined + } } + notfound = false + } catch (err) { + errorIteration += 1 + if (errorIteration == 5) { + notfound = true + await clearCurrentJob() + } + console.warn(err) } - notfound = false - } catch (err) { - errorIteration += 1 - if (errorIteration == 5) { - notfound = true - await clearCurrentJob() - } - console.warn(err) + return isCompleted + } else { + return true } - return isCompleted } async function syncer(id: string): Promise { - syncIteration++ - if (syncIteration == ITERATIONS_BEFORE_SLOW_REFRESH) { - intervalId && clearIntervalAsync(intervalId!) - intervalId = setIntervalAsync(async () => await syncer(id), 500) - } else if (syncIteration == ITERATIONS_BEFORE_SUPER_SLOW_REFRESH) { - intervalId && clearIntervalAsync(intervalId!) - intervalId = setIntervalAsync(async () => await syncer(id), 2000) - } - if (stopCurrentIteration) { + if (currentId != id) { + console.debug('stop') return } + syncIteration++ await loadTestJob(id) + let nextIteration = 50 + if (syncIteration == ITERATIONS_BEFORE_SLOW_REFRESH) { + nextIteration = 500 + } else if (syncIteration == ITERATIONS_BEFORE_SUPER_SLOW_REFRESH) { + nextIteration = 2000 + } + setTimeout(() => syncer(id), nextIteration) } onDestroy(async () => { diff --git a/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte b/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte index 354f323b71..8355c933c3 100644 --- a/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte +++ b/frontend/src/lib/components/apps/components/helpers/RunnableComponent.svelte @@ -187,13 +187,15 @@ let field = fields[k] if (field?.type == 'static' && fields[k]) { staticRunnableInputs[k] = field.value + } else if (field?.type == 'user') { + nonStaticRunnableInputs[k] = args[k] } else { nonStaticRunnableInputs[k] = runnableInputValues[k] } }) const requestBody = { - args: { ...nonStaticRunnableInputs, ...args }, + args: nonStaticRunnableInputs, force_viewer_static_fields: !isEditor ? undefined : staticRunnableInputs } @@ -239,7 +241,7 @@ { + on:done={(e) => { if (testJob && outputs) { const startedAt = new Date(testJob.started_at).getTime() if (startedAt > lastStartedAt) { diff --git a/frontend/src/lib/components/apps/editor/AppEditor.svelte b/frontend/src/lib/components/apps/editor/AppEditor.svelte index 2ae2f11e34..9a51b71df1 100644 --- a/frontend/src/lib/components/apps/editor/AppEditor.svelte +++ b/frontend/src/lib/components/apps/editor/AppEditor.svelte @@ -2,7 +2,7 @@ import SplitPanesWrapper from '$lib/components/splitPanes/SplitPanesWrapper.svelte' import { onMount, setContext } from 'svelte' - import { Pane } from 'svelte-splitpanes' + import { Pane, Splitpanes } from 'svelte-splitpanes' import { writable } from 'svelte/store' import { buildWorld, type World } from '../rx' import type { @@ -129,87 +129,91 @@ {context} /> {:else} - - - - - - - -
- {#if $appStore.grid} -
- + + + + + + + + + +
+ {#if $appStore.grid} +
+ +
+ {/if}
- {/if} -
- - -
- -
-
- - - -
- - -
- - Insert -
-
- -
- - Settings -
-
- - - {#if $selectedComponent !== undefined} - - {:else} -
No component selected.
- {/if} -
- - - -
-
- {#if $connectingInput.opened} -
- -
- Click on the output of the component you want to connect to on the left panel. -
- + + +
+ +
+
+ + + + +
+ + +
+ + Insert +
+
+ +
+ + Settings +
+
+ + + {#if $selectedComponent !== undefined} + + {:else} +
No component selected.
+ {/if} +
+ + + +
+
+ {#if $connectingInput.opened} +
+ +
+ Click on the output of the component you want to connect to on the left panel. +
+ +
-
- -
- {/if} -
- + +
+ {/if} +
+ + {/if} {:else} diff --git a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanel.svelte b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanel.svelte index b65323e7c3..be67ac2715 100644 --- a/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanel.svelte +++ b/frontend/src/lib/components/apps/editor/inlineScriptsPanel/InlineScriptsPanel.svelte @@ -2,7 +2,7 @@ import { getContext } from 'svelte' import type { AppEditorContext } from '../../types' import SplitPanesWrapper from '$lib/components/splitPanes/SplitPanesWrapper.svelte' - import { Pane } from 'svelte-splitpanes' + import { Pane, Splitpanes } from 'svelte-splitpanes' import InlineScriptsPanelList from './InlineScriptsPanelList.svelte' import InlineScriptEditorPanel from './InlineScriptEditorPanel.svelte' import InlineScriptEditor from './InlineScriptEditor.svelte' @@ -12,43 +12,45 @@ let selectedScriptComponentId: string | undefined = undefined - - - - - - {#each $lazyGrid as gridComponent, index (index)} - {#if gridComponent.data.id === selectedScriptComponentId} - - {/if} + + + + + + + {#each $lazyGrid as gridComponent, index (index)} + {#if gridComponent.data.id === selectedScriptComponentId} + + {/if} - {#if gridComponent.data.type === 'tablecomponent'} - {#each gridComponent.data.actionButtons as actionButton, index (index)} - {#if actionButton.id === selectedScriptComponentId} - - {/if} - {/each} - {/if} - {/each} - {#each $app.unusedInlineScripts as unusedInlineScript, index (index)} - {#if `unused-${index}` === selectedScriptComponentId} - { - // remove the script from the array at the index - $app.unusedInlineScripts.splice(index, 1) - $app.unusedInlineScripts = [...$app.unusedInlineScripts] - }} - /> - {/if} - {/each} - + {#if gridComponent.data.type === 'tablecomponent'} + {#each gridComponent.data.actionButtons as actionButton, index (index)} + {#if actionButton.id === selectedScriptComponentId} + + {/if} + {/each} + {/if} + {/each} + {#each $app.unusedInlineScripts as unusedInlineScript, index (index)} + {#if `unused-${index}` === selectedScriptComponentId} + { + // remove the script from the array at the index + $app.unusedInlineScripts.splice(index, 1) + $app.unusedInlineScripts = [...$app.unusedInlineScripts] + }} + /> + {/if} + {/each} + + diff --git a/frontend/src/lib/components/scriptEditor/LogPanel.svelte b/frontend/src/lib/components/scriptEditor/LogPanel.svelte index af52dd49de..6e84052106 100644 --- a/frontend/src/lib/components/scriptEditor/LogPanel.svelte +++ b/frontend/src/lib/components/scriptEditor/LogPanel.svelte @@ -16,7 +16,7 @@ import DrawerContent from '../common/drawer/DrawerContent.svelte' import HighlightCode from '../HighlightCode.svelte' import LogViewer from '../LogViewer.svelte' - import { Pane } from 'svelte-splitpanes' + import { Pane, Splitpanes } from 'svelte-splitpanes' import SplitPanesWrapper from '../splitPanes/SplitPanesWrapper.svelte' import { Loader2 } from 'lucide-svelte' @@ -77,29 +77,31 @@ because SplitPanesWrapper uses the parent element as a reference point. --> {#if selectedTab === 'logs'} - - - - - - {#if previewJob != undefined && 'result' in previewJob && previewJob.result != undefined} -

+			
+				
+					
+						
+					
+					
+						{#if previewJob != undefined && 'result' in previewJob && previewJob.result != undefined}
+							

 						
- {:else} -
- {#if previewIsLoading} - - {:else} - Test to see the result here' - {/if} -
- {/if} -
+ {:else} +
+ {#if previewIsLoading} + + {:else} + Test to see the result here' + {/if} +
+ {/if} + +
{/if} diff --git a/frontend/src/lib/components/splitPanes/SplitPanesWrapper.svelte b/frontend/src/lib/components/splitPanes/SplitPanesWrapper.svelte index b3b9bcd8cd..0a5d23bb15 100644 --- a/frontend/src/lib/components/splitPanes/SplitPanesWrapper.svelte +++ b/frontend/src/lib/components/splitPanes/SplitPanesWrapper.svelte @@ -1,6 +1,5 @@