Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: rewire a notification flow by drag or keyboard

The flow editor can now change a flow's shape on the canvas, not only
through the inspector's fields:

- drag a box onto another to move it and its branch there; a drop the
  save would refuse shows the target dashed red and gives the reason;
- a palette of node kinds adds a node below the picked box on click, or
  below any box it is dragged onto; it offers what the controller lists;
- arrow keys walk the tree, M picks a box up and Enter drops it under
  the focused one, Alt+Up/Down reorder a node among its siblings, Delete
  removes a branch; focus follows the edit;
- each box with siblings says when it runs, and the inspector can move
  it earlier or later, since the router runs children in edge order;
- request_reviewer is a second leaf kind beside todo, with a reviewer
  field;
- leaving with unsaved edits asks first, also for in-app links and the
  back button (a router hook runs navigation past a page's guard).
This commit is contained in:
iris 2026-10-24 14:49:48 +02:00 • committed by mara
commit 68e289fff5

View file

@ -1,25 +1,26 @@
// <NodeInspector> — the fields of the picked node, and what can be done to
// it: add a child, move it under another node, remove it. Every change goes
// out as an `Edit` of the flow; the editor shows the reason when one is
// refused.
// it: move it under another node, change when it runs among its siblings,
// remove it. Every change goes out as an `Edit` of the flow; the editor shows
// the reason when one is refused. New nodes come from the canvas palette.
import { Button } from "../../ui/button/Button.js";
import { CheckboxField } from "../../ui/checkbox-field/CheckboxField.js";
import { SelectField } from "../../ui/select-field/SelectField.js";
import { TextAreaField } from "../../ui/text-area-field/TextAreaField.js";
import { TextField } from "../../ui/text-field/TextField.js";
import {
addChild,
blankNode,
moveAmongSiblings,
parentOf,
removeNode,
reparent,
replaceNode,
siblingPosition,
type Edit,
type Limits,
withOp,
} from "./FlowDraft.js";
import {
kindValues,
ordinal,
type Condition,
type Described,
type Flow,
@ -31,6 +32,9 @@ type TodoNode = Extract<FlowNode, { kind: "todo" }>;
const OPS_FALLBACK = ["upsert", "clear"];
// The kinds this editor has fields for.
const KNOWN_KINDS: string[] = ["source", "match", "todo", "request_reviewer"];
function options(list: Described[]) {
return list.map((d) => ({
value: d.name,
@ -57,15 +61,17 @@ export function NodeInspector({
const firstField = schema.fields[0]?.name ?? "";
const key = `ne-${node.id}`;
const add = (kind: "match" | "todo") => {
const added = blankNode(flow, kind);
onEdit(addChild(flow, node.id, added, limits), added.id);
};
const parent = parentOf(flow, node.id);
// Where it can go: under its current parent, or under any node it could be
// moved to.
const parents = flow.nodes
.filter((n) => n.id !== node.id && reparent(flow, node.id, n.id, limits).ok)
.filter(
(n) =>
n.id === parent ||
(n.id !== node.id && reparent(flow, node.id, n.id, limits).ok),
)
.map((n) => ({ value: n.id, label: `${n.kind} ${n.id}` }));
const order = siblingPosition(flow, node.id);
return (
<div class="notify-inspector">
@ -121,13 +127,46 @@ export function NodeInspector({
/>
) : null}
{node.kind === "request_reviewer" ? (
<fieldset>
<legend>asks for a review</legend>
<TextField
id={`${key}-reviewer`}
label="reviewer (a forge login)"
value={node.reviewer}
onInput={(reviewer) => set({ ...node, reviewer })}
/>
</fieldset>
) : null}
{!KNOWN_KINDS.includes(node.kind) ? (
<p class="notify-hint">
This editor does not know how to edit a {node.kind}. It is kept as it
is when you save.
</p>
) : null}
{order.count > 1 ? (
<div class="notify-inspector-actions">
<span class="notify-hint">
runs {ordinal(order.index + 1)} of {order.count} below its parent
</span>
<Button
disabled={order.index === 0}
onClick={() => onEdit(moveAmongSiblings(flow, node.id, -1))}
>
run earlier
</Button>
<Button
disabled={order.index === order.count - 1}
onClick={() => onEdit(moveAmongSiblings(flow, node.id, 1))}
>
run later
</Button>
</div>
) : null}
<div class="notify-inspector-actions">
{node.kind !== "todo" ? (
<>
<Button onClick={() => add("match")}>add a match below</Button>
<Button onClick={() => add("todo")}>add a todo below</Button>
</>
) : null}
{node.kind !== "source" ? (
<Button
onClick={() =>