mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-07 00:01:49 +00:00
* clean api 2 * the rest * clean tests * stop_after_if test * unbox `modules: Vec<FlowModule>` in `ForloopFlow` * migrate * initFlow stop_after_if_expr and skip_if_stopped * s/migrateInitTransform/migrateFlowModule I didn't read the name before... oops * sql migration for openflow changes * fix frontend migration code Co-authored-by: sqwishy <somebody@froghat.ca>
82 lines
2.0 KiB
TypeScript
82 lines
2.0 KiB
TypeScript
import type { Schema } from '$lib/common'
|
|
import type { Flow, FlowModule } from '$lib/gen'
|
|
import { derived, writable } from 'svelte/store'
|
|
import { emptyFlowModuleSchema, isEmptyFlowModule, loadFlowModuleSchema } from './flowStateUtils'
|
|
|
|
export type FlowModuleSchema = {
|
|
flowModule: FlowModule
|
|
schema: Schema
|
|
childFlowModules?: FlowModuleSchema[]
|
|
previewResult?: any
|
|
}
|
|
|
|
export type FlowState = FlowModuleSchema[]
|
|
|
|
export const flowStateStore = writable<FlowState>(undefined)
|
|
|
|
export async function initFlowState(flow: Flow) {
|
|
const flowState = await flowModulesToFlowState(flow.value.modules)
|
|
flowStateStore.set(flowState)
|
|
}
|
|
|
|
export const isCopyFirstStepSchemaDisabled = derived(
|
|
flowStateStore,
|
|
(flowState: FlowState | undefined) => {
|
|
if (flowState) {
|
|
const firstModule = flowState[0]
|
|
if (!firstModule) {
|
|
return true
|
|
}
|
|
const fm = firstModule.flowModule
|
|
return flowState.length === 0 || isEmptyFlowModule(fm)
|
|
} else {
|
|
return true
|
|
}
|
|
}
|
|
)
|
|
|
|
export async function flowModulesToFlowState(flowModules: FlowModule[]): Promise<FlowState> {
|
|
return Promise.all(
|
|
flowModules.map(async (flowModule: FlowModule) => {
|
|
const value = flowModule.value
|
|
if (value.type === 'forloopflow') {
|
|
const childFlowModules = await Promise.all(
|
|
value.modules.map(async (module) => loadFlowModuleSchema(module))
|
|
)
|
|
const loopFlowModule = await loadFlowModuleSchema(flowModule)
|
|
|
|
return {
|
|
...loopFlowModule,
|
|
childFlowModules
|
|
}
|
|
}
|
|
|
|
if (isEmptyFlowModule(flowModule)) {
|
|
return emptyFlowModuleSchema()
|
|
}
|
|
|
|
return loadFlowModuleSchema(flowModule)
|
|
})
|
|
)
|
|
}
|
|
|
|
export function flowStateToFlow(flowState: FlowState, flow: Flow): Flow {
|
|
if (!flowState || !flow) {
|
|
return flow
|
|
}
|
|
|
|
const modules = flowState.map(({ flowModule, childFlowModules }) => {
|
|
const fmv = flowModule.value
|
|
|
|
if (fmv.type === 'forloopflow' && childFlowModules && Array.isArray(childFlowModules)) {
|
|
fmv.modules = childFlowModules.map((cfm) => cfm.flowModule)
|
|
flowModule.value = fmv
|
|
}
|
|
|
|
return flowModule
|
|
})
|
|
|
|
flow.value.modules = modules
|
|
return flow
|
|
}
|