@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,270 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Workflow Sequence Diagram
|
|
3
|
-
*
|
|
4
|
-
* A wrapper around SequenceDiagramRenderer that handles conversion from
|
|
5
|
-
* workflow scenarios to sequence diagram format, following the graph-to-sequence
|
|
6
|
-
* model where participants are scopes and events are move/transform operations.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { useMemo, useCallback } from 'react';
|
|
10
|
-
import type { WorkflowScenario, Canvas, ExtendedCanvas } from '@principal-ai/subsystems-core';
|
|
11
|
-
import { SequenceDiagramRenderer } from './SequenceDiagramRenderer';
|
|
12
|
-
import type { SequenceEvent, SequenceEdge } from '../hooks/useSequenceLayout';
|
|
13
|
-
import type { UseSequenceLayoutOptions } from '../hooks/useSequenceLayout';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Props for WorkflowSequenceDiagram
|
|
17
|
-
*/
|
|
18
|
-
export interface WorkflowSequenceDiagramProps {
|
|
19
|
-
/** Workflow scenario to visualize */
|
|
20
|
-
scenario: WorkflowScenario;
|
|
21
|
-
|
|
22
|
-
/** Optional canvas for extracting scope metadata from OTEL nodes */
|
|
23
|
-
canvas?: Canvas | ExtendedCanvas | null;
|
|
24
|
-
|
|
25
|
-
/** Optional height for the diagram */
|
|
26
|
-
height?: number | string;
|
|
27
|
-
|
|
28
|
-
/** Optional width for the diagram */
|
|
29
|
-
width?: number | string;
|
|
30
|
-
|
|
31
|
-
/** Layout options for the sequence diagram */
|
|
32
|
-
layoutOptions?: UseSequenceLayoutOptions;
|
|
33
|
-
|
|
34
|
-
/** Whether to show controls */
|
|
35
|
-
showControls?: boolean;
|
|
36
|
-
|
|
37
|
-
/** Whether to show background grid */
|
|
38
|
-
showBackground?: boolean;
|
|
39
|
-
|
|
40
|
-
/** Optional class name */
|
|
41
|
-
className?: string;
|
|
42
|
-
|
|
43
|
-
/** Callback when an event node is clicked - receives the event index (0-based) */
|
|
44
|
-
onEventIndexChange?: (eventIndex: number) => void;
|
|
45
|
-
|
|
46
|
-
/** Currently selected event index (0-based) for visual highlighting */
|
|
47
|
-
selectedEventIndex?: number;
|
|
48
|
-
|
|
49
|
-
/** Whether to show event labels on nodes (default: false, labels already shown on edges) */
|
|
50
|
-
showEventLabels?: boolean;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* When true, render the diagram chrome (canvas background, swimlane fills,
|
|
54
|
-
* header backgrounds) as transparent so the diagram can be composited over
|
|
55
|
-
* an arbitrary backdrop. Defaults to `false`.
|
|
56
|
-
*/
|
|
57
|
-
transparent?: boolean;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Type guard to check if a node is an OTEL event node
|
|
62
|
-
*/
|
|
63
|
-
function isOtelEventNode(node: any): node is {
|
|
64
|
-
type: 'otel-event';
|
|
65
|
-
event: { name: string };
|
|
66
|
-
otel?: { scope?: string };
|
|
67
|
-
label?: string;
|
|
68
|
-
} {
|
|
69
|
-
return node?.type === 'otel-event' && node?.event?.name;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Type guard to check if a node is an OTEL participant node
|
|
74
|
-
*/
|
|
75
|
-
function isOtelParticipantNode(node: any): node is {
|
|
76
|
-
type: 'otel-participant';
|
|
77
|
-
participant: { name: string; scope?: string };
|
|
78
|
-
transformEvents?: Array<{ name: string }>;
|
|
79
|
-
} {
|
|
80
|
-
return node?.type === 'otel-participant' && node?.participant?.name;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Convert workflow scenario to sequence diagram format
|
|
85
|
-
*/
|
|
86
|
-
function convertWorkflowToSequence(
|
|
87
|
-
scenario: WorkflowScenario,
|
|
88
|
-
canvas?: Canvas | ExtendedCanvas | null
|
|
89
|
-
): {
|
|
90
|
-
events: SequenceEvent[];
|
|
91
|
-
edges: SequenceEdge[];
|
|
92
|
-
} {
|
|
93
|
-
// Extract event names from scenario template
|
|
94
|
-
const templateEvents = scenario.template.events || {};
|
|
95
|
-
const eventNames = Object.keys(templateEvents);
|
|
96
|
-
|
|
97
|
-
if (eventNames.length === 0) {
|
|
98
|
-
return { events: [], edges: [] };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Build maps from canvas metadata
|
|
102
|
-
const eventToScopeMap = new Map<string, string>();
|
|
103
|
-
const eventToLabelMap = new Map<string, string>();
|
|
104
|
-
const eventToMoveEventMap = new Map<string, boolean>();
|
|
105
|
-
|
|
106
|
-
if (canvas?.nodes) {
|
|
107
|
-
for (const node of canvas.nodes) {
|
|
108
|
-
// Type guard narrowing - we know the structure but Canvas type doesn't include OTEL specifics
|
|
109
|
-
const nodeData = node as Record<string, any>;
|
|
110
|
-
|
|
111
|
-
// Handle OTEL event nodes
|
|
112
|
-
if (isOtelEventNode(nodeData)) {
|
|
113
|
-
const eventName = nodeData.event.name;
|
|
114
|
-
|
|
115
|
-
if (nodeData.otel?.scope) {
|
|
116
|
-
eventToScopeMap.set(eventName, nodeData.otel.scope);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (nodeData.label) {
|
|
120
|
-
eventToLabelMap.set(eventName, nodeData.label);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Handle OTEL participant nodes (participant-based model)
|
|
125
|
-
if (isOtelParticipantNode(nodeData)) {
|
|
126
|
-
const scope = nodeData.participant.scope || nodeData.participant.name;
|
|
127
|
-
|
|
128
|
-
// Mark transform events (internal to participant)
|
|
129
|
-
if (nodeData.transformEvents) {
|
|
130
|
-
for (const transformEvent of nodeData.transformEvents) {
|
|
131
|
-
eventToScopeMap.set(transformEvent.name, scope);
|
|
132
|
-
eventToMoveEventMap.set(transformEvent.name, false);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Convert to SequenceEvent format
|
|
140
|
-
const events: SequenceEvent[] = eventNames.map((eventName, index) => {
|
|
141
|
-
const canvasScope = eventToScopeMap.get(eventName);
|
|
142
|
-
const label = eventToLabelMap.get(eventName) || eventName.split('.').pop() || eventName;
|
|
143
|
-
|
|
144
|
-
// Determine if this is a move event
|
|
145
|
-
// Default to true unless explicitly marked as transform event in participant node
|
|
146
|
-
const isMoveEvent = eventToMoveEventMap.get(eventName) ?? true;
|
|
147
|
-
|
|
148
|
-
// When the canvas provides a scope, prefix it so the event lands in that
|
|
149
|
-
// participant's lane (the layout uses the first dotted segment as the
|
|
150
|
-
// default lane). Otherwise, use the event name as-is.
|
|
151
|
-
const name = canvasScope ? `${canvasScope}.${eventName}` : eventName;
|
|
152
|
-
const participant = canvasScope ?? eventName.split('.')[0] ?? eventName;
|
|
153
|
-
|
|
154
|
-
return {
|
|
155
|
-
id: `event-${index}`,
|
|
156
|
-
name,
|
|
157
|
-
label,
|
|
158
|
-
moveEvent: isMoveEvent,
|
|
159
|
-
participant,
|
|
160
|
-
};
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
// Create sequential edges
|
|
164
|
-
const edges: SequenceEdge[] = [];
|
|
165
|
-
for (let i = 0; i < events.length - 1; i++) {
|
|
166
|
-
edges.push({
|
|
167
|
-
id: `edge-${i}`,
|
|
168
|
-
fromEvent: events[i].id,
|
|
169
|
-
toEvent: events[i + 1].id,
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return { events, edges };
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* WorkflowSequenceDiagram Component
|
|
178
|
-
*
|
|
179
|
-
* Renders a workflow scenario as a sequence diagram, automatically extracting
|
|
180
|
-
* participant scopes from the canvas and distinguishing between move events
|
|
181
|
-
* (cross-participant communication) and transform events (internal processing).
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```tsx
|
|
185
|
-
* <WorkflowSequenceDiagram
|
|
186
|
-
* scenario={workflowScenario}
|
|
187
|
-
* canvas={otelCanvas}
|
|
188
|
-
* height={600}
|
|
189
|
-
* layoutOptions={{ eventSpacing: 80 }}
|
|
190
|
-
* />
|
|
191
|
-
* ```
|
|
192
|
-
*/
|
|
193
|
-
export function WorkflowSequenceDiagram({
|
|
194
|
-
scenario,
|
|
195
|
-
canvas,
|
|
196
|
-
height = 600,
|
|
197
|
-
width = '100%',
|
|
198
|
-
layoutOptions,
|
|
199
|
-
showControls = true,
|
|
200
|
-
showBackground = false,
|
|
201
|
-
className,
|
|
202
|
-
onEventIndexChange,
|
|
203
|
-
selectedEventIndex,
|
|
204
|
-
showEventLabels = false, // Default to false - labels already on edges
|
|
205
|
-
transparent = false,
|
|
206
|
-
}: WorkflowSequenceDiagramProps) {
|
|
207
|
-
// Convert workflow to sequence format
|
|
208
|
-
const { events, edges } = useMemo(
|
|
209
|
-
() => convertWorkflowToSequence(scenario, canvas),
|
|
210
|
-
[scenario, canvas]
|
|
211
|
-
);
|
|
212
|
-
|
|
213
|
-
// Handle node clicks - map sequence node ID back to event index
|
|
214
|
-
const handleNodeClick = useCallback(
|
|
215
|
-
(nodeId: string) => {
|
|
216
|
-
if (!onEventIndexChange) return;
|
|
217
|
-
|
|
218
|
-
// Node IDs are in format "event-{index}"
|
|
219
|
-
const match = nodeId.match(/^event-(\d+)$/);
|
|
220
|
-
if (match) {
|
|
221
|
-
const eventIndex = parseInt(match[1], 10);
|
|
222
|
-
onEventIndexChange(eventIndex);
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
[onEventIndexChange]
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
// Convert selected event index to node ID
|
|
229
|
-
const selectedNodeId = useMemo(() => {
|
|
230
|
-
if (selectedEventIndex === undefined || selectedEventIndex === null) return undefined;
|
|
231
|
-
return `event-${selectedEventIndex}`;
|
|
232
|
-
}, [selectedEventIndex]);
|
|
233
|
-
|
|
234
|
-
// If no events, show empty state
|
|
235
|
-
if (events.length === 0) {
|
|
236
|
-
return (
|
|
237
|
-
<div
|
|
238
|
-
className={className}
|
|
239
|
-
style={{
|
|
240
|
-
width,
|
|
241
|
-
height,
|
|
242
|
-
display: 'flex',
|
|
243
|
-
alignItems: 'center',
|
|
244
|
-
justifyContent: 'center',
|
|
245
|
-
color: '#888',
|
|
246
|
-
}}
|
|
247
|
-
>
|
|
248
|
-
No events in workflow
|
|
249
|
-
</div>
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Render sequence diagram
|
|
254
|
-
return (
|
|
255
|
-
<SequenceDiagramRenderer
|
|
256
|
-
events={events}
|
|
257
|
-
edges={edges}
|
|
258
|
-
height={height}
|
|
259
|
-
width={width}
|
|
260
|
-
layoutOptions={layoutOptions}
|
|
261
|
-
showControls={showControls}
|
|
262
|
-
showBackground={showBackground}
|
|
263
|
-
className={className}
|
|
264
|
-
onNodeClick={onEventIndexChange ? handleNodeClick : undefined}
|
|
265
|
-
selectedNodeId={selectedNodeId}
|
|
266
|
-
showEventLabels={showEventLabels}
|
|
267
|
-
transparent={transparent}
|
|
268
|
-
/>
|
|
269
|
-
);
|
|
270
|
-
}
|
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DashboardRenderer
|
|
3
|
-
*
|
|
4
|
-
* Main component for rendering a dashboard from a DashboardDefinition.
|
|
5
|
-
* Takes a dashboard definition JSON and a data provider, renders all metrics.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { useMemo, useState, useEffect } from 'react';
|
|
9
|
-
import { useTheme } from '@principal-ade/industry-theme';
|
|
10
|
-
import type { DashboardRendererProps, MetricSource, PanelPlacement, TimeRange, RefreshInterval } from './types';
|
|
11
|
-
import { MetricPanel } from './MetricPanel';
|
|
12
|
-
import { MockDataProvider } from './MockDataProvider';
|
|
13
|
-
import { TimeRangeSelector } from './components';
|
|
14
|
-
|
|
15
|
-
type Breakpoint = 'mobile' | 'tablet' | 'desktop';
|
|
16
|
-
|
|
17
|
-
function useBreakpoint(breakpoints?: { mobile?: number; tablet?: number }): Breakpoint {
|
|
18
|
-
const mobileBreak = breakpoints?.mobile ?? 768;
|
|
19
|
-
const tabletBreak = breakpoints?.tablet ?? 1024;
|
|
20
|
-
|
|
21
|
-
const [breakpoint, setBreakpoint] = useState<Breakpoint>(() => {
|
|
22
|
-
if (typeof window === 'undefined') return 'desktop';
|
|
23
|
-
const width = window.innerWidth;
|
|
24
|
-
if (width < mobileBreak) return 'mobile';
|
|
25
|
-
if (width < tabletBreak) return 'tablet';
|
|
26
|
-
return 'desktop';
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
const handleResize = () => {
|
|
31
|
-
const width = window.innerWidth;
|
|
32
|
-
if (width < mobileBreak) setBreakpoint('mobile');
|
|
33
|
-
else if (width < tabletBreak) setBreakpoint('tablet');
|
|
34
|
-
else setBreakpoint('desktop');
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
window.addEventListener('resize', handleResize);
|
|
38
|
-
return () => window.removeEventListener('resize', handleResize);
|
|
39
|
-
}, [mobileBreak, tabletBreak]);
|
|
40
|
-
|
|
41
|
-
return breakpoint;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function DashboardRenderer({
|
|
45
|
-
dashboard,
|
|
46
|
-
dataProvider,
|
|
47
|
-
timeRange: controlledTimeRange,
|
|
48
|
-
onTimeRangeChange,
|
|
49
|
-
refreshInterval: controlledRefreshInterval,
|
|
50
|
-
onRefreshIntervalChange,
|
|
51
|
-
timeRangeConfig,
|
|
52
|
-
onMetricClick,
|
|
53
|
-
onSourceClick,
|
|
54
|
-
}: DashboardRendererProps) {
|
|
55
|
-
const { theme } = useTheme();
|
|
56
|
-
const breakpoint = useBreakpoint(dashboard.layout.breakpoints);
|
|
57
|
-
|
|
58
|
-
// Internal state for uncontrolled time range
|
|
59
|
-
const [internalTimeRange, setInternalTimeRange] = useState<TimeRange>({
|
|
60
|
-
preset: timeRangeConfig?.defaultRange ?? 'last_1h',
|
|
61
|
-
});
|
|
62
|
-
const [internalRefreshInterval, setInternalRefreshInterval] = useState<RefreshInterval>(
|
|
63
|
-
timeRangeConfig?.defaultRefresh ?? 'off'
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
// Use controlled or internal state
|
|
67
|
-
const timeRange = controlledTimeRange ?? internalTimeRange;
|
|
68
|
-
const refreshInterval = controlledRefreshInterval ?? internalRefreshInterval;
|
|
69
|
-
|
|
70
|
-
const handleTimeRangeChange = (range: TimeRange) => {
|
|
71
|
-
if (onTimeRangeChange) {
|
|
72
|
-
onTimeRangeChange(range);
|
|
73
|
-
} else {
|
|
74
|
-
setInternalTimeRange(range);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const handleRefreshIntervalChange = (interval: RefreshInterval) => {
|
|
79
|
-
if (onRefreshIntervalChange) {
|
|
80
|
-
onRefreshIntervalChange(interval);
|
|
81
|
-
} else {
|
|
82
|
-
setInternalRefreshInterval(interval);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// Grid configuration
|
|
87
|
-
const gridColumns = dashboard.layout.columns ?? 12;
|
|
88
|
-
const gridGap = dashboard.layout.gap ?? 16;
|
|
89
|
-
|
|
90
|
-
// Use provided data provider or create a mock one
|
|
91
|
-
const data = useMemo(() => {
|
|
92
|
-
const provider = dataProvider || new MockDataProvider(dashboard);
|
|
93
|
-
return provider.getAll();
|
|
94
|
-
}, [dashboard, dataProvider]);
|
|
95
|
-
|
|
96
|
-
// Build a map of metric ID → metric definition for quick lookup
|
|
97
|
-
const metricsMap = useMemo(() => {
|
|
98
|
-
const map = new Map<string, (typeof dashboard.metrics)[0]>();
|
|
99
|
-
for (const metric of dashboard.metrics) {
|
|
100
|
-
map.set(metric.id, metric);
|
|
101
|
-
}
|
|
102
|
-
return map;
|
|
103
|
-
}, [dashboard.metrics]);
|
|
104
|
-
|
|
105
|
-
const handleSourceClick = (source: MetricSource) => {
|
|
106
|
-
if (onSourceClick) {
|
|
107
|
-
onSourceClick(source);
|
|
108
|
-
} else {
|
|
109
|
-
// Default behavior: log to console
|
|
110
|
-
console.log('Source clicked:', source);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
// Get span for current breakpoint
|
|
115
|
-
const getSpan = (placement: PanelPlacement, totalPanels: number): number => {
|
|
116
|
-
// Mobile defaults to full width
|
|
117
|
-
if (breakpoint === 'mobile') {
|
|
118
|
-
return placement.spanMobile ?? gridColumns;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Tablet uses spanTablet or falls back to span
|
|
122
|
-
if (breakpoint === 'tablet') {
|
|
123
|
-
return placement.spanTablet ?? placement.span ?? Math.floor(gridColumns / Math.min(totalPanels, 2));
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Desktop uses spanDesktop or span or auto-calculate
|
|
127
|
-
return placement.spanDesktop ?? placement.span ?? Math.floor(gridColumns / Math.min(totalPanels, 3));
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
return (
|
|
131
|
-
<div
|
|
132
|
-
style={{
|
|
133
|
-
backgroundColor: theme.colors.background,
|
|
134
|
-
color: theme.colors.text,
|
|
135
|
-
padding: theme.space?.[4] || 24,
|
|
136
|
-
minHeight: '100%',
|
|
137
|
-
fontFamily: theme.fonts.body,
|
|
138
|
-
}}
|
|
139
|
-
>
|
|
140
|
-
{/* Dashboard Header */}
|
|
141
|
-
<div style={{ marginBottom: theme.space?.[4] || 24 }}>
|
|
142
|
-
<div
|
|
143
|
-
style={{
|
|
144
|
-
display: 'flex',
|
|
145
|
-
justifyContent: 'space-between',
|
|
146
|
-
alignItems: 'flex-start',
|
|
147
|
-
gap: theme.space?.[3] || 16,
|
|
148
|
-
flexWrap: 'wrap',
|
|
149
|
-
}}
|
|
150
|
-
>
|
|
151
|
-
<h1
|
|
152
|
-
style={{
|
|
153
|
-
fontSize: theme.fontSizes[4],
|
|
154
|
-
fontWeight: theme.fontWeights.semibold,
|
|
155
|
-
fontFamily: theme.fonts.heading,
|
|
156
|
-
margin: 0,
|
|
157
|
-
color: theme.colors.text,
|
|
158
|
-
}}
|
|
159
|
-
>
|
|
160
|
-
{dashboard.name}
|
|
161
|
-
</h1>
|
|
162
|
-
|
|
163
|
-
<TimeRangeSelector
|
|
164
|
-
timeRange={timeRange}
|
|
165
|
-
onTimeRangeChange={handleTimeRangeChange}
|
|
166
|
-
refreshInterval={refreshInterval}
|
|
167
|
-
onRefreshIntervalChange={handleRefreshIntervalChange}
|
|
168
|
-
config={timeRangeConfig}
|
|
169
|
-
/>
|
|
170
|
-
</div>
|
|
171
|
-
|
|
172
|
-
{dashboard.description && (
|
|
173
|
-
<p
|
|
174
|
-
style={{
|
|
175
|
-
fontSize: theme.fontSizes[1],
|
|
176
|
-
color: theme.colors.textSecondary,
|
|
177
|
-
margin: 0,
|
|
178
|
-
marginTop: theme.space?.[2] || 8,
|
|
179
|
-
marginBottom: theme.space?.[3] || 12,
|
|
180
|
-
lineHeight: theme.lineHeights.body,
|
|
181
|
-
}}
|
|
182
|
-
>
|
|
183
|
-
{dashboard.description}
|
|
184
|
-
</p>
|
|
185
|
-
)}
|
|
186
|
-
|
|
187
|
-
{/* External links */}
|
|
188
|
-
{dashboard.externalLinks && Object.keys(dashboard.externalLinks).length > 0 && (
|
|
189
|
-
<div style={{ display: 'flex', gap: theme.space?.[3] || 12 }}>
|
|
190
|
-
{Object.entries(dashboard.externalLinks).map(([name, url]) => (
|
|
191
|
-
url && (
|
|
192
|
-
<a
|
|
193
|
-
key={name}
|
|
194
|
-
href={url}
|
|
195
|
-
target="_blank"
|
|
196
|
-
rel="noopener noreferrer"
|
|
197
|
-
style={{
|
|
198
|
-
fontSize: theme.fontSizes[0],
|
|
199
|
-
color: theme.colors.primary || theme.colors.accent,
|
|
200
|
-
textDecoration: 'none',
|
|
201
|
-
display: 'flex',
|
|
202
|
-
alignItems: 'center',
|
|
203
|
-
gap: 4,
|
|
204
|
-
}}
|
|
205
|
-
>
|
|
206
|
-
<svg
|
|
207
|
-
width={12}
|
|
208
|
-
height={12}
|
|
209
|
-
viewBox="0 0 24 24"
|
|
210
|
-
fill="none"
|
|
211
|
-
stroke="currentColor"
|
|
212
|
-
strokeWidth={2}
|
|
213
|
-
>
|
|
214
|
-
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" />
|
|
215
|
-
<polyline points="15 3 21 3 21 9" />
|
|
216
|
-
<line x1="10" y1="14" x2="21" y2="3" />
|
|
217
|
-
</svg>
|
|
218
|
-
{name}
|
|
219
|
-
</a>
|
|
220
|
-
)
|
|
221
|
-
))}
|
|
222
|
-
</div>
|
|
223
|
-
)}
|
|
224
|
-
</div>
|
|
225
|
-
|
|
226
|
-
{/* Dashboard Rows */}
|
|
227
|
-
<div style={{ display: 'flex', flexDirection: 'column', gap: theme.space?.[4] || 24 }}>
|
|
228
|
-
{dashboard.layout.rows.map((row, rowIndex) => (
|
|
229
|
-
<div key={rowIndex}>
|
|
230
|
-
{/* Row title */}
|
|
231
|
-
{row.title && (
|
|
232
|
-
<h2
|
|
233
|
-
style={{
|
|
234
|
-
fontSize: theme.fontSizes[2],
|
|
235
|
-
fontWeight: theme.fontWeights.medium,
|
|
236
|
-
fontFamily: theme.fonts.heading,
|
|
237
|
-
margin: 0,
|
|
238
|
-
marginBottom: theme.space?.[3] || 12,
|
|
239
|
-
color: theme.colors.text,
|
|
240
|
-
paddingBottom: theme.space?.[2] || 8,
|
|
241
|
-
borderBottom: `1px solid ${theme.colors.border}`,
|
|
242
|
-
}}
|
|
243
|
-
>
|
|
244
|
-
{row.title}
|
|
245
|
-
</h2>
|
|
246
|
-
)}
|
|
247
|
-
|
|
248
|
-
{/* Row panels - using CSS Grid with column spans */}
|
|
249
|
-
<div
|
|
250
|
-
style={{
|
|
251
|
-
display: 'grid',
|
|
252
|
-
gridTemplateColumns: `repeat(${gridColumns}, 1fr)`,
|
|
253
|
-
gap: gridGap,
|
|
254
|
-
}}
|
|
255
|
-
>
|
|
256
|
-
{row.panels.map((panel) => {
|
|
257
|
-
const span = getSpan(panel, row.panels.length);
|
|
258
|
-
const metric = metricsMap.get(panel.id);
|
|
259
|
-
|
|
260
|
-
const panelStyle: React.CSSProperties = {
|
|
261
|
-
gridColumn: `span ${span}`,
|
|
262
|
-
minHeight: panel.minHeight,
|
|
263
|
-
height: panel.height === 'auto' ? 'auto' : panel.height,
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
if (!metric) {
|
|
267
|
-
return (
|
|
268
|
-
<div
|
|
269
|
-
key={panel.id}
|
|
270
|
-
style={{
|
|
271
|
-
...panelStyle,
|
|
272
|
-
backgroundColor: theme.colors.surface || theme.colors.background,
|
|
273
|
-
border: `1px solid ${theme.colors.error}`,
|
|
274
|
-
borderRadius: theme.radii?.[2] || 8,
|
|
275
|
-
padding: theme.space?.[3] || 16,
|
|
276
|
-
color: theme.colors.error,
|
|
277
|
-
fontSize: theme.fontSizes[1],
|
|
278
|
-
}}
|
|
279
|
-
>
|
|
280
|
-
Metric not found: {panel.id}
|
|
281
|
-
</div>
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return (
|
|
286
|
-
<div key={panel.id} style={panelStyle}>
|
|
287
|
-
<MetricPanel
|
|
288
|
-
metric={metric}
|
|
289
|
-
data={data[panel.id] || { error: 'No data' }}
|
|
290
|
-
onMetricClick={onMetricClick}
|
|
291
|
-
onSourceClick={handleSourceClick}
|
|
292
|
-
/>
|
|
293
|
-
</div>
|
|
294
|
-
);
|
|
295
|
-
})}
|
|
296
|
-
</div>
|
|
297
|
-
</div>
|
|
298
|
-
))}
|
|
299
|
-
</div>
|
|
300
|
-
|
|
301
|
-
{/* Owner info */}
|
|
302
|
-
{dashboard.owner && (
|
|
303
|
-
<div
|
|
304
|
-
style={{
|
|
305
|
-
marginTop: theme.space?.[5] || 32,
|
|
306
|
-
paddingTop: theme.space?.[3] || 16,
|
|
307
|
-
borderTop: `1px solid ${theme.colors.border}`,
|
|
308
|
-
fontSize: theme.fontSizes[0],
|
|
309
|
-
color: theme.colors.textSecondary,
|
|
310
|
-
}}
|
|
311
|
-
>
|
|
312
|
-
Owner: {dashboard.owner}
|
|
313
|
-
</div>
|
|
314
|
-
)}
|
|
315
|
-
</div>
|
|
316
|
-
);
|
|
317
|
-
}
|