@principal-ai/subsystems-react 0.17.0 → 0.18.0
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/index.d.ts +7 -44
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -32
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +9 -199
- package/src/components/ConfigurationSelector.tsx +0 -133
- package/src/components/GraphRenderer.tsx +0 -3195
- package/src/components/MultiCanvasRenderer.tsx +0 -295
- package/src/components/NodeTooltip.tsx +0 -279
- package/src/components/PendingChanges.test.tsx +0 -375
- package/src/components/SelectionSidebar.tsx +0 -352
- package/src/components/SequenceDiagramRenderer.tsx +0 -1156
- package/src/components/WorkflowSequenceDiagram.tsx +0 -270
- package/src/components/dashboard/DashboardRenderer.tsx +0 -317
- package/src/components/dashboard/MetricPanel.tsx +0 -254
- package/src/components/dashboard/MockDataProvider.ts +0 -330
- package/src/components/dashboard/components/BarChart.tsx +0 -299
- package/src/components/dashboard/components/LineChart.tsx +0 -279
- package/src/components/dashboard/components/MetricCard.tsx +0 -270
- package/src/components/dashboard/components/SourceLink.tsx +0 -63
- package/src/components/dashboard/components/TimeRangeSelector.tsx +0 -280
- package/src/components/dashboard/components/index.ts +0 -5
- package/src/components/dashboard/index.ts +0 -47
- package/src/components/dashboard/types.ts +0 -126
- package/src/components/state-view/PipelineView.tsx +0 -347
- package/src/components/state-view/index.ts +0 -14
- package/src/components/state-view/types.ts +0 -261
- package/src/components/state-view/useStateView.ts +0 -205
- package/src/contexts/GraphEditContext.tsx +0 -27
- package/src/contexts/TooltipPortalContext.ts +0 -8
- package/src/edges/CustomEdge.tsx +0 -402
- package/src/edges/GenericEdge.tsx +0 -36
- package/src/hooks/usePathBasedEvents.ts +0 -192
- package/src/hooks/useSequenceLayout.ts +0 -543
- package/src/hooks/useUndoRedo.ts +0 -144
- package/src/nodes/CustomNode.tsx +0 -1231
- package/src/nodes/GenericNode.tsx +0 -55
- package/src/nodes/otel/OtelBoundaryNode.tsx +0 -224
- package/src/nodes/otel/OtelEventNode.tsx +0 -225
- package/src/nodes/otel/OtelResourceNode.tsx +0 -251
- package/src/nodes/otel/OtelScopeNode.tsx +0 -221
- package/src/nodes/otel/OtelSpanConventionNode.tsx +0 -295
- package/src/nodes/otel/index.ts +0 -23
- package/src/nodes/otel/shared/NodeBadges.tsx +0 -295
- package/src/nodes/otel/shared/NodeContent.tsx +0 -204
- package/src/nodes/otel/shared/index.ts +0 -8
- package/src/nodes/otel/shared/types.ts +0 -138
- package/src/nodes/otel/shared/useNodeBehavior.ts +0 -114
- package/src/stories/Audit/BoundaryNodes.stories.tsx +0 -385
- package/src/stories/Audit/CanvasEdgeTypes.stories.tsx +0 -1448
- package/src/stories/Audit/CanvasNodeTypes.stories.tsx +0 -1049
- package/src/stories/Audit/ColorPriority.stories.tsx +0 -895
- package/src/stories/Audit/DiamondBadges.stories.tsx +0 -629
- package/src/stories/Audit/NodeDimensionsTesting.stories.tsx +0 -724
- package/src/stories/Audit/NodeFieldsAudit.stories.tsx +0 -996
- package/src/stories/Audit/NodeFontSizeTesting.stories.tsx +0 -715
- package/src/stories/Audit/NodeShapes.stories.tsx +0 -1208
- package/src/stories/Audit/WideNodesTesting.stories.tsx +0 -1045
- package/src/stories/Components/DashboardRenderer.stories.tsx +0 -263
- package/src/stories/Components/GraphRenderer.stories.tsx +0 -3236
- package/src/stories/Components/MultiCanvasRenderer.stories.tsx +0 -370
- package/src/stories/Components/SequenceDiagram.stories.tsx +0 -255
- package/src/stories/Components/StateView.stories.tsx +0 -417
- package/src/stories/Components/TraceViewer.stories.tsx +0 -442
- package/src/stories/Components/WorkflowSequenceDiagram.stories.tsx +0 -802
- package/src/stories/Features/AnimationWorkshop.stories.tsx +0 -727
- package/src/stories/Features/ChangeTypeVisual.stories.tsx +0 -67
- package/src/stories/Features/EventDrivenAnimations.stories.tsx +0 -513
- package/src/stories/Features/MultiConfig.stories.tsx +0 -539
- package/src/stories/Layout/ElkEdgeRouting.stories.tsx +0 -539
- package/src/stories/Layout/GraphOrientation.stories.tsx +0 -500
- package/src/stories/Layout/MultiDirectionalConnections.stories.tsx +0 -352
- package/src/stories/Nodes/NodeDefinitionComparison.stories.tsx +0 -560
- package/src/stories/Nodes/NodeNameFallbacks.stories.tsx +0 -491
- package/src/stories/Nodes/NumericColors.stories.tsx +0 -440
- package/src/stories/OTEL/EventNameDisplay.stories.tsx +0 -694
- package/src/stories/OTEL/EventNameFallback.stories.tsx +0 -578
- package/src/stories/OTEL/OtelComponents.stories.tsx +0 -422
- package/src/stories/OTEL/OtelNodeTypesPrototype.stories.tsx +0 -806
- package/src/stories/OTEL/RawEventCards.stories.tsx +0 -57
- package/src/stories/OTEL/SpanBadges.stories.tsx +0 -840
- package/src/stories/OTEL/ValidationEventsCanvas.stories.tsx +0 -209
- package/src/stories/RealWorld/BacklogMdCanvases.stories.tsx +0 -721
- package/src/stories/RealWorld/FileCitySequence.stories.tsx +0 -516
- package/src/stories/RealWorld/RealCanvasFiles.stories.tsx +0 -336
- package/src/stories/__traces__/test-run.canvas.json +0 -241
- package/src/stories/data/activity-feed-analytics.dashboard.json +0 -300
- package/src/stories/data/file-city-images-transformed.otel.canvas.json +0 -295
- package/src/stories/data/file-city-workflows.json +0 -269
- package/src/stories/data/graph-converter-test-execution.json +0 -443
- package/src/stories/data/graph-converter-test.workflow.json +0 -105
- package/src/stories/data/graph-converter-validated-execution.json +0 -58
- package/src/utils/animationMapping.ts +0 -166
- package/src/utils/canvasBounds.ts +0 -146
- package/src/utils/graphConverter.ts +0 -148
- package/src/utils/iconResolver.tsx +0 -53
- package/src/utils/orientationUtils.ts +0 -73
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
import { useMemo, useCallback, useRef, forwardRef } from 'react';
|
|
2
|
-
import type { ExtendedCanvas, ExtendedCanvasNode, ExtendedCanvasEdge } from '@principal-ai/subsystems-core';
|
|
3
|
-
import { GraphRenderer } from './GraphRenderer';
|
|
4
|
-
import type { GraphRendererProps, GraphRendererHandle } from './GraphRenderer';
|
|
5
|
-
|
|
6
|
-
// ============================================================================
|
|
7
|
-
// Types
|
|
8
|
-
// ============================================================================
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* A canvas placement with its position in the combined coordinate space
|
|
12
|
-
*/
|
|
13
|
-
export interface CanvasPlacement {
|
|
14
|
-
/** Unique identifier for this canvas */
|
|
15
|
-
canvasId: string;
|
|
16
|
-
/** The canvas to include */
|
|
17
|
-
canvas: ExtendedCanvas;
|
|
18
|
-
/** Position offset - all nodes in this canvas will be translated by this amount */
|
|
19
|
-
position: { x: number; y: number };
|
|
20
|
-
/** Optional label for the canvas (for future visual grouping) */
|
|
21
|
-
label?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Layout configuration for multiple canvases on a single graph
|
|
26
|
-
*/
|
|
27
|
-
export interface MultiCanvasLayout {
|
|
28
|
-
/** Array of canvas placements with positions */
|
|
29
|
-
placements: CanvasPlacement[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Props for the MultiCanvasRenderer component
|
|
34
|
-
*/
|
|
35
|
-
export interface MultiCanvasRendererProps
|
|
36
|
-
extends Omit<GraphRendererProps, 'canvas' | 'editable'> {
|
|
37
|
-
/** Layout configuration containing canvas placements */
|
|
38
|
-
layout: MultiCanvasLayout;
|
|
39
|
-
/** Callback when layout changes (canvas positions updated) */
|
|
40
|
-
onLayoutChange?: (layout: MultiCanvasLayout) => void;
|
|
41
|
-
/** Whether to show group borders around each canvas (default: true) */
|
|
42
|
-
showGroups?: boolean;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// ============================================================================
|
|
46
|
-
// Canvas Merging Utilities
|
|
47
|
-
// ============================================================================
|
|
48
|
-
|
|
49
|
-
const DEFAULT_NODE_WIDTH = 200;
|
|
50
|
-
const DEFAULT_NODE_HEIGHT = 100;
|
|
51
|
-
const GROUP_PADDING = 40;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Create a prefixed node ID to avoid collisions between canvases
|
|
55
|
-
*/
|
|
56
|
-
function prefixNodeId(canvasId: string, nodeId: string): string {
|
|
57
|
-
return `${canvasId}:${nodeId}`;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Calculate the bounding box of nodes in a canvas (relative to canvas origin)
|
|
62
|
-
*/
|
|
63
|
-
function calculateCanvasBounds(canvas: ExtendedCanvas): {
|
|
64
|
-
minX: number;
|
|
65
|
-
minY: number;
|
|
66
|
-
maxX: number;
|
|
67
|
-
maxY: number;
|
|
68
|
-
} {
|
|
69
|
-
if (!canvas.nodes || canvas.nodes.length === 0) {
|
|
70
|
-
return { minX: 0, minY: 0, maxX: DEFAULT_NODE_WIDTH, maxY: DEFAULT_NODE_HEIGHT };
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
let minX = Infinity;
|
|
74
|
-
let minY = Infinity;
|
|
75
|
-
let maxX = -Infinity;
|
|
76
|
-
let maxY = -Infinity;
|
|
77
|
-
|
|
78
|
-
for (const node of canvas.nodes) {
|
|
79
|
-
const x = node.x ?? 0;
|
|
80
|
-
const y = node.y ?? 0;
|
|
81
|
-
const width = node.width ?? DEFAULT_NODE_WIDTH;
|
|
82
|
-
const height = node.height ?? DEFAULT_NODE_HEIGHT;
|
|
83
|
-
|
|
84
|
-
minX = Math.min(minX, x);
|
|
85
|
-
minY = Math.min(minY, y);
|
|
86
|
-
maxX = Math.max(maxX, x + width);
|
|
87
|
-
maxY = Math.max(maxY, y + height);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return { minX, minY, maxX, maxY };
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Merge multiple canvases into a single canvas with position offsets applied.
|
|
95
|
-
* Each canvas gets a group node border with its name as a label.
|
|
96
|
-
* Node IDs are prefixed with canvasId to avoid collisions (format: "canvasId:nodeId").
|
|
97
|
-
* Original IDs can be recovered using parseNodeId().
|
|
98
|
-
*/
|
|
99
|
-
export function mergeCanvases(
|
|
100
|
-
placements: CanvasPlacement[],
|
|
101
|
-
options: { showGroups?: boolean } = {}
|
|
102
|
-
): ExtendedCanvas {
|
|
103
|
-
const { showGroups = true } = options;
|
|
104
|
-
const groupNodes: ExtendedCanvasNode[] = [];
|
|
105
|
-
const mergedNodes: ExtendedCanvasNode[] = [];
|
|
106
|
-
const mergedEdges: ExtendedCanvasEdge[] = [];
|
|
107
|
-
|
|
108
|
-
for (const placement of placements) {
|
|
109
|
-
const { canvasId, canvas, position, label } = placement;
|
|
110
|
-
|
|
111
|
-
// Calculate bounds for this canvas to create a group node
|
|
112
|
-
if (showGroups && canvas.nodes && canvas.nodes.length > 0) {
|
|
113
|
-
const bounds = calculateCanvasBounds(canvas);
|
|
114
|
-
const groupNode: ExtendedCanvasNode = {
|
|
115
|
-
id: `${canvasId}:__group__`,
|
|
116
|
-
type: 'group',
|
|
117
|
-
label: label ?? canvas.pv?.name ?? canvasId,
|
|
118
|
-
x: position.x + bounds.minX - GROUP_PADDING,
|
|
119
|
-
y: position.y + bounds.minY - GROUP_PADDING,
|
|
120
|
-
width: bounds.maxX - bounds.minX + GROUP_PADDING * 2,
|
|
121
|
-
height: bounds.maxY - bounds.minY + GROUP_PADDING * 2,
|
|
122
|
-
};
|
|
123
|
-
groupNodes.push(groupNode);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Process nodes - apply position offset and prefix IDs
|
|
127
|
-
if (canvas.nodes) {
|
|
128
|
-
for (const node of canvas.nodes) {
|
|
129
|
-
const mergedNode: ExtendedCanvasNode = {
|
|
130
|
-
...node,
|
|
131
|
-
id: prefixNodeId(canvasId, node.id),
|
|
132
|
-
x: (node.x ?? 0) + position.x,
|
|
133
|
-
y: (node.y ?? 0) + position.y,
|
|
134
|
-
};
|
|
135
|
-
mergedNodes.push(mergedNode);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Process edges - update node references with prefixed IDs
|
|
140
|
-
if (canvas.edges) {
|
|
141
|
-
for (const edge of canvas.edges) {
|
|
142
|
-
const mergedEdge: ExtendedCanvasEdge = {
|
|
143
|
-
...edge,
|
|
144
|
-
id: prefixNodeId(canvasId, edge.id),
|
|
145
|
-
fromNode: prefixNodeId(canvasId, edge.fromNode),
|
|
146
|
-
toNode: prefixNodeId(canvasId, edge.toNode),
|
|
147
|
-
};
|
|
148
|
-
mergedEdges.push(mergedEdge);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Create merged canvas - group nodes first so they render behind
|
|
154
|
-
const mergedCanvas: ExtendedCanvas = {
|
|
155
|
-
name: 'Multi-Canvas View',
|
|
156
|
-
nodes: [...groupNodes, ...mergedNodes],
|
|
157
|
-
edges: mergedEdges,
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
return mergedCanvas;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Extract the original canvas ID and node ID from a merged node ID
|
|
165
|
-
*/
|
|
166
|
-
export function parseNodeId(
|
|
167
|
-
mergedNodeId: string
|
|
168
|
-
): { canvasId: string; nodeId: string } | null {
|
|
169
|
-
const colonIndex = mergedNodeId.indexOf(':');
|
|
170
|
-
if (colonIndex === -1) return null;
|
|
171
|
-
return {
|
|
172
|
-
canvasId: mergedNodeId.substring(0, colonIndex),
|
|
173
|
-
nodeId: mergedNodeId.substring(colonIndex + 1),
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// ============================================================================
|
|
178
|
-
// MultiCanvasRenderer Component
|
|
179
|
-
// ============================================================================
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Renders multiple canvases merged into a single graph view.
|
|
183
|
-
*
|
|
184
|
-
* Each canvas is positioned at its specified offset, and all nodes/edges
|
|
185
|
-
* are combined into a unified viewport. Node IDs are prefixed with their
|
|
186
|
-
* source canvas ID to avoid collisions (format: "canvasId:nodeId").
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
* ```tsx
|
|
190
|
-
* <MultiCanvasRenderer
|
|
191
|
-
* layout={{
|
|
192
|
-
* placements: [
|
|
193
|
-
* { canvasId: 'auth', canvas: authCanvas, position: { x: 0, y: 0 } },
|
|
194
|
-
* { canvasId: 'data', canvas: dataCanvas, position: { x: 600, y: 0 } },
|
|
195
|
-
* ],
|
|
196
|
-
* }}
|
|
197
|
-
* showControls
|
|
198
|
-
* />
|
|
199
|
-
* ```
|
|
200
|
-
*/
|
|
201
|
-
export const MultiCanvasRenderer = forwardRef<
|
|
202
|
-
GraphRendererHandle,
|
|
203
|
-
MultiCanvasRendererProps
|
|
204
|
-
>(function MultiCanvasRenderer(
|
|
205
|
-
{ layout, onLayoutChange, showGroups = true, ...graphRendererProps },
|
|
206
|
-
ref
|
|
207
|
-
) {
|
|
208
|
-
// Track group positions at the start of drag to calculate deltas
|
|
209
|
-
const groupPositionsRef = useRef<Map<string, { x: number; y: number }>>(new Map());
|
|
210
|
-
|
|
211
|
-
// Merge all canvases into a single canvas
|
|
212
|
-
const mergedCanvas = useMemo(
|
|
213
|
-
() => mergeCanvases(layout.placements, { showGroups }),
|
|
214
|
-
[layout.placements, showGroups]
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
// Calculate group node IDs for dragging
|
|
218
|
-
const draggableNodeIds = useMemo(() => {
|
|
219
|
-
if (!showGroups) return undefined;
|
|
220
|
-
const ids = new Set<string>();
|
|
221
|
-
for (const placement of layout.placements) {
|
|
222
|
-
if (placement.canvas.nodes && placement.canvas.nodes.length > 0) {
|
|
223
|
-
ids.add(`${placement.canvasId}:__group__`);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return ids.size > 0 ? ids : undefined;
|
|
227
|
-
}, [layout.placements, showGroups]);
|
|
228
|
-
|
|
229
|
-
// Store initial group positions whenever layout changes
|
|
230
|
-
useMemo(() => {
|
|
231
|
-
groupPositionsRef.current.clear();
|
|
232
|
-
for (const placement of layout.placements) {
|
|
233
|
-
if (placement.canvas.nodes && placement.canvas.nodes.length > 0) {
|
|
234
|
-
const bounds = calculateCanvasBounds(placement.canvas);
|
|
235
|
-
// Group position = placement position + bounds offset - padding
|
|
236
|
-
groupPositionsRef.current.set(`${placement.canvasId}:__group__`, {
|
|
237
|
-
x: placement.position.x + bounds.minX - GROUP_PADDING,
|
|
238
|
-
y: placement.position.y + bounds.minY - GROUP_PADDING,
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}, [layout.placements]);
|
|
243
|
-
|
|
244
|
-
// Handle group drag to update layout positions
|
|
245
|
-
const handleNodeDragStop = useCallback(
|
|
246
|
-
(nodeId: string, newPosition: { x: number; y: number }) => {
|
|
247
|
-
// Only handle group nodes
|
|
248
|
-
if (!nodeId.endsWith(':__group__')) return;
|
|
249
|
-
if (!onLayoutChange) return;
|
|
250
|
-
|
|
251
|
-
const parsed = parseNodeId(nodeId);
|
|
252
|
-
if (!parsed) return;
|
|
253
|
-
const { canvasId } = parsed;
|
|
254
|
-
|
|
255
|
-
// Get the original group position
|
|
256
|
-
const originalGroupPos = groupPositionsRef.current.get(nodeId);
|
|
257
|
-
if (!originalGroupPos) return;
|
|
258
|
-
|
|
259
|
-
// Calculate delta
|
|
260
|
-
const deltaX = newPosition.x - originalGroupPos.x;
|
|
261
|
-
const deltaY = newPosition.y - originalGroupPos.y;
|
|
262
|
-
|
|
263
|
-
// Skip if no significant movement
|
|
264
|
-
if (Math.abs(deltaX) < 1 && Math.abs(deltaY) < 1) return;
|
|
265
|
-
|
|
266
|
-
// Create updated layout with new position for this canvas
|
|
267
|
-
const updatedPlacements = layout.placements.map((placement) => {
|
|
268
|
-
if (placement.canvasId === canvasId) {
|
|
269
|
-
return {
|
|
270
|
-
...placement,
|
|
271
|
-
position: {
|
|
272
|
-
x: placement.position.x + deltaX,
|
|
273
|
-
y: placement.position.y + deltaY,
|
|
274
|
-
},
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
return placement;
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
onLayoutChange({ placements: updatedPlacements });
|
|
281
|
-
},
|
|
282
|
-
[layout.placements, onLayoutChange]
|
|
283
|
-
);
|
|
284
|
-
|
|
285
|
-
return (
|
|
286
|
-
<GraphRenderer
|
|
287
|
-
ref={ref}
|
|
288
|
-
canvas={mergedCanvas}
|
|
289
|
-
editable={false}
|
|
290
|
-
draggableNodeIds={draggableNodeIds}
|
|
291
|
-
onNodeDragStop={handleNodeDragStop}
|
|
292
|
-
{...graphRendererProps}
|
|
293
|
-
/>
|
|
294
|
-
);
|
|
295
|
-
});
|
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState, useContext } from 'react';
|
|
2
|
-
import { createPortal } from 'react-dom';
|
|
3
|
-
import { useTheme } from '@principal-ade/industry-theme';
|
|
4
|
-
import { IndustryMarkdownSlide } from 'themed-markdown';
|
|
5
|
-
import { TooltipPortalContext } from '../contexts/TooltipPortalContext';
|
|
6
|
-
|
|
7
|
-
export interface OtelInfo {
|
|
8
|
-
kind: 'type' | 'service' | 'instance';
|
|
9
|
-
category?: string;
|
|
10
|
-
scope?: string;
|
|
11
|
-
files?: string[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface NodeTooltipProps {
|
|
15
|
-
description?: string;
|
|
16
|
-
otel?: OtelInfo;
|
|
17
|
-
/** @deprecated Use otel.files instead */
|
|
18
|
-
sources?: string[];
|
|
19
|
-
/** External references (packages, documentation links) */
|
|
20
|
-
references?: string[];
|
|
21
|
-
visible: boolean;
|
|
22
|
-
/** Reference to the node element for positioning */
|
|
23
|
-
nodeRef?: React.RefObject<HTMLDivElement>;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Tooltip component for displaying node information on hover
|
|
28
|
-
* Uses a portal to render above all other elements
|
|
29
|
-
*/
|
|
30
|
-
export const NodeTooltip: React.FC<NodeTooltipProps> = ({
|
|
31
|
-
description,
|
|
32
|
-
otel,
|
|
33
|
-
sources,
|
|
34
|
-
references,
|
|
35
|
-
visible,
|
|
36
|
-
nodeRef,
|
|
37
|
-
}) => {
|
|
38
|
-
const { theme } = useTheme();
|
|
39
|
-
const portalTarget = useContext(TooltipPortalContext);
|
|
40
|
-
const [position, setPosition] = useState<{ top: number; left: number } | null>(null);
|
|
41
|
-
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
if (visible && nodeRef?.current && portalTarget) {
|
|
44
|
-
const nodeRect = nodeRef.current.getBoundingClientRect();
|
|
45
|
-
const containerRect = portalTarget.getBoundingClientRect();
|
|
46
|
-
// Position relative to the container, not the viewport
|
|
47
|
-
setPosition({
|
|
48
|
-
top: nodeRect.bottom - containerRect.top + 8, // 8px below the node
|
|
49
|
-
left: nodeRect.left - containerRect.left + nodeRect.width / 2, // centered horizontally
|
|
50
|
-
});
|
|
51
|
-
} else if (visible && nodeRef?.current && !portalTarget) {
|
|
52
|
-
// Fallback to viewport positioning if no portal target
|
|
53
|
-
const rect = nodeRef.current.getBoundingClientRect();
|
|
54
|
-
setPosition({
|
|
55
|
-
top: rect.bottom + 8,
|
|
56
|
-
left: rect.left + rect.width / 2,
|
|
57
|
-
});
|
|
58
|
-
} else if (!nodeRef) {
|
|
59
|
-
// No ref provided - will use relative positioning (for storybook demos)
|
|
60
|
-
setPosition({ top: 0, left: 0 });
|
|
61
|
-
}
|
|
62
|
-
}, [visible, nodeRef, portalTarget]);
|
|
63
|
-
|
|
64
|
-
if (!visible) return null;
|
|
65
|
-
|
|
66
|
-
// If no nodeRef, render inline (for storybook demos)
|
|
67
|
-
const usePortal = Boolean(nodeRef);
|
|
68
|
-
|
|
69
|
-
const getKindLabel = (kind: string) => {
|
|
70
|
-
switch (kind) {
|
|
71
|
-
case 'type':
|
|
72
|
-
return 'Type';
|
|
73
|
-
case 'service':
|
|
74
|
-
return 'Service';
|
|
75
|
-
case 'instance':
|
|
76
|
-
return 'Instance';
|
|
77
|
-
default:
|
|
78
|
-
return kind;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const getKindColor = (kind: string) => {
|
|
83
|
-
switch (kind) {
|
|
84
|
-
case 'type':
|
|
85
|
-
return '#4A90E2'; // Blue
|
|
86
|
-
case 'service':
|
|
87
|
-
return '#7ED321'; // Green
|
|
88
|
-
case 'instance':
|
|
89
|
-
return '#9B59B6'; // Purple
|
|
90
|
-
default:
|
|
91
|
-
return '#888';
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const renderTooltipContent = (): React.JSX.Element => (
|
|
96
|
-
<div
|
|
97
|
-
style={{
|
|
98
|
-
// Use absolute positioning relative to portal target container
|
|
99
|
-
position: usePortal ? 'absolute' : 'absolute',
|
|
100
|
-
top: usePortal ? position?.top ?? 0 : '100%',
|
|
101
|
-
left: usePortal ? position?.left ?? 0 : '50%',
|
|
102
|
-
transform: 'translateX(-50%)',
|
|
103
|
-
marginTop: usePortal ? 0 : '8px',
|
|
104
|
-
padding: '8px 12px',
|
|
105
|
-
backgroundColor: 'rgba(0, 0, 0, 0.9)',
|
|
106
|
-
color: 'white',
|
|
107
|
-
borderRadius: '6px',
|
|
108
|
-
fontSize: theme.fontSizes[0],
|
|
109
|
-
fontFamily: theme.fonts.body,
|
|
110
|
-
maxWidth: '400px',
|
|
111
|
-
maxHeight: '500px',
|
|
112
|
-
zIndex: 99999,
|
|
113
|
-
pointerEvents: 'none',
|
|
114
|
-
boxShadow: '0 4px 12px rgba(0,0,0,0.4)',
|
|
115
|
-
whiteSpace: 'normal',
|
|
116
|
-
opacity: usePortal ? (position ? 1 : 0) : 1,
|
|
117
|
-
overflow: 'auto',
|
|
118
|
-
}}
|
|
119
|
-
>
|
|
120
|
-
{/* Arrow */}
|
|
121
|
-
<div
|
|
122
|
-
style={{
|
|
123
|
-
position: 'absolute',
|
|
124
|
-
top: '-6px',
|
|
125
|
-
left: '50%',
|
|
126
|
-
transform: 'translateX(-50%)',
|
|
127
|
-
width: 0,
|
|
128
|
-
height: 0,
|
|
129
|
-
borderLeft: '6px solid transparent',
|
|
130
|
-
borderRight: '6px solid transparent',
|
|
131
|
-
borderBottom: '6px solid rgba(0, 0, 0, 0.9)',
|
|
132
|
-
}}
|
|
133
|
-
/>
|
|
134
|
-
|
|
135
|
-
{/* OTEL Badge */}
|
|
136
|
-
{otel && (
|
|
137
|
-
<div
|
|
138
|
-
style={{
|
|
139
|
-
display: 'flex',
|
|
140
|
-
alignItems: 'center',
|
|
141
|
-
gap: '6px',
|
|
142
|
-
marginBottom: description || otel.scope ? '6px' : 0,
|
|
143
|
-
}}
|
|
144
|
-
>
|
|
145
|
-
<span
|
|
146
|
-
style={{
|
|
147
|
-
backgroundColor: getKindColor(otel.kind),
|
|
148
|
-
color: 'white',
|
|
149
|
-
padding: '2px 6px',
|
|
150
|
-
borderRadius: '3px',
|
|
151
|
-
fontSize: theme.fontSizes[0],
|
|
152
|
-
fontWeight: theme.fontWeights.semibold,
|
|
153
|
-
fontFamily: theme.fonts.body,
|
|
154
|
-
textTransform: 'uppercase',
|
|
155
|
-
}}
|
|
156
|
-
>
|
|
157
|
-
{getKindLabel(otel.kind)}
|
|
158
|
-
</span>
|
|
159
|
-
{otel.category && (
|
|
160
|
-
<span style={{ color: 'rgba(255,255,255,0.7)', fontSize: theme.fontSizes[0], fontFamily: theme.fonts.body }}>
|
|
161
|
-
{otel.category}
|
|
162
|
-
</span>
|
|
163
|
-
)}
|
|
164
|
-
</div>
|
|
165
|
-
)}
|
|
166
|
-
|
|
167
|
-
{/* Scope */}
|
|
168
|
-
{otel?.scope && (
|
|
169
|
-
<div style={{
|
|
170
|
-
marginBottom: description ? '6px' : 0,
|
|
171
|
-
fontSize: theme.fontSizes[0],
|
|
172
|
-
fontFamily: theme.fonts.body,
|
|
173
|
-
color: 'rgba(255,255,255,0.8)'
|
|
174
|
-
}}>
|
|
175
|
-
<span style={{
|
|
176
|
-
color: 'rgba(255,255,255,0.6)',
|
|
177
|
-
fontWeight: theme.fontWeights.semibold
|
|
178
|
-
}}>
|
|
179
|
-
Scope:
|
|
180
|
-
</span>{' '}
|
|
181
|
-
<span style={{ fontFamily: 'monospace' }}>{otel.scope}</span>
|
|
182
|
-
</div>
|
|
183
|
-
)}
|
|
184
|
-
|
|
185
|
-
{/* Description - rendered as markdown */}
|
|
186
|
-
{description ? (
|
|
187
|
-
<div style={{ lineHeight: '1.4', color: 'rgba(255,255,255,0.9)' }}>
|
|
188
|
-
<IndustryMarkdownSlide
|
|
189
|
-
content={description}
|
|
190
|
-
slideIdPrefix="tooltip"
|
|
191
|
-
slideIndex={0}
|
|
192
|
-
isVisible={true}
|
|
193
|
-
theme={{
|
|
194
|
-
...theme,
|
|
195
|
-
colors: {
|
|
196
|
-
...theme.colors,
|
|
197
|
-
background: 'transparent',
|
|
198
|
-
text: 'rgba(255,255,255,0.9)',
|
|
199
|
-
},
|
|
200
|
-
}}
|
|
201
|
-
transparentBackground={true}
|
|
202
|
-
disableScroll={true}
|
|
203
|
-
fontSizeScale={0.85}
|
|
204
|
-
enableKeyboardScrolling={false}
|
|
205
|
-
autoFocusOnVisible={false}
|
|
206
|
-
/>
|
|
207
|
-
</div>
|
|
208
|
-
) : (
|
|
209
|
-
<div style={{ lineHeight: '1.4', color: 'rgba(255,255,255,0.5)' }}>
|
|
210
|
-
No description
|
|
211
|
-
</div>
|
|
212
|
-
)}
|
|
213
|
-
|
|
214
|
-
{/* Source Files - from otel.files or deprecated sources */}
|
|
215
|
-
{(() => {
|
|
216
|
-
const sourceFiles = otel?.files || sources;
|
|
217
|
-
if (!sourceFiles || sourceFiles.length === 0) return null;
|
|
218
|
-
return (
|
|
219
|
-
<div style={{ marginTop: '8px', borderTop: '1px solid rgba(255,255,255,0.2)', paddingTop: '6px' }}>
|
|
220
|
-
<div style={{
|
|
221
|
-
fontSize: theme.fontSizes[0],
|
|
222
|
-
fontWeight: theme.fontWeights.semibold,
|
|
223
|
-
color: 'rgba(255,255,255,0.7)',
|
|
224
|
-
marginBottom: '4px'
|
|
225
|
-
}}>
|
|
226
|
-
Source Files:
|
|
227
|
-
</div>
|
|
228
|
-
<div style={{ fontSize: theme.fontSizes[0], color: 'rgba(255,255,255,0.8)' }}>
|
|
229
|
-
{sourceFiles.map((file, index) => (
|
|
230
|
-
<div key={index} style={{
|
|
231
|
-
fontFamily: 'monospace',
|
|
232
|
-
fontSize: theme.fontSizes[0],
|
|
233
|
-
marginTop: index > 0 ? '2px' : 0,
|
|
234
|
-
wordBreak: 'break-all'
|
|
235
|
-
}}>
|
|
236
|
-
{file}
|
|
237
|
-
</div>
|
|
238
|
-
))}
|
|
239
|
-
</div>
|
|
240
|
-
</div>
|
|
241
|
-
);
|
|
242
|
-
})()}
|
|
243
|
-
|
|
244
|
-
{/* References - external packages/documentation */}
|
|
245
|
-
{references && references.length > 0 && (
|
|
246
|
-
<div style={{ marginTop: '8px', borderTop: '1px solid rgba(255,255,255,0.2)', paddingTop: '6px' }}>
|
|
247
|
-
<div style={{
|
|
248
|
-
fontSize: theme.fontSizes[0],
|
|
249
|
-
fontWeight: theme.fontWeights.semibold,
|
|
250
|
-
color: 'rgba(255,255,255,0.7)',
|
|
251
|
-
marginBottom: '4px'
|
|
252
|
-
}}>
|
|
253
|
-
References:
|
|
254
|
-
</div>
|
|
255
|
-
<div style={{ fontSize: theme.fontSizes[0], color: 'rgba(255,255,255,0.8)' }}>
|
|
256
|
-
{references.map((ref, index) => (
|
|
257
|
-
<div key={index} style={{
|
|
258
|
-
fontFamily: 'monospace',
|
|
259
|
-
fontSize: theme.fontSizes[0],
|
|
260
|
-
marginTop: index > 0 ? '2px' : 0,
|
|
261
|
-
wordBreak: 'break-all'
|
|
262
|
-
}}>
|
|
263
|
-
{ref}
|
|
264
|
-
</div>
|
|
265
|
-
))}
|
|
266
|
-
</div>
|
|
267
|
-
</div>
|
|
268
|
-
)}
|
|
269
|
-
</div>
|
|
270
|
-
);
|
|
271
|
-
|
|
272
|
-
// Use portal to render in the graph container when available, otherwise render inline
|
|
273
|
-
if (usePortal) {
|
|
274
|
-
// Portal to graph container (hides with tab) or fallback to body
|
|
275
|
-
const target = portalTarget || document.body;
|
|
276
|
-
return createPortal(renderTooltipContent(), target);
|
|
277
|
-
}
|
|
278
|
-
return renderTooltipContent();
|
|
279
|
-
};
|