fix(ui): align branch lane ends and route the unmatched switch path down its own lane

This commit is contained in:
sam committed 2026-10-18 23:45:25 +11:00
1 parent 0d6d5e7dd3
commit 168ddde0dd
4 files changed
+32 -28

No files matched your search

+3 -3
View File
@@ -3,14 +3,14 @@ import { Handle, Position } from "@vue-flow/core";
import AddStepMenu from "./AddStepMenu.vue";
defineProps<{ data: { branch?: string; types: string[]; editable: boolean; onInsert: (type: string) => void } }>();
defineProps<{ data: { branch?: string; lane?: string; insertAfter?: unknown; types: string[]; editable: boolean; onInsert: (type: string) => void } }>();
</script>
<template>
<div class="relative flex w-8 justify-center">
<Handle type="target" :position="Position.Top" class="!opacity-0" />
<AddStepMenu v-if="data.editable" :types="data.types" :label="data.branch ? `Add a step to ${data.branch}` : 'Add a step at the end'" @pick="data.onInsert" />
<Handle v-if="data.branch" type="source" :position="Position.Bottom" class="!opacity-0" />
<AddStepMenu v-if="data.editable && data.insertAfter" :types="data.types" :label="data.branch ? `Add a step to ${data.branch}` : 'Add a step at the end'" @pick="data.onInsert" />
<Handle v-if="data.lane" type="source" :position="Position.Bottom" class="!opacity-0" />
<span v-else class="size-2 rounded-full bg-border" aria-hidden="true" />
</div>
</template>
+1 -4
View File
@@ -5,7 +5,7 @@ import { BaseEdge, EdgeLabelRenderer, getSmoothStepPath, type EdgeProps } from "
import AddStepMenu from "./AddStepMenu.vue";
import type { StepPath } from "./workflow-edit";
const props = defineProps<EdgeProps<{ trace?: string; otherwise?: boolean; insertAfter?: StepPath; types: string[]; editable: boolean; onInsert: (after: StepPath, type: string) => void }>>();
const props = defineProps<EdgeProps<{ trace?: string; insertAfter?: StepPath; types: string[]; editable: boolean; onInsert: (after: StepPath, type: string) => void }>>();
const path = computed(() =>
getSmoothStepPath({
@@ -22,9 +22,6 @@ const path = computed(() =>
<template>
<BaseEdge :id="id" :path="path[0]" :class="['workflow-flow-edge', data?.trace && `trace-${data.trace}`]" />
<EdgeLabelRenderer v-if="data?.otherwise">
<div class="absolute text-[11px] text-fg-subtle" :style="{ transform: `translate(8px, -50%) translate(${sourceX}px, ${sourceY}px)` }">otherwise</div>
</EdgeLabelRenderer>
<EdgeLabelRenderer v-if="data?.editable && data.insertAfter !== undefined">
<div
class="workflow-insert absolute p-3 opacity-0 transition-opacity focus-within:opacity-100 hover:opacity-100 has-[[data-state=open]]:opacity-100"
+1 -1
View File
@@ -163,7 +163,7 @@ const edges = computed(() =>
...edge,
type: "insert",
...(otherwise ? { sourceHandle: "otherwise" } : {}),
data: { trace: runs.value.get(edge.target), otherwise, insertAfter, types: typesAt(insertAfter), editable: editable.value, onInsert: (after: StepPath, type: string) => emit("insert", after, type) },
data: { trace: runs.value.get(edge.target), insertAfter, types: typesAt(insertAfter), editable: editable.value, onInsert: (after: StepPath, type: string) => emit("insert", after, type) },
}
: {
...edge,
+27 -20
View File
@@ -327,9 +327,22 @@ export function workflowGraph(source: string): WorkflowGraph {
const passes = kind === "switch" && !branches.some(([name]) => name === "default");
const lanes = branches.length + (passes ? 1 : 0);
const ends: string[] = [];
let depth = 0;
const depth = Math.max(1, ...branches.map(([, branchSteps]) => branchSteps.length));
const laneAt = (column: number) => (column - (lanes - 1) / 2) * COLUMN;
const lane = (id: string, x: number, title: string) =>
nodes.push({
id,
type: "lane",
position: { x: x - 12, y: row * ROW - 40 },
style: { width: `${COLUMN - 16}px`, height: `${(depth + 1) * ROW - 24}px` },
zIndex: -1,
data: { kind: "step", key: title, title, type: "", detail: "", lane: kind },
});
// Every lane closes at the same row, so the + that ends a branch sits at
// the foot of its own box and the joins into the next step line up.
const foot = (row + depth) * ROW;
branches.forEach(([name, branchSteps], column) => {
const x = (column - (lanes - 1) / 2) * COLUMN;
const x = laneAt(column);
let tail = [parent];
const path = ["steps", i, ...base, name];
branchSteps.forEach((branchStep, j) => {
@@ -337,32 +350,26 @@ export function workflowGraph(source: string): WorkflowGraph {
link(tail, id, [...path, j - 1]);
tail = [id];
});
depth = Math.max(depth, branchSteps.length);
const end = `add-${i}-${name}`;
nodes.push({ id: end, type: "add", position: { x: x + 104, y: (row + branchSteps.length) * ROW }, data: { kind: "step", key: end, title: "", type: "", detail: "", branch: name, lane: kind, insertAfter: [...path, branchSteps.length - 1] } });
nodes.push({ id: end, type: "add", position: { x: x + 104, y: foot }, data: { kind: "step", key: end, title: "", type: "", detail: "", branch: name, lane: kind, insertAfter: [...path, branchSteps.length - 1] } });
link(tail, end);
ends.push(end);
});
const height = (Math.max(depth, 1) + 1) * ROW - 24;
branches.forEach(([name], column) => {
const x = (column - (lanes - 1) / 2) * COLUMN;
nodes.push({
id: `lane-${i}-${name}`,
type: "lane",
position: { x: x - 12, y: row * ROW - 40 },
style: { width: `${COLUMN - 16}px`, height: `${height}px` },
zIndex: -1,
data: { kind: "step", key: name, title: name, type: "", detail: "", lane: kind },
});
lane(`lane-${i}-${name}`, x, name);
});
if (passes) {
// The run's way past an unmatched switch: an edge from the switch to
// the step after it, drawn down the last column.
ends.push(parent);
// The run's way past an unmatched switch runs down a lane of its own,
// so it never cuts across the cases.
const x = laneAt(lanes - 1);
const end = `pass-${i}`;
nodes.push({ id: end, type: "add", position: { x: x + 104, y: foot }, data: { kind: "step", key: end, title: "", type: "", detail: "", lane: kind } });
otherwise.add(parent);
link([parent], end);
otherwise.delete(parent);
ends.push(end);
lane(`pass-lane-${i}`, x, "default");
}
previous = ends;
row += Math.max(depth, 1) + 1;
row += depth + 1;
continue;
}
const id = addStep(step, String(i + 1), 0, row * ROW, undefined, undefined, ["steps", i]);