diff options
Diffstat (limited to 'makima/frontend/src')
| -rw-r--r-- | makima/frontend/src/components/directives/DirectiveDAG.tsx | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/makima/frontend/src/components/directives/DirectiveDAG.tsx b/makima/frontend/src/components/directives/DirectiveDAG.tsx index f288a0d..27a80ac 100644 --- a/makima/frontend/src/components/directives/DirectiveDAG.tsx +++ b/makima/frontend/src/components/directives/DirectiveDAG.tsx @@ -16,37 +16,19 @@ interface Layer { function topoSort(steps: DirectiveStep[]): Layer[] { if (steps.length === 0) return []; - const stepMap = new Map(steps.map((s) => [s.id, s])); - const assigned = new Set<string>(); - const layers: Layer[] = []; - - // Iteratively find steps whose dependencies are all assigned - let remaining = [...steps]; - while (remaining.length > 0) { - const layer: DirectiveStep[] = []; - for (const step of remaining) { - const depsResolved = step.dependsOn.every( - (depId) => assigned.has(depId) || !stepMap.has(depId) - ); - if (depsResolved) { - layer.push(step); - } - } - - if (layer.length === 0) { - // Cycle detected or orphaned — push all remaining - layers.push({ steps: remaining }); - break; - } - - for (const s of layer) { - assigned.add(s.id); - } - layers.push({ steps: layer.sort((a, b) => a.orderIndex - b.orderIndex) }); - remaining = remaining.filter((s) => !assigned.has(s.id)); + // Group steps by orderIndex — each unique orderIndex is one execution phase + const byOrder = new Map<number, DirectiveStep[]>(); + for (const step of steps) { + const group = byOrder.get(step.orderIndex) ?? []; + group.push(step); + byOrder.set(step.orderIndex, group); } - return layers; + // Sort groups by ascending orderIndex + const sortedKeys = [...byOrder.keys()].sort((a, b) => a - b); + return sortedKeys.map((key) => ({ + steps: byOrder.get(key)!.sort((a, b) => a.name.localeCompare(b.name)), + })); } export function DirectiveDAG({ steps, onComplete, onFail, onSkip }: DirectiveDAGProps) { |
