|
1
|
import { WorkflowSteps, WorkflowStepUi } from "types" |
|
2
|
|
|
3
|
export const createNodeClusters = (steps: WorkflowSteps) => { |
|
4
|
const clusters: Record<number, WorkflowStepUi[]> = {} |
|
5
|
|
|
6
|
steps.forEach((step) => { |
|
7
|
if (!clusters[step.depth]) { |
|
8
|
clusters[step.depth] = [] |
|
9
|
} |
|
10
|
|
|
11
|
if (step.type === "when") { |
|
12
|
const whenSteps = step.steps.map((whenStep) => ({ |
|
13
|
...whenStep, |
|
14
|
depth: step.depth, |
|
15
|
when: step, |
|
16
|
})) |
|
17
|
clusters[step.depth].push(...whenSteps) |
|
18
|
} else { |
|
19
|
clusters[step.depth].push(step) |
|
20
|
} |
|
21
|
}) |
|
22
|
|
|
23
|
return clusters |
|
24
|
} |
|
25
|
|
|
26
|
export const getNextCluster = ( |
|
27
|
clusters: Record<number, WorkflowStepUi[]>, |
|
28
|
depth: number |
|
29
|
) => { |
|
30
|
const nextDepth = depth + 1 |
|
31
|
return clusters[nextDepth] |
|
32
|
} |