|
17 | 17 | } from '$lib/gen'
|
18 | 18 | import { inferArgs } from '$lib/infer'
|
19 | 19 | import { setCopilotInfo, userStore, workspaceStore } from '$lib/stores'
|
20 |
| - import { emptySchema, readFieldsRecursively, sendUserToast } from '$lib/utils' |
| 20 | + import { emptySchema, readFieldsRecursively, sendUserToast, type StateStore } from '$lib/utils' |
21 | 21 | import { Pane, Splitpanes } from 'svelte-splitpanes'
|
22 | 22 | import { onDestroy, onMount, setContext, untrack } from 'svelte'
|
23 | 23 | import DarkModeToggle from '$lib/components/sidebar/DarkModeToggle.svelte'
|
|
27 | 27 | import FlowModuleSchemaMap from './flows/map/FlowModuleSchemaMap.svelte'
|
28 | 28 | import FlowEditorPanel from './flows/content/FlowEditorPanel.svelte'
|
29 | 29 | import { deepEqual } from 'fast-equals'
|
30 |
| - import { writable, type Writable } from 'svelte/store' |
| 30 | + import { writable } from 'svelte/store' |
31 | 31 | import type { FlowState } from './flows/flowState'
|
32 | 32 | import { initHistory } from '$lib/history.svelte'
|
33 | 33 | import type { FlowEditorContext, FlowInput, FlowInputEditorState } from './flows/types'
|
|
51 | 51 | import { TestSteps } from './flows/testSteps.svelte'
|
52 | 52 | import { ModulesTestStates } from './modulesTest.svelte'
|
53 | 53 | import type { GraphModuleState } from './graph'
|
54 |
| - import { updateDerivedModuleStatesFromTestJobs } from './flows/utils' |
55 | 54 |
|
56 | 55 | let flowCopilotContext: FlowCopilotContext = {
|
57 | 56 | shouldUpdatePropertyType: writable<{
|
|
116 | 115 | const flowPreviewContent = $derived(flowPreviewButtons?.getFlowPreviewContent())
|
117 | 116 | const job: Job | undefined = $derived(flowPreviewContent?.getJob())
|
118 | 117 | let showJobStatus = $state(false)
|
119 |
| - let testModuleId: string | undefined = $state(undefined) |
120 | 118 |
|
121 | 119 | type LastEditScript = {
|
122 | 120 | content: string
|
|
453 | 451 | }
|
454 | 452 | }
|
455 | 453 |
|
456 |
| - const flowStateStore = writable({} as FlowState) |
| 454 | + const flowStateStore = $state({ val: {} }) as StateStore<FlowState> |
457 | 455 |
|
458 | 456 | const previewArgsStore = $state({ val: {} })
|
459 | 457 | const scriptEditorDrawer = writable(undefined)
|
|
464 | 462 | const triggersCount = writable<TriggersCount | undefined>(undefined)
|
465 | 463 | const modulesTestStates = new ModulesTestStates((moduleId) => {
|
466 | 464 | // Update the derived store with test job states
|
467 |
| - delete $derivedModuleStates[moduleId] |
468 |
| - testModuleId = moduleId |
469 | 465 | showJobStatus = false
|
470 | 466 | })
|
471 | 467 | const outputPickerOpenFns: Record<string, () => void> = $state({})
|
|
538 | 534 | }
|
539 | 535 |
|
540 | 536 | mod.value.input_transforms = input_transforms
|
541 |
| - if (!deepEqual(schema, $flowStateStore[mod.id]?.schema)) { |
542 |
| - if (!$flowStateStore[mod.id]) { |
543 |
| - $flowStateStore[mod.id] = { schema } |
| 537 | + if (!deepEqual(schema, flowStateStore.val[mod.id]?.schema)) { |
| 538 | + if (!flowStateStore.val[mod.id]) { |
| 539 | + flowStateStore.val[mod.id] = { schema } |
544 | 540 | } else {
|
545 |
| - $flowStateStore[mod.id].schema = schema |
| 541 | + flowStateStore.val[mod.id].schema = schema |
546 | 542 | }
|
547 | 543 | reload++
|
548 | 544 | }
|
|
586 | 582 | $selectedIdStore && untrack(() => inferModuleArgs($selectedIdStore))
|
587 | 583 | })
|
588 | 584 |
|
589 |
| - const localModuleStates: Writable<Record<string, GraphModuleState>> = $derived( |
590 |
| - flowPreviewContent?.getLocalModuleStates() ?? writable({}) |
591 |
| - ) |
| 585 | + let localModuleStates: Record<string, GraphModuleState> = $state({}) |
592 | 586 |
|
593 |
| - const suspendStatus: Writable<Record<string, { job: Job; nb: number }>> = $derived( |
594 |
| - flowPreviewContent?.getSuspendStatus() ?? writable({}) |
595 |
| - ) |
| 587 | + let suspendStatus: StateStore<Record<string, { job: Job; nb: number }>> = $state({ val: {} }) |
596 | 588 |
|
597 | 589 | // Create a derived store that only shows the module states when showModuleStatus is true
|
598 | 590 | // this store can also be updated
|
599 |
| - let derivedModuleStates = writable<Record<string, GraphModuleState>>({}) |
600 |
| - $effect(() => { |
601 |
| - derivedModuleStates.update((currentStates) => { |
602 |
| - return showJobStatus ? $localModuleStates : currentStates |
603 |
| - }) |
604 |
| - }) |
605 |
| - $effect(() => { |
606 |
| - updateDerivedModuleStatesFromTestJobs(testModuleId, modulesTestStates, derivedModuleStates) |
607 |
| - }) |
608 | 591 |
|
609 | 592 | let flowModuleSchemaMap: FlowModuleSchemaMap | undefined = $state()
|
610 | 593 | function onJobDone() {
|
|
639 | 622 | }
|
640 | 623 |
|
641 | 624 | function resetModulesStates() {
|
642 |
| - derivedModuleStates.set({}) |
643 | 625 | showJobStatus = false
|
644 | 626 | }
|
645 | 627 |
|
646 |
| - const individualStepTests = $derived( |
647 |
| - !(showJobStatus && job) && Object.keys($derivedModuleStates).length > 0 |
648 |
| - ) |
649 |
| -
|
650 | 628 | const flowHasChanged = $derived(flowPreviewContent?.flowHasChanged())
|
651 | 629 | </script>
|
652 | 630 |
|
|
785 | 763 | bind:this={flowPreviewButtons}
|
786 | 764 | {onJobDone}
|
787 | 765 | onRunPreview={() => {
|
788 |
| - localModuleStates.set({}) |
| 766 | + localModuleStates = {} |
789 | 767 | showJobStatus = true
|
790 | 768 | }}
|
791 | 769 | />
|
|
800 | 778 | disableTutorials
|
801 | 779 | smallErrorHandler={true}
|
802 | 780 | disableStaticInputs
|
803 |
| - localModuleStates={derivedModuleStates} |
| 781 | + {localModuleStates} |
804 | 782 | onTestUpTo={flowPreviewButtons?.testUpTo}
|
| 783 | + testModuleStates={modulesTestStates} |
805 | 784 | isOwner={flowPreviewContent?.getIsOwner?.()}
|
806 | 785 | onTestFlow={flowPreviewButtons?.runPreview}
|
807 | 786 | isRunning={flowPreviewContent?.getIsRunning?.()}
|
808 | 787 | onCancelTestFlow={flowPreviewContent?.cancelTest}
|
809 | 788 | onOpenPreview={flowPreviewButtons?.openPreview}
|
810 | 789 | onHideJobStatus={resetModulesStates}
|
811 |
| - {individualStepTests} |
812 | 790 | flowJob={job}
|
813 | 791 | {showJobStatus}
|
814 | 792 | onDelete={(id) => {
|
815 |
| - delete $derivedModuleStates[id] |
| 793 | + delete localModuleStates[id] |
| 794 | + delete modulesTestStates.states[id] |
816 | 795 | }}
|
817 | 796 | {flowHasChanged}
|
818 | 797 | />
|
|
0 commit comments