Skip to content

Commit

Permalink
Show renderWith elections results
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon committed Oct 17, 2024
1 parent f6fcc40 commit 91dedb3
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions src/components/Process/Chained.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -303,6 +317,7 @@ export const getAllProcessesInFlow = async (
if (meta) {
initialIds.push(...getProcessIdsInFlowStep(meta))
}

for (const id of initialIds) {
await loadProcess(id)
}
Expand All @@ -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
Expand Down

0 comments on commit 91dedb3

Please sign in to comment.