@atolis-hq/corum 0.1.49 → 0.1.51

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/corum",
3
- "version": "0.1.49",
3
+ "version": "0.1.51",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,6 +42,10 @@ function applyEdgeTypeFilter(edges, visibleTypes) {
42
42
  return edges.filter(e => visibleTypes.has(e.type));
43
43
  }
44
44
 
45
+ function collectEdgeTypes(...edgeLists) {
46
+ return [...new Set(edgeLists.flatMap(edges => edges.map(edge => edge.type)))].sort();
47
+ }
48
+
45
49
  // Weakly connected components. Edges use {from, to}; extraLinks are additional
46
50
  // affinity pairs (e.g. group co-membership) that merge components without
47
51
  // being real edges. Returns arrays of node ids.
@@ -108,8 +112,8 @@ function filterOwnerScope(nodes, edges, parentId) {
108
112
  }
109
113
 
110
114
  if (typeof module !== 'undefined' && module.exports) {
111
- module.exports = { buildComponentMap, applyEdgeTypeFilter, getDisplayName, computeConnectedComponents, filterThreadScope, filterOwnerScope };
115
+ module.exports = { buildComponentMap, applyEdgeTypeFilter, collectEdgeTypes, getDisplayName, computeConnectedComponents, filterThreadScope, filterOwnerScope };
112
116
  }
113
117
  if (typeof window !== 'undefined') {
114
- window.CorumGraphUtils = { buildComponentMap, applyEdgeTypeFilter, getDisplayName, computeConnectedComponents, filterThreadScope, filterOwnerScope };
118
+ window.CorumGraphUtils = { buildComponentMap, applyEdgeTypeFilter, collectEdgeTypes, getDisplayName, computeConnectedComponents, filterThreadScope, filterOwnerScope };
115
119
  }
@@ -1,6 +1,6 @@
1
1
  // run with: node web/graph-utils.test.js
2
2
  const graphUtils = require('./graph-utils.js');
3
- const { buildComponentMap, applyEdgeTypeFilter, getDisplayName } = graphUtils;
3
+ const { buildComponentMap, applyEdgeTypeFilter, collectEdgeTypes, getDisplayName } = graphUtils;
4
4
 
5
5
  (async () => {
6
6
  let passed = 0, failed = 0;
@@ -43,6 +43,12 @@ const { buildComponentMap, applyEdgeTypeFilter, getDisplayName } = graphUtils;
43
43
  const none = applyEdgeTypeFilter(edges, new Set([]));
44
44
  assert(none.length === 0, 'applyEdgeTypeFilter: empty set returns nothing');
45
45
 
46
+ const focusOnlyEdges = [{ id: 'e4', from: 'orders.DomainModel.order', to: 'payments.DomainModel.payment', type: 'precedes' }];
47
+ assert(
48
+ JSON.stringify(collectEdgeTypes(edges, focusOnlyEdges)) === JSON.stringify(['calls', 'precedes', 'reads']),
49
+ 'collectEdgeTypes: includes types that exist only in focus data',
50
+ );
51
+
46
52
  const { computeConnectedComponents, filterThreadScope, filterOwnerScope } = graphUtils;
47
53
 
48
54
  const ccAll = computeConnectedComponents(nodes, edges);
package/web/graph.jsx CHANGED
@@ -3,7 +3,7 @@
3
3
  const { useState, useEffect, useMemo, useCallback, useRef } = React;
4
4
  const { navigate, Icon, TemplateBadge, StateTag, StabilityTag } = window.CorumPrimitives;
5
5
  const { buildRoute, parseRoute } = window.CorumRouter;
6
- const { buildComponentMap, applyEdgeTypeFilter, getDisplayName, computeConnectedComponents, filterThreadScope, filterOwnerScope } = window.CorumGraphUtils;
6
+ const { buildComponentMap, applyEdgeTypeFilter, collectEdgeTypes, getDisplayName, computeConnectedComponents, filterThreadScope, filterOwnerScope } = window.CorumGraphUtils;
7
7
 
8
8
  const RF = window.ReactFlow;
9
9
  const ReactFlowCanvas = RF.ReactFlow || RF.default;
@@ -31,7 +31,7 @@ const EDGE_PILL_STYLES = {
31
31
  'derived-from': { background: '#f3f4f6', color: '#6b7280' },
32
32
  };
33
33
 
34
- const ALL_EDGE_TYPES = ['triggers', 'produces', 'reads', 'uses-type', 'calls', 'implements', 'maps-to', 'derived-from'];
34
+ const LEGACY_EDGE_TYPES = ['triggers', 'produces', 'reads', 'uses-type', 'calls', 'implements', 'maps-to', 'derived-from'];
35
35
  const DEPTH_STEPS = [1, 2, 3, 4, 5, Infinity];
36
36
 
37
37
  const NODE_W = 210;
@@ -39,16 +39,21 @@ const NODE_H = 100;
39
39
  const COMP_W = 180;
40
40
  const COMP_H = 72;
41
41
 
42
- function loadVisibleEdgeTypes() {
42
+ function loadHiddenEdgeTypes() {
43
43
  try {
44
44
  const stored = localStorage.getItem('corum:graphEdgeTypes');
45
- if (stored) return new Set(JSON.parse(stored));
45
+ if (!stored) return new Set();
46
+ const parsed = JSON.parse(stored);
47
+ if (Array.isArray(parsed)) {
48
+ return new Set(LEGACY_EDGE_TYPES.filter(type => !parsed.includes(type)));
49
+ }
50
+ if (Array.isArray(parsed?.hiddenTypes)) return new Set(parsed.hiddenTypes);
46
51
  } catch {}
47
- return new Set(ALL_EDGE_TYPES);
52
+ return new Set();
48
53
  }
49
54
 
50
- function saveVisibleEdgeTypes(types) {
51
- try { localStorage.setItem('corum:graphEdgeTypes', JSON.stringify([...types])); } catch {}
55
+ function saveHiddenEdgeTypes(types) {
56
+ try { localStorage.setItem('corum:graphEdgeTypes', JSON.stringify({ version: 2, hiddenTypes: [...types].sort() })); } catch {}
52
57
  }
53
58
 
54
59
  function loadLayoutMode() {
@@ -505,7 +510,7 @@ function describeScope(scope, scopeOptions) {
505
510
  return parts.join(' · ');
506
511
  }
507
512
 
508
- function GraphToolbar({ visibleEdgeTypes, onToggleEdgeType, showMinimap, onToggleMinimap, onResetLayout, level, depth, onDepth, allNodes, focalNodeId, onFocalNode, layoutMode, onLayoutMode, scope, onScope, scopeOptions, scopeInfo }) {
513
+ function GraphToolbar({ edgeTypes, visibleEdgeTypes, onToggleEdgeType, showMinimap, onToggleMinimap, onResetLayout, level, depth, onDepth, allNodes, focalNodeId, onFocalNode, layoutMode, onLayoutMode, scope, onScope, scopeOptions, scopeInfo }) {
509
514
  const [searchQuery, setSearchQuery] = useState('');
510
515
  const [searchOpen, setSearchOpen] = useState(false);
511
516
  const [scopeOpen, setScopeOpen] = useState(false);
@@ -540,9 +545,9 @@ function GraphToolbar({ visibleEdgeTypes, onToggleEdgeType, showMinimap, onToggl
540
545
 
541
546
  return (
542
547
  <div className="graph-toolbar">
543
- {ALL_EDGE_TYPES.map(type => {
548
+ {edgeTypes.map(type => {
544
549
  const active = visibleEdgeTypes.has(type);
545
- const pill = EDGE_PILL_STYLES[type] || {};
550
+ const pill = EDGE_PILL_STYLES[type] || { background: '#f3f4f6', color: '#6b7280' };
546
551
  return (
547
552
  <span
548
553
  key={type}
@@ -645,7 +650,7 @@ function GraphToolbar({ visibleEdgeTypes, onToggleEdgeType, showMinimap, onToggl
645
650
  function GraphView({ route, viewingRef, templates }) {
646
651
  const [graphData, setGraphData] = useState(null);
647
652
  const [error, setError] = useState(null);
648
- const [visibleEdgeTypes, setVisibleEdgeTypes] = useState(loadVisibleEdgeTypes);
653
+ const [hiddenEdgeTypes, setHiddenEdgeTypes] = useState(loadHiddenEdgeTypes);
649
654
  const [showMinimap, setShowMinimap] = useState(false);
650
655
  const [depth, setDepth] = useState(2);
651
656
  const [layoutKey, setLayoutKey] = useState(0);
@@ -712,6 +717,11 @@ function GraphView({ route, viewingRef, templates }) {
712
717
  }, [focalNodeId, depth, viewingRef]);
713
718
 
714
719
  const templateMap = useMemo(() => new Map((templates ?? []).map(t => [t.name, t])), [templates]);
720
+ const availableEdgeTypes = useMemo(() => collectEdgeTypes(graphData?.edges ?? [], focusData?.edges ?? []), [graphData, focusData]);
721
+ const visibleEdgeTypes = useMemo(
722
+ () => new Set(availableEdgeTypes.filter(type => !hiddenEdgeTypes.has(type))),
723
+ [availableEdgeTypes, hiddenEdgeTypes],
724
+ );
715
725
 
716
726
  const templateColour = useCallback(templateName => {
717
727
  return templateMap.get(templateName)?.ui?.colour ?? 'var(--ink-4)';
@@ -776,7 +786,7 @@ function GraphView({ route, viewingRef, templates }) {
776
786
  parentCounts.set(n.parentId, (parentCounts.get(n.parentId) ?? 0) + 1);
777
787
  }
778
788
  const scopeOptions = {
779
- edgeTypes: ALL_EDGE_TYPES.filter(t => visibleEdgeTypes.has(t) && typedEdges.some(e => e.type === t)),
789
+ edgeTypes: availableEdgeTypes.filter(t => visibleEdgeTypes.has(t) && typedEdges.some(e => e.type === t)),
780
790
  templates: [...new Set(allVisibleNodes.map(n => n.template))].sort()
781
791
  .map(name => ({ name, label: templateMap.get(name)?.ui?.displayName ?? name })),
782
792
  owners: [...parentCounts.entries()].filter(([, c]) => c >= 2).map(([pid]) => pid).sort()
@@ -812,7 +822,7 @@ function GraphView({ route, viewingRef, templates }) {
812
822
  return isCross ? { ...e, style: { ...e.style, opacity: 0.45 }, labelStyle: { ...e.labelStyle, opacity: 0.45 } } : e;
813
823
  });
814
824
  return { rfN, rfE, scopeOptions, scopeInfo };
815
- }, [graphData, selectedComponent, visibleEdgeTypes, templateMap, layoutKey, navToFocus, scope]);
825
+ }, [graphData, selectedComponent, availableEdgeTypes, visibleEdgeTypes, templateMap, layoutKey, navToFocus, scope]);
816
826
 
817
827
  useEffect(() => {
818
828
  if (level !== 'interior' || !level2) return;
@@ -903,10 +913,10 @@ function GraphView({ route, viewingRef, templates }) {
903
913
  }, [setRfNodes]);
904
914
 
905
915
  function handleToggleEdgeType(type) {
906
- setVisibleEdgeTypes(prev => {
916
+ setHiddenEdgeTypes(prev => {
907
917
  const next = new Set(prev);
908
918
  next.has(type) ? next.delete(type) : next.add(type);
909
- saveVisibleEdgeTypes(next);
919
+ saveHiddenEdgeTypes(next);
910
920
  return next;
911
921
  });
912
922
  }
@@ -924,6 +934,7 @@ function GraphView({ route, viewingRef, templates }) {
924
934
  onNavigateToComponent={navToComponent}
925
935
  />
926
936
  <GraphToolbar
937
+ edgeTypes={availableEdgeTypes}
927
938
  visibleEdgeTypes={visibleEdgeTypes}
928
939
  onToggleEdgeType={handleToggleEdgeType}
929
940
  showMinimap={showMinimap}