1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
|
diff --git a/src/ui/pages/diagnostics-detail.tsx b/src/ui/pages/diagnostics-detail.tsx
index 2bd4710ef..bb3912e9c 100644
--- a/src/ui/pages/diagnostics-detail.tsx
+++ b/src/ui/pages/diagnostics-detail.tsx
@@ -1,12 +1,164 @@
import { selectAptibleAiUrl } from "@app/config";
import { useSelector } from "@app/react";
+import React, { useRef, useContext } from "react";
import { diagnosticsCreateUrl } from "@app/routes";
import { selectAccessToken } from "@app/token";
-import { useEffect, useState } from "react";
-import { Link, useParams, useSearchParams } from "react-router-dom";
+import { useEffect, useState, createContext } from "react";
+import { useSearchParams } from "react-router-dom";
import useWebSocket, { ReadyState } from "react-use-websocket";
import { AppSidebarLayout } from "../layouts";
-import { Breadcrumbs, PreText } from "../shared";
+import { Breadcrumbs } from "../shared";
+import {
+ IconBox,
+ IconCloud,
+ IconCylinder,
+ IconEndpoint,
+ IconService,
+ IconSource,
+ IconInfo,
+} from "../shared/icons";
+import {
+ CategoryScale,
+ Chart as ChartJS,
+ Colors,
+ Legend,
+ LineElement,
+ LinearScale,
+ PointElement,
+ TimeScale,
+ type TimeUnit,
+ Title,
+ Tooltip,
+} from "chart.js";
+import "chartjs-adapter-luxon";
+import { Line } from "react-chartjs-2";
+import { StreamingText } from "../shared/llm";
+
+// Chart.js plugin to draw a vertical line on hover
+const verticalLinePlugin = {
+ id: 'verticalLine',
+ beforeDraw: (chart: ChartJS) => {
+ if (chart.tooltip?.getActiveElements()?.length) {
+ const activePoint = chart.tooltip.getActiveElements()[0];
+ const ctx = chart.ctx;
+ const x = activePoint.element.x;
+ const topY = chart.scales.y.top;
+ const bottomY = chart.scales.y.bottom;
+
+ ctx.save();
+ ctx.beginPath();
+ ctx.moveTo(x, topY);
+ ctx.lineTo(x, bottomY);
+ ctx.lineWidth = 1;
+ ctx.strokeStyle = '#94a3b8';
+ ctx.setLineDash([5, 5]);
+ ctx.stroke();
+ ctx.restore();
+ }
+ }
+};
+
+// ChartJS plugin to draw annotations
+declare module 'chart.js' {
+ interface Chart {
+ annotationAreas?: Array<{
+ x1: number;
+ x2: number;
+ y1: number;
+ y2: number;
+ description: string;
+ }>;
+ }
+
+ interface PluginOptionsByType<TType> {
+ annotations?: Annotation[];
+ }
+}
+
+const annotationsPlugin = {
+ id: 'annotations',
+ afterDraw: (chart: ChartJS, args: any, options: any) => {
+ const ctx = chart.ctx;
+ const annotations = chart.options?.plugins?.annotations || [];
+
+ annotations.forEach((annotation: any) => {
+ // Convert timestamps to numbers for the time scale
+ const xScale = chart.scales.x;
+ const yScale = chart.scales.y;
+
+ // Parse the timestamps into Date objects and get their timestamps
+ const x1 = new Date(annotation.x_min).getTime();
+ const x2 = new Date(annotation.x_max).getTime();
+
+ // Convert to pixel coordinates
+ const pixelX1 = xScale.getPixelForValue(x1);
+ const pixelX2 = xScale.getPixelForValue(x2);
+ const pixelY1 = yScale.getPixelForValue(annotation.y_max);
+ const pixelY2 = yScale.getPixelForValue(annotation.y_min);
+
+ // Draw annotation rectangle
+ ctx.save();
+ ctx.fillStyle = 'rgba(255, 0, 0, 0.5)'; // Solid red with 50% opacity
+ ctx.fillRect(pixelX1, pixelY1, pixelX2 - pixelX1, pixelY2 - pixelY1);
+
+ // Rectangle border
+ ctx.strokeStyle = 'rgb(200, 0, 0)'; // Solid darker red
+ ctx.strokeRect(pixelX1, pixelY1, pixelX2 - pixelX1, pixelY2 - pixelY1);
+
+ // Annotation label
+ ctx.save();
+ const padding = 4;
+ ctx.font = '10px monospace'; // Reduced font size
+ const textMetrics = ctx.measureText(annotation.label);
+ const textHeight = 12; // Reduced height to match smaller font
+ const radius = 4; // Border radius
+
+ // Calculate label box dimensions
+ const boxX = pixelX1 + padding;
+ const boxY = pixelY1 - textHeight - padding * 2;
+ const boxWidth = textMetrics.width + padding * 2;
+ const boxHeight = textHeight + padding * 2;
+
+ // Label box shadow
+ ctx.shadowColor = 'rgba(0, 0, 0, 0.3)';
+ ctx.shadowBlur = 4;
+ ctx.shadowOffsetX = 2;
+ ctx.shadowOffsetY = 2;
+
+ // Label box background
+ ctx.fillStyle = 'rgba(200, 0, 0, 0.75)';
+ ctx.beginPath();
+ ctx.roundRect(boxX, boxY, boxWidth, boxHeight, radius);
+ ctx.fill();
+
+ // Border
+ ctx.shadowColor = 'transparent';
+ ctx.strokeStyle = 'rgb(200, 0, 0)';
+ ctx.lineWidth = 1;
+ ctx.stroke();
+
+ // Label text
+ ctx.fillStyle = 'white';
+ ctx.textBaseline = 'bottom';
+ ctx.fillText(annotation.label, pixelX1 + padding * 2, pixelY1 - padding);
+ ctx.restore();
+ });
+ }
+};
+
+ChartJS.register(
+ CategoryScale,
+ Colors,
+ LinearScale,
+ PointElement,
+ LineElement,
+ TimeScale,
+ Title,
+ Tooltip,
+ Legend,
+ verticalLinePlugin,
+ annotationsPlugin
+);
type Message = {
id: string;
@@ -72,6 +224,493 @@ type Dashboard = {
messages: Message[];
};
+type HoverState = {
+ timestamp: string | null;
+ setTimestamp: (timestamp: string | null) => void;
+};
+
+const HoverContext = createContext<HoverState>({
+ timestamp: null,
+ setTimestamp: () => { },
+});
+
+const OperationsTimeline = ({
+ operations,
+ startTime,
+ endTime,
+ synchronizedHoverContext
+}: {
+ operations: Operation[],
+ startTime: string,
+ endTime: string,
+ synchronizedHoverContext: React.Context<HoverState>
+}) => {
+ const { timestamp, setTimestamp } = useContext(synchronizedHoverContext);
+ const start = new Date(startTime);
+ const end = new Date(endTime);
+ const minutesDiff = Math.floor((end.getTime() - start.getTime()) / (1000 * 60));
+ const timelineRef = useRef<HTMLDivElement>(null);
+
+ // Create array of all minutes between start and end
+ const minutes = Array.from({ length: minutesDiff + 1 }, (_, i) => i);
+
+ // Map operations to their minute positions
+ const operationsByMinute = operations.reduce((acc, op) => {
+ const opTime = new Date(op.created_at);
+ const minute = Math.floor((opTime.getTime() - start.getTime()) / (1000 * 60));
+ acc[minute] = op;
+ return acc;
+ }, {} as { [key: number]: Operation });
+
+ // Handle mouse move over timeline
+ const handleMouseMove = (e: React.MouseEvent) => {
+ if (!timelineRef.current) return;
+
+ const rect = timelineRef.current.getBoundingClientRect();
+ const x = e.clientX - rect.left;
+ const percentage = x / rect.width;
+ const totalMilliseconds = end.getTime() - start.getTime();
+ const hoverTime = new Date(start.getTime() + (percentage * totalMilliseconds));
+
+ // Round to nearest minute
+ hoverTime.setSeconds(0);
+ hoverTime.setMilliseconds(0);
+
+ // Format timestamp correctly
+ const formattedTimestamp = hoverTime.toISOString().slice(0, -5) + 'Z';
+ setTimestamp(formattedTimestamp);
+ };
+
+ // Handle mouse leave
+ const handleMouseLeave = () => {
+ setTimestamp(null);
+ };
+
+ // Calculate vertical line position when timestamp changes
+ const getVerticalLinePosition = () => {
+ if (!timestamp) return null;
+
+ try {
+ const hoverTime = new Date(timestamp);
+ const timeElapsed = hoverTime.getTime() - start.getTime();
+ const totalDuration = end.getTime() - start.getTime();
+ const position = (timeElapsed / totalDuration) * 100;
+
+ // Ensure position is between 0 and 100
+ return Math.max(0, Math.min(100, position));
+ } catch (error) {
+ console.error('Error calculating vertical line position:', error);
+ return null;
+ }
+ };
+
+ const verticalLinePosition = getVerticalLinePosition();
+
+ // Helper function to extract operation type from description
+ const getOperationType = (description: string) => {
+ const match = description.match(/^\((succeeded|failed)\) (\w+)/);
+ return match ? match[2] : 'unknown';
+ };
+
+ return (
+ <div className="mt-4">
+ <div
+ ref={timelineRef}
+ className="relative h-16"
+ onMouseMove={handleMouseMove}
+ onMouseLeave={handleMouseLeave}
+ >
+ <div className="absolute w-full h-0.5 bg-gray-200 top-1/2 transform -translate-y-1/2" />
+
+ {/* Vertical hover line */}
+ {verticalLinePosition !== null && (
+ <div
+ className="absolute h-full w-px bg-transparent top-0"
+ style={{
+ left: `${verticalLinePosition}%`,
+ borderLeft: '1px dashed #94a3b8'
+ }}
+ />
+ )}
+
+ {minutes.map((minute) => {
+ const leftPercentage = (minute / minutesDiff) * 100;
+ const operation = operationsByMinute[minute];
+
+ return (
+ <div
+ key={minute}
+ className="absolute top-1/2 transform -translate-y-1/2"
+ style={{ left: `${leftPercentage}%` }}
+ >
+ <div className="group relative">
+ {operation ? (
+ <>
+ <div className={`relative w-3 h-3 ${operation.status === 'succeeded' ? 'bg-lime-400' : 'bg-red-400'} rounded-full cursor-pointer before:absolute before:inset-0 before:rounded-full before:animate-ping before:opacity-75 ${operation.status === 'succeeded' ? 'before:bg-lime-400' : 'before:bg-red-400'}`} />
+
+ {/* Operation type label */}
+ <div className="absolute top-4 left-1/2 transform -translate-x-1/2 bg-gray-100 px-1 rounded">
+ <span className="font-mono text-[10px] whitespace-nowrap uppercase">
+ {getOperationType(operation.description)}
+ </span>
+ </div>
+
+ {/* Tooltip */}
+ <div className="invisible group-hover:visible absolute bottom-full mb-2 -left-1/2 w-48 bg-gray-800 text-white text-sm rounded p-2 z-10">
+ <p className="text-sm">{operation.description}</p>
+ <p className="text-xs text-gray-300">({new Date(operation.created_at).toLocaleTimeString()} local)</p>
+ </div>
+ </>
+ ) : (
+ // Empty marker for minutes without operations
+ <div className="hidden" />
+ )}
+ </div>
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ );
+};
+
+const DiagnosticsMessages = ({ messages, showAllMessages, setShowAllMessages }: {
+ messages: Message[];
+ showAllMessages: boolean;
+ setShowAllMessages: (show: boolean) => void;
+}) => {
+ return (
+ <div className="border rounded-lg p-4 bg-gray-50">
+ <div className="flex justify-between items-center mb-4">
+ <h2 className="text-lg font-semibold">Messages</h2>
+ {messages.length > 1 && (
+ <button
+ onClick={() => setShowAllMessages(!showAllMessages)}
+ className="text-blue-600 hover:text-blue-800 text-sm"
+ >
+ {showAllMessages ? 'Show Latest' : `Show All (${messages.length})`}
+ </button>
+ )}
+ </div>
+ <div className="space-y-6">
+ {(showAllMessages ? messages : messages.slice(-1)).map((message, index) => (
+ <div
+ key={message.id}
+ className="flex items-start"
+ >
+ <img
+ src={message.id === 'completion-message' ? '/aptible-mark.png' : '/thinking.gif'}
+ className="w-[28px] h-[28px] mr-3"
+ aria-label="App"
+ />
+ <div className="flex-1 bg-white rounded-lg px-4 py-2 shadow-sm">
+ <StreamingText
+ text={message.message}
+ showEllipsis={(showAllMessages ? index === messages.length - 1 : true) && message.id !== 'completion-message'}
+ animate={showAllMessages ? index === messages.length - 1 : true}
+ />
+ </div>
+ </div>
+ ))}
+ </div>
+ </div>
+ );
+};
+
+const DiagnosticsResource = ({
+ resourceId,
+ resource,
+ startTime,
+ endTime,
+ synchronizedHoverContext
+}: {
+ resourceId: string;
+ resource: Resource;
+ startTime: string;
+ endTime: string;
+ synchronizedHoverContext: React.Context<HoverState>;
+}) => {
+ return (
+ <div className="border rounded-lg p-4">
+ <h3 className="font-medium text-xl flex gap-2 items-center bg-gray-50 p-4 -m-4 mb-4 border-b rounded-t-lg">
+ {resource.type === "app" ? <IconBox /> :
+ resource.type === "database" ? <IconCylinder /> :
+ resource.type === "endpoint" ? <IconEndpoint /> :
+ resource.type === "service" ? <IconService /> :
+ resource.type === "source" ? <IconSource /> :
+ <IconCloud />}
+ <span className="font-mono text-lg font-bold">{resourceId}</span>
+ </h3>
+
+ {/* Operations */}
+ {resource.operations && resource.operations.length > 0 && (
+ <div className="mt-2">
+ <div className="border rounded-lg bg-white shadow-sm animate-fade-in">
+ <h4 className="font-medium text-gray-900 p-3 rounded-t-lg border-b">Operations</h4>
+ <div className="p-6">
+ <OperationsTimeline
+ operations={resource.operations}
+ startTime={startTime}
+ endTime={endTime}
+ synchronizedHoverContext={synchronizedHoverContext}
+ />
+ </div>
+ </div>
+ </div>
+ )}
+
+ {/* Plots */}
+ {resource.plots && Object.entries(resource.plots).length > 0 && (
+ <div className="mt-2">
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-4 mt-4">
+ {Object.entries(resource.plots)
+ .filter(([_, plot]) =>
+ plot.series.some(series => series.points && series.points.length > 0)
+ )
+ .map(([plotId, plot]) => (
+ <div
+ key={plotId}
+ className="border rounded-lg bg-white shadow-sm animate-fade-in"
+ >
+ <h4 className="font-medium text-gray-900 p-3 rounded-t-lg border-b">
+ {plot.title}
+ </h4>
+ <div className="p-6">
+ {plot.interpretation && (
+ <div className="mt-4 bg-orange-100 p-3 rounded-md">
+ <div className="flex items-start gap-2">
+ <IconInfo className="w-4 h-4 mt-1 text-yellow-600 flex-shrink-0" />
+ <div>
+ <p className="text-gray-600">
+ <strong className="mr-1">Interpretation:</strong>
+ {plot.interpretation}
+ </p>
+ </div>
+ </div>
+ </div>
+ )}
+ <div className="mt-2 min-h-[200px]">
+ <SynchronizedHoverLineChartWrapper
+ showLegend={true}
+ keyId={plot.id}
+ chart={{
+ title: " ",
+ labels: plot.series[0]?.points.map(point => point.timestamp) || [],
+ datasets: plot.series.map(series => ({
+ label: series.label,
+ data: series.points.map(point => point.value)
+ }))
+ }}
+ xAxisUnit="minute"
+ yAxisLabel={plot.title}
+ yAxisUnit={plot.unit}
+ annotations={plot.annotations}
+ synchronizedHoverContext={synchronizedHoverContext}
+ />
+ </div>
+ {plot.analysis && (
+ <div className="mt-4">
+ <p className="mt-1 text-gray-500 text-xs">
+ <strong>Analysis:</strong>
+ {plot.analysis}
+ </p>
+ </div>
+ )}
+ </div>
+ </div>
+ ))}
+ </div>
+ </div>
+ )}
+ </div>
+ );
+};
+
+const SynchronizedHoverLineChartWrapper = ({
+ showLegend = true,
+ keyId,
+ chart: { labels, datasets: originalDatasets, title },
+ xAxisUnit,
+ yAxisLabel,
+ yAxisUnit,
+ annotations = [],
+ synchronizedHoverContext,
+}: {
+ showLegend?: boolean;
+ keyId: string;
+ chart: {
+ title: string;
+ labels: string[];
+ datasets: Array<{
+ label: string;
+ data: number[];
+ }>;
+ };
+ xAxisUnit: TimeUnit;
+ yAxisLabel?: string;
+ yAxisUnit?: string;
+ annotations?: Annotation[];
+ synchronizedHoverContext: React.Context<HoverState>;
+}) => {
+ const { timestamp, setTimestamp } = useContext(synchronizedHoverContext);
+ const chartRef = React.useRef<ChartJS<"line">>();
+
+ // Truncate sha256 resource names to 8 chars
+ const datasets = originalDatasets.map(dataset => ({
+ ...dataset,
+ label: dataset.label.length === 64 ? dataset.label.slice(0, 8) : dataset.label
+ }));
+
+ if (!datasets || !title) return null;
+
+ React.useEffect(() => {
+ const chart = chartRef.current;
+ if (!chart) return;
+
+ if (!timestamp) {
+ chart.setActiveElements([]);
+ chart.tooltip?.setActiveElements([], { x: 0, y: 0 });
+ chart.update();
+ return;
+ }
+
+ const timestampIndex = labels.indexOf(timestamp);
+ if (timestampIndex === -1) return;
+
+ const activeElements = datasets.map((dataset, datasetIndex) => ({
+ datasetIndex,
+ index: timestampIndex,
+ }));
+
+ chart.setActiveElements(activeElements);
+ chart.tooltip?.setActiveElements(activeElements, { x: 0, y: 0 });
+ chart.update();
+ }, [timestamp, labels, datasets]);
+
+ const formatYAxisTick = (value: number, unit?: string) => {
+ if (!unit) return value;
+
+ unit = unit.trim();
+ if (unit === '%') return `${value}%`;
+ if (unit.endsWith('B')) return `${value}${unit}`;
+
+ return value;
+ };
+
+ return (
+ <Line
+ ref={chartRef}
+ datasetIdKey={keyId}
+ data={{
+ labels,
+ datasets,
+ }}
+ options={{
+ responsive: true,
+ maintainAspectRatio: false,
+ animation: false,
+ plugins: {
+ tooltip: {
+ enabled: true,
+ mode: 'index',
+ intersect: false,
+ },
+ colors: {
+ forceOverride: true,
+ },
+ legend: {
+ display: showLegend,
+ labels: {
+ usePointStyle: true,
+ boxHeight: 5,
+ boxWidth: 3,
+ padding: 20,
+ },
+ },
+ title: {
+ font: {
+ size: 16,
+ weight: "normal",
+ },
+ color: "#595E63",
+ align: "start",
+ display: false,
+ text: title,
+ padding: showLegend
+ ? undefined
+ : {
+ top: 10,
+ bottom: 30,
+ },
+ },
+ annotations: annotations,
+ },
+ interaction: {
+ mode: 'index',
+ intersect: false,
+ },
+ onHover: (event, elements, chart) => {
+ if (!event.native) return;
+
+ if (elements && elements.length > 0) {
+ const timestamp = labels[elements[0].index];
+ setTimestamp(timestamp);
+ } else {
+ setTimestamp(null);
+ }
+ },
+ scales: {
+ x: {
+ border: {
+ color: "#111920",
+ },
+ grid: {
+ display: false,
+ },
+ ticks: {
+ color: "#111920",
+ maxRotation: 0,
+ minRotation: 0,
+ autoSkip: true,
+ maxTicksLimit: 5,
+ },
+ adapters: {
+ date: {
+ zone: "UTC",
+ },
+ },
+ time: {
+ tooltipFormat: "yyyy-MM-dd HH:mm:ss 'UTC'",
+ unit: xAxisUnit,
+ displayFormats: {
+ minute: "HH:mm 'UTC'",
+ day: "MMM dd",
+ },
+ },
+ type: "time",
+ },
+ y: {
+ min: 0,
+ border: {
+ display: false,
+ },
+ title: yAxisLabel
+ ? {
+ display: true,
+ text: yAxisLabel,
+ }
+ : undefined,
+ ticks: {
+ callback: (value) => formatYAxisTick(value as number, yAxisUnit),
+ color: "#111920",
+ },
+ },
+ },
+ }}
+ />
+ );
+};
+
export const DiagnosticsDetailPage = () => {
// Parse the investigation parameters from the query string.
const [searchParams, setSearchParams] = useSearchParams();
@@ -120,6 +759,10 @@ export const DiagnosticsDetailPage = () => {
messages: [],
});
+ const [showAllMessages, setShowAllMessages] = useState(false);
+ const [hoverTimestamp, setHoverTimestamp] = useState<string | null>(null);
+ const [hasShownCompletion, setHasShownCompletion] = useState(false);
+
// Process each event from the websocket, and update the dashboard state.
useEffect(() => {
if (event?.type === "ResourceDiscovered") {
@@ -131,7 +774,7 @@ export const DiagnosticsDetailPage = () => {
id: event.resource_id,
type: event.resource_type,
notes: event.notes,
- metrics: [],
+ plots: {},
operations: [],
},
},
@@ -146,8 +789,14 @@ export const DiagnosticsDetailPage = () => {
plots: {
...prev.resources[event.resource_id].plots,
[event.metric_name]: {
- name: event.metric_name,
- plot: event.plot,
+ id: event.plot.id,
+ title: event.plot.title,
+ description: event.plot.description,
+ interpretation: event.plot.interpretation,
+ analysis: event.plot.analysis,
+ unit: event.plot.unit,
+ series: event.plot.series,
+ annotations: event.plot.annotations,
},
},
},
@@ -184,6 +833,24 @@ export const DiagnosticsDetailPage = () => {
}
}, [JSON.stringify(event)]);
+ // Insert an "analysis complete" message if the socket is closed
+ useEffect(() => {
+ if (readyState === ReadyState.CLOSED && !hasShownCompletion) {
+ setHasShownCompletion(true);
+ setDashboard((prev) => ({
+ ...prev,
+ messages: [
+ ...prev.messages,
+ {
+ id: 'completion-message',
+ severity: 'info',
+ message: 'Analysis complete.',
+ },
+ ],
+ }));
+ }
+ }, [readyState, hasShownCompletion]);
+
return (
<AppSidebarLayout>
<Breadcrumbs
@@ -199,12 +866,29 @@ export const DiagnosticsDetailPage = () => {
]}
/>
- <div className="flex flex-row items-center justify-center flex-1 min-h-[500px]">
- <PreText
- className="max-w-7xl overflow-x-auto overflow-y-auto"
- text={JSON.stringify(dashboard, null, 2)}
- allowCopy
- />
+ <div className="flex flex-col gap-4 p-4">
+ <HoverContext.Provider value={{ timestamp: hoverTimestamp, setTimestamp: setHoverTimestamp }}>
+ <DiagnosticsMessages
+ messages={dashboard.messages}
+ showAllMessages={showAllMessages}
+ setShowAllMessages={setShowAllMessages}
+ />
+
+ {/* Resources Section */}
+ <h2 className="text-lg font-semibold mb-2">Resources</h2>
+ <div className="space-y-4">
+ {Object.entries(dashboard.resources).map(([resourceId, resource]) => (
+ <DiagnosticsResource
+ key={resourceId}
+ resourceId={resourceId}
+ resource={resource}
+ startTime={startTime!}
+ endTime={endTime!}
+ synchronizedHoverContext={HoverContext}
+ />
+ ))}
+ </div>
+ </HoverContext.Provider>
</div>
</AppSidebarLayout>
);
|