diff --git a/src/components/Process/Chained.tsx b/src/components/Process/Chained.tsx index 436e6eb..8093a21 100644 --- a/src/components/Process/Chained.tsx +++ b/src/components/Process/Chained.tsx @@ -248,12 +248,16 @@ const getProcessIdsInFlowStep = (meta: FlowNode) => { ids.push(meta.default) } - if (!meta.conditions) { - return ids + if (meta.renderWith) { + for (const renderWith of meta.renderWith) { + ids.push(renderWith.id) + } } - for (const condition of meta.conditions) { - ids.push(condition.goto) + if (meta.conditions) { + for (const condition of meta.conditions) { + ids.push(condition.goto) + } } return ids @@ -273,7 +277,7 @@ export const getAllProcessesInFlow = async ( processes[id] = election const meta = election.get('multiprocess') - if (meta && meta.default && !visited.has(meta.default)) { + if (meta && (meta.default || meta.renderWith) && !visited.has(meta.default)) { const idsToFetch = getProcessIdsInFlowStep(meta) for (const nextId of idsToFetch) { await loadProcess(nextId) @@ -289,6 +293,16 @@ export const getAllProcessesInFlow = async ( } } + // Add renderWith processes + if (meta.renderWith) { + for (const renderWithElection of meta.renderWith as RenderWith[]) { + if (!visited.has(renderWithElection.id)) { + visited.add(renderWithElection.id) + ids.push(renderWithElection.id) + } + } + } + // Add defaults after conditions if (!visited.has(meta.default)) { visited.add(meta.default) @@ -303,6 +317,7 @@ export const getAllProcessesInFlow = async ( if (meta) { initialIds.push(...getProcessIdsInFlowStep(meta)) } + for (const id of initialIds) { await loadProcess(id) } @@ -319,9 +334,17 @@ type FlowCondition = { } // FlowNode can have or conditions or renderWith, but not both -type FlowNode = { - default: string -} & ({ conditions?: FlowCondition[]; renderWith?: never } | { conditions?: never; renderWith: RenderWith[] }) +export type FlowNode = + | { + conditions?: FlowCondition[] + renderWith?: never + default: string + } + | { + conditions?: never + renderWith: RenderWith[] + default?: string // Default is optional for renderWith elections + } export type RenderWith = { id: string