@atolis-hq/corum 0.1.62 → 0.1.63
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/src/adapters/asyncapi/mapper.js +1 -1
- package/dist/src/adapters/corum/mapper.js +1 -1
- package/dist/src/adapters/openapi/mapper.js +1 -1
- package/dist/src/graph/index.js +39 -8
- package/dist/src/linter/index.js +29 -1
- package/dist/src/loader/cluster-loader.js +5 -2
- package/dist/src/loader/index.js +5 -0
- package/dist/src/loader/kind-loader.js +63 -0
- package/dist/src/loader/namespace-loader.js +36 -0
- package/dist/src/mcp/index.js +15 -10
- package/dist/src/mcp/prompts/usage-guide.js +9 -9
- package/dist/src/mcp/serializers.js +1 -1
- package/dist/src/mutate/apply-cluster.js +1 -1
- package/dist/src/reconcile/index.js +1 -1
- package/dist/src/web/server.js +25 -5
- package/dist/src/writer/graph-writer.js +7 -1
- package/package.json +1 -1
- package/web/app.jsx +175 -24
- package/web/graph-utils.js +45 -11
- package/web/graph-utils.test.js +42 -15
- package/web/graph.jsx +68 -20
- package/web/nav.js +36 -5
- package/web/router.js +1 -1
- package/web/search-utils.test.js +4 -4
- package/web/search.jsx +1 -1
- package/web/style.css +22 -0
package/web/app.jsx
CHANGED
|
@@ -11,8 +11,9 @@ const {
|
|
|
11
11
|
PropertiesTable,
|
|
12
12
|
SchemaCard,
|
|
13
13
|
} = window.CorumPrimitives;
|
|
14
|
-
const { buildNavTree, buildOverlayIndicatorIds } = window.CorumNav;
|
|
14
|
+
const { buildNavTree, buildOverlayIndicatorIds, groupNamespacesByKind, namespaceEdges } = window.CorumNav;
|
|
15
15
|
const { parseRoute, buildRoute } = window.CorumRouter;
|
|
16
|
+
const { kindColour } = window.CorumGraphUtils;
|
|
16
17
|
const { SearchModal } = window.CorumSearch;
|
|
17
18
|
|
|
18
19
|
// uses-type is excluded here: it's the auto-generated type-reference edge
|
|
@@ -95,7 +96,7 @@ function TopBar({ onSearchOpen }) {
|
|
|
95
96
|
function NavRail({ activeSection, onSection, debugMode, onDebugMode }) {
|
|
96
97
|
const items = [
|
|
97
98
|
{ id: 'dashboard', icon: 'grip', label: 'Dashboard' },
|
|
98
|
-
{ id: '
|
|
99
|
+
{ id: 'namespaces', icon: 'circle-nodes', label: 'Namespaces' },
|
|
99
100
|
{ id: 'graph', icon: 'diagram-project', label: 'Graph' },
|
|
100
101
|
];
|
|
101
102
|
|
|
@@ -134,7 +135,7 @@ function entryKey(entry) {
|
|
|
134
135
|
return entry.kind === 'group' ? entry.groupTemplateName : entry.templateName;
|
|
135
136
|
}
|
|
136
137
|
|
|
137
|
-
function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds }) {
|
|
138
|
+
function NavTree({ navTree, kindSections, templates, activeNodeId, onNode, onNamespace, overlayIndicatorIds }) {
|
|
138
139
|
const sortedComponents = [...navTree.keys()].sort((a, b) => a.localeCompare(b));
|
|
139
140
|
const [openComponent, setOpenComponent] = useState();
|
|
140
141
|
const [openEntryKeys, setOpenEntryKeys] = useState(new Set());
|
|
@@ -197,9 +198,11 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
197
198
|
setOpenGroupKeys(new Set());
|
|
198
199
|
}, [activeNodeId, navTree]);
|
|
199
200
|
|
|
200
|
-
function toggleComponent(component) {
|
|
201
|
+
function toggleComponent(component, kind) {
|
|
201
202
|
if (openComponent === component) { openComponentWithEntries(null); }
|
|
202
203
|
else { openComponentWithEntries(component); }
|
|
204
|
+
// Kinds other than the default have no dedicated view: open the generic namespace page.
|
|
205
|
+
if (kind !== 'component') onNamespace(component);
|
|
203
206
|
}
|
|
204
207
|
|
|
205
208
|
function toggleEntry(key) {
|
|
@@ -221,11 +224,14 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
221
224
|
event.target.click();
|
|
222
225
|
}
|
|
223
226
|
}}>
|
|
224
|
-
{
|
|
225
|
-
|
|
227
|
+
{kindSections.map(section => (
|
|
228
|
+
<div key={section.kind} className="nav-kind-section" data-kind={section.kind}>
|
|
229
|
+
{kindSections.length > 1 && <div className="nav-kind-head">{section.label}</div>}
|
|
230
|
+
{section.namespaces.map(component => {
|
|
231
|
+
const entries = navTree.get(component) ?? [];
|
|
226
232
|
return (
|
|
227
233
|
<div key={component}>
|
|
228
|
-
<div className="nav-section-head" role="button" tabIndex={0} aria-expanded={openComponent === component} onClick={() => toggleComponent(component)}>
|
|
234
|
+
<div className="nav-section-head" role="button" tabIndex={0} aria-expanded={openComponent === component} onClick={() => toggleComponent(component, section.kind)}>
|
|
229
235
|
<span>{component}</span>
|
|
230
236
|
<Icon name={openComponent === component ? 'chevron-down' : 'chevron-right'} size={12} />
|
|
231
237
|
</div>
|
|
@@ -361,6 +367,8 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
361
367
|
</div>
|
|
362
368
|
);
|
|
363
369
|
})}
|
|
370
|
+
</div>
|
|
371
|
+
))}
|
|
364
372
|
</div>
|
|
365
373
|
);
|
|
366
374
|
}
|
|
@@ -516,7 +524,7 @@ function HeroCard({ value, label }) {
|
|
|
516
524
|
);
|
|
517
525
|
}
|
|
518
526
|
|
|
519
|
-
function DashboardPage({ nodes, templates, gitMode, viewingRef, branches, branchResults }) {
|
|
527
|
+
function DashboardPage({ nodes, templates, kinds, gitMode, viewingRef, branches, branchResults }) {
|
|
520
528
|
const [stats, setStats] = useState(null);
|
|
521
529
|
const [branchDiff, setBranchDiff] = useState(null);
|
|
522
530
|
|
|
@@ -551,8 +559,13 @@ function DashboardPage({ nodes, templates, gitMode, viewingRef, branches, branch
|
|
|
551
559
|
? Object.entries(stats.nodesByTemplate).sort((a, b) => b[1] - a[1])
|
|
552
560
|
: [];
|
|
553
561
|
|
|
562
|
+
const kindLabels = new Map((kinds ?? []).map(kind => [kind.id, kind.label]));
|
|
563
|
+
const namespacesByKind = stats
|
|
564
|
+
? Object.entries(stats.namespacesByKind ?? {}).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
565
|
+
: [];
|
|
566
|
+
|
|
554
567
|
const nodesByComponent = stats
|
|
555
|
-
? Object.entries(stats.
|
|
568
|
+
? Object.entries(stats.nodesByNamespace).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
|
|
556
569
|
: [];
|
|
557
570
|
|
|
558
571
|
const nodesByState = stats
|
|
@@ -574,7 +587,7 @@ function DashboardPage({ nodes, templates, gitMode, viewingRef, branches, branch
|
|
|
574
587
|
return (
|
|
575
588
|
<div className="content">
|
|
576
589
|
<div className="dashboard-hero">
|
|
577
|
-
<HeroCard value={stats ? stats.
|
|
590
|
+
<HeroCard value={stats ? stats.namespaceCount : '…'} label="Namespaces" />
|
|
578
591
|
<HeroCard value={stats ? stats.nodeCount : '…'} label="Nodes" />
|
|
579
592
|
<HeroCard value={totalEdges} label="Edges" />
|
|
580
593
|
<HeroCard value={stats ? stats.orphanNodeCount : '…'} label="Orphan Nodes" />
|
|
@@ -614,7 +627,23 @@ function DashboardPage({ nodes, templates, gitMode, viewingRef, branches, branch
|
|
|
614
627
|
</div>
|
|
615
628
|
|
|
616
629
|
<div className="dashboard-panel">
|
|
617
|
-
<div className="card-head">
|
|
630
|
+
<div className="card-head">Namespaces by Kind</div>
|
|
631
|
+
<div className="card-body" style={{ padding: '12px 16px' }}>
|
|
632
|
+
{stats === null && <div className="label-sm">Loading…</div>}
|
|
633
|
+
{namespacesByKind.map(([kind, count]) => (
|
|
634
|
+
<div key={kind} className="stat-row">
|
|
635
|
+
<span className="stat-row-label">
|
|
636
|
+
<span className="stat-colour-dot" style={{ background: kindColour(kind) }} />
|
|
637
|
+
{kindLabels.get(kind) ?? kind}
|
|
638
|
+
</span>
|
|
639
|
+
<span className="stat-row-value">{count}</span>
|
|
640
|
+
</div>
|
|
641
|
+
))}
|
|
642
|
+
</div>
|
|
643
|
+
</div>
|
|
644
|
+
|
|
645
|
+
<div className="dashboard-panel">
|
|
646
|
+
<div className="card-head">Nodes by Namespace</div>
|
|
618
647
|
<div className="card-body" style={{ padding: '12px 16px' }}>
|
|
619
648
|
{stats === null && <div className="label-sm">Loading…</div>}
|
|
620
649
|
{nodesByComponent.map(([name, count]) => (
|
|
@@ -726,8 +755,106 @@ function DashboardPage({ nodes, templates, gitMode, viewingRef, branches, branch
|
|
|
726
755
|
);
|
|
727
756
|
}
|
|
728
757
|
|
|
729
|
-
function
|
|
730
|
-
return <div className="content"><h1>
|
|
758
|
+
function NamespacesPage() {
|
|
759
|
+
return <div className="content"><h1>Namespaces</h1></div>;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
// Generic fallback view for any namespace: owned nodes plus inbound and outbound edges.
|
|
763
|
+
// Contains no knowledge of specific kinds; richer views are a separate plugin mechanism.
|
|
764
|
+
function NamespacePage({ namespace, nodes, templates, kinds, onNavigate, viewingRef }) {
|
|
765
|
+
const [graph, setGraph] = useState(null);
|
|
766
|
+
const [error, setError] = useState(null);
|
|
767
|
+
|
|
768
|
+
useEffect(() => {
|
|
769
|
+
setGraph(null);
|
|
770
|
+
setError(null);
|
|
771
|
+
const refParam = viewingRef ? `?ref=${encodeURIComponent(viewingRef)}` : '';
|
|
772
|
+
fetch(`/api/graph${refParam}`)
|
|
773
|
+
.then(res => res.ok ? res.json() : Promise.reject(res.status))
|
|
774
|
+
.then(setGraph)
|
|
775
|
+
.catch(err => setError(String(err)));
|
|
776
|
+
}, [namespace, viewingRef]);
|
|
777
|
+
|
|
778
|
+
const owned = nodes.filter(node => node.namespace === namespace);
|
|
779
|
+
if (owned.length === 0) {
|
|
780
|
+
return <div className="content"><p className="label-sm">Namespace not found: {namespace}</p></div>;
|
|
781
|
+
}
|
|
782
|
+
const kind = owned[0].kind ?? 'component';
|
|
783
|
+
const kindLabel = (kinds ?? []).find(k => k.id === kind)?.label ?? kind;
|
|
784
|
+
const templateMap = new Map(templates.map(t => [t.name, t]));
|
|
785
|
+
|
|
786
|
+
const byTemplate = new Map();
|
|
787
|
+
for (const node of owned) {
|
|
788
|
+
if (!byTemplate.has(node.template)) byTemplate.set(node.template, []);
|
|
789
|
+
byTemplate.get(node.template).push(node);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
const nodeMap = new Map((graph?.nodes ?? []).map(n => [n.id, n]));
|
|
793
|
+
const { inbound, outbound } = namespaceEdges(graph?.edges ?? [], namespace);
|
|
794
|
+
|
|
795
|
+
function NodeLink({ id }) {
|
|
796
|
+
const node = nodeMap.get(id);
|
|
797
|
+
const tmpl = node ? templateMap.get(node.template) : null;
|
|
798
|
+
return (
|
|
799
|
+
<span
|
|
800
|
+
role="link" tabIndex={0}
|
|
801
|
+
style={{ cursor: 'pointer' }}
|
|
802
|
+
title={id}
|
|
803
|
+
onClick={() => onNavigate(id)}
|
|
804
|
+
onKeyDown={event => { if (event.key === 'Enter') onNavigate(id); }}
|
|
805
|
+
>
|
|
806
|
+
<span style={{ fontWeight: 500 }}>{displayName(id)}</span>
|
|
807
|
+
{tmpl && <span className="label-sm"> · {templateDisplayName(tmpl)}</span>}
|
|
808
|
+
<span className="label-sm mono"> {id}</span>
|
|
809
|
+
</span>
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
function EdgeList({ title, edges, endpoint }) {
|
|
814
|
+
return (
|
|
815
|
+
<div className="card" style={{ marginBottom: 16 }} data-testid={`namespace-${title.toLowerCase()}`}>
|
|
816
|
+
<div className="card-head">{title} ({edges.length})</div>
|
|
817
|
+
<div className="card-body" style={{ padding: '12px 16px' }}>
|
|
818
|
+
{graph === null && !error && <div className="label-sm">Loading…</div>}
|
|
819
|
+
{error && <div style={{ color: 'var(--warn)' }}>Error loading edges: {error}</div>}
|
|
820
|
+
{graph !== null && edges.length === 0 && <div className="label-sm">None.</div>}
|
|
821
|
+
{edges.map(edge => (
|
|
822
|
+
<div key={edge.id} style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '5px 0' }}>
|
|
823
|
+
<span className="tag" style={EDGE_TYPE_STYLES[edge.type] ?? {}}>{edge.type}</span>
|
|
824
|
+
<NodeLink id={edge[endpoint]} />
|
|
825
|
+
</div>
|
|
826
|
+
))}
|
|
827
|
+
</div>
|
|
828
|
+
</div>
|
|
829
|
+
);
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
return (
|
|
833
|
+
<div className="content">
|
|
834
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 6, flexWrap: 'wrap' }}>
|
|
835
|
+
<h1 style={{ margin: 0 }}>{namespace}</h1>
|
|
836
|
+
<span className="ns-kind-pill" style={{ background: kindColour(kind) }}>{kindLabel}</span>
|
|
837
|
+
</div>
|
|
838
|
+
<div className="label-sm" style={{ marginBottom: 16 }}>Namespace · {owned.length} {owned.length === 1 ? 'node' : 'nodes'}</div>
|
|
839
|
+
|
|
840
|
+
<div className="card" style={{ marginBottom: 16 }}>
|
|
841
|
+
<div className="card-head">Owned nodes</div>
|
|
842
|
+
<div className="card-body" style={{ padding: '12px 16px' }}>
|
|
843
|
+
{[...byTemplate.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([templateName, list]) => (
|
|
844
|
+
<div key={templateName} style={{ marginBottom: 10 }}>
|
|
845
|
+
<div className="label-xs" style={{ marginBottom: 4 }}>{templateDisplayName(templateMap.get(templateName)) || templateName}</div>
|
|
846
|
+
{list.sort((a, b) => a.id.localeCompare(b.id)).map(node => (
|
|
847
|
+
<div key={node.id} style={{ padding: '3px 0' }}><NodeLink id={node.id} /></div>
|
|
848
|
+
))}
|
|
849
|
+
</div>
|
|
850
|
+
))}
|
|
851
|
+
</div>
|
|
852
|
+
</div>
|
|
853
|
+
|
|
854
|
+
<EdgeList title="Inbound" edges={inbound} endpoint="from" />
|
|
855
|
+
<EdgeList title="Outbound" edges={outbound} endpoint="to" />
|
|
856
|
+
</div>
|
|
857
|
+
);
|
|
731
858
|
}
|
|
732
859
|
|
|
733
860
|
function EdgePanel({ inbound, outbound, allNodes, templates, onNavigate, viewingRef }) {
|
|
@@ -902,7 +1029,7 @@ function NodePage({ nodeId, templates, onNavigate, refreshToken, viewingRef, ove
|
|
|
902
1029
|
|
|
903
1030
|
<div className="meta-strip">
|
|
904
1031
|
{[
|
|
905
|
-
['
|
|
1032
|
+
['Namespace', root.namespace],
|
|
906
1033
|
['State', root.state],
|
|
907
1034
|
['Stability', root.stability],
|
|
908
1035
|
['Schema version', root.schemaVersion],
|
|
@@ -985,6 +1112,7 @@ function resolveTemplates(templates) {
|
|
|
985
1112
|
function App() {
|
|
986
1113
|
const [templates, setTemplates] = useState([]);
|
|
987
1114
|
const [nodes, setNodes] = useState([]);
|
|
1115
|
+
const [kinds, setKinds] = useState([]);
|
|
988
1116
|
const [loading, setLoading] = useState(true);
|
|
989
1117
|
const [error, setError] = useState(null);
|
|
990
1118
|
const [route, setRoute] = useState(() => parseRoute(window.location.hash));
|
|
@@ -1019,10 +1147,12 @@ function App() {
|
|
|
1019
1147
|
return Promise.all([
|
|
1020
1148
|
fetch(`/api/templates${refParam}`).then(response => response.ok ? response.json() : Promise.reject(response.status)),
|
|
1021
1149
|
fetch(`/api/nodes${refParam}`).then(response => response.ok ? response.json() : Promise.reject(response.status)),
|
|
1150
|
+
fetch(`/api/kinds${refParam}`).then(response => response.ok ? response.json() : Promise.reject(response.status)),
|
|
1022
1151
|
])
|
|
1023
|
-
.then(([templateData, nodeData]) => {
|
|
1152
|
+
.then(([templateData, nodeData, kindData]) => {
|
|
1024
1153
|
setTemplates(resolveTemplates(templateData));
|
|
1025
1154
|
setNodes(nodeData);
|
|
1155
|
+
setKinds(kindData.kinds ?? []);
|
|
1026
1156
|
setRefreshToken(token => token + 1);
|
|
1027
1157
|
setLoading(false);
|
|
1028
1158
|
})
|
|
@@ -1081,17 +1211,17 @@ function App() {
|
|
|
1081
1211
|
useEffect(() => {
|
|
1082
1212
|
let previous = parseRoute(window.location.hash);
|
|
1083
1213
|
function syncHistory(next) {
|
|
1084
|
-
if (matchMedia('(max-width: 780px)').matches && next.pathname === '/node' && !history.state?.corumDetail) {
|
|
1214
|
+
if (matchMedia('(max-width: 780px)').matches && (next.pathname === '/node' || next.pathname === '/namespace') && !history.state?.corumDetail) {
|
|
1085
1215
|
// Seed a list entry behind direct links and nodes opened from other sections.
|
|
1086
1216
|
const hash = location.hash;
|
|
1087
|
-
history.replaceState(null, '', buildRoute({ pathname: '/
|
|
1217
|
+
history.replaceState(null, '', buildRoute({ pathname: '/namespaces', branch: next.branch }));
|
|
1088
1218
|
history.pushState({ corumDetail: true }, '', hash);
|
|
1089
1219
|
}
|
|
1090
1220
|
}
|
|
1091
1221
|
syncHistory(previous);
|
|
1092
1222
|
const handler = () => {
|
|
1093
1223
|
const next = parseRoute(location.hash);
|
|
1094
|
-
if (next.pathname === '/node' && previous.pathname === '/
|
|
1224
|
+
if ((next.pathname === '/node' || next.pathname === '/namespace') && previous.pathname === '/namespaces') {
|
|
1095
1225
|
history.replaceState({ corumDetail: true }, '');
|
|
1096
1226
|
} else {
|
|
1097
1227
|
syncHistory(next);
|
|
@@ -1125,10 +1255,12 @@ function App() {
|
|
|
1125
1255
|
|
|
1126
1256
|
const activeNodeId = route.pathname === '/node' ? route.params.get('id') : null;
|
|
1127
1257
|
if (activeNodeId) retainedNode.current = activeNodeId;
|
|
1128
|
-
const detailOpen = route.pathname === '/node';
|
|
1129
|
-
const
|
|
1258
|
+
const detailOpen = route.pathname === '/node' || route.pathname === '/namespace';
|
|
1259
|
+
const activeNamespace = route.pathname === '/namespace' ? route.params.get('name') : null;
|
|
1260
|
+
const activeSection = activeNodeId || activeNamespace ? 'namespaces' : (route.pathname.slice(1) || 'dashboard');
|
|
1130
1261
|
const navTree = useMemo(() => buildNavTree(nodes, templates), [nodes, templates]);
|
|
1131
|
-
const
|
|
1262
|
+
const kindSections = useMemo(() => groupNamespacesByKind(nodes, kinds), [nodes, kinds]);
|
|
1263
|
+
const showTree = (activeSection === 'namespaces' || activeNodeId) && activeSection !== 'graph';
|
|
1132
1264
|
useEffect(() => {
|
|
1133
1265
|
if (!mobile || !showTree) return;
|
|
1134
1266
|
const pane = detailOpen ? detailPane.current : listPane.current;
|
|
@@ -1183,6 +1315,10 @@ function App() {
|
|
|
1183
1315
|
navigate(buildRoute({ pathname: `/${section}`, params: {}, branch: viewingRef }));
|
|
1184
1316
|
}
|
|
1185
1317
|
|
|
1318
|
+
function handleNamespace(name) {
|
|
1319
|
+
navigate(buildRoute({ pathname: '/namespace', params: { name }, branch: viewingRef }));
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1186
1322
|
function handleNode(nodeId) {
|
|
1187
1323
|
navigate(buildRoute({ pathname: '/node', params: { id: nodeId }, branch: viewingRef }));
|
|
1188
1324
|
}
|
|
@@ -1197,14 +1333,27 @@ function App() {
|
|
|
1197
1333
|
<DashboardPage
|
|
1198
1334
|
nodes={nodes}
|
|
1199
1335
|
templates={templates}
|
|
1336
|
+
kinds={kinds}
|
|
1200
1337
|
gitMode={gitMode}
|
|
1201
1338
|
viewingRef={viewingRef}
|
|
1202
1339
|
branches={branches}
|
|
1203
1340
|
branchResults={branchResults}
|
|
1204
1341
|
/>
|
|
1205
1342
|
);
|
|
1206
|
-
} else if (route.pathname === '/
|
|
1207
|
-
page = <
|
|
1343
|
+
} else if (route.pathname === '/namespaces') {
|
|
1344
|
+
page = <NamespacesPage />;
|
|
1345
|
+
} else if (route.pathname === '/namespace') {
|
|
1346
|
+
page = (
|
|
1347
|
+
<NamespacePage
|
|
1348
|
+
key={activeNamespace}
|
|
1349
|
+
namespace={activeNamespace}
|
|
1350
|
+
nodes={nodes}
|
|
1351
|
+
templates={templates}
|
|
1352
|
+
kinds={kinds}
|
|
1353
|
+
onNavigate={handleNode}
|
|
1354
|
+
viewingRef={viewingRef}
|
|
1355
|
+
/>
|
|
1356
|
+
);
|
|
1208
1357
|
} else if (route.pathname === '/node') {
|
|
1209
1358
|
page = (
|
|
1210
1359
|
<NodePage
|
|
@@ -1272,9 +1421,11 @@ function App() {
|
|
|
1272
1421
|
{showTree && !loading && !error && (
|
|
1273
1422
|
<NavTree
|
|
1274
1423
|
navTree={navTree}
|
|
1424
|
+
kindSections={kindSections}
|
|
1275
1425
|
templates={templates}
|
|
1276
1426
|
activeNodeId={activeNodeId || retainedNode.current}
|
|
1277
1427
|
onNode={handleNode}
|
|
1428
|
+
onNamespace={handleNamespace}
|
|
1278
1429
|
overlayIndicatorIds={overlayIndicatorIds}
|
|
1279
1430
|
/>
|
|
1280
1431
|
)}
|
|
@@ -1286,7 +1437,7 @@ function App() {
|
|
|
1286
1437
|
>
|
|
1287
1438
|
{showTree && (
|
|
1288
1439
|
<button type="button" className="mobile-back" onClick={() => history.back()}>
|
|
1289
|
-
<span aria-hidden="true">←</span> Back to
|
|
1440
|
+
<span aria-hidden="true">←</span> Back to namespaces
|
|
1290
1441
|
</button>
|
|
1291
1442
|
)}
|
|
1292
1443
|
{page}
|
package/web/graph-utils.js
CHANGED
|
@@ -4,15 +4,49 @@ function getDisplayName(nodeId) {
|
|
|
4
4
|
return nodeId.split('.').pop();
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const KIND_PALETTE = ['#2f6fb0', '#b0562f', '#4a8a3c', '#8a3c7a', '#b08a2f', '#2f8a8a', '#7a3c3c', '#5a5ab0'];
|
|
8
|
+
|
|
9
|
+
// Stable colour per kind id. The default kind has a fixed slot; others hash into the rest.
|
|
10
|
+
function kindColour(kind) {
|
|
11
|
+
const id = kind ?? 'component';
|
|
12
|
+
if (id === 'component') return KIND_PALETTE[0];
|
|
13
|
+
let hash = 0;
|
|
14
|
+
for (const ch of id) hash = (hash * 31 + ch.charCodeAt(0)) >>> 0;
|
|
15
|
+
return KIND_PALETTE[1 + (hash % (KIND_PALETTE.length - 1))];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Distinct kind ids present in a node list, sorted.
|
|
19
|
+
function collectKinds(nodes) {
|
|
20
|
+
return [...new Set(nodes.map(n => n.kind ?? 'component'))].sort((a, b) => a.localeCompare(b));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Keep only nodes of one kind (and edges between them). null/'all' keeps everything.
|
|
24
|
+
function filterByKind(nodes, edges, kind) {
|
|
25
|
+
if (!kind || kind === 'all') return { nodes, edges };
|
|
26
|
+
const kept = nodes.filter(n => (n.kind ?? 'component') === kind);
|
|
27
|
+
const ids = new Set(kept.map(n => n.id));
|
|
28
|
+
return { nodes: kept, edges: edges.filter(e => ids.has(e.from) && ids.has(e.to)) };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Kind filter in effect: an explicit choice wins; otherwise the default kind,
|
|
32
|
+
// or 'all' when the graph has no namespaces of the default kind.
|
|
33
|
+
function resolveKindFilter(requested, nodes) {
|
|
34
|
+
if (requested) return requested;
|
|
35
|
+
return collectKinds(nodes).includes('component') ? 'component' : 'all';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function buildNamespaceMap(nodes, edges) {
|
|
39
|
+
const counts = new Map();
|
|
40
|
+
const kinds = new Map();
|
|
9
41
|
for (const node of nodes) {
|
|
10
|
-
|
|
42
|
+
counts.set(node.namespace, (counts.get(node.namespace) ?? 0) + 1);
|
|
43
|
+
kinds.set(node.namespace, node.kind ?? 'component');
|
|
11
44
|
}
|
|
12
45
|
|
|
13
|
-
const componentNodes = [...
|
|
14
|
-
id:
|
|
15
|
-
|
|
46
|
+
const componentNodes = [...counts.entries()].map(([namespace, count]) => ({
|
|
47
|
+
id: namespace,
|
|
48
|
+
namespace,
|
|
49
|
+
kind: kinds.get(namespace),
|
|
16
50
|
count,
|
|
17
51
|
}));
|
|
18
52
|
|
|
@@ -22,9 +56,9 @@ function buildComponentMap(nodes, edges) {
|
|
|
22
56
|
const fromNode = nodeById.get(edge.from);
|
|
23
57
|
const toNode = nodeById.get(edge.to);
|
|
24
58
|
if (!fromNode || !toNode) continue;
|
|
25
|
-
if (fromNode.
|
|
26
|
-
const key = `${fromNode.
|
|
27
|
-
if (!compEdgeMap.has(key)) compEdgeMap.set(key, { from: fromNode.
|
|
59
|
+
if (fromNode.namespace === toNode.namespace) continue;
|
|
60
|
+
const key = `${fromNode.namespace}__${toNode.namespace}`;
|
|
61
|
+
if (!compEdgeMap.has(key)) compEdgeMap.set(key, { from: fromNode.namespace, to: toNode.namespace, types: new Set() });
|
|
28
62
|
compEdgeMap.get(key).types.add(edge.type);
|
|
29
63
|
}
|
|
30
64
|
|
|
@@ -112,8 +146,8 @@ function filterOwnerScope(nodes, edges, parentId) {
|
|
|
112
146
|
}
|
|
113
147
|
|
|
114
148
|
if (typeof module !== 'undefined' && module.exports) {
|
|
115
|
-
module.exports = {
|
|
149
|
+
module.exports = { buildNamespaceMap, kindColour, collectKinds, filterByKind, resolveKindFilter, applyEdgeTypeFilter, collectEdgeTypes, getDisplayName, computeConnectedComponents, filterThreadScope, filterOwnerScope };
|
|
116
150
|
}
|
|
117
151
|
if (typeof window !== 'undefined') {
|
|
118
|
-
window.CorumGraphUtils = {
|
|
152
|
+
window.CorumGraphUtils = { buildNamespaceMap, kindColour, collectKinds, filterByKind, resolveKindFilter, applyEdgeTypeFilter, collectEdgeTypes, getDisplayName, computeConnectedComponents, filterThreadScope, filterOwnerScope };
|
|
119
153
|
}
|
package/web/graph-utils.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// run with: node web/graph-utils.test.js
|
|
2
2
|
const graphUtils = require('./graph-utils.js');
|
|
3
|
-
const {
|
|
3
|
+
const { buildNamespaceMap, applyEdgeTypeFilter, collectEdgeTypes, getDisplayName } = graphUtils;
|
|
4
4
|
|
|
5
5
|
(async () => {
|
|
6
6
|
let passed = 0, failed = 0;
|
|
@@ -10,10 +10,10 @@ const { buildComponentMap, applyEdgeTypeFilter, collectEdgeTypes, getDisplayName
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const nodes = [
|
|
13
|
-
{ id: 'orders.DomainModel.order', template: 'DomainModel',
|
|
14
|
-
{ id: 'orders.RestAPI.ordersApi', template: 'RestAPI',
|
|
15
|
-
{ id: 'payments.DomainModel.payment', template: 'DomainModel',
|
|
16
|
-
{ id: 'payments.RestAPI.paymentsApi', template: 'RestAPI',
|
|
13
|
+
{ id: 'orders.DomainModel.order', template: 'DomainModel', namespace: 'orders', state: 'agreed', stability: 'stable' },
|
|
14
|
+
{ id: 'orders.RestAPI.ordersApi', template: 'RestAPI', namespace: 'orders', state: 'agreed', stability: 'stable' },
|
|
15
|
+
{ id: 'payments.DomainModel.payment', template: 'DomainModel', namespace: 'payments', state: 'proposed', stability: 'unstable' },
|
|
16
|
+
{ id: 'payments.RestAPI.paymentsApi', template: 'RestAPI', namespace: 'payments', state: 'proposed', stability: 'unstable' },
|
|
17
17
|
];
|
|
18
18
|
|
|
19
19
|
const edges = [
|
|
@@ -26,16 +26,16 @@ const { buildComponentMap, applyEdgeTypeFilter, collectEdgeTypes, getDisplayName
|
|
|
26
26
|
assert(getDisplayName('orders.DomainModel.order') === 'order', 'getDisplayName returns last segment');
|
|
27
27
|
assert(getDisplayName('payments.RestAPI.paymentsApi') === 'paymentsApi', 'getDisplayName handles nested id');
|
|
28
28
|
|
|
29
|
-
const cm =
|
|
30
|
-
assert(cm.nodes.length === 2, '
|
|
31
|
-
assert(cm.nodes.every(n => typeof n.count === 'number' && n.count > 0), '
|
|
29
|
+
const cm = buildNamespaceMap(nodes, edges);
|
|
30
|
+
assert(cm.nodes.length === 2, 'buildNamespaceMap: one node per component');
|
|
31
|
+
assert(cm.nodes.every(n => typeof n.count === 'number' && n.count > 0), 'buildNamespaceMap: nodes have count');
|
|
32
32
|
const cmOrders = cm.nodes.find(n => n.id === 'orders');
|
|
33
|
-
assert(cmOrders?.count === 2, '
|
|
34
|
-
assert(cm.edges.length === 1, '
|
|
35
|
-
assert(cm.edges[0].from === 'orders' && cm.edges[0].to === 'payments', '
|
|
36
|
-
assert(cm.edges[0].types.includes('calls'), '
|
|
37
|
-
const sameCmEdges =
|
|
38
|
-
assert(sameCmEdges.edges.length === 0, '
|
|
33
|
+
assert(cmOrders?.count === 2, 'buildNamespaceMap: orders has 2 nodes');
|
|
34
|
+
assert(cm.edges.length === 1, 'buildNamespaceMap: one cross-component edge');
|
|
35
|
+
assert(cm.edges[0].from === 'orders' && cm.edges[0].to === 'payments', 'buildNamespaceMap: edge direction correct');
|
|
36
|
+
assert(cm.edges[0].types.includes('calls'), 'buildNamespaceMap: edge types collected');
|
|
37
|
+
const sameCmEdges = buildNamespaceMap(nodes, [{ id: 'x', from: 'orders.DomainModel.order', to: 'orders.RestAPI.ordersApi', type: 'reads' }]);
|
|
38
|
+
assert(sameCmEdges.edges.length === 0, 'buildNamespaceMap: intra-component edges excluded');
|
|
39
39
|
|
|
40
40
|
const filtered = applyEdgeTypeFilter(edges, new Set(['reads']));
|
|
41
41
|
assert(filtered.length === 2, 'applyEdgeTypeFilter: keeps only matching type');
|
|
@@ -55,7 +55,7 @@ const { buildComponentMap, applyEdgeTypeFilter, collectEdgeTypes, getDisplayName
|
|
|
55
55
|
assert(ccAll.length === 1, 'computeConnectedComponents: fully linked graph is one component');
|
|
56
56
|
const ccSplit = computeConnectedComponents(nodes, [edges[0], edges[2]]);
|
|
57
57
|
assert(ccSplit.length === 2, 'computeConnectedComponents: removing bridge edge splits components');
|
|
58
|
-
const ccIsolated = computeConnectedComponents([...nodes, { id: 'lone.Node.x', template: 'X',
|
|
58
|
+
const ccIsolated = computeConnectedComponents([...nodes, { id: 'lone.Node.x', template: 'X', namespace: 'lone' }], edges);
|
|
59
59
|
assert(ccIsolated.some(c => c.length === 1 && c[0] === 'lone.Node.x'), 'computeConnectedComponents: isolated node is own component');
|
|
60
60
|
const ccMerged = computeConnectedComponents(nodes, [edges[0], edges[2]], [{ from: 'orders.DomainModel.order', to: 'payments.DomainModel.payment' }]);
|
|
61
61
|
assert(ccMerged.length === 1, 'computeConnectedComponents: extraLinks merge components');
|
|
@@ -87,6 +87,33 @@ const { buildComponentMap, applyEdgeTypeFilter, collectEdgeTypes, getDisplayName
|
|
|
87
87
|
assert(aggScope.has('a.T.reader'), 'filterOwnerScope: keeps neighbours of the owner node');
|
|
88
88
|
assert(!aggScope.has('a.T.unrelated'), 'filterOwnerScope: drops unrelated nodes');
|
|
89
89
|
|
|
90
|
+
// Kind filtering and colouring
|
|
91
|
+
const { filterByKind, collectKinds, kindColour } = graphUtils;
|
|
92
|
+
const kNodes = [
|
|
93
|
+
{ id: 'orders.A.a', namespace: 'orders', kind: 'component' },
|
|
94
|
+
{ id: 'orders.A.b', namespace: 'orders' },
|
|
95
|
+
{ id: 'signup.J.j', namespace: 'signup', kind: 'journey' },
|
|
96
|
+
];
|
|
97
|
+
const kEdges = [
|
|
98
|
+
{ id: 'k1', from: 'orders.A.a', to: 'orders.A.b', type: 'reads' },
|
|
99
|
+
{ id: 'k2', from: 'signup.J.j', to: 'orders.A.a', type: 'calls' },
|
|
100
|
+
];
|
|
101
|
+
assert(JSON.stringify(collectKinds(kNodes)) === JSON.stringify(['component', 'journey']), 'collectKinds: distinct sorted kinds, default component');
|
|
102
|
+
const fc = filterByKind(kNodes, kEdges, 'component');
|
|
103
|
+
assert(fc.nodes.length === 2 && fc.edges.length === 1, 'filterByKind: component keeps only component nodes and internal edges');
|
|
104
|
+
const fj = filterByKind(kNodes, kEdges, 'journey');
|
|
105
|
+
assert(fj.nodes.length === 1 && fj.edges.length === 0, 'filterByKind: journey keeps journey namespace only');
|
|
106
|
+
assert(filterByKind(kNodes, kEdges, 'all').nodes.length === 3, 'filterByKind: all keeps everything');
|
|
107
|
+
assert(filterByKind(kNodes, kEdges, 'mystery').nodes.length === 0, 'filterByKind: unrecognised kind matches exactly');
|
|
108
|
+
assert(kindColour('journey') === kindColour('journey') && kindColour('journey') !== kindColour('component'), 'kindColour: stable and distinct from component');
|
|
109
|
+
const { resolveKindFilter } = graphUtils;
|
|
110
|
+
assert(resolveKindFilter(null, kNodes) === 'component', 'resolveKindFilter: defaults to component when present');
|
|
111
|
+
assert(resolveKindFilter(null, [{ id: 's.J.j', namespace: 's', kind: 'journey' }]) === 'all', 'resolveKindFilter: falls back to all when no component namespace');
|
|
112
|
+
assert(resolveKindFilter(null, [{ id: 's.J.j', namespace: 's', kind: 'mystery' }]) === 'all', 'resolveKindFilter: falls back to all for unknown-only kinds');
|
|
113
|
+
assert(resolveKindFilter('journey', kNodes) === 'journey', 'resolveKindFilter: explicit choice wins');
|
|
114
|
+
const km = buildNamespaceMap(kNodes, kEdges);
|
|
115
|
+
assert(km.nodes.find(n => n.id === 'signup')?.kind === 'journey', 'buildNamespaceMap: carries kind');
|
|
116
|
+
|
|
90
117
|
console.log(`\n${passed} passed, ${failed} failed`);
|
|
91
118
|
if (failed > 0) process.exit(1);
|
|
92
119
|
})();
|