Files
windmill/frontend/src/lib/components/flows/flowStore.ts
T
Ruben Fiszel 9e8c9fb1cb feat: add ability to edit id in flows (#4364)
* all

* all

* nit mailto

* fix

* fix
2024-09-10 20:16:43 +02:00

43 lines
1.2 KiB
TypeScript

import type { Flow, OpenFlow } from '$lib/gen'
import { writable, type Writable } from 'svelte/store'
import { initFlowState, type FlowState } from './flowState'
export type FlowMode = 'push' | 'pull'
export const importFlowStore = writable<Flow | undefined>(undefined)
export async function initFlow(
flow: Flow,
flowStore: Writable<Flow>,
flowStateStore: Writable<FlowState>
) {
await initFlowState(flow, flowStateStore)
flowStore.set(flow)
}
export async function copyFirstStepSchema(flowState: FlowState, flowStore: Writable<OpenFlow>) {
flowStore.update((flow) => {
const firstModuleId = flow.value.modules[0]?.id
if (flowState[firstModuleId] && firstModuleId) {
flow.schema = structuredClone(flowState[firstModuleId].schema)
const v = flow.value.modules[0].value
if (v.type == 'rawscript' || v.type == 'script') {
Object.keys(v.input_transforms ?? {}).forEach((key) => {
v.input_transforms[key] = {
type: 'javascript',
expr: `flow_input.${key}`
}
})
}
}
return flow
})
}
export function replaceId(expr: string, id: string, newId: string): string {
return expr
.replaceAll(`results.${id}`, `results.${newId}`)
.replaceAll(`results?.${id}`, `results?.${newId}`)
}