Files
windmill/frontend/src/lib/components/FlowLoopIterationPreview.svelte
T
Guilhem c000bbca28 fix(frontend): scope raw-app, flow and script editors to the session workspace (#10015)
* fix(frontend): scope raw-app/flow/script editors to the session workspace

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(frontend): scope flow and script editor operations to the session workspace

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(frontend): scope flow preview, inline-script creation and datatable schema to the session workspace

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(frontend): address Codex review — thread session workspace through flow resource pickers, script fetch, preview cancel/recording and path collision check

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(frontend): address Claude review — pass session workspace to preview FlowStatusViewer and align FlowChatManager guards

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(frontend): address Pi review — show acting workspace in script-not-found message and fetch picked script from it in EditorBar

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(frontend): address Codex review round 2 — thread session workspace into flow step test, raw-app inline runnable, inline editor toolbars and MCP OAuth path

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(frontend): address Codex review round 3 — thread session workspace into dynamic-input helpers and the flow-preview argument side panel (history/saved-inputs/captures)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(frontend): address Codex review round 4 — thread session workspace into nested flow/script drawers, flow chat inputs and the flow input side tabs

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(frontend): address Codex review round 5 — thread session workspace into script-module fork/reload and key the raw-app schema cache by workspace

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(frontend): address Codex review round 6 — key the DB manager schema cache by acting workspace

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(frontend): address Codex review round 7 — thread session workspace into resource-valued arg pickers and the editor variable/resource helper drawers

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(frontend): scope the flow asset explorer's ResourceEditorDrawer to the acting workspace

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix: thread acting workspace through flow asset explore controls

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix: thread acting workspace through SQL REPL, secret args, helper forms, S3 inputs, saved inputs

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 01:53:43 +02:00

202 lines
4.6 KiB
Svelte

<script lang="ts">
import { type Job, JobService, type FlowModule, type RestartedFrom } from '$lib/gen'
import { workspaceStore } from '$lib/stores'
import { Button } from './common'
import { createEventDispatcher, getContext } from 'svelte'
import type { FlowEditorContext } from './flows/types'
import { runFlowPreview } from './flows/utils.svelte'
import SchemaForm from './SchemaForm.svelte'
import FlowStatusViewer from '../components/FlowStatusViewer.svelte'
import FlowProgressBar from './flows/FlowProgressBar.svelte'
import { CornerDownLeft, Play, RefreshCw, X } from 'lucide-svelte'
import type { Schema } from '$lib/common'
interface Props {
open: boolean
jobId?: string | undefined
job?: Job | undefined
modules: FlowModule[]
previewArgs?: Record<string, any>
whileLoop?: boolean
}
let {
open,
jobId = $bindable(undefined),
job = $bindable(undefined),
modules,
previewArgs = $bindable({}),
whileLoop = false
}: Props = $props()
export const forloopSchema: Schema = {
$schema: 'https://json-schema.org/draft/2020-12/schema' as string | undefined,
properties: {
iter: {
type: 'object',
properties: {
index: {
type: 'number'
},
value: {
type: 'object'
}
}
}
},
required: [],
type: 'object'
}
export const whileLoopSchema: Schema = {
$schema: 'https://json-schema.org/draft/2020-12/schema' as string | undefined,
properties: {
iter: {
type: 'object',
properties: {
index: {
type: 'number'
}
}
}
},
required: [],
type: 'object'
}
let selectedJobStep: string | undefined = $state(undefined)
let isRunning: boolean = $state(false)
let progressBar: FlowProgressBar | undefined = $state(undefined)
export function test() {
runPreview(previewArgs, undefined)
}
const { flowStateStore, pathStore, opWorkspace } =
getContext<FlowEditorContext>('FlowEditorContext')
const dispatch = createEventDispatcher()
export async function runPreview(
args: Record<string, any>,
restartedFrom: RestartedFrom | undefined
) {
progressBar?.reset()
const newFlow = { value: { modules }, summary: '' }
jobId = await runFlowPreview(
args,
newFlow,
$pathStore,
restartedFrom,
undefined,
undefined,
opWorkspace?.()
)
isRunning = true
}
function onKeyDown(event: KeyboardEvent) {
if (open) {
switch (event.key) {
case 'Enter':
if (event.ctrlKey || event.metaKey) {
event.preventDefault()
runPreview(previewArgs, undefined)
}
break
}
}
}
$effect(() => {
if (job?.type === 'CompletedJob') {
isRunning = false
}
})
</script>
<svelte:window onkeydown={onKeyDown} />
<div class="flex flex-col space-y-2 h-screen bg-surface px-6 py-2 w-full" id="flow-preview-content">
<div class="flex flex-row justify-between w-full items-center gap-x-2">
<div class="w-8">
<Button
on:click={() => dispatch('close')}
startIcon={{ icon: X }}
iconOnly
unifiedSize="md"
variant="default"
btnClasses="hover:bg-surface-hover bg-surface-secondaryw-8 h-8 rounded-full p-0"
/>
</div>
{#if isRunning}
<Button
variant="accent"
destructive
on:click={async () => {
isRunning = false
try {
jobId &&
(await JobService.cancelQueuedJob({
workspace: opWorkspace?.() ?? $workspaceStore ?? '',
id: jobId,
requestBody: {}
}))
} catch {}
}}
unifiedSize="md"
btnClasses="w-full max-w-lg"
loading={true}
clickableWhileLoading
>
Cancel
</Button>
{:else}
<Button
variant="accent"
startIcon={{ icon: isRunning ? RefreshCw : Play }}
unifiedSize="md"
btnClasses="w-full max-w-lg"
on:click={() => runPreview(previewArgs, undefined)}
id="flow-editor-test-flow-drawer"
shortCut={{
Icon: CornerDownLeft
}}
>
Test iteration
</Button>
{/if}
<div></div>
</div>
<div class="w-full flex flex-col gap-y-1">
<FlowProgressBar {job} bind:this={progressBar} />
</div>
<div class="overflow-y-auto grow pr-4">
<div class="max-h-1/2 overflow-auto border-b">
<SchemaForm
noVariablePicker
compact
className="py-4 max-w-3xl"
schema={whileLoop ? whileLoopSchema : forloopSchema}
bind:args={previewArgs}
/>
</div>
<div class="pt-4 grow">
{#if jobId}
<FlowStatusViewer
bind:flowState={flowStateStore.val}
workspaceId={opWorkspace?.()}
{jobId}
onJobsLoaded={({ job: newJob }) => {
job = newJob
}}
bind:selectedJobStep
/>
{:else}
<div class="italic text-primary h-full grow"> Flow status will be displayed here </div>
{/if}
</div>
</div>
</div>