@principal-ai/subsystems-react 0.56.40 → 0.56.41
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 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/subsystem/C4ContainersPanel.d.ts +32 -2
- package/dist/subsystem/C4ContainersPanel.d.ts.map +1 -1
- package/dist/subsystem/C4ContainersPanel.js +89 -21
- package/dist/subsystem/C4ContainersPanel.js.map +1 -1
- package/dist/subsystem/C4Graph.d.ts +13 -0
- package/dist/subsystem/C4Graph.d.ts.map +1 -1
- package/dist/subsystem/C4Graph.js +19 -2
- package/dist/subsystem/C4Graph.js.map +1 -1
- package/dist/subsystem/C4NodeCard.d.ts +15 -2
- package/dist/subsystem/C4NodeCard.d.ts.map +1 -1
- package/dist/subsystem/C4NodeCard.js +124 -7
- package/dist/subsystem/C4NodeCard.js.map +1 -1
- package/dist/subsystem/C4ProjectionView.d.ts +8 -1
- package/dist/subsystem/C4ProjectionView.d.ts.map +1 -1
- package/dist/subsystem/C4ProjectionView.js +3 -3
- package/dist/subsystem/C4ProjectionView.js.map +1 -1
- package/dist/subsystem/C4SketchView.d.ts +9 -1
- package/dist/subsystem/C4SketchView.d.ts.map +1 -1
- package/dist/subsystem/C4SketchView.js +2 -2
- package/dist/subsystem/C4SketchView.js.map +1 -1
- package/dist/subsystem/__fixtures__/c4Deployments.d.ts +18 -0
- package/dist/subsystem/__fixtures__/c4Deployments.d.ts.map +1 -0
- package/dist/subsystem/__fixtures__/c4Deployments.js +185 -0
- package/dist/subsystem/__fixtures__/c4Deployments.js.map +1 -0
- package/dist/subsystem/c4.d.ts +63 -0
- package/dist/subsystem/c4.d.ts.map +1 -1
- package/dist/subsystem/c4.js.map +1 -1
- package/dist/subsystem/c4Deployment.d.ts +78 -0
- package/dist/subsystem/c4Deployment.d.ts.map +1 -0
- package/dist/subsystem/c4Deployment.js +68 -0
- package/dist/subsystem/c4Deployment.js.map +1 -0
- package/dist/subsystem/techIcons/cloudflare.d.ts +15 -0
- package/dist/subsystem/techIcons/cloudflare.d.ts.map +1 -0
- package/dist/subsystem/techIcons/cloudflare.js +15 -0
- package/dist/subsystem/techIcons/cloudflare.js.map +1 -0
- package/dist/subsystem/techIcons/index.d.ts +14 -1
- package/dist/subsystem/techIcons/index.d.ts.map +1 -1
- package/dist/subsystem/techIcons/index.js +17 -0
- package/dist/subsystem/techIcons/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +25 -1
- package/src/stories/Canvases/C4/C4Sketch.stories.tsx +51 -0
- package/src/subsystem/C4ContainersPanel.test.tsx +90 -2
- package/src/subsystem/C4ContainersPanel.tsx +142 -35
- package/src/subsystem/C4Graph.tsx +49 -3
- package/src/subsystem/C4NodeCard.tsx +217 -7
- package/src/subsystem/C4ProjectionView.tsx +12 -0
- package/src/subsystem/C4SketchView.tsx +13 -0
- package/src/subsystem/__fixtures__/c4Deployments.ts +196 -0
- package/src/subsystem/c4.ts +62 -0
- package/src/subsystem/c4Deployment.test.tsx +211 -0
- package/src/subsystem/c4Deployment.tsx +137 -0
- package/src/subsystem/techIcons/cloudflare.ts +14 -0
- package/src/subsystem/techIcons/index.tsx +30 -1
- package/src/subsystem/techIcons/techIcons.test.ts +12 -2
|
@@ -15,12 +15,15 @@ import { useTheme } from '@principal-ade/industry-theme';
|
|
|
15
15
|
import { ChevronRight, Component, Database, AppWindow } from 'lucide-react';
|
|
16
16
|
import { Fragment } from 'react';
|
|
17
17
|
import type { CSSProperties } from 'react';
|
|
18
|
-
import type { C4Component, C4Container } from './c4';
|
|
18
|
+
import type { C4Component, C4Container, C4DeploymentObservation } from './c4';
|
|
19
|
+
import { elementStanding } from './c4Deployment';
|
|
19
20
|
import { nodeKindIcon, nodeStyle, nodeTechnology } from './C4NodeCard';
|
|
20
|
-
import { TechMark, technologyBrand } from './techIcons';
|
|
21
|
+
import { TechMark, providerBrand, technologyBrand } from './techIcons';
|
|
21
22
|
|
|
22
23
|
/** One row height for containers and their members, so the dropdown stays tabular. */
|
|
23
24
|
const ROW_HEIGHT = 38;
|
|
25
|
+
/** A container row that also states its technology: two stacked lines. */
|
|
26
|
+
const STACKED_ROW_HEIGHT = 50;
|
|
24
27
|
|
|
25
28
|
export interface C4ContainerListItem {
|
|
26
29
|
/** Element id — the container the canvas toggles and frames. */
|
|
@@ -41,6 +44,68 @@ export interface C4ContainersPanelProps {
|
|
|
41
44
|
onSelect: (id: string) => void;
|
|
42
45
|
onOpenAll: () => void;
|
|
43
46
|
onCloseAll: () => void;
|
|
47
|
+
/**
|
|
48
|
+
* Live-deployment observations keyed by `resourceKey`. Containers observed
|
|
49
|
+
* running are grouped under the provider they run on.
|
|
50
|
+
*/
|
|
51
|
+
deployments?: ReadonlyMap<string, C4DeploymentObservation>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* One section of the list.
|
|
56
|
+
*
|
|
57
|
+
* - `provider` — containers observed running there. Where it runs is the
|
|
58
|
+
* heading, so the rows need no per-row tag.
|
|
59
|
+
* - `proposed` — unconfirmed hypotheses running nowhere we have observed.
|
|
60
|
+
* - `settled` — accepted (or rejected) and not observed running. Drawn
|
|
61
|
+
* first and without a heading: nothing about it needs calling out.
|
|
62
|
+
*/
|
|
63
|
+
export interface C4ContainerGroup {
|
|
64
|
+
key: string;
|
|
65
|
+
kind: 'settled' | 'provider' | 'proposed';
|
|
66
|
+
/** The provider id, on a `provider` group. */
|
|
67
|
+
provider?: string;
|
|
68
|
+
items: C4ContainerListItem[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Group containers by where they are deployed.
|
|
73
|
+
*
|
|
74
|
+
* Only an observation that says `deployed` places a container under a
|
|
75
|
+
* provider: one that is merely configured for Cloudflare is still a
|
|
76
|
+
* hypothesis and stays under `proposed`. Order within a group is the caller's;
|
|
77
|
+
* provider groups appear in first-seen order.
|
|
78
|
+
*/
|
|
79
|
+
export function groupContainersByDeployment(
|
|
80
|
+
containers: readonly C4ContainerListItem[],
|
|
81
|
+
deployments?: ReadonlyMap<string, C4DeploymentObservation>,
|
|
82
|
+
): C4ContainerGroup[] {
|
|
83
|
+
const settled: C4ContainerListItem[] = [];
|
|
84
|
+
const proposed: C4ContainerListItem[] = [];
|
|
85
|
+
const providers = new Map<string, C4ContainerListItem[]>();
|
|
86
|
+
for (const item of containers) {
|
|
87
|
+
const deployment = item.container.deployment;
|
|
88
|
+
const observation = deployment ? deployments?.get(deployment.resourceKey) : undefined;
|
|
89
|
+
if (deployment && observation?.status === 'deployed') {
|
|
90
|
+
const list = providers.get(deployment.provider) ?? [];
|
|
91
|
+
list.push(item);
|
|
92
|
+
providers.set(deployment.provider, list);
|
|
93
|
+
} else if (elementStanding(item.container, observation) === 'proposed') {
|
|
94
|
+
proposed.push(item);
|
|
95
|
+
} else {
|
|
96
|
+
settled.push(item);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return [
|
|
100
|
+
...(settled.length > 0 ? [{ key: 'settled', kind: 'settled' as const, items: settled }] : []),
|
|
101
|
+
...[...providers].map(([provider, items]) => ({
|
|
102
|
+
key: `provider:${provider}`,
|
|
103
|
+
kind: 'provider' as const,
|
|
104
|
+
provider,
|
|
105
|
+
items,
|
|
106
|
+
})),
|
|
107
|
+
...(proposed.length > 0 ? [{ key: 'proposed', kind: 'proposed' as const, items: proposed }] : []),
|
|
108
|
+
];
|
|
44
109
|
}
|
|
45
110
|
|
|
46
111
|
export function C4ContainersPanel({
|
|
@@ -50,6 +115,7 @@ export function C4ContainersPanel({
|
|
|
50
115
|
onSelect,
|
|
51
116
|
onOpenAll,
|
|
52
117
|
onCloseAll,
|
|
118
|
+
deployments,
|
|
53
119
|
}: C4ContainersPanelProps) {
|
|
54
120
|
const { theme } = useTheme();
|
|
55
121
|
const muted = theme.colors.textMuted ?? theme.colors.textSecondary;
|
|
@@ -124,32 +190,67 @@ export function C4ContainersPanel({
|
|
|
124
190
|
aria-label="Containers"
|
|
125
191
|
style={{ listStyle: 'none', margin: 0, padding: '6px 0', overflow: 'auto', minHeight: 0 }}
|
|
126
192
|
>
|
|
127
|
-
{containers.map((
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
193
|
+
{groupContainersByDeployment(containers, deployments).map((group) => (
|
|
194
|
+
<Fragment key={group.key}>
|
|
195
|
+
<GroupHeading group={group} />
|
|
196
|
+
{group.items.map((item) => {
|
|
197
|
+
const canToggle = item.members.length > 0;
|
|
198
|
+
return (
|
|
199
|
+
<Fragment key={item.container.id}>
|
|
200
|
+
<ContainerRow
|
|
201
|
+
item={item}
|
|
202
|
+
active={item.container.id === activeId}
|
|
203
|
+
canToggle={canToggle}
|
|
204
|
+
onActivate={() =>
|
|
205
|
+
canToggle ? onActivate(item.container.id) : onSelect(item.container.id)
|
|
206
|
+
}
|
|
207
|
+
/>
|
|
208
|
+
{item.open &&
|
|
209
|
+
item.members.map((member) => (
|
|
210
|
+
<ContainerMemberRow key={member.id} component={member} />
|
|
211
|
+
))}
|
|
212
|
+
</Fragment>
|
|
213
|
+
);
|
|
214
|
+
})}
|
|
215
|
+
</Fragment>
|
|
216
|
+
))}
|
|
148
217
|
</ul>
|
|
149
218
|
</div>
|
|
150
219
|
);
|
|
151
220
|
}
|
|
152
221
|
|
|
222
|
+
/**
|
|
223
|
+
* The line above a group: the provider's mark and name for a deployed group,
|
|
224
|
+
* or "Proposed". A settled group has none.
|
|
225
|
+
*/
|
|
226
|
+
function GroupHeading({ group }: { group: C4ContainerGroup }) {
|
|
227
|
+
const { theme } = useTheme();
|
|
228
|
+
const muted = theme.colors.textMuted ?? theme.colors.textSecondary;
|
|
229
|
+
if (group.kind === 'settled') return null;
|
|
230
|
+
const brand = group.kind === 'provider' ? providerBrand(group.provider) : undefined;
|
|
231
|
+
const label = group.kind === 'provider' ? brand?.name ?? group.provider! : 'Proposed';
|
|
232
|
+
return (
|
|
233
|
+
<li
|
|
234
|
+
data-container-group={group.key}
|
|
235
|
+
style={{
|
|
236
|
+
display: 'flex',
|
|
237
|
+
alignItems: 'center',
|
|
238
|
+
gap: 6,
|
|
239
|
+
padding: '10px 12px 4px',
|
|
240
|
+
fontFamily: theme.fonts.monospace,
|
|
241
|
+
fontSize: theme.fontSizes[0],
|
|
242
|
+
letterSpacing: 0.5,
|
|
243
|
+
textTransform: 'uppercase',
|
|
244
|
+
color: group.kind === 'proposed' ? '#e3b341' : theme.colors.textSecondary,
|
|
245
|
+
}}
|
|
246
|
+
>
|
|
247
|
+
{brand && <TechMark brand={brand} size={16} showTitle={false} />}
|
|
248
|
+
<span style={{ flex: 1 }}>{label}</span>
|
|
249
|
+
<span style={{ color: muted }}>{group.items.length}</span>
|
|
250
|
+
</li>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
153
254
|
function ContainerRow({
|
|
154
255
|
item,
|
|
155
256
|
active,
|
|
@@ -166,7 +267,7 @@ function ContainerRow({
|
|
|
166
267
|
const { container, open } = item;
|
|
167
268
|
const Icon = nodeKindIcon(container) ?? (container.containerKind === 'data-store' ? Database : AppWindow);
|
|
168
269
|
const brand = technologyBrand(nodeTechnology(container) ?? container.containerKind);
|
|
169
|
-
const
|
|
270
|
+
const technology = nodeTechnology(container)?.trim();
|
|
170
271
|
|
|
171
272
|
return (
|
|
172
273
|
<li
|
|
@@ -177,7 +278,7 @@ function ContainerRow({
|
|
|
177
278
|
display: 'flex',
|
|
178
279
|
alignItems: 'center',
|
|
179
280
|
gap: 8,
|
|
180
|
-
height: ROW_HEIGHT,
|
|
281
|
+
height: technology ? STACKED_ROW_HEIGHT : ROW_HEIGHT,
|
|
181
282
|
boxSizing: 'border-box',
|
|
182
283
|
padding: '0 12px',
|
|
183
284
|
} as CSSProperties
|
|
@@ -226,8 +327,9 @@ function ContainerRow({
|
|
|
226
327
|
gridColumn: 2,
|
|
227
328
|
gridRow: 1,
|
|
228
329
|
display: 'flex',
|
|
229
|
-
|
|
230
|
-
|
|
330
|
+
flexDirection: 'column',
|
|
331
|
+
justifyContent: 'center',
|
|
332
|
+
gap: 2,
|
|
231
333
|
fontSize: theme.fontSizes[2],
|
|
232
334
|
fontWeight: 600,
|
|
233
335
|
lineHeight: 1.35,
|
|
@@ -243,21 +345,26 @@ function ContainerRow({
|
|
|
243
345
|
>
|
|
244
346
|
{container.label}
|
|
245
347
|
</span>
|
|
246
|
-
{
|
|
348
|
+
{technology && (
|
|
349
|
+
// The technology under the name, as on the card's top row. It is what
|
|
350
|
+
// tells apart two containers that share a label (a Worker and the
|
|
351
|
+
// bucket named after it).
|
|
247
352
|
<span
|
|
353
|
+
data-container-technology
|
|
248
354
|
style={{
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
color:
|
|
355
|
+
overflow: 'hidden',
|
|
356
|
+
textOverflow: 'ellipsis',
|
|
357
|
+
whiteSpace: 'nowrap',
|
|
358
|
+
lineHeight: 1.2,
|
|
359
|
+
color: muted,
|
|
254
360
|
fontFamily: theme.fonts.monospace,
|
|
255
|
-
fontSize:
|
|
361
|
+
fontSize: theme.fontSizes[0],
|
|
362
|
+
fontWeight: 400,
|
|
256
363
|
letterSpacing: 0.4,
|
|
257
364
|
textTransform: 'uppercase',
|
|
258
365
|
}}
|
|
259
366
|
>
|
|
260
|
-
|
|
367
|
+
{technology}
|
|
261
368
|
</span>
|
|
262
369
|
)}
|
|
263
370
|
</span>
|
|
@@ -46,6 +46,14 @@ import {
|
|
|
46
46
|
nodeStyle,
|
|
47
47
|
} from './C4NodeCard';
|
|
48
48
|
import { TechMark, technologyBrand } from './techIcons';
|
|
49
|
+
import {
|
|
50
|
+
C4DeploymentContext,
|
|
51
|
+
elementDeployment,
|
|
52
|
+
resolveDeploymentView,
|
|
53
|
+
useC4Deployments,
|
|
54
|
+
} from './c4Deployment';
|
|
55
|
+
import type { C4DeploymentContextValue } from './c4Deployment';
|
|
56
|
+
import type { C4DeploymentObservation } from './c4';
|
|
49
57
|
import {
|
|
50
58
|
absoluteRectOf,
|
|
51
59
|
diffLayoutRects,
|
|
@@ -233,6 +241,17 @@ export interface C4GraphProps {
|
|
|
233
241
|
* @default 28
|
|
234
242
|
*/
|
|
235
243
|
gutter?: number;
|
|
244
|
+
/**
|
|
245
|
+
* Live-deployment observations keyed by `resourceKey`, joined to each
|
|
246
|
+
* container's `deployment` anchor. A container with an anchor and no
|
|
247
|
+
* observation still draws its provider mark, as configured-only.
|
|
248
|
+
*/
|
|
249
|
+
deployments?: ReadonlyMap<string, C4DeploymentObservation>;
|
|
250
|
+
/**
|
|
251
|
+
* Open a deployment link outside the app. Without it the provider mark is
|
|
252
|
+
* drawn but no links are.
|
|
253
|
+
*/
|
|
254
|
+
onOpenExternal?: C4DeploymentContextValue['onOpenExternal'];
|
|
236
255
|
}
|
|
237
256
|
|
|
238
257
|
function C4NodeView(
|
|
@@ -283,6 +302,14 @@ function C4NodeView(
|
|
|
283
302
|
} = props.data;
|
|
284
303
|
const grown = open === true;
|
|
285
304
|
|
|
305
|
+
// Deployment state comes through context, not node data: an observation
|
|
306
|
+
// refreshing must not rebuild the nodes or re-run layout.
|
|
307
|
+
const { observations, onOpenExternal } = useC4Deployments();
|
|
308
|
+
const deployment = elementDeployment(element);
|
|
309
|
+
const deploymentView = deployment
|
|
310
|
+
? resolveDeploymentView(deployment, observations?.get(deployment.resourceKey))
|
|
311
|
+
: undefined;
|
|
312
|
+
|
|
286
313
|
// Position-only FLIP. The card resizes through its own `width`/`height`
|
|
287
314
|
// transition, so scaling here would distort the text and fight that transition.
|
|
288
315
|
// A card that only changed *size* has nothing to slide — no transform and no
|
|
@@ -335,6 +362,18 @@ function C4NodeView(
|
|
|
335
362
|
showDescription={showDescriptionFor(open, settled)}
|
|
336
363
|
transitionDelayMs={moveDelayMs}
|
|
337
364
|
sizeTransitionMs={MORPH_MS}
|
|
365
|
+
deploymentView={deploymentView}
|
|
366
|
+
onOpenDeployment={
|
|
367
|
+
deployment && onOpenExternal
|
|
368
|
+
? (kind, url) =>
|
|
369
|
+
onOpenExternal({
|
|
370
|
+
url,
|
|
371
|
+
kind,
|
|
372
|
+
elementId: element.id,
|
|
373
|
+
resourceKey: deployment.resourceKey,
|
|
374
|
+
})
|
|
375
|
+
: undefined
|
|
376
|
+
}
|
|
338
377
|
handles={
|
|
339
378
|
<>
|
|
340
379
|
<Handle type="target" position={Position.Left} style={{ opacity: 0 }} />
|
|
@@ -2725,9 +2764,16 @@ function Inner({ model, containerFocus, selectedNodeId, selectedEdgeId: controll
|
|
|
2725
2764
|
}
|
|
2726
2765
|
|
|
2727
2766
|
export function C4Graph(props: C4GraphProps) {
|
|
2767
|
+
const { deployments, onOpenExternal } = props;
|
|
2768
|
+
const deploymentContext = useMemo(
|
|
2769
|
+
() => ({ observations: deployments, onOpenExternal }),
|
|
2770
|
+
[deployments, onOpenExternal],
|
|
2771
|
+
);
|
|
2728
2772
|
return (
|
|
2729
|
-
<
|
|
2730
|
-
<
|
|
2731
|
-
|
|
2773
|
+
<C4DeploymentContext.Provider value={deploymentContext}>
|
|
2774
|
+
<ReactFlowProvider>
|
|
2775
|
+
<Inner {...props} />
|
|
2776
|
+
</ReactFlowProvider>
|
|
2777
|
+
</C4DeploymentContext.Provider>
|
|
2732
2778
|
);
|
|
2733
2779
|
}
|
|
@@ -12,11 +12,13 @@
|
|
|
12
12
|
* wants it: technology on the top row, description under the label.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
import { useState } from 'react';
|
|
15
16
|
import { useTheme } from '@principal-ade/industry-theme';
|
|
16
|
-
import { AppWindow, Component, Database, Maximize2 } from 'lucide-react';
|
|
17
|
+
import { AppWindow, CloudCog, Component, Database, Globe, Maximize2 } from 'lucide-react';
|
|
17
18
|
import type { LucideIcon } from 'lucide-react';
|
|
18
|
-
import { technologyBrand } from './techIcons';
|
|
19
|
+
import { TechMark, providerBrand, technologyBrand } from './techIcons';
|
|
19
20
|
import type { C4Element } from './c4';
|
|
21
|
+
import type { C4DeploymentLinkKind, C4DeploymentView } from './c4Deployment';
|
|
20
22
|
import {
|
|
21
23
|
CARD_GAP,
|
|
22
24
|
CARD_PAD_Y,
|
|
@@ -114,7 +116,7 @@ export function descriptionLineBudget(opts: {
|
|
|
114
116
|
/** The card's border, which sits above the content and varies by kind. */
|
|
115
117
|
borderWidth: number;
|
|
116
118
|
hasTechRow: boolean;
|
|
117
|
-
/** Whether
|
|
119
|
+
/** Whether anything is drawn in the footer band — the expand affordance or the deployment badge. */
|
|
118
120
|
reservesFooter: boolean;
|
|
119
121
|
}): number {
|
|
120
122
|
const { reservedHeight, lineHeight, borderWidth, hasTechRow, reservesFooter } = opts;
|
|
@@ -370,12 +372,45 @@ export interface C4NodeCardProps {
|
|
|
370
372
|
* @default 420
|
|
371
373
|
*/
|
|
372
374
|
sizeTransitionMs?: number;
|
|
375
|
+
/**
|
|
376
|
+
* Where this container is deployed, already resolved against the host's
|
|
377
|
+
* observation. Draws the provider mark bottom-left; absent → nothing drawn.
|
|
378
|
+
*/
|
|
379
|
+
deploymentView?: C4DeploymentView;
|
|
380
|
+
/**
|
|
381
|
+
* Follow a deployment link. The card never navigates itself; without this
|
|
382
|
+
* the mark is drawn but the links are not.
|
|
383
|
+
*/
|
|
384
|
+
onOpenDeployment?: (kind: C4DeploymentLinkKind, url: string) => void;
|
|
373
385
|
}
|
|
374
386
|
|
|
375
|
-
|
|
387
|
+
/** One line saying what the deployment badge means, for its tooltip. */
|
|
388
|
+
export function deploymentSummary(view: C4DeploymentView): string {
|
|
389
|
+
const { deployment, phase, observation } = view;
|
|
390
|
+
const provider = providerBrand(deployment.provider)?.name ?? deployment.provider;
|
|
391
|
+
const what = `${deployment.resourceType} ${deployment.name}`;
|
|
392
|
+
if (phase === 'deployed') {
|
|
393
|
+
return `Deployed on ${provider} · ${what} · observed ${observation!.observedAt}`;
|
|
394
|
+
}
|
|
395
|
+
if (phase === 'not-found') {
|
|
396
|
+
return `Declared for ${provider} but not found · ${what} · checked ${observation!.observedAt}`;
|
|
397
|
+
}
|
|
398
|
+
const where = deployment.source ? ` in ${deployment.source.file}` : '';
|
|
399
|
+
return `Configured for ${provider}${where} · ${what} · live state not checked`;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export function C4NodeCard({ node, selected = false, handles, onClick, componentCount = 0, onExpand, width, height, showDescription = true, children, transitionDelayMs = 0, sizeTransitionMs = 420, deploymentView, onOpenDeployment }: C4NodeCardProps) {
|
|
376
403
|
const { theme } = useTheme();
|
|
377
404
|
const muted = theme.colors.textMuted ?? theme.colors.textSecondary;
|
|
378
|
-
|
|
405
|
+
// A proposed element observed running is no longer a hypothesis, so it draws
|
|
406
|
+
// with the solid border of something confirmed. Derived, never stored: the
|
|
407
|
+
// dash comes back by itself if the observation stops saying `deployed`.
|
|
408
|
+
const confirmedByDeployment = node.state === 'proposed' && deploymentView?.phase === 'deployed';
|
|
409
|
+
const style = nodeStyle(
|
|
410
|
+
confirmedByDeployment ? { ...node, state: 'accepted' } : node,
|
|
411
|
+
theme,
|
|
412
|
+
selected,
|
|
413
|
+
);
|
|
379
414
|
const shape = nodeShape(node);
|
|
380
415
|
const Icon = nodeKindIcon(node);
|
|
381
416
|
const brand = technologyBrand(nodeTechnology(node));
|
|
@@ -403,8 +438,8 @@ export function C4NodeCard({ node, selected = false, handles, onClick, component
|
|
|
403
438
|
lineHeight: descLineHeightPx,
|
|
404
439
|
borderWidth: style.width,
|
|
405
440
|
hasTechRow,
|
|
406
|
-
// The
|
|
407
|
-
reservesFooter: !!onExpand,
|
|
441
|
+
// The footer band holds the expand affordance and the deployment badge.
|
|
442
|
+
reservesFooter: !!onExpand || !!deploymentView,
|
|
408
443
|
});
|
|
409
444
|
const centered = shape.align === 'center';
|
|
410
445
|
// The pill's inset is a separate concern from alignment, and a centred
|
|
@@ -512,7 +547,182 @@ export function C4NodeCard({ node, selected = false, handles, onClick, component
|
|
|
512
547
|
<Maximize2 size={13} strokeWidth={2.25} />
|
|
513
548
|
</button>
|
|
514
549
|
)}
|
|
550
|
+
{deploymentView && (
|
|
551
|
+
<DeploymentBadge
|
|
552
|
+
view={deploymentView}
|
|
553
|
+
onOpen={onOpenDeployment}
|
|
554
|
+
surface={theme.colors.backgroundSecondary ?? theme.colors.background}
|
|
555
|
+
muted={muted}
|
|
556
|
+
error={theme.colors.error}
|
|
557
|
+
/>
|
|
558
|
+
)}
|
|
515
559
|
{handles}
|
|
516
560
|
</div>
|
|
517
561
|
);
|
|
518
562
|
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Where a container runs: the provider's mark, then a link for each place a
|
|
566
|
+
* reader can go. Bottom-left, mirroring the expand affordance's box so the two
|
|
567
|
+
* share one footer band.
|
|
568
|
+
*
|
|
569
|
+
* The links are inline rather than in a menu because the card clips its
|
|
570
|
+
* overflow (its height is a contract with the layout), so a popover anchored
|
|
571
|
+
* here would be cut off.
|
|
572
|
+
*/
|
|
573
|
+
function DeploymentBadge({
|
|
574
|
+
view,
|
|
575
|
+
onOpen,
|
|
576
|
+
surface,
|
|
577
|
+
muted,
|
|
578
|
+
error,
|
|
579
|
+
}: {
|
|
580
|
+
view: C4DeploymentView;
|
|
581
|
+
onOpen?: (kind: C4DeploymentLinkKind, url: string) => void;
|
|
582
|
+
surface: string;
|
|
583
|
+
muted: string;
|
|
584
|
+
error: string;
|
|
585
|
+
}) {
|
|
586
|
+
const brand = providerBrand(view.deployment.provider);
|
|
587
|
+
const live = view.phase === 'deployed';
|
|
588
|
+
const frame = live ? brand?.color ?? muted : view.phase === 'not-found' ? error : muted;
|
|
589
|
+
const links: Array<{ kind: C4DeploymentLinkKind; url: string; label: string; Icon: LucideIcon }> = [];
|
|
590
|
+
if (onOpen && view.liveUrl) {
|
|
591
|
+
links.push({ kind: 'live', url: view.liveUrl, label: 'Open live deployment', Icon: Globe });
|
|
592
|
+
}
|
|
593
|
+
if (onOpen && view.consoleUrl) {
|
|
594
|
+
links.push({
|
|
595
|
+
kind: 'console',
|
|
596
|
+
url: view.consoleUrl,
|
|
597
|
+
label: `Open in ${brand?.name ?? view.deployment.provider}`,
|
|
598
|
+
// Not `LayoutDashboard`: Studio uses that glyph for a subsystem model.
|
|
599
|
+
Icon: CloudCog,
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
// One joined pill, not a row of separate boxes: the provider's mark is the
|
|
603
|
+
// label of the group and the links are its actions, so they share a single
|
|
604
|
+
// frame. The mark sits on a tint and has no border of its own — it is
|
|
605
|
+
// context, and must not read as something to press.
|
|
606
|
+
const segment = {
|
|
607
|
+
display: 'inline-flex',
|
|
608
|
+
alignItems: 'center',
|
|
609
|
+
justifyContent: 'center',
|
|
610
|
+
height: '100%',
|
|
611
|
+
boxSizing: 'border-box',
|
|
612
|
+
} as const;
|
|
613
|
+
return (
|
|
614
|
+
<span
|
|
615
|
+
data-deployment-phase={view.phase}
|
|
616
|
+
style={{
|
|
617
|
+
position: 'absolute',
|
|
618
|
+
left: TOGGLE_INSET,
|
|
619
|
+
bottom: TOGGLE_INSET,
|
|
620
|
+
display: 'inline-flex',
|
|
621
|
+
alignItems: 'stretch',
|
|
622
|
+
height: TOGGLE_SIZE,
|
|
623
|
+
boxSizing: 'border-box',
|
|
624
|
+
borderRadius: 4,
|
|
625
|
+
overflow: 'hidden',
|
|
626
|
+
background: surface,
|
|
627
|
+
// Solid when observed live; dashed while it is only a declaration.
|
|
628
|
+
border: `1px ${view.phase === 'configured' ? 'dashed' : 'solid'} ${frame}`,
|
|
629
|
+
}}
|
|
630
|
+
>
|
|
631
|
+
<span
|
|
632
|
+
title={deploymentSummary(view)}
|
|
633
|
+
style={{
|
|
634
|
+
...segment,
|
|
635
|
+
padding: brand ? '0 5px' : '0 6px',
|
|
636
|
+
background: `color-mix(in srgb, ${frame} 16%, transparent)`,
|
|
637
|
+
color: muted,
|
|
638
|
+
fontSize: 10,
|
|
639
|
+
lineHeight: 1,
|
|
640
|
+
}}
|
|
641
|
+
>
|
|
642
|
+
{brand ? (
|
|
643
|
+
<span
|
|
644
|
+
style={{
|
|
645
|
+
display: 'inline-flex',
|
|
646
|
+
// Full colour only for something observed running — a declared
|
|
647
|
+
// but unconfirmed deployment must not read the same as a live one.
|
|
648
|
+
filter: live ? 'none' : 'grayscale(1)',
|
|
649
|
+
opacity: live ? 1 : 0.6,
|
|
650
|
+
}}
|
|
651
|
+
>
|
|
652
|
+
{/* Larger than the technology row's mark: a provider logo is often wide,
|
|
653
|
+
and a square slot leaves it only a fraction of the height. */}
|
|
654
|
+
<TechMark brand={brand} size={20} showTitle={false} />
|
|
655
|
+
</span>
|
|
656
|
+
) : (
|
|
657
|
+
// No official mark held: name the provider rather than draw a stand-in.
|
|
658
|
+
view.deployment.provider
|
|
659
|
+
)}
|
|
660
|
+
</span>
|
|
661
|
+
{links.map(({ kind, url, label, Icon }) => (
|
|
662
|
+
<DeploymentLinkButton
|
|
663
|
+
key={kind}
|
|
664
|
+
label={label}
|
|
665
|
+
Icon={Icon}
|
|
666
|
+
frame={frame}
|
|
667
|
+
onClick={() => onOpen!(kind, url)}
|
|
668
|
+
/>
|
|
669
|
+
))}
|
|
670
|
+
</span>
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* One action segment of the deployment pill. Hover and keyboard focus fill the
|
|
676
|
+
* segment with the frame colour and flip the glyph to the card surface, so the
|
|
677
|
+
* pressable segments answer the pointer and the provider mark beside them —
|
|
678
|
+
* which never changes — stays visibly inert.
|
|
679
|
+
*/
|
|
680
|
+
function DeploymentLinkButton({
|
|
681
|
+
label,
|
|
682
|
+
Icon,
|
|
683
|
+
frame,
|
|
684
|
+
onClick,
|
|
685
|
+
}: {
|
|
686
|
+
label: string;
|
|
687
|
+
Icon: LucideIcon;
|
|
688
|
+
frame: string;
|
|
689
|
+
onClick: () => void;
|
|
690
|
+
}) {
|
|
691
|
+
const { theme } = useTheme();
|
|
692
|
+
const [active, setActive] = useState(false);
|
|
693
|
+
return (
|
|
694
|
+
<button
|
|
695
|
+
type="button"
|
|
696
|
+
title={label}
|
|
697
|
+
aria-label={label}
|
|
698
|
+
onClick={(e) => {
|
|
699
|
+
e.stopPropagation();
|
|
700
|
+
onClick();
|
|
701
|
+
}}
|
|
702
|
+
onMouseEnter={() => setActive(true)}
|
|
703
|
+
onMouseLeave={() => setActive(false)}
|
|
704
|
+
onFocus={() => setActive(true)}
|
|
705
|
+
onBlur={() => setActive(false)}
|
|
706
|
+
style={{
|
|
707
|
+
display: 'inline-flex',
|
|
708
|
+
alignItems: 'center',
|
|
709
|
+
justifyContent: 'center',
|
|
710
|
+
height: '100%',
|
|
711
|
+
boxSizing: 'border-box',
|
|
712
|
+
width: TOGGLE_SIZE,
|
|
713
|
+
padding: 0,
|
|
714
|
+
border: 'none',
|
|
715
|
+
// A hairline between segments instead of a gap between boxes.
|
|
716
|
+
borderLeft: `1px solid color-mix(in srgb, ${frame} 45%, transparent)`,
|
|
717
|
+
outline: 'none',
|
|
718
|
+
background: active ? frame : 'transparent',
|
|
719
|
+
color: active ? theme.colors.backgroundSecondary ?? theme.colors.background : frame,
|
|
720
|
+
cursor: 'pointer',
|
|
721
|
+
lineHeight: 1,
|
|
722
|
+
transition: 'background 120ms ease, color 120ms ease',
|
|
723
|
+
}}
|
|
724
|
+
>
|
|
725
|
+
<Icon size={13} strokeWidth={2.25} />
|
|
726
|
+
</button>
|
|
727
|
+
);
|
|
728
|
+
}
|
|
@@ -83,6 +83,13 @@ export interface C4ProjectionViewProps {
|
|
|
83
83
|
persistKey?: string;
|
|
84
84
|
/** Outer style for the flex fill. */
|
|
85
85
|
style?: CSSProperties;
|
|
86
|
+
/**
|
|
87
|
+
* Live-deployment observations keyed by `resourceKey`, joined to each
|
|
88
|
+
* container's `deployment` anchor.
|
|
89
|
+
*/
|
|
90
|
+
deployments?: C4GraphProps['deployments'];
|
|
91
|
+
/** Open a deployment link outside the app. Without it no links are drawn. */
|
|
92
|
+
onOpenExternal?: C4GraphProps['onOpenExternal'];
|
|
86
93
|
}
|
|
87
94
|
|
|
88
95
|
function parentIdsOf(model: C4Model): Map<string, string> {
|
|
@@ -226,6 +233,8 @@ export function C4ProjectionView({
|
|
|
226
233
|
hideDrawer = false,
|
|
227
234
|
persistKey,
|
|
228
235
|
style,
|
|
236
|
+
deployments,
|
|
237
|
+
onOpenExternal,
|
|
229
238
|
}: C4ProjectionViewProps) {
|
|
230
239
|
const { theme } = useTheme();
|
|
231
240
|
const [notesOpen, setNotesOpen] = useState(false);
|
|
@@ -657,6 +666,7 @@ export function C4ProjectionView({
|
|
|
657
666
|
onSelect={selectContainer}
|
|
658
667
|
onOpenAll={openAll}
|
|
659
668
|
onCloseAll={collapseAll}
|
|
669
|
+
deployments={deployments}
|
|
660
670
|
/>
|
|
661
671
|
)
|
|
662
672
|
}
|
|
@@ -690,6 +700,8 @@ export function C4ProjectionView({
|
|
|
690
700
|
renderFileViewer={renderFileViewer}
|
|
691
701
|
renderTrailViewer={renderTrailViewer}
|
|
692
702
|
hideDrawer={hideDrawer}
|
|
703
|
+
deployments={deployments}
|
|
704
|
+
onOpenExternal={onOpenExternal}
|
|
693
705
|
/>
|
|
694
706
|
</GraphWithSidebar>
|
|
695
707
|
</div>
|
|
@@ -19,6 +19,7 @@ import { GraphWithSidebar } from './GraphWithSidebar';
|
|
|
19
19
|
import type { C4Component, C4Container } from './c4';
|
|
20
20
|
import { C4_SKETCH_DESCRIPTION_MAX } from './c4Sketch';
|
|
21
21
|
import type { C4Sketch } from './c4Sketch';
|
|
22
|
+
import type { C4GraphProps } from './C4Graph';
|
|
22
23
|
|
|
23
24
|
export interface C4SketchViewProps {
|
|
24
25
|
sketch: C4Sketch;
|
|
@@ -33,6 +34,13 @@ export interface C4SketchViewProps {
|
|
|
33
34
|
persistKey?: string;
|
|
34
35
|
/** Outer style for the flex fill. */
|
|
35
36
|
style?: CSSProperties;
|
|
37
|
+
/**
|
|
38
|
+
* Live-deployment observations keyed by `resourceKey`, joined to each
|
|
39
|
+
* container's `deployment` anchor.
|
|
40
|
+
*/
|
|
41
|
+
deployments?: C4GraphProps['deployments'];
|
|
42
|
+
/** Open a deployment link outside the app. Without it no links are drawn. */
|
|
43
|
+
onOpenExternal?: C4GraphProps['onOpenExternal'];
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
export function C4SketchView({
|
|
@@ -43,6 +51,8 @@ export function C4SketchView({
|
|
|
43
51
|
onShare,
|
|
44
52
|
persistKey,
|
|
45
53
|
style,
|
|
54
|
+
deployments,
|
|
55
|
+
onOpenExternal,
|
|
46
56
|
}: C4SketchViewProps) {
|
|
47
57
|
const { theme } = useTheme();
|
|
48
58
|
const [internalOpenIds, setInternalOpenIds] = useState<string[]>(() =>
|
|
@@ -244,6 +254,7 @@ export function C4SketchView({
|
|
|
244
254
|
onSelect={selectContainer}
|
|
245
255
|
onOpenAll={openAll}
|
|
246
256
|
onCloseAll={collapseAll}
|
|
257
|
+
deployments={deployments}
|
|
247
258
|
/>
|
|
248
259
|
}
|
|
249
260
|
>
|
|
@@ -260,6 +271,8 @@ export function C4SketchView({
|
|
|
260
271
|
model={model}
|
|
261
272
|
onToggleContainer={toggleContainer}
|
|
262
273
|
containerFocus={focus}
|
|
274
|
+
deployments={deployments}
|
|
275
|
+
onOpenExternal={onOpenExternal}
|
|
263
276
|
/>
|
|
264
277
|
</GraphWithSidebar>
|
|
265
278
|
</div>
|