Skip to content

Commit fbbaf93

Browse files
authored
fix(workflow): keep the drawer fit fixed while a node is dragged (#1575) (#1576)
Fixes #1575 Owner: Dev3 Reviewer: Reviewer Written-by: Dev-3 Base: `9b866a5c797e8efe95e445885b69da4b8ca5c35b` (`main`, #1556) Tip: `91c6dc037dd32a6fefff1e7a8f8bbde199e17517` Tree: `4e7e7f74f2f1bcd308902b486cdc98b81b756f5b` Dragging the leftmost, rightmost or topmost node in the drawer left it pinned on screen while its stored coordinate moved. The drawer paints a fitted copy of the graph, and the fit was recomputed every frame from a node list that already contained the drag ghost: for an extreme node the fitted position is a constant of the fit (`width/2 + room/2` horizontally, `FIT_PAD` vertically), so the node stood still, every other node was re-centred and squashed, and `pointerup` committed the wider world graph the user never saw. The fit is now computed from `workflow.nodes` and held for the whole gesture; the ghost stays a world coordinate and is drawn inside that same frame (`x * scale + offsetX`, `y + offsetY`). A middle-node drag was already correct and stays as it was, and the existing payload assertion (`test/client.test.js:234`) is untouched. ## What changed - `plugins/workflow/client.js` — `nodes` is the stored graph again, so `fitPlane` sees no ghost; `scale`, `offsetX` and `offsetY` are therefore fixed for the gesture. A `drawn` map starts from the fitted nodes and puts the ghost into panel coordinates; node boxes, wires and parallel frames read it. `fitPlane` itself is unchanged and the Settings canvas keeps its own plane. - `plugins/workflow/test/client.test.js` — three tests. Rightmost: in a span-344 graph (scale exactly 0.5) drag 40px right and assert the node's `style.left` grows 40px while the other two nodes' `style.left` do not move, then the commit is `344 + 80`. Topmost: drag 40px up and assert `style.top` falls 40px, the others do not move, and the commit is `-40`. Middle node: the same 1:1 movement and commit as today — it passes on `main` too, so it is the regression lock. - `changelog.d/1575-drawer-drag-extreme-node.fixed.md`. Byte proof that `main`'s own work is untouched: the branch is based on `9b866a5c` (the tip's parent), and `git diff 9b866a5 91c6dc0 -- plugins/workflow/client.js` is only the freeze hunk (+14/−8); `#1556`'s Settings-graph form and node-handle lines are byte-identical. ## Red, then green At live `main` `9b866a5c`, source untouched, with only the three new tests (`plugins/workflow/test/client.test.js`): - **46 tests / 44 pass / 2 fail.** - `not ok 2 - dragging the rightmost node moves it on screen inside the frame the drag started with (#1575)` — `expected: 224`, `actual: 184`, at `client.test.js:301` (the rightmost node did not move at all). - `not ok 3 - dragging the topmost node up moves it on screen inside the frame the drag started with (#1575)` — `expected: -28`, `actual: 12`, at `client.test.js:325` (the topmost node stayed on the `FIT_PAD` line). - `ok 4 - a middle-node drag keeps the frame it started with (#1575)` — already correct on `main`. At this tip: **46 / 46 / 0**, and the whole `plugins/workflow` suite is **139 / 139 / 0** (136 on `main`, so the three new tests are the only addition). ## Verification at this tip `TZ=UTC ARCH_DOCS_BASE=9b866a5c npm_config_cache=<writable> npm run verify` — exit 0: core **1868**, social 527, tree 125, timeline 125, workflow **139**, `.github` 548, interop 37, live-e2e 24, every suite `# fail 0`; lint 0 errors (core 63 warnings, social 36, timeline 9, tree 2, workflow 13); `arch-docs: OK (3 changed file(s))`; `build-client --check` and `ds-bot-patches check` pass. `node .github/scripts/changelog.mjs check` — 63 fragments well formed. The `npm_config_cache` override is environment only: the plugin pack-import step runs `npm pack`, and `~/.npm` is read-only in my sandbox. The counts are from this tip (`91c6dc03`, tree `4e7e7f74`). Not run: the smoke test and the test bench (no `index.js` or `core/src/host/` change), and no browser check (the drawer geometry is covered by the rendered-position tests; the host is untouched). Docs-not-needed: `#1575` limits the change to `plugins/workflow/client.js` and its test; the drawer fit rule (`fitPlane` scales centres, a pointer delta is divided by the start scale) and `docs/subsystems/workflow.md` are unchanged. Risk: T2 — `plugins/**` sets the tier; `plugins/workflow/test/**` and `changelog.d/**` are T1. ## Checkpoint <!-- flybot:checkpoint --> ```json { "pr": 1576, "claim": "Dev3", "issue": 1575, "summary": "Dragging an extreme node in the workflow drawer pinned it while the fit was recomputed from a node list that already held the drag ghost: the node sat still, the rest of the graph re-centred and shrank, and pointerup stored the wider graph. The fit now comes from the stored graph only and is frozen for the gesture, with the ghost drawn inside that frame, so an extreme node follows the pointer 1:1 and a middle-node drag is unchanged. Pointerup still commits the world coordinates from the start scale. The new tests assert rendered positions, not just the payload.", "files": [ "plugins/workflow/client.js", "plugins/workflow/test/client.test.js", "changelog.d/1575-drawer-drag-extreme-node.fixed.md" ], "checks": { "ran": "TZ=UTC ARCH_DOCS_BASE=9b866a5c npm run verify; plugins/workflow npm test; base-plus-tests-only red run at 9b866a5", "result": "green", "at": "91c6dc037dd32a6fefff1e7a8f8bbde199e17517" }, "next": "none — ready for review at this tip" } ``` <!-- /flybot:checkpoint -->
1 parent 59fb637 commit fbbaf93

3 files changed

Lines changed: 107 additions & 8 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Dragging the leftmost, rightmost or topmost node in the workflow drawer moves the node under the pointer instead of leaving it pinned while the fit re-centres and rescales the rest of the graph; the fit is now fixed for the whole gesture, so a drag commits the coordinates the user saw. ([#1575](https://github.com/ThinkFlowLab/FlyBot/issues/1575))

‎plugins/workflow/client.js‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -617,13 +617,19 @@ window.__ModuleLoader__.load({
617617
const [dragPreview, setDragPreview] = useState(null)
618618
const [selectedNode, setSelectedNode] = useState(null)
619619
const status = run?.nodeStatus ?? {}
620-
const nodes = workflow.nodes.map(node => ghost?.[node.id] ? { ...node, ...ghost[node.id] } : node)
620+
const nodes = workflow.nodes
621621
const edges = workflow.edges ?? []
622-
// The drawer paints a fitted copy; `nodes` stays the world graph so a drag
623-
// commits the same coordinates the Settings canvas would (#1513).
622+
// The drawer paints a fitted copy of the world graph (#1513). The fit is a
623+
// fixed frame for the whole gesture: folding the ghost back into it re-centred
624+
// and rescaled the graph under the pointer and pinned an extreme node (#1575).
624625
const plane = fitPlane(nodes, DRAWER_FLOW_W)
625-
const fitted = new Map(plane.nodes.map(node => [node.id, node]))
626626
const scale = plane.scale || 1
627+
const fitted = new Map(plane.nodes.map(node => [node.id, node]))
628+
const drawn = new Map(fitted)
629+
for (const [id, spot] of Object.entries(ghost ?? {})) {
630+
const base = fitted.get(id)
631+
if (base) drawn.set(id, { ...base, x: spot.x * scale + plane.offsetX, y: spot.y + plane.offsetY })
632+
}
627633
const height = plane.height
628634
const locals = (roster?.bots ?? []).filter(bot => bot && bot.remote !== true && !nodes.some(node => node.botId === bot.id))
629635
const selected = nodes.find(node => node.id === selectedNode)
@@ -688,8 +694,8 @@ window.__ModuleLoader__.load({
688694
h('div', { className: 'wf-plane', 'data-plane': '1', style: { height, width: plane.width } },
689695
h('svg', { className: 'wf-wires', 'aria-hidden': true, ...wireSvgProps(height, plane.width) },
690696
edges.map(edge => {
691-
const from = fitted.get(edge.from)
692-
const to = fitted.get(edge.to)
697+
const from = drawn.get(edge.from)
698+
const to = drawn.get(edge.to)
693699
if (!from || !to) return null
694700
return h('g', { key: `${edge.from}>${edge.to}` },
695701
h('path', { d: wirePath(from, to, 0) }),
@@ -700,15 +706,15 @@ window.__ModuleLoader__.load({
700706
}) : null)
701707
})),
702708
(workflow.layers ?? []).filter(layer => layer.length > 1).map(layer => {
703-
const members = layer.map(id => fitted.get(id)).filter(Boolean)
709+
const members = layer.map(id => drawn.get(id)).filter(Boolean)
704710
if (members.length < 2) return null
705711
return h('div', {
706712
key: layer.join('+'), className: 'wf-par wf-abs',
707713
style: parallelFrameStyle(members),
708714
}, h('div', { className: 'wf-plabel' }, tr('Parallel branches · Merge after all pass')))
709715
}),
710716
nodes.map(node => {
711-
const spot = fitted.get(node.id) ?? node
717+
const spot = drawn.get(node.id) ?? node
712718
return h('div', {
713719
key: node.id,
714720
'data-node': node.id,

‎plugins/workflow/test/client.test.js‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,98 @@ test('the sidebar opens the flowchart, and a drag, a wire and a dropped Bot are
262262
view.unmount()
263263
})
264264

265+
// A drawer-sized graph: span 344 in the 364px plane is scale 0.5 exactly, so a
266+
// 40px pointer move is 80 world units and the rounding stays out of the numbers.
267+
function drawerGraph(id, name, nodes) {
268+
return { ...delivery(), id, name, layers: [], nodes, edges: [] }
269+
}
270+
271+
async function openDrawer(graph) {
272+
const calls = []
273+
const call = async (name, body) => {
274+
calls.push({ name, body })
275+
if (name === 'workflow/state') return { workflows: [graph], templates: [] }
276+
return { ok: true, workflows: [graph] }
277+
}
278+
const view = mount(client.Section, { roster: { bots: [] }, call, actions: {} })
279+
await settle()
280+
findAll(view.tree, node => node.type === 'button' && textOf(node).includes(graph.name))[0].props.onClick()
281+
button(view.tree, 'Flow').props.onClick()
282+
button(view.tree, 'Edit').props.onClick()
283+
const nodeAt = id => findAll(view.tree, node => node.props?.['data-node'] === id)[0]
284+
const canvas = () => findAll(view.tree, node => String(node.props?.className ?? '').split(' ').includes('wf-canvas'))[0]
285+
return { view, calls, nodeAt, canvas }
286+
}
287+
288+
test('dragging the rightmost node moves it on screen inside the frame the drag started with (#1575)', async () => {
289+
const nodes = [
290+
{ id: 'left', name: 'Left', role: '', x: 0, y: 100 },
291+
{ id: 'middle', name: 'Middle', role: '', x: 172, y: 100 },
292+
{ id: 'right', name: 'Right', role: '', x: 344, y: 100 },
293+
]
294+
const { view, calls, nodeAt, canvas } = await openDrawer(drawerGraph('wide', 'Wide graph', nodes))
295+
const fit = client.fitPlane(nodes, client.DRAWER_FLOW_W)
296+
assert.equal(fit.scale, 0.5, 'the fixture spans wider than the drawer room')
297+
const before = Object.fromEntries(nodes.map(node => [node.id, { ...nodeAt(node.id).props.style }]))
298+
299+
nodeAt('right').props.onPointerDown({ clientX: 300, clientY: 100, target: { dataset: {} } })
300+
canvas().props.onPointerMove({ clientX: 320, clientY: 100 })
301+
canvas().props.onPointerMove({ clientX: 340, clientY: 100 })
302+
assert.equal(nodeAt('right').props.style.left, before.right.left + 40, 'the rightmost node follows the pointer 1:1')
303+
assert.equal(nodeAt('middle').props.style.left, before.middle.left, 'the fit did not re-centre another node')
304+
assert.equal(nodeAt('left').props.style.left, before.left.left, 'the fit did not re-centre another node')
305+
306+
canvas().props.onPointerUp({ clientX: 340, clientY: 100, target: { dataset: {} } })
307+
const saved = calls.filter(item => item.name === 'workflow/graph').at(-1)
308+
assert.equal(saved.body.nodes.find(node => node.id === 'right').x, 344 + 80, 'the commit uses the start frame, not an intermediate one')
309+
view.unmount()
310+
})
311+
312+
test('dragging the topmost node up moves it on screen inside the frame the drag started with (#1575)', async () => {
313+
const nodes = [
314+
{ id: 'top', name: 'Top', role: '', x: 172, y: 0 },
315+
{ id: 'middle', name: 'Middle', role: '', x: 172, y: 200 },
316+
{ id: 'bottom', name: 'Bottom', role: '', x: 172, y: 400 },
317+
]
318+
const { view, calls, nodeAt, canvas } = await openDrawer(drawerGraph('tall', 'Tall graph', nodes))
319+
const fit = client.fitPlane(nodes, client.DRAWER_FLOW_W)
320+
assert.equal(fit.scale, 1, 'a vertical chain is not scaled')
321+
const before = Object.fromEntries(nodes.map(node => [node.id, { ...nodeAt(node.id).props.style }]))
322+
323+
nodeAt('top').props.onPointerDown({ clientX: 100, clientY: 100, target: { dataset: {} } })
324+
canvas().props.onPointerMove({ clientX: 100, clientY: 70 })
325+
canvas().props.onPointerMove({ clientX: 100, clientY: 60 })
326+
assert.equal(nodeAt('top').props.style.top, before.top.top - 40, 'the topmost node follows the pointer 1:1')
327+
assert.equal(nodeAt('middle').props.style.top, before.middle.top, 'the fit did not push another node around')
328+
assert.equal(nodeAt('bottom').props.style.top, before.bottom.top, 'the fit did not push another node around')
329+
330+
canvas().props.onPointerUp({ clientX: 100, clientY: 60, target: { dataset: {} } })
331+
const saved = calls.filter(item => item.name === 'workflow/graph').at(-1)
332+
assert.equal(saved.body.nodes.find(node => node.id === 'top').y, -40, 'the commit keeps the start frame')
333+
view.unmount()
334+
})
335+
336+
test('a middle-node drag keeps the frame it started with (#1575)', async () => {
337+
const nodes = [
338+
{ id: 'left', name: 'Left', role: '', x: 0, y: 100 },
339+
{ id: 'middle', name: 'Middle', role: '', x: 172, y: 100 },
340+
{ id: 'right', name: 'Right', role: '', x: 344, y: 100 },
341+
]
342+
const { view, calls, nodeAt, canvas } = await openDrawer(drawerGraph('middle', 'Middle graph', nodes))
343+
const before = Object.fromEntries(nodes.map(node => [node.id, { ...nodeAt(node.id).props.style }]))
344+
345+
nodeAt('middle').props.onPointerDown({ clientX: 300, clientY: 100, target: { dataset: {} } })
346+
canvas().props.onPointerMove({ clientX: 340, clientY: 100 })
347+
assert.equal(nodeAt('middle').props.style.left, before.middle.left + 40, 'a middle node still follows the pointer')
348+
assert.equal(nodeAt('left').props.style.left, before.left.left)
349+
assert.equal(nodeAt('right').props.style.left, before.right.left)
350+
351+
canvas().props.onPointerUp({ clientX: 340, clientY: 100, target: { dataset: {} } })
352+
const saved = calls.filter(item => item.name === 'workflow/graph').at(-1)
353+
assert.equal(saved.body.nodes.find(node => node.id === 'middle').x, 172 + 80)
354+
view.unmount()
355+
})
356+
265357
test('clicking a sidebar workflow, New, or Hand-a-task keeps the section and opens the stage', async () => {
266358
// The shell's createPortal throws when the container is missing — the same
267359
// throw the sidebar slot boundary turns into an empty Workflows section (#1375).

0 commit comments

Comments
 (0)