@scality/core-ui 0.186.0 → 0.188.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.
Files changed (171) hide show
  1. package/dist/components/{linetemporalchart/MetricTimespanProvider.d.ts → charts/MetricsTimeSpanProvider.d.ts} +1 -1
  2. package/dist/components/charts/MetricsTimeSpanProvider.d.ts.map +1 -0
  3. package/dist/components/{barchartv2/Barchart.component.d.ts → charts/barchart/Barchart.d.ts} +2 -33
  4. package/dist/components/charts/barchart/Barchart.d.ts.map +1 -0
  5. package/dist/components/charts/barchart/Barchart.js +56 -0
  6. package/dist/components/{barchartv2/utils.d.ts → charts/barchart/Barchart.utils.d.ts} +8 -35
  7. package/dist/components/charts/barchart/Barchart.utils.d.ts.map +1 -0
  8. package/dist/components/{barchartv2/utils.js → charts/barchart/Barchart.utils.js} +7 -88
  9. package/dist/components/{barchartv2 → charts/barchart}/BarchartTooltip.d.ts +2 -1
  10. package/dist/components/charts/barchart/BarchartTooltip.d.ts.map +1 -0
  11. package/dist/components/{barchartv2 → charts/barchart}/BarchartTooltip.js +3 -3
  12. package/dist/components/{charttooltip → charts/common}/ChartTooltip.d.ts +9 -2
  13. package/dist/components/charts/common/ChartTooltip.d.ts.map +1 -0
  14. package/dist/components/{charttooltip → charts/common}/ChartTooltip.js +11 -15
  15. package/dist/components/charts/common/SharedComponents.d.ts +47 -0
  16. package/dist/components/charts/common/SharedComponents.d.ts.map +1 -0
  17. package/dist/components/charts/common/SharedComponents.js +83 -0
  18. package/dist/components/charts/common/chartUtils.d.ts +91 -0
  19. package/dist/components/charts/common/chartUtils.d.ts.map +1 -0
  20. package/dist/components/charts/common/chartUtils.js +243 -0
  21. package/dist/components/{globalhealthbar/GlobalHealthBarRecharts.component.d.ts → charts/globalhealthbar/GlobalHealthBar.d.ts} +2 -2
  22. package/dist/components/charts/globalhealthbar/GlobalHealthBar.d.ts.map +1 -0
  23. package/dist/components/{globalhealthbar/useHealthBarData.d.ts → charts/globalhealthbar/GlobalHealthBar.hooks.d.ts} +1 -1
  24. package/dist/components/charts/globalhealthbar/GlobalHealthBar.hooks.d.ts.map +1 -0
  25. package/dist/components/{globalhealthbar/GlobalHealthBarRecharts.component.js → charts/globalhealthbar/GlobalHealthBar.js} +4 -4
  26. package/dist/components/{globalhealthbar/healthBarUtils.d.ts → charts/globalhealthbar/GlobalHealthBar.utils.d.ts} +1 -1
  27. package/dist/components/charts/globalhealthbar/GlobalHealthBar.utils.d.ts.map +1 -0
  28. package/dist/components/{globalhealthbar/healthBarUtils.js → charts/globalhealthbar/GlobalHealthBar.utils.js} +1 -1
  29. package/dist/components/{globalhealthbar/components → charts/globalhealthbar}/GlobalHealthBarTooltip.d.ts +1 -1
  30. package/dist/components/charts/globalhealthbar/GlobalHealthBarTooltip.d.ts.map +1 -0
  31. package/dist/components/{globalhealthbar/components → charts/globalhealthbar}/GlobalHealthBarTooltip.js +7 -3
  32. package/dist/components/charts/globalhealthbar/HealthBarXAxis.d.ts.map +1 -0
  33. package/dist/components/{globalhealthbar/components → charts/globalhealthbar}/HealthBarXAxis.js +1 -1
  34. package/dist/components/charts/index.d.ts +16 -0
  35. package/dist/components/charts/index.d.ts.map +1 -0
  36. package/dist/components/charts/index.js +15 -0
  37. package/dist/components/{chartlegend → charts/legend}/ChartLegend.d.ts +1 -1
  38. package/dist/components/charts/legend/ChartLegend.d.ts.map +1 -0
  39. package/dist/components/{chartlegend → charts/legend}/ChartLegend.js +2 -2
  40. package/dist/components/{chartlegend → charts/legend}/ChartLegendWrapper.d.ts +1 -1
  41. package/dist/components/charts/legend/ChartLegendWrapper.d.ts.map +1 -0
  42. package/dist/components/{linetimeseriechart/linetimeseriechart.component.d.ts → charts/linetimeseries/LineTimeSerieChart.d.ts} +12 -2
  43. package/dist/components/charts/linetimeseries/LineTimeSerieChart.d.ts.map +1 -0
  44. package/dist/components/{linetimeseriechart/linetimeseriechart.component.js → charts/linetimeseries/LineTimeSerieChart.js} +34 -35
  45. package/dist/components/charts/linetimeseries/LineTimeSerieChart.utils.d.ts +14 -0
  46. package/dist/components/charts/linetimeseries/LineTimeSerieChart.utils.d.ts.map +1 -0
  47. package/dist/components/{linetimeseriechart/utils.js → charts/linetimeseries/LineTimeSerieChart.utils.js} +4 -6
  48. package/dist/components/charts/sparkline/Sparkline.d.ts +23 -0
  49. package/dist/components/charts/sparkline/Sparkline.d.ts.map +1 -0
  50. package/dist/components/{sparkline/sparkline.component.js → charts/sparkline/Sparkline.js} +12 -6
  51. package/dist/components/charts/types.d.ts +34 -0
  52. package/dist/components/charts/types.d.ts.map +1 -0
  53. package/dist/components/charts/types.js +4 -0
  54. package/dist/components/icon/Icon.component.d.ts +1 -0
  55. package/dist/components/icon/Icon.component.d.ts.map +1 -1
  56. package/dist/components/icon/Icon.component.js +2 -2
  57. package/dist/components/textbadge/TextBadge.component.d.ts +1 -1
  58. package/dist/components/textbadge/TextBadge.component.d.ts.map +1 -1
  59. package/dist/index.d.ts +0 -2
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +4 -2
  62. package/dist/next.d.ts +3 -11
  63. package/dist/next.d.ts.map +1 -1
  64. package/dist/next.js +4 -11
  65. package/package.json +2 -6
  66. package/src/lib/components/{barchartv2/Barchart.component.test.tsx → charts/barchart/Barchart.test.tsx} +35 -10
  67. package/src/lib/components/{barchartv2/Barchart.component.tsx → charts/barchart/Barchart.tsx} +42 -207
  68. package/src/lib/components/{barchartv2/utils.test.ts → charts/barchart/Barchart.utils.test.ts} +2 -141
  69. package/src/lib/components/{barchartv2/utils.ts → charts/barchart/Barchart.utils.ts} +17 -143
  70. package/src/lib/components/{barchartv2 → charts/barchart}/BarchartTooltip.tsx +5 -9
  71. package/src/lib/components/{charttooltip → charts/common}/ChartTooltip.tsx +13 -20
  72. package/src/lib/components/charts/common/SharedComponents.tsx +193 -0
  73. package/src/lib/components/charts/common/chartUtils.test.ts +402 -0
  74. package/src/lib/components/charts/common/chartUtils.ts +334 -0
  75. package/src/lib/components/{globalhealthbar/useHealthBarData.spec.tsx → charts/globalhealthbar/GlobalHealthBar.hooks.test.tsx} +1 -1
  76. package/src/lib/components/{globalhealthbar/GlobalHealthBarRecharts.component.tsx → charts/globalhealthbar/GlobalHealthBar.tsx} +4 -4
  77. package/src/lib/components/{globalhealthbar/healthBarUtils.spec.ts → charts/globalhealthbar/GlobalHealthBar.utils.test.ts} +1 -1
  78. package/src/lib/components/{globalhealthbar/healthBarUtils.ts → charts/globalhealthbar/GlobalHealthBar.utils.ts} +1 -1
  79. package/src/lib/components/{globalhealthbar/components → charts/globalhealthbar}/GlobalHealthBarTooltip.tsx +8 -4
  80. package/src/lib/components/{globalhealthbar/components → charts/globalhealthbar}/HealthBarXAxis.tsx +1 -1
  81. package/src/lib/components/charts/index.ts +59 -0
  82. package/src/lib/components/{chartlegend → charts/legend}/ChartLegend.tsx +2 -2
  83. package/src/lib/components/{chartlegend → charts/legend}/ChartLegendWrapper.tsx +1 -1
  84. package/src/lib/components/{linetimeseriechart/linetimeseriechart.test.tsx → charts/linetimeseries/LineTimeSerieChart.test.tsx} +3 -6
  85. package/src/lib/components/{linetimeseriechart/linetimeseriechart.component.tsx → charts/linetimeseries/LineTimeSerieChart.tsx} +48 -44
  86. package/src/lib/components/{linetimeseriechart/utils.test.ts → charts/linetimeseries/LineTimeSerieChart.utils.test.ts} +1 -1
  87. package/src/lib/components/{linetimeseriechart/utils.ts → charts/linetimeseries/LineTimeSerieChart.utils.ts} +4 -6
  88. package/src/lib/components/charts/sparkline/Sparkline.tsx +80 -0
  89. package/src/lib/components/charts/types.ts +36 -0
  90. package/src/lib/components/icon/Icon.component.tsx +12 -8
  91. package/src/lib/components/textbadge/TextBadge.component.tsx +1 -1
  92. package/src/lib/index.ts +4 -2
  93. package/src/lib/next.ts +26 -13
  94. package/stories/BarChart/barchart.stories.tsx +10 -9
  95. package/stories/GlobalHealthBar/{globalhealthbarRecharts.stories.tsx → globalhealthbar.stories.tsx} +3 -21
  96. package/stories/GlobalHealthBar/globalheathbarrecharts.guideline.mdx +2 -2
  97. package/stories/guideline/chart-guideline.mdx +1 -38
  98. package/stories/linetimeseriechart.stories.tsx +4 -6
  99. package/stories/sparkline.stories.tsx +13 -11
  100. package/stories/textbadge.stories.tsx +15 -0
  101. package/dist/components/barchart/BarChart.component.d.ts +0 -17
  102. package/dist/components/barchart/BarChart.component.d.ts.map +0 -1
  103. package/dist/components/barchart/BarChart.component.js +0 -27
  104. package/dist/components/barchartv2/Barchart.component.d.ts.map +0 -1
  105. package/dist/components/barchartv2/Barchart.component.js +0 -122
  106. package/dist/components/barchartv2/BarchartTooltip.d.ts.map +0 -1
  107. package/dist/components/barchartv2/utils.d.ts.map +0 -1
  108. package/dist/components/chartlegend/ChartLegend.d.ts.map +0 -1
  109. package/dist/components/chartlegend/ChartLegendWrapper.d.ts.map +0 -1
  110. package/dist/components/charttooltip/ChartTooltip.d.ts.map +0 -1
  111. package/dist/components/globalhealthbar/GlobalHealthBar.component.d.ts +0 -23
  112. package/dist/components/globalhealthbar/GlobalHealthBar.component.d.ts.map +0 -1
  113. package/dist/components/globalhealthbar/GlobalHealthBar.component.js +0 -173
  114. package/dist/components/globalhealthbar/GlobalHealthBarRecharts.component.d.ts.map +0 -1
  115. package/dist/components/globalhealthbar/components/GlobalHealthBarTooltip.d.ts.map +0 -1
  116. package/dist/components/globalhealthbar/components/HealthBarXAxis.d.ts.map +0 -1
  117. package/dist/components/globalhealthbar/healthBarUtils.d.ts.map +0 -1
  118. package/dist/components/globalhealthbar/healthBarUtils.spec.d.ts +0 -2
  119. package/dist/components/globalhealthbar/healthBarUtils.spec.d.ts.map +0 -1
  120. package/dist/components/globalhealthbar/healthBarUtils.spec.js +0 -391
  121. package/dist/components/globalhealthbar/tooltip/index.d.ts +0 -8
  122. package/dist/components/globalhealthbar/tooltip/index.d.ts.map +0 -1
  123. package/dist/components/globalhealthbar/tooltip/index.js +0 -55
  124. package/dist/components/globalhealthbar/useHealthBarData.d.ts.map +0 -1
  125. package/dist/components/globalhealthbar/useHealthBarData.spec.d.ts +0 -2
  126. package/dist/components/globalhealthbar/useHealthBarData.spec.d.ts.map +0 -1
  127. package/dist/components/globalhealthbar/useHealthBarData.spec.js +0 -209
  128. package/dist/components/linetemporalchart/ChartUtil.d.ts +0 -41
  129. package/dist/components/linetemporalchart/ChartUtil.d.ts.map +0 -1
  130. package/dist/components/linetemporalchart/ChartUtil.js +0 -148
  131. package/dist/components/linetemporalchart/LineTemporalChart.component.d.ts +0 -46
  132. package/dist/components/linetemporalchart/LineTemporalChart.component.d.ts.map +0 -1
  133. package/dist/components/linetemporalchart/LineTemporalChart.component.js +0 -579
  134. package/dist/components/linetemporalchart/MetricTimespanProvider.d.ts.map +0 -1
  135. package/dist/components/linetemporalchart/tooltip/index.d.ts +0 -30
  136. package/dist/components/linetemporalchart/tooltip/index.d.ts.map +0 -1
  137. package/dist/components/linetemporalchart/tooltip/index.js +0 -104
  138. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts.map +0 -1
  139. package/dist/components/linetimeseriechart/utils.d.ts +0 -16
  140. package/dist/components/linetimeseriechart/utils.d.ts.map +0 -1
  141. package/dist/components/sparkline/sparkline.component.d.ts +0 -17
  142. package/dist/components/sparkline/sparkline.component.d.ts.map +0 -1
  143. package/dist/components/vegachartv2/SyncedCursorCharts.d.ts +0 -12
  144. package/dist/components/vegachartv2/SyncedCursorCharts.d.ts.map +0 -1
  145. package/dist/components/vegachartv2/SyncedCursorCharts.js +0 -15
  146. package/dist/components/vegachartv2/VegaChartV2.component.d.ts +0 -15
  147. package/dist/components/vegachartv2/VegaChartV2.component.d.ts.map +0 -1
  148. package/dist/components/vegachartv2/VegaChartV2.component.js +0 -218
  149. package/src/lib/components/barchart/BarChart.component.tsx +0 -51
  150. package/src/lib/components/globalhealthbar/GlobalHealthBar.component.tsx +0 -204
  151. package/src/lib/components/globalhealthbar/tooltip/index.ts +0 -72
  152. package/src/lib/components/linetemporalchart/ChartUtil.test.ts +0 -250
  153. package/src/lib/components/linetemporalchart/ChartUtil.ts +0 -225
  154. package/src/lib/components/linetemporalchart/LineTemporalChart.component.tsx +0 -800
  155. package/src/lib/components/linetemporalchart/tooltip/index.ts +0 -178
  156. package/src/lib/components/sparkline/sparkline.component.tsx +0 -56
  157. package/src/lib/components/vegachartv2/SyncedCursorCharts.tsx +0 -28
  158. package/src/lib/components/vegachartv2/VegaChartV2.component.tsx +0 -276
  159. package/stories/barchart.stories.tsx +0 -142
  160. package/stories/globalhealthbar.stories.tsx +0 -191
  161. package/stories/guideline/mdxExampleComponents.tsx +0 -57
  162. package/stories/linecharttemporal.stories.tsx +0 -88
  163. /package/dist/components/{linetemporalchart/MetricTimespanProvider.js → charts/MetricsTimeSpanProvider.js} +0 -0
  164. /package/dist/components/{globalhealthbar/useHealthBarData.js → charts/globalhealthbar/GlobalHealthBar.hooks.js} +0 -0
  165. /package/dist/components/{globalhealthbar/components → charts/globalhealthbar}/HealthBarXAxis.d.ts +0 -0
  166. /package/dist/components/{chartlegend → charts/legend}/ChartLegendWrapper.js +0 -0
  167. /package/src/lib/components/{linetemporalchart/MetricTimespanProvider.tsx → charts/MetricsTimeSpanProvider.tsx} +0 -0
  168. /package/src/lib/components/{barchartv2 → charts/barchart}/BarchartTooltip.test.tsx +0 -0
  169. /package/src/lib/components/{globalhealthbar/useHealthBarData.ts → charts/globalhealthbar/GlobalHealthBar.hooks.ts} +0 -0
  170. /package/src/lib/components/{chartlegend → charts/legend}/ChartLegend.test.tsx +0 -0
  171. /package/src/lib/components/{chartlegend → charts/legend}/ChartLegendWrapper.test.tsx +0 -0
@@ -1,209 +0,0 @@
1
- import { useHealthBarData } 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
- const createMockAlert = (severity, startsAt, endsAt, description = 'Test alert') => ({
9
- description,
10
- severity,
11
- startsAt,
12
- endsAt,
13
- key: `${severity}_${startsAt}`,
14
- });
15
- describe('Alert Filtering', () => {
16
- it('should include alerts that are completely within the time range', () => {
17
- const alerts = [
18
- createMockAlert('critical', '2023-12-01T02:00:00Z', '2023-12-01T04:00:00Z'),
19
- createMockAlert('warning', '2023-12-01T06:00:00Z', '2023-12-01T08:00:00Z'),
20
- ];
21
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
22
- expect(result.current.chartData[0]).toHaveProperty('critical_0');
23
- expect(result.current.chartData[0]).toHaveProperty('warning_1');
24
- expect(result.current.alertKeys.criticalKeys).toContain('critical_0');
25
- expect(result.current.alertKeys.warningKeys).toContain('warning_1');
26
- });
27
- it('should include alerts that start before and end within the time range', () => {
28
- const alerts = [
29
- createMockAlert('critical', '2023-11-30T22:00:00Z', '2023-12-01T04:00:00Z'),
30
- ];
31
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
32
- expect(result.current.chartData[0]).toHaveProperty('critical_0');
33
- expect(result.current.alertKeys.criticalKeys).toContain('critical_0');
34
- });
35
- it('should include alerts that start within and end after the time range', () => {
36
- const alerts = [
37
- createMockAlert('warning', '2023-12-01T10:00:00Z', '2023-12-01T14:00:00Z'),
38
- ];
39
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
40
- expect(result.current.chartData[0]).toHaveProperty('warning_0');
41
- expect(result.current.alertKeys.warningKeys).toContain('warning_0');
42
- });
43
- it('should include alerts that span the entire time range', () => {
44
- const alerts = [
45
- createMockAlert('critical', '2023-11-30T20:00:00Z', '2023-12-01T16:00:00Z'),
46
- ];
47
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
48
- expect(result.current.chartData[0]).toHaveProperty('critical_0');
49
- expect(result.current.alertKeys.criticalKeys).toContain('critical_0');
50
- });
51
- it('should exclude alerts that are completely before the time range', () => {
52
- const alerts = [
53
- createMockAlert('warning', '2023-11-30T10:00:00Z', '2023-11-30T20:00:00Z'),
54
- ];
55
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
56
- expect(result.current.chartData[0]).not.toHaveProperty('warning_0');
57
- expect(result.current.alertKeys.warningKeys).toHaveLength(0);
58
- });
59
- it('should exclude alerts that are completely after the time range', () => {
60
- const alerts = [
61
- createMockAlert('critical', '2023-12-01T14:00:00Z', '2023-12-01T18:00:00Z'),
62
- ];
63
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
64
- expect(result.current.chartData[0]).not.toHaveProperty('critical_0');
65
- expect(result.current.alertKeys.criticalKeys).toHaveLength(0);
66
- });
67
- });
68
- describe('Data Transformation', () => {
69
- it('should create correct data structure with basic properties', () => {
70
- const alerts = [
71
- createMockAlert('warning', '2023-12-01T02:00:00Z', '2023-12-01T04:00:00Z'),
72
- ];
73
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
74
- const data = result.current.chartData[0];
75
- expect(data.range).toEqual([mockTimestamp.start, mockTimestamp.end]);
76
- });
77
- it('should create correct alert data keys with timestamps', () => {
78
- const alerts = [
79
- createMockAlert('critical', '2023-12-01T02:00:00Z', '2023-12-01T04:00:00Z'),
80
- ];
81
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
82
- const data = result.current.chartData[0];
83
- const expectedStartTime = new Date('2023-12-01T02:00:00Z').getTime();
84
- const expectedEndTime = new Date('2023-12-01T04:00:00Z').getTime();
85
- expect(data['critical_0']).toEqual([expectedStartTime, expectedEndTime]);
86
- });
87
- it('should create alert metadata with correct structure', () => {
88
- const alerts = [
89
- createMockAlert('warning', '2023-12-01T02:00:00Z', '2023-12-01T04:00:00Z', 'Test warning'),
90
- ];
91
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
92
- expect(result.current.alertsMap['warning_0']).toEqual({
93
- description: 'Test warning',
94
- severity: 'warning',
95
- startsAt: '2023-12-01T02:00:00Z',
96
- endsAt: '2023-12-01T04:00:00Z',
97
- key: 'warning_0',
98
- });
99
- });
100
- it('should handle multiple alerts with correct indexing', () => {
101
- const alerts = [
102
- createMockAlert('warning', '2023-12-01T01:00:00Z', '2023-12-01T02:00:00Z'),
103
- createMockAlert('critical', '2023-12-01T03:00:00Z', '2023-12-01T04:00:00Z'),
104
- createMockAlert('warning', '2023-12-01T05:00:00Z', '2023-12-01T06:00:00Z'),
105
- ];
106
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
107
- const data = result.current.chartData[0];
108
- expect(data).toHaveProperty('warning_0');
109
- expect(data).toHaveProperty('critical_1');
110
- expect(data).toHaveProperty('warning_2');
111
- expect(result.current.alertsMap).toHaveProperty('warning_0');
112
- expect(result.current.alertsMap).toHaveProperty('critical_1');
113
- expect(result.current.alertsMap).toHaveProperty('warning_2');
114
- });
115
- });
116
- describe('Alert Key Categorization', () => {
117
- it('should categorize alert keys by severity', () => {
118
- const alerts = [
119
- createMockAlert('warning', '2023-12-01T01:00:00Z', '2023-12-01T02:00:00Z'),
120
- createMockAlert('critical', '2023-12-01T03:00:00Z', '2023-12-01T04:00:00Z'),
121
- createMockAlert('warning', '2023-12-01T05:00:00Z', '2023-12-01T06:00:00Z'),
122
- createMockAlert('critical', '2023-12-01T07:00:00Z', '2023-12-01T08:00:00Z'),
123
- ];
124
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
125
- expect(result.current.alertKeys.warningKeys).toEqual([
126
- 'warning_0',
127
- 'warning_2',
128
- ]);
129
- expect(result.current.alertKeys.criticalKeys).toEqual([
130
- 'critical_1',
131
- 'critical_3',
132
- ]);
133
- expect(result.current.alertKeys.unavailableKeys).toEqual([]);
134
- });
135
- it('should handle only warning alerts', () => {
136
- const alerts = [
137
- createMockAlert('warning', '2023-12-01T01:00:00Z', '2023-12-01T02:00:00Z'),
138
- createMockAlert('warning', '2023-12-01T03:00:00Z', '2023-12-01T04:00:00Z'),
139
- ];
140
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
141
- expect(result.current.alertKeys.warningKeys).toEqual([
142
- 'warning_0',
143
- 'warning_1',
144
- ]);
145
- expect(result.current.alertKeys.criticalKeys).toEqual([]);
146
- expect(result.current.alertKeys.unavailableKeys).toEqual([]);
147
- });
148
- it('should handle only critical alerts', () => {
149
- const alerts = [
150
- createMockAlert('critical', '2023-12-01T01:00:00Z', '2023-12-01T02:00:00Z'),
151
- createMockAlert('critical', '2023-12-01T03:00:00Z', '2023-12-01T04:00:00Z'),
152
- ];
153
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
154
- expect(result.current.alertKeys.warningKeys).toEqual([]);
155
- expect(result.current.alertKeys.criticalKeys).toEqual([
156
- 'critical_0',
157
- 'critical_1',
158
- ]);
159
- expect(result.current.alertKeys.unavailableKeys).toEqual([]);
160
- });
161
- it('should only include alert bar keys and exclude metadata and basic properties', () => {
162
- const alerts = [
163
- createMockAlert('warning', '2023-12-01T01:00:00Z', '2023-12-01T02:00:00Z'),
164
- ];
165
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
166
- // Should only contain the actual alert bar keys for rendering
167
- expect(result.current.alertKeys.warningKeys).toEqual(['warning_0']);
168
- // Should not contain basic data properties
169
- expect(result.current.alertKeys.warningKeys).not.toContain('start');
170
- expect(result.current.alertKeys.warningKeys).not.toContain('end');
171
- expect(result.current.alertKeys.warningKeys).not.toContain('range');
172
- expect(result.current.alertKeys.warningKeys).not.toContain('id');
173
- // Should not contain alert metadata keys (used for tooltips, not bars)
174
- expect(result.current.alertKeys.warningKeys).not.toContain('alert_warning_0');
175
- });
176
- });
177
- describe('Edge Cases', () => {
178
- it('should handle empty alerts array', () => {
179
- const { result } = renderHook(() => useHealthBarData([], mockTimestamp.start, mockTimestamp.end, 'test-id'));
180
- const data = result.current.chartData[0];
181
- expect(data.range).toEqual([mockTimestamp.start, mockTimestamp.end]);
182
- expect(result.current.alertKeys.warningKeys).toEqual([]);
183
- expect(result.current.alertKeys.criticalKeys).toEqual([]);
184
- expect(result.current.alertKeys.unavailableKeys).toEqual([]);
185
- });
186
- it('should handle overlapping alerts correctly', () => {
187
- const alerts = [
188
- createMockAlert('warning', '2023-12-01T01:00:00Z', '2023-12-01T04:00:00Z'),
189
- createMockAlert('critical', '2023-12-01T02:00:00Z', '2023-12-01T05:00:00Z'),
190
- ];
191
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
192
- expect(result.current.chartData[0]).toHaveProperty('warning_0');
193
- expect(result.current.chartData[0]).toHaveProperty('critical_1');
194
- expect(result.current.alertKeys.warningKeys).toContain('warning_0');
195
- expect(result.current.alertKeys.criticalKeys).toContain('critical_1');
196
- });
197
- it('should handle alerts with same timestamps', () => {
198
- const alerts = [
199
- createMockAlert('warning', '2023-12-01T02:00:00Z', '2023-12-01T04:00:00Z'),
200
- createMockAlert('critical', '2023-12-01T02:00:00Z', '2023-12-01T04:00:00Z'),
201
- ];
202
- const { result } = renderHook(() => useHealthBarData(alerts, mockTimestamp.start, mockTimestamp.end, 'test-id'));
203
- expect(result.current.chartData[0]).toHaveProperty('warning_0');
204
- expect(result.current.chartData[0]).toHaveProperty('critical_1');
205
- expect(result.current.alertKeys.warningKeys).toContain('warning_0');
206
- expect(result.current.alertKeys.criticalKeys).toContain('critical_1');
207
- });
208
- });
209
- });
@@ -1,41 +0,0 @@
1
- import { Serie } from './LineTemporalChart.component';
2
- import './LineTemporalChart.component';
3
- export type VegaData = {
4
- timestamp: number;
5
- label: string;
6
- value: number | 'NAN';
7
- isNegativeValue: boolean;
8
- isDashed: boolean;
9
- }[];
10
- export declare function normlizeVegaFieldName(fieldName: string): string;
11
- export declare function convert2VegaData(addedMissingDataPointSeries: Serie[]): VegaData;
12
- export declare function convertDataBaseValue(data: VegaData, base: number): VegaData;
13
- /**
14
- * Return the unit label base on the current dataset, and the valueBase which is used to convert the data
15
- * @param {any} unitRange
16
- * @param {any} maxValue the maximum value among the data set
17
- * @returns {any}
18
- */
19
- export declare function getUnitLabel(unitRange: {
20
- threshold: number;
21
- label: string;
22
- }[], maxValue: number): {
23
- valueBase: number;
24
- unitLabel: string;
25
- };
26
- /**
27
- * This function manually adds the missing data points with `null` value caused by downtime of the VMs
28
- * Missing data points are only added when the gap between consecutive data points is bigger than 2 intervals
29
- *
30
- * @param {array} orginalValues - The array of the data points are already sorted according to the time series
31
- * @param {number} startingTimeStamp - The starting timestamp in seconds
32
- * @param {number} sampleDuration - The time span value in seconds
33
- * @param {number} sampleInterval - The time difference between two data points in seconds
34
- *
35
- */
36
- export declare function addMissingDataPoint(orginalValues: [number, number | string | null][], startingTimeStamp?: number, sampleDuration?: number, sampleInterval?: number): [number, number | string | null][];
37
- export declare const getRelativeValue: (value: number, base: number) => number;
38
- export declare const relativeDatumToOriginalDatum: <T>(datum: T, base: number) => T;
39
- export declare const getAbsoluteValue: (relativeValue: number, base: number) => number;
40
- export declare const getColorDomains: (series: Serie[]) => string[];
41
- //# sourceMappingURL=ChartUtil.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChartUtil.d.ts","sourceRoot":"","sources":["../../../src/lib/components/linetemporalchart/ChartUtil.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,+BAA+B,CAAC;AAEvC,MAAM,MAAM,QAAQ,GAAG;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IAEd,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC;IAEtB,eAAe,EAAE,OAAO,CAAC;IAEzB,QAAQ,EAAE,OAAO,CAAC;CACnB,EAAE,CAAC;AAKJ,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,UAEtD;AACD,wBAAgB,gBAAgB,CAC9B,2BAA2B,EAAE,KAAK,EAAE,GACnC,QAAQ,CAqBV;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,CAU3E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE;IACT,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,EAAE,EACH,QAAQ,EAAE,MAAM,GACf;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAwCA;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,EAAE,EACjD,iBAAiB,CAAC,EAAE,MAAM,EAC1B,cAAc,CAAC,EAAE,MAAM,EACvB,cAAc,CAAC,EAAE,MAAM,GACtB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,EAAE,CAoEpC;AAID,eAAO,MAAM,gBAAgB,UAAW,MAAM,QAAQ,MAAM,WAE3D,CAAC;AACF,eAAO,MAAM,4BAA4B,GAAI,CAAC,SAAS,CAAC,QAAQ,MAAM,KAAG,CAQxE,CAAC;AACF,eAAO,MAAM,gBAAgB,kBAAmB,MAAM,QAAQ,MAAM,WAEnE,CAAC;AAEF,eAAO,MAAM,eAAe,WAAY,KAAK,EAAE,KAAG,MAAM,EAMvD,CAAC"}
@@ -1,148 +0,0 @@
1
- import './LineTemporalChart.component';
2
- import { NAN_STRING } from '../constants';
3
- //Given a field containing dots ".", vega is interpreting this as an accessor
4
- //for nested objects, breaking then the internal mechnism to retrieve tooltip
5
- //data from the mouse position. We are fixing it by replacing the dots by a
6
- //well-known string that we expect no one would use to label a serie.
7
- export function normlizeVegaFieldName(fieldName) {
8
- return fieldName.replace(/(\.)/g, 'VEGADOESNTSUPPORTDOTINFIELDNAME');
9
- }
10
- export function convert2VegaData(addedMissingDataPointSeries) {
11
- const flatArr = [];
12
- addedMissingDataPointSeries.forEach((line) => {
13
- line.data.forEach((datum) => {
14
- const obj = {
15
- timestamp: datum[0] * 1000,
16
- // convert to million second
17
- label: normlizeVegaFieldName(line.getTooltipLabel(line.metricPrefix, line.resource)),
18
- resource: line.resource,
19
- value: datum[1] && datum[1] !== NAN_STRING ? Number(datum[1]) : NAN_STRING,
20
- isNegativeValue: line.metricPrefix === 'read' || line.metricPrefix === 'out',
21
- isDashed: line.isLineDashed || false,
22
- };
23
- flatArr.push(obj);
24
- });
25
- });
26
- return flatArr;
27
- }
28
- // base on the current base value, convert the original vegadata to
29
- export function convertDataBaseValue(data, base) {
30
- return data.map((datum) => {
31
- return {
32
- ...datum,
33
- value: typeof datum.value === 'number'
34
- ? getRelativeValue(datum.value, base)
35
- : NAN_STRING,
36
- };
37
- });
38
- }
39
- /**
40
- * Return the unit label base on the current dataset, and the valueBase which is used to convert the data
41
- * @param {any} unitRange
42
- * @param {any} maxValue the maximum value among the data set
43
- * @returns {any}
44
- */
45
- export function getUnitLabel(unitRange, maxValue) {
46
- if (!unitRange || unitRange.length === 0) {
47
- return {
48
- valueBase: 1,
49
- unitLabel: '',
50
- };
51
- }
52
- // first sort the unitRange
53
- unitRange.sort((unitA, unitB) => {
54
- return unitA.threshold - unitB.threshold;
55
- });
56
- let index = unitRange.findIndex((range) => range.threshold > maxValue);
57
- // last unit
58
- if (index === -1) {
59
- index = unitRange.length;
60
- }
61
- if (index === 0) {
62
- return {
63
- valueBase: unitRange[index].threshold,
64
- unitLabel: unitRange[index].label,
65
- };
66
- }
67
- return {
68
- valueBase: unitRange[index - 1].threshold,
69
- unitLabel: unitRange[index - 1].label,
70
- };
71
- }
72
- /**
73
- * This function manually adds the missing data points with `null` value caused by downtime of the VMs
74
- * Missing data points are only added when the gap between consecutive data points is bigger than 2 intervals
75
- *
76
- * @param {array} orginalValues - The array of the data points are already sorted according to the time series
77
- * @param {number} startingTimeStamp - The starting timestamp in seconds
78
- * @param {number} sampleDuration - The time span value in seconds
79
- * @param {number} sampleInterval - The time difference between two data points in seconds
80
- *
81
- */
82
- export function addMissingDataPoint(orginalValues, startingTimeStamp, sampleDuration, sampleInterval) {
83
- if (!orginalValues ||
84
- startingTimeStamp === undefined ||
85
- !sampleDuration ||
86
- !sampleInterval ||
87
- startingTimeStamp < 0 ||
88
- sampleDuration <= 0 ||
89
- sampleInterval <= 0) {
90
- return [];
91
- }
92
- // If there are no original values, return empty array
93
- if (orginalValues.length === 0) {
94
- return [];
95
- }
96
- const newValues = [];
97
- // add missing data points for the starting time
98
- for (let i = startingTimeStamp; i < orginalValues[0][0]; i += sampleInterval) {
99
- newValues.push([i, NAN_STRING]);
100
- }
101
- // Process all but the last element
102
- for (let i = 0; i < orginalValues.length - 1; i++) {
103
- if (orginalValues[i][0] < startingTimeStamp ||
104
- orginalValues[i][0] > startingTimeStamp + sampleDuration) {
105
- continue;
106
- }
107
- // Always add the current data point
108
- newValues.push(orginalValues[i]);
109
- const currentTimestamp = orginalValues[i][0];
110
- const nextTimestamp = orginalValues[i + 1][0];
111
- const gap = nextTimestamp - currentTimestamp;
112
- // Calculate how many missing points to add
113
- const missingIntervals = Math.floor(gap / sampleInterval) - 1;
114
- // Add missing data points with NAN_STRING (only executes if missingIntervals > 0)
115
- for (let j = 1; j <= missingIntervals; j++) {
116
- const missingTimestamp = currentTimestamp + j * sampleInterval;
117
- newValues.push([missingTimestamp, NAN_STRING]);
118
- }
119
- }
120
- // Add the last element
121
- newValues.push(orginalValues[orginalValues.length - 1]);
122
- // add missing data points for the ending time
123
- for (let i = orginalValues[orginalValues.length - 1][0] + sampleInterval; i < startingTimeStamp + sampleDuration; i += sampleInterval) {
124
- newValues.push([i, NAN_STRING]);
125
- }
126
- return newValues;
127
- }
128
- // get the value for the based value
129
- // TODO: We need to handle the negative value in the future
130
- export const getRelativeValue = (value, base) => {
131
- return value / (base || 1);
132
- };
133
- export const relativeDatumToOriginalDatum = (datum, base) => {
134
- // $FlowFixMe
135
- return Object.fromEntries(Object.entries(datum).map(([key, value]) => [
136
- key,
137
- getAbsoluteValue(value, base),
138
- ]));
139
- };
140
- export const getAbsoluteValue = (relativeValue, base) => {
141
- return relativeValue * (base || 1);
142
- };
143
- // extract the labels from getTooltipLabel function to define the domain in color
144
- export const getColorDomains = (series) => {
145
- return series.map((serie) => {
146
- return normlizeVegaFieldName(serie.getTooltipLabel(serie.metricPrefix, serie.resource));
147
- });
148
- };
@@ -1,46 +0,0 @@
1
- export declare const YAXIS_TITLE_READ_WRITE = "write(+) / read(-)";
2
- export declare const YAXIS_TITLE_IN_OUT = "in(+) / out(-)";
3
- export declare const UNIT_RANGE_BS: {
4
- threshold: number;
5
- label: string;
6
- }[];
7
- export type Serie = {
8
- resource: string;
9
- data: [number, string | null][];
10
- getTooltipLabel: (metricPrefix?: string, resource?: string) => string;
11
- getLegendLabel?: (metricPrefix?: string, resource?: string) => string;
12
- color?: string;
13
- metricPrefix?: string;
14
- isLineDashed?: boolean;
15
- };
16
- export type LineChartProps = {
17
- series: Serie[];
18
- title: string;
19
- height: number;
20
- startingTimeStamp: number;
21
- unitRange?: {
22
- threshold: number;
23
- label: string;
24
- }[];
25
- isLoading?: boolean;
26
- isLegendHidden?: boolean;
27
- yAxisType?: 'default' | 'percentage' | 'symmetrical';
28
- yAxisTitle?: string;
29
- helpText?: string | JSX.Element;
30
- onHover?: (dataPoint: any) => void;
31
- renderTooltipSerie?: (arg0: {
32
- color?: string;
33
- isLineDashed?: boolean;
34
- name: string;
35
- value: string;
36
- key: string;
37
- unitLabel: string;
38
- }, tooltipData: any) => string;
39
- };
40
- /**
41
- * @deprecated Use LineTimeSerieChart instead
42
- * @example import { LineTimeSerieChart } from '@scality/core-ui/dist/next';
43
- */
44
- declare function LineTemporalChart({ series, title, height, startingTimeStamp, unitRange, isLoading, isLegendHidden, yAxisType, yAxisTitle, helpText, renderTooltipSerie, onHover, ...rest }: LineChartProps): import("react/jsx-runtime").JSX.Element;
45
- export { LineTemporalChart };
46
- //# sourceMappingURL=LineTemporalChart.component.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LineTemporalChart.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/linetemporalchart/LineTemporalChart.component.tsx"],"names":[],"mappings":"AAoCA,eAAO,MAAM,sBAAsB,uBAAuB,CAAC;AAC3D,eAAO,MAAM,kBAAkB,mBAAmB,CAAC;AACnD,eAAO,MAAM,aAAa;;;GAqBzB,CAAC;AA+BF,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,EAAE,MAAM,CAAC;IAEjB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;IAEhC,eAAe,EAAE,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAEtE,cAAc,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAEtE,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AACF,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,MAAM,CAAC;IAE1B,SAAS,CAAC,EAAE;QACV,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,MAAM,CAAC;KACf,EAAE,CAAC;IACJ,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,SAAS,GAAG,YAAY,GAAG,aAAa,CAAC;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,KAAK,IAAI,CAAC;IACnC,kBAAkB,CAAC,EAAE,CACnB,IAAI,EAAE;QACJ,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,SAAS,EAAE,MAAM,CAAC;KACnB,EACD,WAAW,EAAE,GAAG,KACb,MAAM,CAAC;CACb,CAAC;AAkCF;;;GAGG;AACH,iBAAS,iBAAiB,CAAC,EACzB,MAAM,EACN,KAAK,EACL,MAAM,EACN,iBAAiB,EACjB,SAAS,EACT,SAAiB,EACjB,cAAsB,EACtB,SAAqB,EACrB,UAAU,EACV,QAAQ,EACR,kBAAkB,EAClB,OAAO,EACP,GAAG,IAAI,EACR,EAAE,cAAc,2CAomBhB;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}