@scality/core-ui 0.170.0 → 0.172.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/__mocks__/uuid.js +11 -0
- package/dist/components/barchartv2/Barchart.component.d.ts.map +1 -1
- package/dist/components/barchartv2/Barchart.component.js +4 -4
- package/dist/components/barchartv2/BarchartTooltip.d.ts +11 -0
- package/dist/components/barchartv2/BarchartTooltip.d.ts.map +1 -0
- package/dist/components/barchartv2/BarchartTooltip.js +27 -0
- package/dist/components/chartlegend/ChartLegend.d.ts +3 -1
- package/dist/components/chartlegend/ChartLegend.d.ts.map +1 -1
- package/dist/components/chartlegend/ChartLegend.js +2 -2
- package/dist/components/chartlegend/ChartLegendWrapper.d.ts +3 -1
- package/dist/components/chartlegend/ChartLegendWrapper.d.ts.map +1 -1
- package/dist/components/chartlegend/ChartLegendWrapper.js +43 -9
- package/dist/components/charttooltip/ChartTooltip.d.ts +13 -0
- package/dist/components/charttooltip/ChartTooltip.d.ts.map +1 -0
- package/dist/components/charttooltip/ChartTooltip.js +49 -0
- package/dist/components/globalhealthbar/GlobalHealthBar.component.d.ts +4 -0
- package/dist/components/globalhealthbar/GlobalHealthBar.component.d.ts.map +1 -1
- package/dist/components/globalhealthbar/GlobalHealthBar.component.js +4 -0
- package/dist/components/globalhealthbar/GlobalHealthBarRecharts.component.d.ts +10 -0
- package/dist/components/globalhealthbar/GlobalHealthBarRecharts.component.d.ts.map +1 -0
- package/dist/components/globalhealthbar/GlobalHealthBarRecharts.component.js +78 -0
- package/dist/components/globalhealthbar/components/GlobalHealthBarTooltip.d.ts +18 -0
- package/dist/components/globalhealthbar/components/GlobalHealthBarTooltip.d.ts.map +1 -0
- package/dist/components/globalhealthbar/components/GlobalHealthBarTooltip.js +95 -0
- package/dist/components/globalhealthbar/components/HealthBarXAxis.d.ts +7 -0
- package/dist/components/globalhealthbar/components/HealthBarXAxis.d.ts.map +1 -0
- package/dist/components/globalhealthbar/components/HealthBarXAxis.js +25 -0
- package/dist/components/globalhealthbar/healthBarUtils.d.ts +77 -0
- package/dist/components/globalhealthbar/healthBarUtils.d.ts.map +1 -0
- package/dist/components/globalhealthbar/healthBarUtils.js +196 -0
- package/dist/components/globalhealthbar/healthBarUtils.spec.d.ts +2 -0
- package/dist/components/globalhealthbar/healthBarUtils.spec.d.ts.map +1 -0
- package/dist/components/globalhealthbar/healthBarUtils.spec.js +391 -0
- package/dist/components/globalhealthbar/useHealthBarData.d.ts +18 -0
- package/dist/components/globalhealthbar/useHealthBarData.d.ts.map +1 -0
- package/dist/components/globalhealthbar/useHealthBarData.js +46 -0
- package/dist/components/globalhealthbar/useHealthBarData.spec.d.ts +2 -0
- package/dist/components/globalhealthbar/useHealthBarData.spec.d.ts.map +1 -0
- package/dist/components/globalhealthbar/useHealthBarData.spec.js +207 -0
- package/dist/components/icon/Icon.component.d.ts +2 -0
- package/dist/components/icon/Icon.component.d.ts.map +1 -1
- package/dist/components/icon/Icon.component.js +2 -0
- package/dist/components/linetemporalchart/ChartUtil.d.ts.map +1 -1
- package/dist/components/linetemporalchart/ChartUtil.js +12 -0
- package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts +8 -5
- package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts.map +1 -1
- package/dist/components/linetimeseriechart/linetimeseriechart.component.js +95 -100
- package/dist/components/sparkline/sparkline.component.d.ts +16 -0
- package/dist/components/sparkline/sparkline.component.d.ts.map +1 -0
- package/dist/components/sparkline/sparkline.component.js +20 -0
- package/dist/components/text/Text.component.d.ts +2 -1
- package/dist/components/text/Text.component.d.ts.map +1 -1
- package/dist/components/text/Text.component.js +6 -1
- package/dist/next.d.ts +4 -2
- package/dist/next.d.ts.map +1 -1
- package/dist/next.js +4 -2
- package/package.json +4 -2
- package/src/lib/components/barchartv2/Barchart.component.tsx +5 -4
- package/src/lib/components/barchartv2/{ChartTooltip.test.tsx → BarchartTooltip.test.tsx} +35 -12
- package/src/lib/components/barchartv2/BarchartTooltip.tsx +89 -0
- package/src/lib/components/chartlegend/ChartLegend.tsx +4 -2
- package/src/lib/components/chartlegend/ChartLegendWrapper.test.tsx +197 -0
- package/src/lib/components/chartlegend/ChartLegendWrapper.tsx +65 -9
- package/src/lib/components/charttooltip/ChartTooltip.tsx +83 -0
- package/src/lib/components/globalhealthbar/GlobalHealthBar.component.tsx +4 -1
- package/src/lib/components/globalhealthbar/GlobalHealthBarRecharts.component.tsx +203 -0
- package/src/lib/components/globalhealthbar/components/GlobalHealthBarTooltip.tsx +173 -0
- package/src/lib/components/globalhealthbar/components/HealthBarXAxis.tsx +94 -0
- package/src/lib/components/globalhealthbar/healthBarUtils.spec.ts +701 -0
- package/src/lib/components/globalhealthbar/healthBarUtils.ts +311 -0
- package/src/lib/components/globalhealthbar/useHealthBarData.spec.tsx +487 -0
- package/src/lib/components/globalhealthbar/useHealthBarData.ts +74 -0
- package/src/lib/components/icon/Icon.component.tsx +2 -0
- package/src/lib/components/linetemporalchart/ChartUtil.ts +26 -0
- package/src/lib/components/linetimeseriechart/linetimeseriechart.component.tsx +272 -229
- package/src/lib/components/sparkline/sparkline.component.tsx +54 -0
- package/src/lib/components/text/Text.component.tsx +15 -2
- package/src/lib/next.ts +12 -2
- package/stories/BarChart/barchart.stories.tsx +7 -1
- package/stories/GlobalHealthBar/globalhealthbarRecharts.stories.tsx +145 -0
- package/stories/GlobalHealthBar/globalheathbarrecharts.guideline.mdx +5 -0
- package/stories/InlineInput/InlineInput.stories.tsx +7 -1
- package/stories/globalhealthbar.stories.tsx +25 -5
- package/stories/linetimeseriechart.stories.tsx +217 -1
- package/stories/sparkline.stories.tsx +168 -0
- package/dist/components/barchartv2/ChartTooltip.d.ts +0 -14
- package/dist/components/barchartv2/ChartTooltip.d.ts.map +0 -1
- package/dist/components/barchartv2/ChartTooltip.js +0 -41
- package/src/lib/components/barchartv2/ChartTooltip.tsx +0 -106
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
import { useHealthBarData, Alert } from './useHealthBarData';
|
|
2
|
+
import { renderHook } from '@testing-library/react';
|
|
3
|
+
describe('useHealthBarData', () => {
|
|
4
|
+
const mockTimestamp = {
|
|
5
|
+
start: new Date('2023-12-01T00:00:00Z').getTime(),
|
|
6
|
+
end: new Date('2023-12-01T12:00:00Z').getTime(),
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const createMockAlert = (
|
|
10
|
+
severity: 'warning' | 'critical',
|
|
11
|
+
startsAt: string,
|
|
12
|
+
endsAt: string,
|
|
13
|
+
description = 'Test alert',
|
|
14
|
+
): Alert => ({
|
|
15
|
+
description,
|
|
16
|
+
severity,
|
|
17
|
+
startsAt,
|
|
18
|
+
endsAt,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('Alert Filtering', () => {
|
|
22
|
+
it('should include alerts that are completely within the time range', () => {
|
|
23
|
+
const alerts: Alert[] = [
|
|
24
|
+
createMockAlert(
|
|
25
|
+
'critical',
|
|
26
|
+
'2023-12-01T02:00:00Z',
|
|
27
|
+
'2023-12-01T04:00:00Z',
|
|
28
|
+
),
|
|
29
|
+
createMockAlert(
|
|
30
|
+
'warning',
|
|
31
|
+
'2023-12-01T06:00:00Z',
|
|
32
|
+
'2023-12-01T08:00:00Z',
|
|
33
|
+
),
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const { result } = renderHook(() =>
|
|
37
|
+
useHealthBarData(
|
|
38
|
+
alerts,
|
|
39
|
+
mockTimestamp.start,
|
|
40
|
+
mockTimestamp.end,
|
|
41
|
+
'test-id',
|
|
42
|
+
),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
expect(result.current.chartData[0]).toHaveProperty('critical_0');
|
|
46
|
+
expect(result.current.chartData[0]).toHaveProperty('warning_1');
|
|
47
|
+
expect(result.current.alertKeys.criticalKeys).toContain('critical_0');
|
|
48
|
+
expect(result.current.alertKeys.warningKeys).toContain('warning_1');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should include alerts that start before and end within the time range', () => {
|
|
52
|
+
const alerts: Alert[] = [
|
|
53
|
+
createMockAlert(
|
|
54
|
+
'critical',
|
|
55
|
+
'2023-11-30T22:00:00Z',
|
|
56
|
+
'2023-12-01T04:00:00Z',
|
|
57
|
+
),
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
const { result } = renderHook(() =>
|
|
61
|
+
useHealthBarData(
|
|
62
|
+
alerts,
|
|
63
|
+
mockTimestamp.start,
|
|
64
|
+
mockTimestamp.end,
|
|
65
|
+
'test-id',
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
expect(result.current.chartData[0]).toHaveProperty('critical_0');
|
|
70
|
+
expect(result.current.alertKeys.criticalKeys).toContain('critical_0');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should include alerts that start within and end after the time range', () => {
|
|
74
|
+
const alerts: Alert[] = [
|
|
75
|
+
createMockAlert(
|
|
76
|
+
'warning',
|
|
77
|
+
'2023-12-01T10:00:00Z',
|
|
78
|
+
'2023-12-01T14:00:00Z',
|
|
79
|
+
),
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const { result } = renderHook(() =>
|
|
83
|
+
useHealthBarData(
|
|
84
|
+
alerts,
|
|
85
|
+
mockTimestamp.start,
|
|
86
|
+
mockTimestamp.end,
|
|
87
|
+
'test-id',
|
|
88
|
+
),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
expect(result.current.chartData[0]).toHaveProperty('warning_0');
|
|
92
|
+
expect(result.current.alertKeys.warningKeys).toContain('warning_0');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should include alerts that span the entire time range', () => {
|
|
96
|
+
const alerts: Alert[] = [
|
|
97
|
+
createMockAlert(
|
|
98
|
+
'critical',
|
|
99
|
+
'2023-11-30T20:00:00Z',
|
|
100
|
+
'2023-12-01T16:00:00Z',
|
|
101
|
+
),
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
const { result } = renderHook(() =>
|
|
105
|
+
useHealthBarData(
|
|
106
|
+
alerts,
|
|
107
|
+
mockTimestamp.start,
|
|
108
|
+
mockTimestamp.end,
|
|
109
|
+
'test-id',
|
|
110
|
+
),
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
expect(result.current.chartData[0]).toHaveProperty('critical_0');
|
|
114
|
+
expect(result.current.alertKeys.criticalKeys).toContain('critical_0');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should exclude alerts that are completely before the time range', () => {
|
|
118
|
+
const alerts: Alert[] = [
|
|
119
|
+
createMockAlert(
|
|
120
|
+
'warning',
|
|
121
|
+
'2023-11-30T10:00:00Z',
|
|
122
|
+
'2023-11-30T20:00:00Z',
|
|
123
|
+
),
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
const { result } = renderHook(() =>
|
|
127
|
+
useHealthBarData(
|
|
128
|
+
alerts,
|
|
129
|
+
mockTimestamp.start,
|
|
130
|
+
mockTimestamp.end,
|
|
131
|
+
'test-id',
|
|
132
|
+
),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
expect(result.current.chartData[0]).not.toHaveProperty('warning_0');
|
|
136
|
+
expect(result.current.alertKeys.warningKeys).toHaveLength(0);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should exclude alerts that are completely after the time range', () => {
|
|
140
|
+
const alerts: Alert[] = [
|
|
141
|
+
createMockAlert(
|
|
142
|
+
'critical',
|
|
143
|
+
'2023-12-01T14:00:00Z',
|
|
144
|
+
'2023-12-01T18:00:00Z',
|
|
145
|
+
),
|
|
146
|
+
];
|
|
147
|
+
|
|
148
|
+
const { result } = renderHook(() =>
|
|
149
|
+
useHealthBarData(
|
|
150
|
+
alerts,
|
|
151
|
+
mockTimestamp.start,
|
|
152
|
+
mockTimestamp.end,
|
|
153
|
+
'test-id',
|
|
154
|
+
),
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
expect(result.current.chartData[0]).not.toHaveProperty('critical_0');
|
|
158
|
+
expect(result.current.alertKeys.criticalKeys).toHaveLength(0);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe('Data Transformation', () => {
|
|
163
|
+
it('should create correct data structure with basic properties', () => {
|
|
164
|
+
const alerts: Alert[] = [
|
|
165
|
+
createMockAlert(
|
|
166
|
+
'warning',
|
|
167
|
+
'2023-12-01T02:00:00Z',
|
|
168
|
+
'2023-12-01T04:00:00Z',
|
|
169
|
+
),
|
|
170
|
+
];
|
|
171
|
+
|
|
172
|
+
const { result } = renderHook(() =>
|
|
173
|
+
useHealthBarData(
|
|
174
|
+
alerts,
|
|
175
|
+
mockTimestamp.start,
|
|
176
|
+
mockTimestamp.end,
|
|
177
|
+
'test-id',
|
|
178
|
+
),
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
const data = result.current.chartData[0];
|
|
182
|
+
expect(data.range).toEqual([mockTimestamp.start, mockTimestamp.end]);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should create correct alert data keys with timestamps', () => {
|
|
186
|
+
const alerts: Alert[] = [
|
|
187
|
+
createMockAlert(
|
|
188
|
+
'critical',
|
|
189
|
+
'2023-12-01T02:00:00Z',
|
|
190
|
+
'2023-12-01T04:00:00Z',
|
|
191
|
+
),
|
|
192
|
+
];
|
|
193
|
+
|
|
194
|
+
const { result } = renderHook(() =>
|
|
195
|
+
useHealthBarData(
|
|
196
|
+
alerts,
|
|
197
|
+
mockTimestamp.start,
|
|
198
|
+
mockTimestamp.end,
|
|
199
|
+
'test-id',
|
|
200
|
+
),
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const data = result.current.chartData[0];
|
|
204
|
+
const expectedStartTime = new Date('2023-12-01T02:00:00Z').getTime();
|
|
205
|
+
const expectedEndTime = new Date('2023-12-01T04:00:00Z').getTime();
|
|
206
|
+
|
|
207
|
+
expect(data['critical_0']).toEqual([expectedStartTime, expectedEndTime]);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('should create alert metadata with correct structure', () => {
|
|
211
|
+
const alerts: Alert[] = [
|
|
212
|
+
createMockAlert(
|
|
213
|
+
'warning',
|
|
214
|
+
'2023-12-01T02:00:00Z',
|
|
215
|
+
'2023-12-01T04:00:00Z',
|
|
216
|
+
'Test warning',
|
|
217
|
+
),
|
|
218
|
+
];
|
|
219
|
+
|
|
220
|
+
const { result } = renderHook(() =>
|
|
221
|
+
useHealthBarData(
|
|
222
|
+
alerts,
|
|
223
|
+
mockTimestamp.start,
|
|
224
|
+
mockTimestamp.end,
|
|
225
|
+
'test-id',
|
|
226
|
+
),
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
expect(result.current.alertsMap['warning_0']).toEqual({
|
|
230
|
+
description: 'Test warning',
|
|
231
|
+
severity: 'warning',
|
|
232
|
+
startsAt: '2023-12-01T02:00:00Z',
|
|
233
|
+
endsAt: '2023-12-01T04:00:00Z',
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('should handle multiple alerts with correct indexing', () => {
|
|
238
|
+
const alerts: Alert[] = [
|
|
239
|
+
createMockAlert(
|
|
240
|
+
'warning',
|
|
241
|
+
'2023-12-01T01:00:00Z',
|
|
242
|
+
'2023-12-01T02:00:00Z',
|
|
243
|
+
),
|
|
244
|
+
createMockAlert(
|
|
245
|
+
'critical',
|
|
246
|
+
'2023-12-01T03:00:00Z',
|
|
247
|
+
'2023-12-01T04:00:00Z',
|
|
248
|
+
),
|
|
249
|
+
createMockAlert(
|
|
250
|
+
'warning',
|
|
251
|
+
'2023-12-01T05:00:00Z',
|
|
252
|
+
'2023-12-01T06:00:00Z',
|
|
253
|
+
),
|
|
254
|
+
];
|
|
255
|
+
|
|
256
|
+
const { result } = renderHook(() =>
|
|
257
|
+
useHealthBarData(
|
|
258
|
+
alerts,
|
|
259
|
+
mockTimestamp.start,
|
|
260
|
+
mockTimestamp.end,
|
|
261
|
+
'test-id',
|
|
262
|
+
),
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
const data = result.current.chartData[0];
|
|
266
|
+
expect(data).toHaveProperty('warning_0');
|
|
267
|
+
expect(data).toHaveProperty('critical_1');
|
|
268
|
+
expect(data).toHaveProperty('warning_2');
|
|
269
|
+
expect(result.current.alertsMap).toHaveProperty('warning_0');
|
|
270
|
+
expect(result.current.alertsMap).toHaveProperty('critical_1');
|
|
271
|
+
expect(result.current.alertsMap).toHaveProperty('warning_2');
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
describe('Alert Key Categorization', () => {
|
|
276
|
+
it('should categorize alert keys by severity', () => {
|
|
277
|
+
const alerts: Alert[] = [
|
|
278
|
+
createMockAlert(
|
|
279
|
+
'warning',
|
|
280
|
+
'2023-12-01T01:00:00Z',
|
|
281
|
+
'2023-12-01T02:00:00Z',
|
|
282
|
+
),
|
|
283
|
+
createMockAlert(
|
|
284
|
+
'critical',
|
|
285
|
+
'2023-12-01T03:00:00Z',
|
|
286
|
+
'2023-12-01T04:00:00Z',
|
|
287
|
+
),
|
|
288
|
+
createMockAlert(
|
|
289
|
+
'warning',
|
|
290
|
+
'2023-12-01T05:00:00Z',
|
|
291
|
+
'2023-12-01T06:00:00Z',
|
|
292
|
+
),
|
|
293
|
+
createMockAlert(
|
|
294
|
+
'critical',
|
|
295
|
+
'2023-12-01T07:00:00Z',
|
|
296
|
+
'2023-12-01T08:00:00Z',
|
|
297
|
+
),
|
|
298
|
+
];
|
|
299
|
+
|
|
300
|
+
const { result } = renderHook(() =>
|
|
301
|
+
useHealthBarData(
|
|
302
|
+
alerts,
|
|
303
|
+
mockTimestamp.start,
|
|
304
|
+
mockTimestamp.end,
|
|
305
|
+
'test-id',
|
|
306
|
+
),
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
expect(result.current.alertKeys.warningKeys).toEqual([
|
|
310
|
+
'warning_0',
|
|
311
|
+
'warning_2',
|
|
312
|
+
]);
|
|
313
|
+
expect(result.current.alertKeys.criticalKeys).toEqual([
|
|
314
|
+
'critical_1',
|
|
315
|
+
'critical_3',
|
|
316
|
+
]);
|
|
317
|
+
expect(result.current.alertKeys.unavailableKeys).toEqual([]);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('should handle only warning alerts', () => {
|
|
321
|
+
const alerts: Alert[] = [
|
|
322
|
+
createMockAlert(
|
|
323
|
+
'warning',
|
|
324
|
+
'2023-12-01T01:00:00Z',
|
|
325
|
+
'2023-12-01T02:00:00Z',
|
|
326
|
+
),
|
|
327
|
+
createMockAlert(
|
|
328
|
+
'warning',
|
|
329
|
+
'2023-12-01T03:00:00Z',
|
|
330
|
+
'2023-12-01T04:00:00Z',
|
|
331
|
+
),
|
|
332
|
+
];
|
|
333
|
+
|
|
334
|
+
const { result } = renderHook(() =>
|
|
335
|
+
useHealthBarData(
|
|
336
|
+
alerts,
|
|
337
|
+
mockTimestamp.start,
|
|
338
|
+
mockTimestamp.end,
|
|
339
|
+
'test-id',
|
|
340
|
+
),
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
expect(result.current.alertKeys.warningKeys).toEqual([
|
|
344
|
+
'warning_0',
|
|
345
|
+
'warning_1',
|
|
346
|
+
]);
|
|
347
|
+
expect(result.current.alertKeys.criticalKeys).toEqual([]);
|
|
348
|
+
expect(result.current.alertKeys.unavailableKeys).toEqual([]);
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('should handle only critical alerts', () => {
|
|
352
|
+
const alerts: Alert[] = [
|
|
353
|
+
createMockAlert(
|
|
354
|
+
'critical',
|
|
355
|
+
'2023-12-01T01:00:00Z',
|
|
356
|
+
'2023-12-01T02:00:00Z',
|
|
357
|
+
),
|
|
358
|
+
createMockAlert(
|
|
359
|
+
'critical',
|
|
360
|
+
'2023-12-01T03:00:00Z',
|
|
361
|
+
'2023-12-01T04:00:00Z',
|
|
362
|
+
),
|
|
363
|
+
];
|
|
364
|
+
|
|
365
|
+
const { result } = renderHook(() =>
|
|
366
|
+
useHealthBarData(
|
|
367
|
+
alerts,
|
|
368
|
+
mockTimestamp.start,
|
|
369
|
+
mockTimestamp.end,
|
|
370
|
+
'test-id',
|
|
371
|
+
),
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
expect(result.current.alertKeys.warningKeys).toEqual([]);
|
|
375
|
+
expect(result.current.alertKeys.criticalKeys).toEqual([
|
|
376
|
+
'critical_0',
|
|
377
|
+
'critical_1',
|
|
378
|
+
]);
|
|
379
|
+
expect(result.current.alertKeys.unavailableKeys).toEqual([]);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('should only include alert bar keys and exclude metadata and basic properties', () => {
|
|
383
|
+
const alerts: Alert[] = [
|
|
384
|
+
createMockAlert(
|
|
385
|
+
'warning',
|
|
386
|
+
'2023-12-01T01:00:00Z',
|
|
387
|
+
'2023-12-01T02:00:00Z',
|
|
388
|
+
),
|
|
389
|
+
];
|
|
390
|
+
|
|
391
|
+
const { result } = renderHook(() =>
|
|
392
|
+
useHealthBarData(
|
|
393
|
+
alerts,
|
|
394
|
+
mockTimestamp.start,
|
|
395
|
+
mockTimestamp.end,
|
|
396
|
+
'test-id',
|
|
397
|
+
),
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
// Should only contain the actual alert bar keys for rendering
|
|
401
|
+
expect(result.current.alertKeys.warningKeys).toEqual(['warning_0']);
|
|
402
|
+
|
|
403
|
+
// Should not contain basic data properties
|
|
404
|
+
expect(result.current.alertKeys.warningKeys).not.toContain('start');
|
|
405
|
+
expect(result.current.alertKeys.warningKeys).not.toContain('end');
|
|
406
|
+
expect(result.current.alertKeys.warningKeys).not.toContain('range');
|
|
407
|
+
expect(result.current.alertKeys.warningKeys).not.toContain('id');
|
|
408
|
+
|
|
409
|
+
// Should not contain alert metadata keys (used for tooltips, not bars)
|
|
410
|
+
expect(result.current.alertKeys.warningKeys).not.toContain(
|
|
411
|
+
'alert_warning_0',
|
|
412
|
+
);
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
describe('Edge Cases', () => {
|
|
417
|
+
it('should handle empty alerts array', () => {
|
|
418
|
+
const { result } = renderHook(() =>
|
|
419
|
+
useHealthBarData([], mockTimestamp.start, mockTimestamp.end, 'test-id'),
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
const data = result.current.chartData[0];
|
|
423
|
+
expect(data.range).toEqual([mockTimestamp.start, mockTimestamp.end]);
|
|
424
|
+
expect(result.current.alertKeys.warningKeys).toEqual([]);
|
|
425
|
+
expect(result.current.alertKeys.criticalKeys).toEqual([]);
|
|
426
|
+
expect(result.current.alertKeys.unavailableKeys).toEqual([]);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it('should handle overlapping alerts correctly', () => {
|
|
430
|
+
const alerts: Alert[] = [
|
|
431
|
+
createMockAlert(
|
|
432
|
+
'warning',
|
|
433
|
+
'2023-12-01T01:00:00Z',
|
|
434
|
+
'2023-12-01T04:00:00Z',
|
|
435
|
+
),
|
|
436
|
+
createMockAlert(
|
|
437
|
+
'critical',
|
|
438
|
+
'2023-12-01T02:00:00Z',
|
|
439
|
+
'2023-12-01T05:00:00Z',
|
|
440
|
+
),
|
|
441
|
+
];
|
|
442
|
+
|
|
443
|
+
const { result } = renderHook(() =>
|
|
444
|
+
useHealthBarData(
|
|
445
|
+
alerts,
|
|
446
|
+
mockTimestamp.start,
|
|
447
|
+
mockTimestamp.end,
|
|
448
|
+
'test-id',
|
|
449
|
+
),
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
expect(result.current.chartData[0]).toHaveProperty('warning_0');
|
|
453
|
+
expect(result.current.chartData[0]).toHaveProperty('critical_1');
|
|
454
|
+
expect(result.current.alertKeys.warningKeys).toContain('warning_0');
|
|
455
|
+
expect(result.current.alertKeys.criticalKeys).toContain('critical_1');
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
it('should handle alerts with same timestamps', () => {
|
|
459
|
+
const alerts: Alert[] = [
|
|
460
|
+
createMockAlert(
|
|
461
|
+
'warning',
|
|
462
|
+
'2023-12-01T02:00:00Z',
|
|
463
|
+
'2023-12-01T04:00:00Z',
|
|
464
|
+
),
|
|
465
|
+
createMockAlert(
|
|
466
|
+
'critical',
|
|
467
|
+
'2023-12-01T02:00:00Z',
|
|
468
|
+
'2023-12-01T04:00:00Z',
|
|
469
|
+
),
|
|
470
|
+
];
|
|
471
|
+
|
|
472
|
+
const { result } = renderHook(() =>
|
|
473
|
+
useHealthBarData(
|
|
474
|
+
alerts,
|
|
475
|
+
mockTimestamp.start,
|
|
476
|
+
mockTimestamp.end,
|
|
477
|
+
'test-id',
|
|
478
|
+
),
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
expect(result.current.chartData[0]).toHaveProperty('warning_0');
|
|
482
|
+
expect(result.current.chartData[0]).toHaveProperty('critical_1');
|
|
483
|
+
expect(result.current.alertKeys.warningKeys).toContain('warning_0');
|
|
484
|
+
expect(result.current.alertKeys.criticalKeys).toContain('critical_1');
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface Alert {
|
|
4
|
+
description: string;
|
|
5
|
+
startsAt: string;
|
|
6
|
+
endsAt: string;
|
|
7
|
+
severity: 'warning' | 'critical' | 'unavailable';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const useHealthBarData = (
|
|
11
|
+
alerts: Alert[],
|
|
12
|
+
startTimestamp: number,
|
|
13
|
+
endTimestamp: number,
|
|
14
|
+
id: string,
|
|
15
|
+
) => {
|
|
16
|
+
// Filter alerts to only include alerts that are within the start and end timestamp
|
|
17
|
+
const filteredAlerts = useMemo(
|
|
18
|
+
() =>
|
|
19
|
+
alerts.filter(
|
|
20
|
+
(alert) =>
|
|
21
|
+
(new Date(alert.endsAt).getTime() >= startTimestamp &&
|
|
22
|
+
new Date(alert.startsAt).getTime() <= endTimestamp) ||
|
|
23
|
+
(new Date(alert.startsAt).getTime() <= endTimestamp &&
|
|
24
|
+
new Date(alert.endsAt).getTime() >= startTimestamp),
|
|
25
|
+
),
|
|
26
|
+
[alerts, startTimestamp, endTimestamp],
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// Create chart data and alerts map separately
|
|
30
|
+
const { chartData, alertsMap, alertKeys } = useMemo(() => {
|
|
31
|
+
const alertBars: Record<string, [number, number]> = {};
|
|
32
|
+
const alertsMapData: Record<string, Alert> = {};
|
|
33
|
+
|
|
34
|
+
filteredAlerts.forEach((alert, index) => {
|
|
35
|
+
// Use alert index with severity to create unique keys for bars dataKey
|
|
36
|
+
// Bars format is: dataKey: [startTimestamp, endTimestamp]
|
|
37
|
+
const uniqueKey = `${alert.severity}_${index}`;
|
|
38
|
+
|
|
39
|
+
alertBars[uniqueKey] = [
|
|
40
|
+
new Date(alert.startsAt).getTime(),
|
|
41
|
+
new Date(alert.endsAt).getTime(),
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
// Store alert data separately for tooltip access
|
|
45
|
+
alertsMapData[uniqueKey] = {
|
|
46
|
+
...alert,
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Chart data - ready for BarChart (as array)
|
|
51
|
+
const chartDataArray = [
|
|
52
|
+
{
|
|
53
|
+
range: [startTimestamp, endTimestamp],
|
|
54
|
+
...alertBars,
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
// Alert keys for bar rendering
|
|
59
|
+
const allKeys = Object.keys(alertBars);
|
|
60
|
+
const alertKeysData = {
|
|
61
|
+
warningKeys: allKeys.filter((key) => key.startsWith('warning')),
|
|
62
|
+
criticalKeys: allKeys.filter((key) => key.startsWith('critical')),
|
|
63
|
+
unavailableKeys: allKeys.filter((key) => key.startsWith('unavailable')),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
chartData: chartDataArray,
|
|
68
|
+
alertsMap: alertsMapData,
|
|
69
|
+
alertKeys: alertKeysData,
|
|
70
|
+
};
|
|
71
|
+
}, [filteredAlerts, startTimestamp, endTimestamp]);
|
|
72
|
+
|
|
73
|
+
return { chartData, alertsMap, alertKeys };
|
|
74
|
+
};
|
|
@@ -148,8 +148,24 @@ export function addMissingDataPoint(
|
|
|
148
148
|
|
|
149
149
|
const newValues: [number, number | string | null][] = [];
|
|
150
150
|
|
|
151
|
+
// add missing data points for the starting time
|
|
152
|
+
for (
|
|
153
|
+
let i = startingTimeStamp;
|
|
154
|
+
i < orginalValues[0][0];
|
|
155
|
+
i += sampleInterval
|
|
156
|
+
) {
|
|
157
|
+
newValues.push([i, NAN_STRING]);
|
|
158
|
+
}
|
|
159
|
+
|
|
151
160
|
// Process all but the last element
|
|
152
161
|
for (let i = 0; i < orginalValues.length - 1; i++) {
|
|
162
|
+
if (
|
|
163
|
+
orginalValues[i][0] < startingTimeStamp ||
|
|
164
|
+
orginalValues[i][0] > startingTimeStamp + sampleDuration
|
|
165
|
+
) {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
|
|
153
169
|
// Always add the current data point
|
|
154
170
|
newValues.push(orginalValues[i]);
|
|
155
171
|
|
|
@@ -170,8 +186,18 @@ export function addMissingDataPoint(
|
|
|
170
186
|
// Add the last element
|
|
171
187
|
newValues.push(orginalValues[orginalValues.length - 1]);
|
|
172
188
|
|
|
189
|
+
// add missing data points for the ending time
|
|
190
|
+
for (
|
|
191
|
+
let i = orginalValues[orginalValues.length - 1][0] + sampleInterval;
|
|
192
|
+
i < startingTimeStamp + sampleDuration;
|
|
193
|
+
i += sampleInterval
|
|
194
|
+
) {
|
|
195
|
+
newValues.push([i, NAN_STRING]);
|
|
196
|
+
}
|
|
197
|
+
|
|
173
198
|
return newValues;
|
|
174
199
|
}
|
|
200
|
+
|
|
175
201
|
// get the value for the based value
|
|
176
202
|
// TODO: We need to handle the negative value in the future
|
|
177
203
|
export const getRelativeValue = (value: number, base: number) => {
|