@atolis-hq/corum 0.1.61 → 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/bin/corum.js +2 -1
- package/dist/src/graph/index.js +39 -8
- package/dist/src/linter/index.js +31 -2
- package/dist/src/loader/cluster-loader.js +7 -3
- 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 +3 -2
- package/dist/src/reconcile/index.js +1 -1
- package/dist/src/source/file-source.js +1 -3
- package/dist/src/source/git-source.js +2 -1
- package/dist/src/source/graph-paths.js +6 -0
- package/dist/src/web/server.js +25 -5
- package/dist/src/writer/graph-writer.js +9 -2
- 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/dist/src/web/server.js
CHANGED
|
@@ -6,7 +6,7 @@ import { existsSync, readFileSync, readdirSync, watch } from 'node:fs';
|
|
|
6
6
|
import { readdir } from 'node:fs/promises';
|
|
7
7
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
8
8
|
import { parse as parseYaml } from 'yaml';
|
|
9
|
-
import { computeClusterOverlay, getClusterView, getGraphSummary, expandExternalNodes, getLineage, getStructuralNodeTemplates, isVisibleEdgeType, listNodes, searchNodes, } from '../graph/index.js';
|
|
9
|
+
import { computeClusterOverlay, getClusterView, getGraphSummary, expandExternalNodes, getKindLabel, getKindRegistry, getLineage, getNamespaces, getStructuralNodeTemplates, isVisibleEdgeType, listNodes, searchNodes, } from '../graph/index.js';
|
|
10
10
|
import { loadGraph, loadMultiGraph } from '../loader/index.js';
|
|
11
11
|
import { CORE_EDGE_TYPES } from '../loader/constants.js';
|
|
12
12
|
import { getOwnedSections } from '../loader/pack-loader.js';
|
|
@@ -170,6 +170,8 @@ export function replaceGraph(target, source) {
|
|
|
170
170
|
target.templates = source.templates;
|
|
171
171
|
target.diagnostics = source.diagnostics;
|
|
172
172
|
target.edgeTypes = source.edgeTypes;
|
|
173
|
+
target.namespaceDeclarations = source.namespaceDeclarations;
|
|
174
|
+
target.kinds = source.kinds;
|
|
173
175
|
target.sourceContent = source.sourceContent;
|
|
174
176
|
}
|
|
175
177
|
function isFileWatcherEnabled(options) {
|
|
@@ -303,7 +305,7 @@ export function createApp(graph, reloadEvents = createReloadEvents(), source, mu
|
|
|
303
305
|
res.json(templates);
|
|
304
306
|
});
|
|
305
307
|
app.get('/api/nodes', async (req, res) => {
|
|
306
|
-
const {
|
|
308
|
+
const { namespace, kind, state, stability } = req.query;
|
|
307
309
|
const includeCore = req.query.includeCore === 'true';
|
|
308
310
|
const singleTemplate = typeof req.query.template === 'string' && req.query.template
|
|
309
311
|
? [req.query.template]
|
|
@@ -315,7 +317,8 @@ export function createApp(graph, reloadEvents = createReloadEvents(), source, mu
|
|
|
315
317
|
: undefined;
|
|
316
318
|
const filter = {
|
|
317
319
|
templates: multiTemplates ?? singleTemplate,
|
|
318
|
-
|
|
320
|
+
namespace: typeof namespace === 'string' ? namespace : undefined,
|
|
321
|
+
kind: typeof kind === 'string' ? kind : undefined,
|
|
319
322
|
state: typeof state === 'string' ? state : undefined,
|
|
320
323
|
stability: typeof stability === 'string' ? stability : undefined,
|
|
321
324
|
};
|
|
@@ -323,6 +326,7 @@ export function createApp(graph, reloadEvents = createReloadEvents(), source, mu
|
|
|
323
326
|
if (typeof req.query.ref === 'string' && multiCache) {
|
|
324
327
|
targetGraph = await getGraphForRef(req.query.ref, multiCache, graph);
|
|
325
328
|
}
|
|
329
|
+
const namespaces = getNamespaces(targetGraph);
|
|
326
330
|
const nodes = listNodes(targetGraph, filter)
|
|
327
331
|
.filter(node => includeCore || !targetGraph.templates.get(node.template)?.info?.core)
|
|
328
332
|
.map(node => {
|
|
@@ -330,7 +334,8 @@ export function createApp(graph, reloadEvents = createReloadEvents(), source, mu
|
|
|
330
334
|
return {
|
|
331
335
|
id: ownership.id,
|
|
332
336
|
template: ownership.template,
|
|
333
|
-
|
|
337
|
+
namespace: ownership.namespace,
|
|
338
|
+
kind: namespaces.get(ownership.namespace)?.kind ?? 'component',
|
|
334
339
|
state: ownership.state,
|
|
335
340
|
stability: ownership.stability,
|
|
336
341
|
parentId: ownership.parentId,
|
|
@@ -358,6 +363,7 @@ export function createApp(graph, reloadEvents = createReloadEvents(), source, mu
|
|
|
358
363
|
: filterExcludeTemplates?.length
|
|
359
364
|
? new Set(filterExcludeTemplates)
|
|
360
365
|
: getStructuralNodeTemplates(targetGraph);
|
|
366
|
+
const namespaces = getNamespaces(targetGraph);
|
|
361
367
|
const nodes = [];
|
|
362
368
|
for (const node of targetGraph.nodesById.values()) {
|
|
363
369
|
if (filterTemplates?.length && !filterTemplates.includes(node.template))
|
|
@@ -368,7 +374,8 @@ export function createApp(graph, reloadEvents = createReloadEvents(), source, mu
|
|
|
368
374
|
nodes.push({
|
|
369
375
|
id: node.id,
|
|
370
376
|
template: node.template,
|
|
371
|
-
|
|
377
|
+
namespace: node.namespace,
|
|
378
|
+
kind: namespaces.get(node.namespace)?.kind ?? 'component',
|
|
372
379
|
state: node.state,
|
|
373
380
|
stability: node.stability,
|
|
374
381
|
parentId: ownership?.parentId ?? null,
|
|
@@ -396,6 +403,19 @@ export function createApp(graph, reloadEvents = createReloadEvents(), source, mu
|
|
|
396
403
|
res.status(500).json({ error: String(err) });
|
|
397
404
|
}
|
|
398
405
|
});
|
|
406
|
+
app.get('/api/kinds', async (req, res) => {
|
|
407
|
+
let targetGraph = graph;
|
|
408
|
+
if (typeof req.query.ref === 'string' && multiCache) {
|
|
409
|
+
targetGraph = await getGraphForRef(req.query.ref, multiCache, graph);
|
|
410
|
+
}
|
|
411
|
+
const namespaces = getNamespaces(targetGraph);
|
|
412
|
+
res.json({
|
|
413
|
+
kinds: getKindRegistry(targetGraph),
|
|
414
|
+
namespaces: [...namespaces]
|
|
415
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
416
|
+
.map(([name, ns]) => ({ namespace: name, kind: ns.kind, label: getKindLabel(targetGraph, ns.kind) })),
|
|
417
|
+
});
|
|
418
|
+
});
|
|
399
419
|
app.get('/api/stats', async (req, res) => {
|
|
400
420
|
let targetGraph = graph;
|
|
401
421
|
if (typeof req.query.ref === 'string' && multiCache) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isNamespaceDeclaration } from '../loader/namespace-loader.js';
|
|
2
|
+
import { NODE_ROOT_DIR } from '../source/graph-paths.js';
|
|
1
3
|
import fs from 'node:fs';
|
|
2
4
|
import path from 'node:path';
|
|
3
5
|
import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
|
|
@@ -10,6 +12,11 @@ const YAML_STRINGIFY_OPTIONS = { singleQuote: true };
|
|
|
10
12
|
export function serializeGraph(graph, options = {}) {
|
|
11
13
|
const map = new Map();
|
|
12
14
|
map.set('graph.yaml', buildGraphYaml(graph, options));
|
|
15
|
+
// Preserve declarations verbatim; never synthesize undeclared namespaces.
|
|
16
|
+
for (const [key, content] of graph.sourceContent ?? []) {
|
|
17
|
+
if (isNamespaceDeclaration(key))
|
|
18
|
+
map.set(key, content);
|
|
19
|
+
}
|
|
13
20
|
for (const root of getRootNodes(graph)) {
|
|
14
21
|
map.set(clusterPath(root), stringifyGraphYaml(toClusterDocument(graph, root)));
|
|
15
22
|
}
|
|
@@ -26,7 +33,7 @@ function clusterPath(node) {
|
|
|
26
33
|
if (parts.length < 3)
|
|
27
34
|
throw new Error(`clusterPath: expected at least 3-segment root node ID, got: ${node.id}`);
|
|
28
35
|
const [component, template, ...rest] = parts;
|
|
29
|
-
return
|
|
36
|
+
return `${NODE_ROOT_DIR}/${component}/${template}s/${rest.join('/')}.yaml`;
|
|
30
37
|
}
|
|
31
38
|
export async function saveGraph(graph, options) {
|
|
32
39
|
const { sourceGraphPath, outputGraphPath, replace = true } = options;
|
|
@@ -63,7 +70,7 @@ function normalizeContentKey(value) {
|
|
|
63
70
|
function toClusterDocument(graph, root) {
|
|
64
71
|
const sourceDoc = loadSourceClusterDocument(graph, root);
|
|
65
72
|
const metadata = {
|
|
66
|
-
component: root.
|
|
73
|
+
component: root.namespace,
|
|
67
74
|
state: root.state,
|
|
68
75
|
stability: root.stability,
|
|
69
76
|
lastModifiedAt: root.lastModifiedAt,
|
package/package.json
CHANGED
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
|
}
|