@principal-ai/principal-view-react 0.14.23 → 0.14.24
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/components/GraphRenderer.d.ts.map +1 -1
- package/dist/components/GraphRenderer.js +5 -1
- package/dist/components/GraphRenderer.js.map +1 -1
- package/dist/components/SequenceDiagramRenderer.d.ts.map +1 -1
- package/dist/components/SequenceDiagramRenderer.js +62 -39
- package/dist/components/SequenceDiagramRenderer.js.map +1 -1
- package/dist/hooks/useSequenceLayout.d.ts +1 -1
- package/dist/hooks/useSequenceLayout.d.ts.map +1 -1
- package/dist/hooks/useSequenceLayout.js +28 -4
- package/dist/hooks/useSequenceLayout.js.map +1 -1
- package/package.json +3 -3
- package/src/components/GraphRenderer.tsx +6 -0
- package/src/components/SequenceDiagramRenderer.tsx +84 -45
- package/src/hooks/useSequenceLayout.ts +34 -5
- package/src/stories/RealCanvasFiles.stories.tsx +336 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import '@xyflow/react/dist/style.css';
|
|
4
|
+
import { GraphRenderer } from '../components/GraphRenderer';
|
|
5
|
+
import type { ExtendedCanvas } from '@principal-ai/principal-view-core';
|
|
6
|
+
import { ThemeProvider, defaultEditorTheme } from '@principal-ade/industry-theme';
|
|
7
|
+
|
|
8
|
+
// Import canvas files as URLs
|
|
9
|
+
import scopesCanvasUrl from '../../../../.principal-views/architecture.scopes.canvas?url';
|
|
10
|
+
import spansCanvasUrl from '../../../../.principal-views/architecture.spans.canvas?url';
|
|
11
|
+
import resourcesCanvasUrl from '../../../../.principal-views/resources.canvas?url';
|
|
12
|
+
import matchingLogicCanvasUrl from '../../../../.principal-views/matching-logic-current-state.canvas?url';
|
|
13
|
+
import validationCanvasUrl from '../../../../.principal-views/validation/validation.otel.canvas?url';
|
|
14
|
+
|
|
15
|
+
// Helper to load canvas from URL
|
|
16
|
+
async function loadCanvas(url: string): Promise<ExtendedCanvas> {
|
|
17
|
+
const response = await fetch(url);
|
|
18
|
+
return await response.json();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Wrapper component that loads canvas data
|
|
22
|
+
function CanvasLoader({ url, children }: { url: string; children: (canvas: ExtendedCanvas) => React.ReactNode }) {
|
|
23
|
+
const [canvas, setCanvas] = useState<ExtendedCanvas | null>(null);
|
|
24
|
+
const [error, setError] = useState<string | null>(null);
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
loadCanvas(url)
|
|
28
|
+
.then(setCanvas)
|
|
29
|
+
.catch((err) => setError(err.message));
|
|
30
|
+
}, [url]);
|
|
31
|
+
|
|
32
|
+
if (error) {
|
|
33
|
+
return <div style={{ padding: 20, color: 'red' }}>Error loading canvas: {error}</div>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!canvas) {
|
|
37
|
+
return <div style={{ padding: 20 }}>Loading canvas...</div>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div style={{ width: '100%', height: '100vh' }}>
|
|
42
|
+
{children(canvas)}
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const meta = {
|
|
48
|
+
title: 'Real Canvas Files',
|
|
49
|
+
component: GraphRenderer,
|
|
50
|
+
parameters: {
|
|
51
|
+
layout: 'fullscreen',
|
|
52
|
+
},
|
|
53
|
+
tags: ['autodocs'],
|
|
54
|
+
decorators: [
|
|
55
|
+
(Story) => (
|
|
56
|
+
<ThemeProvider theme={defaultEditorTheme}>
|
|
57
|
+
<div style={{ width: '100vw', height: '100vh' }}>
|
|
58
|
+
<Story />
|
|
59
|
+
</div>
|
|
60
|
+
</ThemeProvider>
|
|
61
|
+
),
|
|
62
|
+
],
|
|
63
|
+
} satisfies Meta<typeof GraphRenderer>;
|
|
64
|
+
|
|
65
|
+
export default meta;
|
|
66
|
+
type Story = StoryObj<typeof meta>;
|
|
67
|
+
|
|
68
|
+
// ============================================================================
|
|
69
|
+
// Architecture Canvas Files
|
|
70
|
+
// ============================================================================
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Scopes Canvas - Documents instrumentation scopes
|
|
74
|
+
*
|
|
75
|
+
* File: .principal-views/architecture.scopes.canvas
|
|
76
|
+
* Type: otel-scope nodes
|
|
77
|
+
* Purpose: Shows OpenTelemetry instrumentation scopes (getTracer calls)
|
|
78
|
+
*/
|
|
79
|
+
export const ScopesCanvas: Story = {
|
|
80
|
+
render: () => (
|
|
81
|
+
<CanvasLoader url={scopesCanvasUrl}>
|
|
82
|
+
{(canvas) => <GraphRenderer canvas={canvas} />}
|
|
83
|
+
</CanvasLoader>
|
|
84
|
+
),
|
|
85
|
+
parameters: {
|
|
86
|
+
docs: {
|
|
87
|
+
description: {
|
|
88
|
+
story: `
|
|
89
|
+
Renders the actual **architecture.scopes.canvas** file from the project.
|
|
90
|
+
|
|
91
|
+
This canvas documents instrumentation scopes using \`otel-scope\` nodes with:
|
|
92
|
+
- Top-level \`type: "otel-scope"\`
|
|
93
|
+
- \`label\` for display name
|
|
94
|
+
- \`otel.scope\` for the scope identifier
|
|
95
|
+
- Circular node shape
|
|
96
|
+
|
|
97
|
+
**Use this to:**
|
|
98
|
+
- Preview how scope architecture canvases render
|
|
99
|
+
- Verify visual changes to scope nodes
|
|
100
|
+
- Test new features on real project files
|
|
101
|
+
`,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Spans Canvas - Defines span naming conventions
|
|
109
|
+
*
|
|
110
|
+
* File: .principal-views/architecture.spans.canvas
|
|
111
|
+
* Type: otel-span-convention nodes
|
|
112
|
+
* Purpose: Documents span patterns and valid parent-child relationships
|
|
113
|
+
*/
|
|
114
|
+
export const SpansCanvas: Story = {
|
|
115
|
+
render: () => (
|
|
116
|
+
<CanvasLoader url={spansCanvasUrl}>
|
|
117
|
+
{(canvas) => <GraphRenderer canvas={canvas} />}
|
|
118
|
+
</CanvasLoader>
|
|
119
|
+
),
|
|
120
|
+
parameters: {
|
|
121
|
+
docs: {
|
|
122
|
+
description: {
|
|
123
|
+
story: `
|
|
124
|
+
Renders the actual **architecture.spans.canvas** file from the project.
|
|
125
|
+
|
|
126
|
+
This canvas defines span naming conventions using \`otel-span-convention\` nodes with:
|
|
127
|
+
- Top-level \`type: "otel-span-convention"\`
|
|
128
|
+
- \`label\` for display name
|
|
129
|
+
- \`otel.spanPattern\` for matching pattern
|
|
130
|
+
- \`otel.spanKind\` for span kind
|
|
131
|
+
- Hexagon shape
|
|
132
|
+
|
|
133
|
+
**Use this to:**
|
|
134
|
+
- Preview how span convention canvases render
|
|
135
|
+
- Verify workflow chips display
|
|
136
|
+
- Test edge relationships between spans
|
|
137
|
+
`,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Resources Canvas - Documents OTEL resources
|
|
145
|
+
*
|
|
146
|
+
* File: .principal-views/resources.canvas
|
|
147
|
+
* Type: Mixed (text nodes and otel-resource nodes)
|
|
148
|
+
* Purpose: Shows service resources and their instrumentation scopes
|
|
149
|
+
*/
|
|
150
|
+
export const ResourcesCanvas: Story = {
|
|
151
|
+
render: () => (
|
|
152
|
+
<CanvasLoader url={resourcesCanvasUrl}>
|
|
153
|
+
{(canvas) => <GraphRenderer canvas={canvas} />}
|
|
154
|
+
</CanvasLoader>
|
|
155
|
+
),
|
|
156
|
+
parameters: {
|
|
157
|
+
docs: {
|
|
158
|
+
description: {
|
|
159
|
+
story: `
|
|
160
|
+
Renders the actual **resources.canvas** file from the project.
|
|
161
|
+
|
|
162
|
+
This canvas documents OTEL resources (service.name) and how they map to instrumentation scopes.
|
|
163
|
+
|
|
164
|
+
**Use this to:**
|
|
165
|
+
- Preview resource topology visualization
|
|
166
|
+
- Test resource node rendering
|
|
167
|
+
- Verify resource → scope relationships
|
|
168
|
+
`,
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// ============================================================================
|
|
175
|
+
// Workflow/Event Canvas Files
|
|
176
|
+
// ============================================================================
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Validation Workflow Canvas - Event-driven workflow
|
|
180
|
+
*
|
|
181
|
+
* File: .principal-views/validation/validation.otel.canvas
|
|
182
|
+
* Type: otel-event nodes
|
|
183
|
+
* Purpose: Documents validation pipeline events and transitions
|
|
184
|
+
*/
|
|
185
|
+
export const ValidationOtelCanvas: Story = {
|
|
186
|
+
render: () => (
|
|
187
|
+
<CanvasLoader url={validationCanvasUrl}>
|
|
188
|
+
{(canvas) => <GraphRenderer canvas={canvas} />}
|
|
189
|
+
</CanvasLoader>
|
|
190
|
+
),
|
|
191
|
+
parameters: {
|
|
192
|
+
docs: {
|
|
193
|
+
description: {
|
|
194
|
+
story: `
|
|
195
|
+
Renders the actual **validation.otel.canvas** file from the project.
|
|
196
|
+
|
|
197
|
+
This canvas shows the validation pipeline workflow using \`otel-event\` nodes with:
|
|
198
|
+
- Top-level \`type: "otel-event"\`
|
|
199
|
+
- \`label\` for display name
|
|
200
|
+
- \`event.name\` for the event identifier
|
|
201
|
+
- \`event.attributes\` for event schema
|
|
202
|
+
- Rectangle/rounded shapes
|
|
203
|
+
|
|
204
|
+
**Use this to:**
|
|
205
|
+
- Preview workflow event canvases
|
|
206
|
+
- Test event node rendering
|
|
207
|
+
- Verify event schema tooltips
|
|
208
|
+
`,
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// ============================================================================
|
|
215
|
+
// General Canvas Files
|
|
216
|
+
// ============================================================================
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Matching Logic Canvas - Planning/documentation canvas
|
|
220
|
+
*
|
|
221
|
+
* File: .principal-views/matching-logic-current-state.canvas
|
|
222
|
+
* Type: Regular canvas (text nodes with pv extensions)
|
|
223
|
+
* Purpose: Documents implementation status and architecture planning
|
|
224
|
+
*/
|
|
225
|
+
export const MatchingLogicCanvas: Story = {
|
|
226
|
+
render: () => (
|
|
227
|
+
<CanvasLoader url={matchingLogicCanvasUrl}>
|
|
228
|
+
{(canvas) => <GraphRenderer canvas={canvas} />}
|
|
229
|
+
</CanvasLoader>
|
|
230
|
+
),
|
|
231
|
+
parameters: {
|
|
232
|
+
docs: {
|
|
233
|
+
description: {
|
|
234
|
+
story: `
|
|
235
|
+
Renders the actual **matching-logic-current-state.canvas** file from the project.
|
|
236
|
+
|
|
237
|
+
This is a regular \`.canvas\` file used for architecture planning and implementation tracking.
|
|
238
|
+
Uses standard JSON Canvas \`text\` nodes with \`pv\` extensions for:
|
|
239
|
+
- Custom node types (\`pv.nodeType\`)
|
|
240
|
+
- Visual styling (\`pv.shape\`, \`pv.fill\`, \`pv.stroke\`)
|
|
241
|
+
- References to code files (\`pv.references\`)
|
|
242
|
+
|
|
243
|
+
**Use this to:**
|
|
244
|
+
- Preview general-purpose canvas files
|
|
245
|
+
- Test pv extension rendering
|
|
246
|
+
- Verify backward compatibility with old format
|
|
247
|
+
`,
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// ============================================================================
|
|
254
|
+
// Combined View - All Canvas Files Side by Side
|
|
255
|
+
// ============================================================================
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* All Canvas Files - Side by side comparison
|
|
259
|
+
*/
|
|
260
|
+
export const AllCanvasTypes: Story = {
|
|
261
|
+
render: () => {
|
|
262
|
+
const [canvases, setCanvases] = useState<{
|
|
263
|
+
scopes?: ExtendedCanvas;
|
|
264
|
+
spans?: ExtendedCanvas;
|
|
265
|
+
resources?: ExtendedCanvas;
|
|
266
|
+
validation?: ExtendedCanvas;
|
|
267
|
+
matching?: ExtendedCanvas;
|
|
268
|
+
}>({});
|
|
269
|
+
|
|
270
|
+
useEffect(() => {
|
|
271
|
+
Promise.all([
|
|
272
|
+
loadCanvas(scopesCanvasUrl),
|
|
273
|
+
loadCanvas(spansCanvasUrl),
|
|
274
|
+
loadCanvas(resourcesCanvasUrl),
|
|
275
|
+
loadCanvas(validationCanvasUrl),
|
|
276
|
+
loadCanvas(matchingLogicCanvasUrl),
|
|
277
|
+
]).then(([scopes, spans, resources, validation, matching]) => {
|
|
278
|
+
setCanvases({ scopes, spans, resources, validation, matching });
|
|
279
|
+
});
|
|
280
|
+
}, []);
|
|
281
|
+
|
|
282
|
+
if (!canvases.scopes) {
|
|
283
|
+
return <div style={{ padding: 20 }}>Loading all canvases...</div>;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return (
|
|
287
|
+
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '20px', padding: '20px' }}>
|
|
288
|
+
<div>
|
|
289
|
+
<h3 style={{ marginTop: 0 }}>Scopes Canvas</h3>
|
|
290
|
+
<div style={{ height: '300px', border: '1px solid #ccc' }}>
|
|
291
|
+
<GraphRenderer canvas={canvases.scopes} />
|
|
292
|
+
</div>
|
|
293
|
+
</div>
|
|
294
|
+
<div>
|
|
295
|
+
<h3 style={{ marginTop: 0 }}>Spans Canvas</h3>
|
|
296
|
+
<div style={{ height: '300px', border: '1px solid #ccc' }}>
|
|
297
|
+
{canvases.spans && <GraphRenderer canvas={canvases.spans} />}
|
|
298
|
+
</div>
|
|
299
|
+
</div>
|
|
300
|
+
<div>
|
|
301
|
+
<h3 style={{ marginTop: 0 }}>Resources Canvas</h3>
|
|
302
|
+
<div style={{ height: '300px', border: '1px solid #ccc' }}>
|
|
303
|
+
{canvases.resources && <GraphRenderer canvas={canvases.resources} />}
|
|
304
|
+
</div>
|
|
305
|
+
</div>
|
|
306
|
+
<div>
|
|
307
|
+
<h3 style={{ marginTop: 0 }}>Validation (OTEL Events)</h3>
|
|
308
|
+
<div style={{ height: '300px', border: '1px solid #ccc' }}>
|
|
309
|
+
{canvases.validation && <GraphRenderer canvas={canvases.validation} />}
|
|
310
|
+
</div>
|
|
311
|
+
</div>
|
|
312
|
+
<div style={{ gridColumn: '1 / -1' }}>
|
|
313
|
+
<h3 style={{ marginTop: 0 }}>Matching Logic (Regular Canvas)</h3>
|
|
314
|
+
<div style={{ height: '400px', border: '1px solid #ccc' }}>
|
|
315
|
+
{canvases.matching && <GraphRenderer canvas={canvases.matching} />}
|
|
316
|
+
</div>
|
|
317
|
+
</div>
|
|
318
|
+
</div>
|
|
319
|
+
);
|
|
320
|
+
},
|
|
321
|
+
parameters: {
|
|
322
|
+
docs: {
|
|
323
|
+
description: {
|
|
324
|
+
story: `
|
|
325
|
+
Shows all canvas file types rendered side by side for comparison.
|
|
326
|
+
|
|
327
|
+
This view helps:
|
|
328
|
+
- Compare visual styling across different canvas types
|
|
329
|
+
- Test layout consistency
|
|
330
|
+
- Verify theme application
|
|
331
|
+
- Spot visual regressions quickly
|
|
332
|
+
`,
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
};
|