@transitrix/diagrams 1.5.0 → 1.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/capability-map/CapabilityCardNode.d.ts +19 -0
- package/dist/capability-map/CapabilityCardNode.js +66 -0
- package/dist/capability-map/CapabilityMapView.d.ts +59 -0
- package/dist/capability-map/CapabilityMapView.js +204 -0
- package/dist/capability-map/CapabilityRootNode.d.ts +12 -0
- package/dist/capability-map/CapabilityRootNode.js +23 -0
- package/dist/capability-map/__tests__/CapabilityMapView.test.d.ts +1 -0
- package/dist/capability-map/__tests__/CapabilityMapView.test.js +217 -0
- package/dist/capability-map/__tests__/address.test.d.ts +1 -0
- package/dist/capability-map/__tests__/address.test.js +49 -0
- package/dist/capability-map/__tests__/dsm-layout.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-layout.test.js +46 -0
- package/dist/capability-map/__tests__/dsm-mutations.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-mutations.test.js +125 -0
- package/dist/capability-map/__tests__/dsm-validate.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-validate.test.js +56 -0
- package/dist/capability-map/address.d.ts +12 -0
- package/dist/capability-map/address.js +48 -0
- package/dist/capability-map/dsm-layout.d.ts +9 -0
- package/dist/capability-map/dsm-layout.js +125 -0
- package/dist/capability-map/dsm-mutations.d.ts +28 -0
- package/dist/capability-map/dsm-mutations.js +196 -0
- package/dist/capability-map/dsm-schema.d.ts +71 -0
- package/dist/capability-map/dsm-schema.js +14 -0
- package/dist/capability-map/dsm-theme.d.ts +20 -0
- package/dist/capability-map/dsm-theme.js +36 -0
- package/dist/capability-map/dsm-validate.d.ts +2 -0
- package/dist/capability-map/dsm-validate.js +93 -0
- package/dist/capability-map/index.d.ts +9 -0
- package/dist/capability-map/index.js +6 -0
- package/dist/codex/__tests__/example.test.d.ts +1 -0
- package/dist/codex/__tests__/example.test.js +33 -0
- package/dist/codex/__tests__/validate.test.d.ts +1 -0
- package/dist/codex/__tests__/validate.test.js +68 -0
- package/dist/codex/index.d.ts +4 -0
- package/dist/codex/index.js +2 -0
- package/dist/codex/types.d.ts +7 -0
- package/dist/codex/types.js +8 -0
- package/dist/codex/validate.d.ts +11 -0
- package/dist/codex/validate.js +103 -0
- package/dist/compliance/__tests__/canon-catalog.test.d.ts +1 -0
- package/dist/compliance/__tests__/canon-catalog.test.js +60 -0
- package/dist/compliance/__tests__/trace.test.d.ts +1 -0
- package/dist/compliance/__tests__/trace.test.js +144 -0
- package/dist/compliance/__tests__/view-resolution.test.d.ts +1 -0
- package/dist/compliance/__tests__/view-resolution.test.js +59 -0
- package/dist/compliance/canon-catalog.d.ts +19 -0
- package/dist/compliance/canon-catalog.js +59 -0
- package/dist/compliance/classify.js +7 -1
- package/dist/compliance/coverage-metric.d.ts +12 -0
- package/dist/compliance/coverage-metric.js +35 -0
- package/dist/compliance/impact.d.ts +7 -1
- package/dist/compliance/impact.js +53 -0
- package/dist/compliance/index.d.ts +8 -5
- package/dist/compliance/index.js +4 -2
- package/dist/compliance/reverse-index.js +4 -1
- package/dist/compliance/trace.d.ts +26 -0
- package/dist/compliance/trace.js +89 -0
- package/dist/compliance/types.d.ts +94 -1
- package/dist/constraint/__tests__/example.test.d.ts +1 -0
- package/dist/constraint/__tests__/example.test.js +14 -0
- package/dist/constraint/__tests__/validate.test.d.ts +1 -0
- package/dist/constraint/__tests__/validate.test.js +58 -0
- package/dist/constraint/index.d.ts +4 -0
- package/dist/constraint/index.js +2 -0
- package/dist/constraint/types.d.ts +4 -0
- package/dist/constraint/types.js +2 -0
- package/dist/constraint/validate.d.ts +7 -0
- package/dist/constraint/validate.js +115 -0
- package/dist/fgca/__tests__/parse-canonical.test.js +31 -0
- package/dist/fgca/parse-canonical.d.ts +1 -1
- package/dist/fgca/parse-canonical.js +18 -4
- package/dist/goals/GoalNode.d.ts +19 -0
- package/dist/goals/GoalNode.js +96 -0
- package/dist/goals/GoalTreeView.d.ts +59 -0
- package/dist/goals/GoalTreeView.js +245 -0
- package/dist/goals/__tests__/GoalTreeView.test.d.ts +1 -0
- package/dist/goals/__tests__/GoalTreeView.test.js +337 -0
- package/dist/goals/__tests__/mutations.test.js +39 -0
- package/dist/goals/__tests__/parse-canonical.test.js +2 -0
- package/dist/goals/index.d.ts +3 -0
- package/dist/goals/index.js +1 -0
- package/dist/goals/layout.js +2 -1
- package/dist/goals/mutations.js +6 -6
- package/dist/goals/parse-canonical.d.ts +5 -0
- package/dist/goals/parse-canonical.js +5 -0
- package/dist/goals/theme.d.ts +22 -0
- package/dist/goals/theme.js +32 -0
- package/dist/goals/types.d.ts +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/repo-validate/types.js +2 -3
- package/dist/webview/__tests__/render-goals.test.js +17 -3
- package/dist/webview/render-goals.js +2 -1
- package/package.json +4 -1
- package/src/capability-map/CapabilityCardNode.tsx +146 -0
- package/src/capability-map/CapabilityMapView.tsx +331 -0
- package/src/capability-map/CapabilityRootNode.tsx +38 -0
- package/src/capability-map/__tests__/CapabilityMapView.test.tsx +232 -0
- package/src/capability-map/__tests__/address.test.ts +59 -0
- package/src/capability-map/__tests__/dsm-layout.test.ts +52 -0
- package/src/capability-map/__tests__/dsm-mutations.test.ts +141 -0
- package/src/capability-map/__tests__/dsm-validate.test.ts +65 -0
- package/src/capability-map/address.ts +48 -0
- package/src/capability-map/dsm-layout.ts +142 -0
- package/src/capability-map/dsm-mutations.ts +208 -0
- package/src/capability-map/dsm-schema.ts +80 -0
- package/src/capability-map/dsm-theme.ts +53 -0
- package/src/capability-map/dsm-validate.ts +103 -0
- package/src/capability-map/index.ts +35 -0
- package/src/codex/__tests__/example.test.ts +40 -0
- package/src/codex/__tests__/validate.test.ts +84 -0
- package/src/codex/index.ts +4 -0
- package/src/codex/types.ts +13 -0
- package/src/codex/validate.ts +125 -0
- package/src/compliance/__tests__/canon-catalog.test.ts +68 -0
- package/src/compliance/__tests__/trace.test.ts +157 -0
- package/src/compliance/__tests__/view-resolution.test.ts +80 -0
- package/src/compliance/canon-catalog.ts +76 -0
- package/src/compliance/classify.ts +7 -1
- package/src/compliance/coverage-metric.ts +50 -0
- package/src/compliance/impact.ts +67 -1
- package/src/compliance/index.ts +16 -1
- package/src/compliance/reverse-index.ts +3 -1
- package/src/compliance/trace.ts +118 -0
- package/src/compliance/types.ts +101 -1
- package/src/constraint/__tests__/example.test.ts +19 -0
- package/src/constraint/__tests__/validate.test.ts +68 -0
- package/src/constraint/index.ts +4 -0
- package/src/constraint/types.ts +5 -0
- package/src/constraint/validate.ts +131 -0
- package/src/fgca/__tests__/parse-canonical.test.ts +34 -0
- package/src/fgca/parse-canonical.ts +17 -4
- package/src/goals/GoalNode.tsx +219 -0
- package/src/goals/GoalTreeView.tsx +384 -0
- package/src/goals/__tests__/GoalTreeView.test.tsx +361 -0
- package/src/goals/__tests__/mutations.test.ts +42 -0
- package/src/goals/__tests__/parse-canonical.test.ts +2 -0
- package/src/goals/index.ts +4 -0
- package/src/goals/layout.ts +2 -1
- package/src/goals/mutations.ts +6 -6
- package/src/goals/parse-canonical.ts +6 -0
- package/src/goals/theme.ts +54 -0
- package/src/goals/types.ts +2 -0
- package/src/index.ts +29 -1
- package/src/repo-validate/types.ts +2 -3
- package/src/webview/__tests__/render-goals.test.ts +17 -3
- package/src/webview/render-goals.ts +2 -1
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo, useState, useEffect } from 'react';
|
|
3
|
+
import ReactFlow, { Controls, MiniMap, Background, ConnectionLineType, useNodesState, useEdgesState, } from 'reactflow';
|
|
4
|
+
import 'reactflow/dist/style.css';
|
|
5
|
+
import { layoutGoalTree } from './layout.js';
|
|
6
|
+
import { reparent, addChild, deleteWithDescendants, moveToBacklog, restoreFromBacklog } from './mutations.js';
|
|
7
|
+
import { resolveTheme } from './theme.js';
|
|
8
|
+
import GoalNode from './GoalNode.js';
|
|
9
|
+
const BACKLOG_DRAG_MIME = 'application/x-transitrix-goal-id';
|
|
10
|
+
const nodeTypes = { goalNode: GoalNode };
|
|
11
|
+
/**
|
|
12
|
+
* Pure decision: given where a dragged card was dropped, compute the mutation
|
|
13
|
+
* and the GoalTreeChange to report (or null for a no-op drop). Kept separate
|
|
14
|
+
* from the DOM/pointer-event glue in onNodeDragStop so the mutation-selection
|
|
15
|
+
* logic — which card wins reparent vs moveToBacklog vs a refused mutation —
|
|
16
|
+
* is unit-testable without needing a real drag gesture through reactflow's
|
|
17
|
+
* internal, DOM-measurement-gated dragging.
|
|
18
|
+
*/
|
|
19
|
+
export function computeDragOutcome(tree, sourceId, dropTarget) {
|
|
20
|
+
if (!dropTarget)
|
|
21
|
+
return null;
|
|
22
|
+
if (dropTarget.kind === 'backlog') {
|
|
23
|
+
const mutation = moveToBacklog(tree, sourceId);
|
|
24
|
+
if (!mutation.ok || !mutation.result)
|
|
25
|
+
return null;
|
|
26
|
+
return { kind: 'moveToBacklog', id: sourceId, result: mutation.result };
|
|
27
|
+
}
|
|
28
|
+
if (dropTarget.id === sourceId)
|
|
29
|
+
return null;
|
|
30
|
+
const mutation = reparent(tree, sourceId, dropTarget.id);
|
|
31
|
+
if (!mutation.ok || !mutation.result)
|
|
32
|
+
return null;
|
|
33
|
+
return { kind: 'reparent', sourceId, targetId: dropTarget.id, result: mutation.result };
|
|
34
|
+
}
|
|
35
|
+
/** Goals reachable from a root (level 0 or parent_id 0) via valid parent_id chains. */
|
|
36
|
+
function partitionCanvasAndBacklog(goals) {
|
|
37
|
+
const children = new Map();
|
|
38
|
+
for (const g of goals) {
|
|
39
|
+
if (!children.has(g.parent_id))
|
|
40
|
+
children.set(g.parent_id, []);
|
|
41
|
+
children.get(g.parent_id).push(g);
|
|
42
|
+
}
|
|
43
|
+
const roots = goals.filter((g) => g.level === 0 || g.parent_id === 0);
|
|
44
|
+
const reachable = new Set();
|
|
45
|
+
const stack = [...roots.map((r) => r.id)];
|
|
46
|
+
while (stack.length > 0) {
|
|
47
|
+
const id = stack.pop();
|
|
48
|
+
if (reachable.has(id))
|
|
49
|
+
continue;
|
|
50
|
+
reachable.add(id);
|
|
51
|
+
for (const child of children.get(id) ?? [])
|
|
52
|
+
stack.push(child.id);
|
|
53
|
+
}
|
|
54
|
+
const canvas = [];
|
|
55
|
+
const backlog = [];
|
|
56
|
+
for (const g of goals) {
|
|
57
|
+
if (reachable.has(g.id))
|
|
58
|
+
canvas.push(g);
|
|
59
|
+
else
|
|
60
|
+
backlog.push(g); // unreachable from any root — broken/orphaned parent chain
|
|
61
|
+
}
|
|
62
|
+
return { canvas, backlog };
|
|
63
|
+
}
|
|
64
|
+
function GoalTreeViewInner({ tree, layout: layoutProp, layoutOptions, theme: themeProp, readOnly = false, showBacklog = false, defaultBacklogOpen = true, showMiniMap = false, onChange, onEditRequest, onFactorClick, }) {
|
|
65
|
+
const theme = useMemo(() => resolveTheme(themeProp), [themeProp]);
|
|
66
|
+
const [collapsedIds, setCollapsedIds] = useState(new Set());
|
|
67
|
+
const [hoveredId, setHoveredId] = useState(null);
|
|
68
|
+
const [isBacklogOpen, setIsBacklogOpen] = useState(defaultBacklogOpen);
|
|
69
|
+
const { canvas: canvasGoals, backlog: backlogGoals } = useMemo(() => partitionCanvasAndBacklog(tree.goals), [tree.goals]);
|
|
70
|
+
const layout = useMemo(() => {
|
|
71
|
+
if (layoutProp)
|
|
72
|
+
return layoutProp;
|
|
73
|
+
const hideCollapsed = [...(layoutOptions?.hideCollapsed ?? []), ...collapsedIds];
|
|
74
|
+
return layoutGoalTree({ goal_types: tree.goal_types, goals: canvasGoals }, { ...layoutOptions, hideCollapsed });
|
|
75
|
+
}, [layoutProp, layoutOptions, collapsedIds, tree.goal_types, canvasGoals]);
|
|
76
|
+
const onAddChild = useCallback((parentId, parentLevel) => {
|
|
77
|
+
if (readOnly)
|
|
78
|
+
return;
|
|
79
|
+
const before = new Set(tree.goals.map((g) => g.id));
|
|
80
|
+
const mutation = addChild(tree, parentId, { name: 'New goal', type: '', level: parentLevel + 1, parent_id: parentId });
|
|
81
|
+
if (!mutation.ok || !mutation.result)
|
|
82
|
+
return;
|
|
83
|
+
const newGoal = mutation.result.goals.find((g) => !before.has(g.id));
|
|
84
|
+
if (!newGoal)
|
|
85
|
+
return;
|
|
86
|
+
onChange?.({ kind: 'addChild', parentId, newGoal, result: mutation.result });
|
|
87
|
+
}, [tree, readOnly, onChange]);
|
|
88
|
+
const onDeleteNode = useCallback((id) => {
|
|
89
|
+
if (readOnly)
|
|
90
|
+
return;
|
|
91
|
+
const mutation = deleteWithDescendants(tree, id);
|
|
92
|
+
if (!mutation.ok || !mutation.result)
|
|
93
|
+
return;
|
|
94
|
+
onChange?.({ kind: 'delete', id, result: mutation.result });
|
|
95
|
+
}, [tree, readOnly, onChange]);
|
|
96
|
+
const onRestoreFromBacklog = useCallback((id, newParentId) => {
|
|
97
|
+
if (readOnly)
|
|
98
|
+
return;
|
|
99
|
+
const mutation = restoreFromBacklog(tree, id, newParentId);
|
|
100
|
+
if (!mutation.ok || !mutation.result)
|
|
101
|
+
return;
|
|
102
|
+
onChange?.({ kind: 'restoreFromBacklog', id, newParentId, result: mutation.result });
|
|
103
|
+
}, [tree, readOnly, onChange]);
|
|
104
|
+
const onToggleCollapse = useCallback((id) => {
|
|
105
|
+
setCollapsedIds((prev) => {
|
|
106
|
+
const next = new Set(prev);
|
|
107
|
+
if (next.has(id))
|
|
108
|
+
next.delete(id);
|
|
109
|
+
else
|
|
110
|
+
next.add(id);
|
|
111
|
+
return next;
|
|
112
|
+
});
|
|
113
|
+
}, []);
|
|
114
|
+
const buildNodes = useCallback(() => {
|
|
115
|
+
return layout.nodes.map((n) => ({
|
|
116
|
+
id: String(n.id),
|
|
117
|
+
type: 'goalNode',
|
|
118
|
+
position: { x: n.x, y: n.y },
|
|
119
|
+
draggable: !readOnly,
|
|
120
|
+
data: {
|
|
121
|
+
goal: n.data,
|
|
122
|
+
theme,
|
|
123
|
+
readOnly,
|
|
124
|
+
isDropTarget: hoveredId === n.id,
|
|
125
|
+
hasHiddenChildren: n.hasHiddenChildren,
|
|
126
|
+
isCollapsed: collapsedIds.has(n.id),
|
|
127
|
+
onAddChild,
|
|
128
|
+
onDelete: onDeleteNode,
|
|
129
|
+
onToggleCollapse,
|
|
130
|
+
onFactorClick,
|
|
131
|
+
},
|
|
132
|
+
}));
|
|
133
|
+
}, [layout.nodes, theme, readOnly, hoveredId, collapsedIds, onAddChild, onDeleteNode, onToggleCollapse, onFactorClick]);
|
|
134
|
+
const buildEdges = useCallback(() => {
|
|
135
|
+
return layout.edges.map((e) => ({
|
|
136
|
+
id: `e${e.source}-${e.target}`,
|
|
137
|
+
source: String(e.source),
|
|
138
|
+
target: String(e.target),
|
|
139
|
+
type: 'default',
|
|
140
|
+
style: { stroke: theme.edgeColor, strokeWidth: theme.edgeWidth },
|
|
141
|
+
}));
|
|
142
|
+
}, [layout.edges, theme]);
|
|
143
|
+
const [nodes, setNodes, onNodesChange] = useNodesState(buildNodes());
|
|
144
|
+
const [edges, setEdges, onEdgesChange] = useEdgesState(buildEdges());
|
|
145
|
+
// Re-sync whenever the underlying layout/theme/interaction state changes —
|
|
146
|
+
// tree/layout are host-controlled props, not owned by this component.
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
setNodes(buildNodes());
|
|
149
|
+
setEdges(buildEdges());
|
|
150
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
151
|
+
}, [layout, theme, readOnly, hoveredId, collapsedIds]);
|
|
152
|
+
const checkIntersection = useCallback((a, b) => {
|
|
153
|
+
const midX = a.position.x + 125;
|
|
154
|
+
const midY = a.position.y + 40;
|
|
155
|
+
return midX > b.position.x && midX < b.position.x + 250 && midY > b.position.y && midY < b.position.y + 80;
|
|
156
|
+
}, []);
|
|
157
|
+
const onNodeDrag = useCallback((_event, node) => {
|
|
158
|
+
if (readOnly)
|
|
159
|
+
return;
|
|
160
|
+
const hit = nodes.find((n) => n.id !== node.id && checkIntersection(node, n));
|
|
161
|
+
setHoveredId(hit ? Number(hit.id) : null);
|
|
162
|
+
}, [readOnly, nodes, checkIntersection]);
|
|
163
|
+
const onNodeDragStop = useCallback((event, node) => {
|
|
164
|
+
if (readOnly) {
|
|
165
|
+
setHoveredId(null);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const sourceId = Number(node.id);
|
|
169
|
+
const mouseEvent = event;
|
|
170
|
+
const dropEl = typeof document !== 'undefined' && 'clientX' in mouseEvent
|
|
171
|
+
? document.elementFromPoint(mouseEvent.clientX, mouseEvent.clientY)
|
|
172
|
+
: null;
|
|
173
|
+
const dropTarget = dropEl?.closest('[data-goaltree-backlog-zone]')
|
|
174
|
+
? { kind: 'backlog' }
|
|
175
|
+
: hoveredId != null ? { kind: 'node', id: hoveredId } : null;
|
|
176
|
+
const change = computeDragOutcome(tree, sourceId, dropTarget);
|
|
177
|
+
if (change)
|
|
178
|
+
onChange?.(change);
|
|
179
|
+
setHoveredId(null);
|
|
180
|
+
}, [readOnly, hoveredId, tree, onChange]);
|
|
181
|
+
const onNodeDoubleClick = useCallback((_event, node) => {
|
|
182
|
+
const goal = tree.goals.find((g) => g.id === Number(node.id));
|
|
183
|
+
if (goal)
|
|
184
|
+
onEditRequest?.(goal);
|
|
185
|
+
}, [tree.goals, onEditRequest]);
|
|
186
|
+
const onBacklogItemDragStart = useCallback((event, goalId) => {
|
|
187
|
+
event.dataTransfer.setData(BACKLOG_DRAG_MIME, String(goalId));
|
|
188
|
+
event.dataTransfer.effectAllowed = 'move';
|
|
189
|
+
}, []);
|
|
190
|
+
const onCanvasDragOver = useCallback((event) => {
|
|
191
|
+
if (readOnly)
|
|
192
|
+
return;
|
|
193
|
+
event.preventDefault();
|
|
194
|
+
}, [readOnly]);
|
|
195
|
+
const onCanvasDrop = useCallback((event) => {
|
|
196
|
+
if (readOnly)
|
|
197
|
+
return;
|
|
198
|
+
event.preventDefault();
|
|
199
|
+
const idStr = event.dataTransfer.getData(BACKLOG_DRAG_MIME);
|
|
200
|
+
if (!idStr)
|
|
201
|
+
return;
|
|
202
|
+
const goalId = Number(idStr);
|
|
203
|
+
const targetEl = document.elementFromPoint(event.clientX, event.clientY);
|
|
204
|
+
const nodeEl = targetEl?.closest('.react-flow__node');
|
|
205
|
+
const targetIdAttr = nodeEl?.getAttribute('data-id');
|
|
206
|
+
if (targetIdAttr == null)
|
|
207
|
+
return;
|
|
208
|
+
onRestoreFromBacklog(goalId, Number(targetIdAttr));
|
|
209
|
+
}, [readOnly, onRestoreFromBacklog]);
|
|
210
|
+
const showBacklogPanel = showBacklog && backlogGoals.length > 0;
|
|
211
|
+
return (_jsxs("div", { style: { display: 'flex', width: '100%', height: '100%' }, children: [showBacklogPanel && (_jsxs("div", { ...(isBacklogOpen ? { 'data-goaltree-backlog-zone': true } : {}), style: {
|
|
212
|
+
width: isBacklogOpen ? 220 : 28,
|
|
213
|
+
flexShrink: 0,
|
|
214
|
+
borderRight: '1px solid #e2e8f0',
|
|
215
|
+
background: '#f8fafc',
|
|
216
|
+
display: 'flex',
|
|
217
|
+
flexDirection: 'column',
|
|
218
|
+
position: 'relative',
|
|
219
|
+
}, children: [_jsx("button", { type: "button", "aria-label": isBacklogOpen ? 'Collapse backlog' : 'Expand backlog', title: isBacklogOpen ? 'Collapse backlog' : 'Expand backlog', onClick: () => setIsBacklogOpen((v) => !v), style: {
|
|
220
|
+
alignSelf: 'flex-end',
|
|
221
|
+
margin: '6px 6px 0 6px',
|
|
222
|
+
width: 16,
|
|
223
|
+
height: 16,
|
|
224
|
+
border: '1px solid #cbd5e1',
|
|
225
|
+
borderRadius: 4,
|
|
226
|
+
background: '#ffffff',
|
|
227
|
+
color: '#64748b',
|
|
228
|
+
fontSize: 10,
|
|
229
|
+
lineHeight: '14px',
|
|
230
|
+
padding: 0,
|
|
231
|
+
cursor: 'pointer',
|
|
232
|
+
flexShrink: 0,
|
|
233
|
+
}, children: isBacklogOpen ? '◀' : '▶' }), isBacklogOpen && (_jsxs("div", { style: { padding: '4px 10px 10px', overflowY: 'auto', flex: 1 }, children: [_jsx("div", { style: { fontWeight: 700, fontSize: 12, color: '#334155', marginBottom: 8 }, children: "Backlog" }), backlogGoals.map((goal) => (_jsxs("div", { draggable: !readOnly, onDragStart: (e) => onBacklogItemDragStart(e, goal.id), onDoubleClick: () => onEditRequest?.(goal), title: "Drag onto a canvas card to set its parent", style: {
|
|
234
|
+
padding: 8,
|
|
235
|
+
marginBottom: 6,
|
|
236
|
+
background: '#ffffff',
|
|
237
|
+
border: '1px solid #cbd5e1',
|
|
238
|
+
borderRadius: 6,
|
|
239
|
+
fontSize: 11,
|
|
240
|
+
cursor: readOnly ? 'default' : 'grab',
|
|
241
|
+
}, children: [_jsx("div", { style: { fontWeight: 600 }, children: goal.name }), _jsxs("div", { style: { color: '#64748b' }, children: ["Level: ", goal.level] })] }, goal.id)))] }))] })), _jsx("div", { style: { flex: 1, position: 'relative' }, onDragOver: onCanvasDragOver, onDrop: onCanvasDrop, children: _jsxs(ReactFlow, { nodes: nodes, edges: edges, onNodesChange: readOnly ? undefined : onNodesChange, onEdgesChange: readOnly ? undefined : onEdgesChange, nodeTypes: nodeTypes, nodesDraggable: !readOnly, nodesConnectable: false, onNodeDrag: onNodeDrag, onNodeDragStop: onNodeDragStop, onNodeDoubleClick: onNodeDoubleClick, connectionLineType: ConnectionLineType.Bezier, fitView: true, children: [_jsx(Background, {}), _jsx(Controls, {}), showMiniMap && _jsx(MiniMap, { pannable: true, zoomable: true })] }) })] }));
|
|
242
|
+
}
|
|
243
|
+
export function GoalTreeView(props) {
|
|
244
|
+
return _jsx(GoalTreeViewInner, { ...props });
|
|
245
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _MockResizeObserver_callback;
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
// @vitest-environment jsdom
|
|
15
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
16
|
+
import { render, screen, cleanup, waitFor } from '@testing-library/react';
|
|
17
|
+
import { GoalTreeView, computeDragOutcome } from '../GoalTreeView.js';
|
|
18
|
+
// jsdom has no ResizeObserver / layout engine. reactflow keeps a node's DOM
|
|
19
|
+
// wrapper `visibility: hidden` and excludes it from drag/intersection logic
|
|
20
|
+
// until it has been "measured" via ResizeObserver — so the mock must
|
|
21
|
+
// actually invoke its callback (with the mocked getBoundingClientRect below)
|
|
22
|
+
// for nodes to become interactive, not just satisfy the constructor call.
|
|
23
|
+
class MockResizeObserver {
|
|
24
|
+
constructor(callback) {
|
|
25
|
+
_MockResizeObserver_callback.set(this, void 0);
|
|
26
|
+
__classPrivateFieldSet(this, _MockResizeObserver_callback, callback, "f");
|
|
27
|
+
}
|
|
28
|
+
observe(target) {
|
|
29
|
+
queueMicrotask(() => {
|
|
30
|
+
const rect = target.getBoundingClientRect();
|
|
31
|
+
__classPrivateFieldGet(this, _MockResizeObserver_callback, "f").call(this, [{ target, contentRect: rect }], this);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
unobserve() { }
|
|
35
|
+
disconnect() { }
|
|
36
|
+
}
|
|
37
|
+
_MockResizeObserver_callback = new WeakMap();
|
|
38
|
+
// jsdom also has no DOMMatrixReadOnly, which reactflow's dimension-tracking
|
|
39
|
+
// uses to read the translateX/Y out of a node's computed transform. Only
|
|
40
|
+
// translate() (no scale/rotate) ever appears in this component's own CSS, so
|
|
41
|
+
// a minimal shim covering that one case is enough.
|
|
42
|
+
class MockDOMMatrixReadOnly {
|
|
43
|
+
constructor(transform) {
|
|
44
|
+
this.m41 = 0;
|
|
45
|
+
this.m42 = 0;
|
|
46
|
+
if (!transform || transform === 'none')
|
|
47
|
+
return;
|
|
48
|
+
const t = /translate\((-?[\d.]+)px,\s*(-?[\d.]+)px\)/.exec(transform);
|
|
49
|
+
if (t) {
|
|
50
|
+
this.m41 = Number(t[1]);
|
|
51
|
+
this.m42 = Number(t[2]);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const m = /matrix\(([^)]+)\)/.exec(transform);
|
|
55
|
+
if (m) {
|
|
56
|
+
const parts = m[1].split(',').map((p) => Number(p.trim()));
|
|
57
|
+
this.m41 = parts[4] ?? 0;
|
|
58
|
+
this.m42 = parts[5] ?? 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function makeTree() {
|
|
63
|
+
return {
|
|
64
|
+
goal_types: [
|
|
65
|
+
{ name: 'Strategy', level: 0 },
|
|
66
|
+
{ name: 'Business Goal', level: 1 },
|
|
67
|
+
],
|
|
68
|
+
goals: [
|
|
69
|
+
{ id: 1, name: 'Triple revenue', type: 'Strategy', level: 0, parent_id: 0 },
|
|
70
|
+
{ id: 2, name: 'Launch in EU', type: 'Business Goal', level: 1, parent_id: 1 },
|
|
71
|
+
{
|
|
72
|
+
id: 3,
|
|
73
|
+
name: 'Cut churn',
|
|
74
|
+
type: 'Business Goal',
|
|
75
|
+
level: 1,
|
|
76
|
+
parent_id: 1,
|
|
77
|
+
factors: [
|
|
78
|
+
{ id: 10, name: 'Support backlog', impact_type: 'risk' },
|
|
79
|
+
{ id: 11, name: 'New pricing', impact_type: 'opportunity' },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
beforeEach(() => {
|
|
86
|
+
global.ResizeObserver = MockResizeObserver;
|
|
87
|
+
window.DOMMatrixReadOnly = MockDOMMatrixReadOnly;
|
|
88
|
+
vi.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(function () {
|
|
89
|
+
// Individual goal cards report their real 250x80 footprint (matters for
|
|
90
|
+
// reactflow's own drag/measurement bookkeeping); the flow container and
|
|
91
|
+
// everything else gets a generously large rect so viewport fitting has
|
|
92
|
+
// room to work with.
|
|
93
|
+
const isNode = this.classList?.contains('react-flow__node');
|
|
94
|
+
const width = isNode ? 250 : 1000;
|
|
95
|
+
const height = isNode ? 80 : 800;
|
|
96
|
+
return {
|
|
97
|
+
width, height, top: 0, left: 0, right: width, bottom: height, x: 0, y: 0,
|
|
98
|
+
toJSON() { return this; },
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
afterEach(() => {
|
|
103
|
+
cleanup();
|
|
104
|
+
vi.restoreAllMocks();
|
|
105
|
+
});
|
|
106
|
+
describe('GoalTreeView', () => {
|
|
107
|
+
it('renders without crashing and shows every canvas goal', async () => {
|
|
108
|
+
render(_jsx(GoalTreeView, { tree: makeTree() }));
|
|
109
|
+
await waitFor(() => {
|
|
110
|
+
expect(screen.getByText('Triple revenue')).toBeTruthy();
|
|
111
|
+
expect(screen.getByText('Launch in EU')).toBeTruthy();
|
|
112
|
+
expect(screen.getByText('Cut churn')).toBeTruthy();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
it('renders factor indicators from goal.factors', async () => {
|
|
116
|
+
render(_jsx(GoalTreeView, { tree: makeTree() }));
|
|
117
|
+
await waitFor(() => {
|
|
118
|
+
expect(screen.getByText('Triple revenue')).toBeTruthy();
|
|
119
|
+
});
|
|
120
|
+
// One up-caret (opportunity) and one down-caret (risk) on "Cut churn".
|
|
121
|
+
expect(screen.getByLabelText('1 positive factor')).toBeTruthy();
|
|
122
|
+
expect(screen.getByLabelText('1 negative factor')).toBeTruthy();
|
|
123
|
+
});
|
|
124
|
+
it('puts a goal with a broken parent_id in the backlog, not on canvas', async () => {
|
|
125
|
+
const tree = {
|
|
126
|
+
goal_types: [
|
|
127
|
+
{ name: 'Strategy', level: 0 },
|
|
128
|
+
{ name: 'Business Goal', level: 1 },
|
|
129
|
+
],
|
|
130
|
+
goals: [
|
|
131
|
+
{ id: 1, name: 'Root goal', type: 'Strategy', level: 0, parent_id: 0 },
|
|
132
|
+
// level 1 + a parent_id that resolves to nothing — not a root by
|
|
133
|
+
// either "Roots: level === 0 || parent_id === 0" clause, and
|
|
134
|
+
// unreachable from goal 1 — must land in the backlog.
|
|
135
|
+
{ id: 2, name: 'Orphaned goal', type: 'Business Goal', level: 1, parent_id: 999 },
|
|
136
|
+
],
|
|
137
|
+
};
|
|
138
|
+
render(_jsx(GoalTreeView, { tree: tree, showBacklog: true }));
|
|
139
|
+
await waitFor(() => {
|
|
140
|
+
expect(screen.getByText('Root goal')).toBeTruthy();
|
|
141
|
+
});
|
|
142
|
+
expect(screen.getByText('Orphaned goal')).toBeTruthy();
|
|
143
|
+
expect(screen.queryByText('Backlog')).toBeTruthy();
|
|
144
|
+
});
|
|
145
|
+
it('does not render add/delete affordances when readOnly', async () => {
|
|
146
|
+
render(_jsx(GoalTreeView, { tree: makeTree(), readOnly: true }));
|
|
147
|
+
await waitFor(() => {
|
|
148
|
+
expect(screen.getByText('Triple revenue')).toBeTruthy();
|
|
149
|
+
});
|
|
150
|
+
expect(screen.queryByLabelText('Add child goal')).toBeNull();
|
|
151
|
+
expect(screen.queryByLabelText('Delete goal')).toBeNull();
|
|
152
|
+
});
|
|
153
|
+
it('fires onChange with kind "addChild" when the add-child button is clicked', async () => {
|
|
154
|
+
const onChange = vi.fn();
|
|
155
|
+
render(_jsx(GoalTreeView, { tree: makeTree(), onChange: onChange }));
|
|
156
|
+
await waitFor(() => {
|
|
157
|
+
expect(screen.getByText('Triple revenue')).toBeTruthy();
|
|
158
|
+
});
|
|
159
|
+
// Target the root (id 1, level 0) specifically — makeTree()'s goal_types
|
|
160
|
+
// only go up to level 1, so clicking "add child" on an existing level-1
|
|
161
|
+
// goal would be correctly refused (would exceed max level) and never
|
|
162
|
+
// fire onChange at all.
|
|
163
|
+
const rootNode = document.querySelector('.react-flow__node[data-id="1"]');
|
|
164
|
+
const addButton = rootNode.querySelector('[aria-label="Add child goal"]');
|
|
165
|
+
addButton.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
166
|
+
await waitFor(() => expect(onChange).toHaveBeenCalledTimes(1));
|
|
167
|
+
const event = onChange.mock.calls[0][0];
|
|
168
|
+
expect(event.kind).toBe('addChild');
|
|
169
|
+
if (event.kind === 'addChild') {
|
|
170
|
+
expect(event.result.goals.length).toBe(4);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
it('fires onChange with kind "delete" when the delete button is clicked', async () => {
|
|
174
|
+
const onChange = vi.fn();
|
|
175
|
+
render(_jsx(GoalTreeView, { tree: makeTree(), onChange: onChange }));
|
|
176
|
+
await waitFor(() => {
|
|
177
|
+
expect(screen.getByText('Cut churn')).toBeTruthy();
|
|
178
|
+
});
|
|
179
|
+
const deleteButtons = screen.getAllByLabelText('Delete goal');
|
|
180
|
+
deleteButtons[deleteButtons.length - 1].dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
181
|
+
await waitFor(() => expect(onChange).toHaveBeenCalledTimes(1));
|
|
182
|
+
const event = onChange.mock.calls[0][0];
|
|
183
|
+
expect(event.kind).toBe('delete');
|
|
184
|
+
});
|
|
185
|
+
it('fires onChange with kind "restoreFromBacklog" when a backlog card is dropped onto a canvas card', async () => {
|
|
186
|
+
const tree = {
|
|
187
|
+
goal_types: [
|
|
188
|
+
{ name: 'Strategy', level: 0 },
|
|
189
|
+
{ name: 'Business Goal', level: 1 },
|
|
190
|
+
],
|
|
191
|
+
goals: [
|
|
192
|
+
{ id: 1, name: 'Root goal', type: 'Strategy', level: 0, parent_id: 0 },
|
|
193
|
+
{ id: 2, name: 'Orphaned goal', type: 'Business Goal', level: 1, parent_id: 999 },
|
|
194
|
+
],
|
|
195
|
+
};
|
|
196
|
+
const onChange = vi.fn();
|
|
197
|
+
render(_jsx(GoalTreeView, { tree: tree, onChange: onChange, showBacklog: true }));
|
|
198
|
+
await waitFor(() => {
|
|
199
|
+
expect(screen.getByText('Orphaned goal')).toBeTruthy();
|
|
200
|
+
});
|
|
201
|
+
// jsdom has no native DataTransfer; stub the minimal setData/getData
|
|
202
|
+
// surface this component's native (non-reactflow) HTML5 drag path uses
|
|
203
|
+
// and attach it directly to the dispatched events.
|
|
204
|
+
const store = new Map();
|
|
205
|
+
const dataTransfer = {
|
|
206
|
+
setData: (k, v) => store.set(k, v),
|
|
207
|
+
getData: (k) => store.get(k) ?? '',
|
|
208
|
+
effectAllowed: 'move',
|
|
209
|
+
};
|
|
210
|
+
function fireDnd(el, type, coords) {
|
|
211
|
+
const event = new Event(type, { bubbles: true, cancelable: true });
|
|
212
|
+
Object.defineProperty(event, 'dataTransfer', { value: dataTransfer });
|
|
213
|
+
Object.assign(event, coords);
|
|
214
|
+
el.dispatchEvent(event);
|
|
215
|
+
}
|
|
216
|
+
const backlogItem = screen.getByText('Orphaned goal').closest('div[draggable]');
|
|
217
|
+
const rootNode = document.querySelector('.react-flow__node[data-id="1"]');
|
|
218
|
+
// jsdom doesn't implement elementFromPoint at all (not just "returns null").
|
|
219
|
+
document.elementFromPoint = vi.fn().mockReturnValue(rootNode);
|
|
220
|
+
fireDnd(backlogItem, 'dragstart', { clientX: 0, clientY: 0 });
|
|
221
|
+
fireDnd(rootNode, 'drop', { clientX: 10, clientY: 10 });
|
|
222
|
+
await waitFor(() => expect(onChange).toHaveBeenCalledTimes(1));
|
|
223
|
+
const event = onChange.mock.calls[0][0];
|
|
224
|
+
expect(event.kind).toBe('restoreFromBacklog');
|
|
225
|
+
if (event.kind === 'restoreFromBacklog') {
|
|
226
|
+
expect(event.id).toBe(2);
|
|
227
|
+
expect(event.newParentId).toBe(1);
|
|
228
|
+
expect(event.result.goals.find((g) => g.id === 2)?.parent_id).toBe(1);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
// Dragging a card is choreographed by reactflow's own pointer/DOM-measurement
|
|
232
|
+
// machinery (ResizeObserver-gated node "readiness", d3-drag pointer capture,
|
|
233
|
+
// viewport transform math) — faithfully simulating that in jsdom means
|
|
234
|
+
// re-implementing reactflow's internals rather than testing this component.
|
|
235
|
+
// computeDragOutcome() is the pure decision GoalTreeView's onNodeDragStop
|
|
236
|
+
// calls once reactflow reports a drag: given where a card was dropped, which
|
|
237
|
+
// mutation fires and what onChange payload it produces. Testing it directly
|
|
238
|
+
// covers the actual reparent/moveToBacklog logic without that DOM coupling.
|
|
239
|
+
describe('computeDragOutcome (reparent / moveToBacklog decision logic)', () => {
|
|
240
|
+
const tree = {
|
|
241
|
+
goal_types: [
|
|
242
|
+
{ name: 'Strategy', level: 0 },
|
|
243
|
+
{ name: 'Business Goal', level: 1 },
|
|
244
|
+
],
|
|
245
|
+
goals: [
|
|
246
|
+
{ id: 1, name: 'Goal A', type: 'Strategy', level: 0, parent_id: 0 },
|
|
247
|
+
{ id: 2, name: 'Goal C', type: 'Strategy', level: 0, parent_id: 0 },
|
|
248
|
+
{ id: 3, name: 'Goal B', type: 'Business Goal', level: 1, parent_id: 1 },
|
|
249
|
+
],
|
|
250
|
+
};
|
|
251
|
+
it('fires a "reparent" change when dropped onto another card', () => {
|
|
252
|
+
const change = computeDragOutcome(tree, 3, { kind: 'node', id: 2 });
|
|
253
|
+
expect(change?.kind).toBe('reparent');
|
|
254
|
+
if (change?.kind === 'reparent') {
|
|
255
|
+
expect(change.sourceId).toBe(3);
|
|
256
|
+
expect(change.targetId).toBe(2);
|
|
257
|
+
expect(change.result.goals.find((g) => g.id === 3)?.parent_id).toBe(2);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
it('fires a "moveToBacklog" change when dropped on the backlog zone', () => {
|
|
261
|
+
const change = computeDragOutcome(tree, 3, { kind: 'backlog' });
|
|
262
|
+
expect(change?.kind).toBe('moveToBacklog');
|
|
263
|
+
if (change?.kind === 'moveToBacklog') {
|
|
264
|
+
expect(change.id).toBe(3);
|
|
265
|
+
expect(change.result.goals.find((g) => g.id === 3)?.parent_id).toBe(0);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
it('is a no-op when dropped nowhere in particular', () => {
|
|
269
|
+
expect(computeDragOutcome(tree, 3, null)).toBeNull();
|
|
270
|
+
});
|
|
271
|
+
it('is a no-op when dropped on itself', () => {
|
|
272
|
+
expect(computeDragOutcome(tree, 3, { kind: 'node', id: 3 })).toBeNull();
|
|
273
|
+
});
|
|
274
|
+
it('is a no-op when the reparent would exceed the schema max level', () => {
|
|
275
|
+
// Goal 3 is already level 1 (max); reparenting it under itself-sibling
|
|
276
|
+
// level-1 goal would push it to level 2.
|
|
277
|
+
const deeper = {
|
|
278
|
+
...tree,
|
|
279
|
+
goals: [...tree.goals, { id: 4, name: 'Goal D', type: 'Business Goal', level: 1, parent_id: 1 }],
|
|
280
|
+
};
|
|
281
|
+
expect(computeDragOutcome(deeper, 3, { kind: 'node', id: 4 })).toBeNull();
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
it('fires onFactorClick with the clicked factor when a popover item is clicked', async () => {
|
|
285
|
+
const onFactorClick = vi.fn();
|
|
286
|
+
render(_jsx(GoalTreeView, { tree: makeTree(), onFactorClick: onFactorClick }));
|
|
287
|
+
await waitFor(() => {
|
|
288
|
+
expect(screen.getByText('Cut churn')).toBeTruthy();
|
|
289
|
+
});
|
|
290
|
+
// Open the negative-factor panel on "Cut churn" (id=3, has risk factor "Support backlog")
|
|
291
|
+
const negativeBadge = screen.getByLabelText('1 negative factor');
|
|
292
|
+
negativeBadge.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
293
|
+
// The popover item for the risk factor should now be in the DOM
|
|
294
|
+
const factorItem = await waitFor(() => screen.getByText('Support backlog'));
|
|
295
|
+
factorItem.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
296
|
+
await waitFor(() => expect(onFactorClick).toHaveBeenCalledTimes(1));
|
|
297
|
+
expect(onFactorClick.mock.calls[0][0]).toMatchObject({ id: 10, name: 'Support backlog', impact_type: 'risk' });
|
|
298
|
+
});
|
|
299
|
+
it('backlog panel is collapsible — toggle hides and restores content', async () => {
|
|
300
|
+
const tree = {
|
|
301
|
+
goal_types: [
|
|
302
|
+
{ name: 'Strategy', level: 0 },
|
|
303
|
+
{ name: 'Business Goal', level: 1 },
|
|
304
|
+
],
|
|
305
|
+
goals: [
|
|
306
|
+
{ id: 1, name: 'Root goal', type: 'Strategy', level: 0, parent_id: 0 },
|
|
307
|
+
{ id: 2, name: 'Orphaned goal', type: 'Business Goal', level: 1, parent_id: 999 },
|
|
308
|
+
],
|
|
309
|
+
};
|
|
310
|
+
render(_jsx(GoalTreeView, { tree: tree, showBacklog: true }));
|
|
311
|
+
await waitFor(() => {
|
|
312
|
+
expect(screen.getByText('Backlog')).toBeTruthy();
|
|
313
|
+
});
|
|
314
|
+
// Collapse
|
|
315
|
+
screen.getByLabelText('Collapse backlog').dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
316
|
+
await waitFor(() => {
|
|
317
|
+
expect(screen.queryByText('Backlog')).toBeNull();
|
|
318
|
+
});
|
|
319
|
+
// Expand again
|
|
320
|
+
screen.getByLabelText('Expand backlog').dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
321
|
+
await waitFor(() => {
|
|
322
|
+
expect(screen.getByText('Backlog')).toBeTruthy();
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
it('fires onEditRequest on double-click', async () => {
|
|
326
|
+
const onEditRequest = vi.fn();
|
|
327
|
+
render(_jsx(GoalTreeView, { tree: makeTree(), onEditRequest: onEditRequest }));
|
|
328
|
+
await waitFor(() => {
|
|
329
|
+
expect(screen.getByText('Triple revenue')).toBeTruthy();
|
|
330
|
+
});
|
|
331
|
+
const nodeEl = document.querySelector('.react-flow__node[data-id="1"]');
|
|
332
|
+
expect(nodeEl).toBeTruthy();
|
|
333
|
+
nodeEl.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
|
|
334
|
+
await waitFor(() => expect(onEditRequest).toHaveBeenCalledTimes(1));
|
|
335
|
+
expect(onEditRequest.mock.calls[0][0]).toMatchObject({ id: 1, name: 'Triple revenue' });
|
|
336
|
+
});
|
|
337
|
+
});
|
|
@@ -93,3 +93,42 @@ describe('restoreFromBacklog', () => {
|
|
|
93
93
|
expect(r.result.goals.find(g => g.id === 3).parent_id).toBe(1);
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
|
+
describe('reparent — descendant type relabeling and level cap', () => {
|
|
97
|
+
const DEEP = {
|
|
98
|
+
goal_types: [
|
|
99
|
+
{ name: 'Strategy', level: 0 },
|
|
100
|
+
{ name: 'Business Goal', level: 1 },
|
|
101
|
+
{ name: 'Project', level: 2 },
|
|
102
|
+
{ name: 'Task', level: 3 },
|
|
103
|
+
],
|
|
104
|
+
goals: [
|
|
105
|
+
{ id: 1, name: 'Root', type: 'Strategy', level: 0, parent_id: 0 },
|
|
106
|
+
{ id: 2, name: 'BG1', type: 'Business Goal', level: 1, parent_id: 1 },
|
|
107
|
+
{ id: 3, name: 'Proj1', type: 'Project', level: 2, parent_id: 2 },
|
|
108
|
+
{ id: 4, name: 'Task1', type: 'Task', level: 3, parent_id: 3 },
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
it('relabels descendant types via getTypeForLevel when reparenting shifts levels', () => {
|
|
112
|
+
// Move Proj1 (id=3, level=2) directly under Root (id=1, level=0); delta = -1
|
|
113
|
+
// Task1 (child of Proj1, level=3): new level = 2, type should be 'Project'
|
|
114
|
+
const r = reparent(DEEP, 3, 1);
|
|
115
|
+
expect(r.ok).toBe(true);
|
|
116
|
+
const proj = r.result.goals.find(g => g.id === 3);
|
|
117
|
+
const task = r.result.goals.find(g => g.id === 4);
|
|
118
|
+
expect(proj.level).toBe(1);
|
|
119
|
+
expect(proj.type).toBe('Business Goal');
|
|
120
|
+
expect(task.level).toBe(2);
|
|
121
|
+
expect(task.type).toBe('Project');
|
|
122
|
+
});
|
|
123
|
+
it('caps descendant level at maxLevel and refuses when that violates GOALS-012', () => {
|
|
124
|
+
// Move Root (id=1, level=0) under Root2 (id=5, level=0); delta = +1
|
|
125
|
+
// BG1: 1→2, Proj1: 2→3 (maxLevel), Task1: 3→4, capped at 3
|
|
126
|
+
// Task1 (capped level=3) under Proj1 (level=3) violates GOALS-012 → refused
|
|
127
|
+
const tree = {
|
|
128
|
+
...DEEP,
|
|
129
|
+
goals: [...DEEP.goals, { id: 5, name: 'Root2', type: 'Strategy', level: 0, parent_id: 0 }],
|
|
130
|
+
};
|
|
131
|
+
const r = reparent(tree, 1, 5);
|
|
132
|
+
expect(r.ok).toBe(false);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -107,8 +107,10 @@ describe('parseCanonicalGoals', () => {
|
|
|
107
107
|
it('maps canonical IDs to internal numeric ids; parent_id is the parent\'s mapped id', () => {
|
|
108
108
|
const r = parseCanonicalGoals(VALID);
|
|
109
109
|
expect(r.parsed?.goals[0].id).toBe(1);
|
|
110
|
+
expect(r.parsed?.goals[0].canonical_id).toBe('GOAL-1');
|
|
110
111
|
expect(r.parsed?.goals[0].parent_id).toBe(0);
|
|
111
112
|
expect(r.parsed?.goals[1].id).toBe(2);
|
|
113
|
+
expect(r.parsed?.goals[1].canonical_id).toBe('GOAL-2');
|
|
112
114
|
expect(r.parsed?.goals[1].parent_id).toBe(1);
|
|
113
115
|
});
|
|
114
116
|
});
|
package/dist/goals/index.d.ts
CHANGED
|
@@ -4,3 +4,6 @@ export { parseCanonicalGoals } from './parse-canonical.js';
|
|
|
4
4
|
export type { CanonicalGoalsResult } from './parse-canonical.js';
|
|
5
5
|
export { layoutGoalTree, selectScopedGoals } from './layout.js';
|
|
6
6
|
export { reparent, addChild, deleteWithDescendants, moveToBacklog, restoreFromBacklog } from './mutations.js';
|
|
7
|
+
export { GoalTreeView } from './GoalTreeView.js';
|
|
8
|
+
export type { GoalTreeViewProps, GoalTreeChange } from './GoalTreeView.js';
|
|
9
|
+
export type { ThemeTokens } from './theme.js';
|
package/dist/goals/index.js
CHANGED
|
@@ -2,3 +2,4 @@ export { validateGoalTree } from './validate.js';
|
|
|
2
2
|
export { parseCanonicalGoals } from './parse-canonical.js';
|
|
3
3
|
export { layoutGoalTree, selectScopedGoals } from './layout.js';
|
|
4
4
|
export { reparent, addChild, deleteWithDescendants, moveToBacklog, restoreFromBacklog } from './mutations.js';
|
|
5
|
+
export { GoalTreeView } from './GoalTreeView.js';
|
package/dist/goals/layout.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { displayGoalId } from './parse-canonical.js';
|
|
1
2
|
const DEFAULT_NODE_WIDTH = 250;
|
|
2
3
|
const DEFAULT_NODE_HEIGHT = 80;
|
|
3
4
|
const DEFAULT_RANK_SEP = 80;
|
|
@@ -21,7 +22,7 @@ export function selectScopedGoals(goals, scope) {
|
|
|
21
22
|
children.set(g.parent_id, []);
|
|
22
23
|
children.get(g.parent_id).push(g.id);
|
|
23
24
|
}
|
|
24
|
-
const root = goals.find(g =>
|
|
25
|
+
const root = goals.find(g => displayGoalId(g) === scope.rootGoalId);
|
|
25
26
|
if (!root)
|
|
26
27
|
return [];
|
|
27
28
|
const keep = new Set();
|