@scality/core-ui 0.161.0 → 0.163.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 (173) hide show
  1. package/README.md +15 -15
  2. package/dist/components/accordion/Accordion.component.d.ts +0 -1
  3. package/dist/components/accordion/Accordion.component.d.ts.map +1 -1
  4. package/dist/components/barchartv2/Barchart.component.d.ts +53 -0
  5. package/dist/components/barchartv2/Barchart.component.d.ts.map +1 -0
  6. package/dist/components/barchartv2/Barchart.component.js +86 -0
  7. package/dist/components/barchartv2/utils.d.ts +118 -0
  8. package/dist/components/barchartv2/utils.d.ts.map +1 -0
  9. package/dist/components/barchartv2/utils.js +337 -0
  10. package/dist/components/buttonv2/Buttonv2.component.d.ts +1 -1
  11. package/dist/components/buttonv2/Buttonv2.component.d.ts.map +1 -1
  12. package/dist/components/chartlegend/ChartLegend.d.ts +8 -0
  13. package/dist/components/chartlegend/ChartLegend.d.ts.map +1 -0
  14. package/dist/components/chartlegend/ChartLegend.js +65 -0
  15. package/dist/components/chartlegend/ChartLegendWrapper.d.ts +17 -0
  16. package/dist/components/chartlegend/ChartLegendWrapper.d.ts.map +1 -0
  17. package/dist/components/chartlegend/ChartLegendWrapper.js +50 -0
  18. package/dist/components/constrainedtext/Constrainedtext.component.d.ts +2 -1
  19. package/dist/components/constrainedtext/Constrainedtext.component.d.ts.map +1 -1
  20. package/dist/components/constrainedtext/Constrainedtext.component.js +5 -4
  21. package/dist/components/coreuithemeprovider/CoreUiThemeProvider.d.ts +0 -1
  22. package/dist/components/coreuithemeprovider/CoreUiThemeProvider.d.ts.map +1 -1
  23. package/dist/components/date/FormattedDateTime.d.ts +4 -1
  24. package/dist/components/date/FormattedDateTime.d.ts.map +1 -1
  25. package/dist/components/date/FormattedDateTime.js +24 -1
  26. package/dist/components/date/FormattedDateTime.spec.js +12 -0
  27. package/dist/components/emptytable/Emptytable.component.d.ts +0 -1
  28. package/dist/components/emptytable/Emptytable.component.d.ts.map +1 -1
  29. package/dist/components/emptytable/Emptytable.component.js +1 -0
  30. package/dist/components/error-pages/ErrorPage401.component.d.ts +0 -1
  31. package/dist/components/error-pages/ErrorPage401.component.d.ts.map +1 -1
  32. package/dist/components/error-pages/ErrorPage404.component.d.ts +0 -1
  33. package/dist/components/error-pages/ErrorPage404.component.d.ts.map +1 -1
  34. package/dist/components/error-pages/ErrorPage500.component.d.ts +0 -1
  35. package/dist/components/error-pages/ErrorPage500.component.d.ts.map +1 -1
  36. package/dist/components/error-pages/ErrorPageAuth.component.d.ts.map +1 -1
  37. package/dist/components/form/Form.component.d.ts +2 -2
  38. package/dist/components/form/Form.component.d.ts.map +1 -1
  39. package/dist/components/icon/Icon.component.d.ts +5 -5
  40. package/dist/components/icon/Icon.component.d.ts.map +1 -1
  41. package/dist/components/icon/Icon.component.js +33 -31
  42. package/dist/components/infomessage/InfoMessage.component.d.ts +0 -1
  43. package/dist/components/infomessage/InfoMessage.component.d.ts.map +1 -1
  44. package/dist/components/lateralnavbarlayout/LateralNavbarLayout.component.d.ts.map +1 -1
  45. package/dist/components/layout/Layout.component.d.ts.map +1 -1
  46. package/dist/components/layout/v2/panels.d.ts.map +1 -1
  47. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts +33 -0
  48. package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts.map +1 -0
  49. package/dist/components/linetimeseriechart/linetimeseriechart.component.js +249 -0
  50. package/dist/components/modal/Modal.component.js +2 -2
  51. package/dist/components/navbar/Navbar.component.js +2 -2
  52. package/dist/components/scrollbarwrapper/ScrollbarWrapper.component.d.ts +0 -1
  53. package/dist/components/scrollbarwrapper/ScrollbarWrapper.component.d.ts.map +1 -1
  54. package/dist/components/searchinput/SearchInput.component.d.ts +1 -2
  55. package/dist/components/searchinput/SearchInput.component.d.ts.map +1 -1
  56. package/dist/components/selectv2/Selectv2.component.d.ts +5 -5
  57. package/dist/components/selectv2/Selectv2.component.d.ts.map +1 -1
  58. package/dist/components/selectv2/Selectv2.component.js +11 -6
  59. package/dist/components/statuswrapper/Statuswrapper.component.d.ts +0 -1
  60. package/dist/components/statuswrapper/Statuswrapper.component.d.ts.map +1 -1
  61. package/dist/components/steppers/Stepper.component.d.ts.map +1 -1
  62. package/dist/components/steppers/Stepper.component.js +9 -8
  63. package/dist/components/tablev2/Search.js +2 -2
  64. package/dist/components/tablev2/SingleSelectableContent.d.ts +1 -2
  65. package/dist/components/tablev2/SingleSelectableContent.d.ts.map +1 -1
  66. package/dist/components/tablev2/TableCommon.d.ts +2 -2
  67. package/dist/components/tablev2/TableCommon.d.ts.map +1 -1
  68. package/dist/components/tablev2/TableSync.d.ts +8 -0
  69. package/dist/components/tablev2/TableSync.d.ts.map +1 -0
  70. package/dist/components/tablev2/TableSync.js +11 -0
  71. package/dist/components/tablev2/Tablev2.component.d.ts +2 -1
  72. package/dist/components/tablev2/Tablev2.component.d.ts.map +1 -1
  73. package/dist/components/tablev2/Tablev2.component.js +10 -9
  74. package/dist/components/tabsv2/ScrollButton.d.ts +1 -2
  75. package/dist/components/tabsv2/ScrollButton.d.ts.map +1 -1
  76. package/dist/components/tabsv2/ScrollButton.js +2 -2
  77. package/dist/components/tabsv2/Tabsv2.component.d.ts +2 -2
  78. package/dist/components/tabsv2/Tabsv2.component.d.ts.map +1 -1
  79. package/dist/components/tabsv2/Tabsv2.component.js +2 -2
  80. package/dist/components/text/Text.component.d.ts +0 -1
  81. package/dist/components/text/Text.component.d.ts.map +1 -1
  82. package/dist/components/textarea/TextArea.component.d.ts +3 -3
  83. package/dist/components/textarea/TextArea.component.d.ts.map +1 -1
  84. package/dist/components/textbadge/TextBadge.component.d.ts +0 -1
  85. package/dist/components/textbadge/TextBadge.component.d.ts.map +1 -1
  86. package/dist/components/toast/Toast.component.d.ts +1 -1
  87. package/dist/components/toast/Toast.component.d.ts.map +1 -1
  88. package/dist/components/toast/ToastProvider.d.ts.map +1 -1
  89. package/dist/components/toast/ToastProvider.js +4 -5
  90. package/dist/components/vegachartv2/SyncedCursorCharts.d.ts +1 -2
  91. package/dist/components/vegachartv2/SyncedCursorCharts.d.ts.map +1 -1
  92. package/dist/components/vegachartv2/SyncedCursorCharts.js +3 -5
  93. package/dist/components/vegachartv2/VegaChartV2.component.d.ts +1 -2
  94. package/dist/components/vegachartv2/VegaChartV2.component.d.ts.map +1 -1
  95. package/dist/components/vegachartv2/VegaChartV2.component.js +2 -2
  96. package/dist/icons/branding.d.ts.map +1 -1
  97. package/dist/icons/scality-loading.d.ts.map +1 -1
  98. package/dist/index.d.ts +1 -0
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +1 -0
  101. package/dist/next.d.ts +2 -0
  102. package/dist/next.d.ts.map +1 -1
  103. package/dist/next.js +2 -0
  104. package/dist/style/theme.d.ts +20 -0
  105. package/dist/style/theme.d.ts.map +1 -1
  106. package/dist/style/theme.js +46 -1
  107. package/package.json +7 -4
  108. package/setupTests.js +6 -0
  109. package/src/lib/components/accordion/Accordion.component.tsx +1 -1
  110. package/src/lib/components/accordion/Accordion.test.tsx +7 -15
  111. package/src/lib/components/barchartv2/Barchart.component.test.tsx +364 -0
  112. package/src/lib/components/barchartv2/Barchart.component.tsx +321 -0
  113. package/src/lib/components/barchartv2/utils.test.ts +899 -0
  114. package/src/lib/components/barchartv2/utils.ts +534 -0
  115. package/src/lib/components/buttonv2/Buttonv2.component.tsx +1 -1
  116. package/src/lib/components/chartlegend/ChartLegend.tsx +113 -0
  117. package/src/lib/components/chartlegend/ChartLegendWrapper.tsx +85 -0
  118. package/src/lib/components/constrainedtext/Constrainedtext.component.tsx +22 -3
  119. package/src/lib/components/coreuithemeprovider/CoreUiThemeProvider.tsx +0 -1
  120. package/src/lib/components/date/FormattedDateTime.spec.tsx +24 -0
  121. package/src/lib/components/date/FormattedDateTime.tsx +42 -2
  122. package/src/lib/components/emptytable/Emptytable.component.tsx +1 -1
  123. package/src/lib/components/error-pages/ErrorPage401.component.tsx +0 -1
  124. package/src/lib/components/error-pages/ErrorPage404.component.tsx +0 -1
  125. package/src/lib/components/error-pages/ErrorPage500.component.tsx +0 -1
  126. package/src/lib/components/error-pages/ErrorPageAuth.component.tsx +0 -1
  127. package/src/lib/components/form/Form.component.tsx +1 -1
  128. package/src/lib/components/healthselectorv2/HealthSelector.component.test.tsx +3 -3
  129. package/src/lib/components/icon/Icon.component.tsx +48 -60
  130. package/src/lib/components/infomessage/InfoMessage.component.tsx +0 -1
  131. package/src/lib/components/inlineinput/InlineInput.test.tsx +22 -19
  132. package/src/lib/components/inputlist/InputList.test.tsx +21 -19
  133. package/src/lib/components/lateralnavbarlayout/LateralNavbarLayout.component.tsx +0 -1
  134. package/src/lib/components/layout/Layout.component.tsx +0 -1
  135. package/src/lib/components/layout/v2/panels.tsx +1 -1
  136. package/src/lib/components/linetimeseriechart/linetimeseriechart.component.tsx +502 -0
  137. package/src/lib/components/modal/Modal.component.tsx +2 -2
  138. package/src/lib/components/navbar/Navbar.component.tsx +2 -2
  139. package/src/lib/components/scrollbarwrapper/ScrollbarWrapper.component.tsx +0 -1
  140. package/src/lib/components/searchinput/SearchInput.component.tsx +0 -1
  141. package/src/lib/components/searchinput/SearchInput.test.tsx +3 -7
  142. package/src/lib/components/selectv2/Selectv2.component.tsx +24 -14
  143. package/src/lib/components/selectv2/selectv2.test.tsx +62 -57
  144. package/src/lib/components/sidebar/Sidebar.component.tsx +1 -1
  145. package/src/lib/components/statuswrapper/Statuswrapper.component.tsx +0 -1
  146. package/src/lib/components/steppers/Stepper.component.tsx +10 -8
  147. package/src/lib/components/tablev2/Search.tsx +2 -2
  148. package/src/lib/components/tablev2/SingleSelectableContent.tsx +2 -2
  149. package/src/lib/components/tablev2/TableCommon.tsx +1 -1
  150. package/src/lib/components/tablev2/TableSync.test.tsx +28 -0
  151. package/src/lib/components/tablev2/TableSync.tsx +36 -0
  152. package/src/lib/components/tablev2/Tablev2.component.tsx +11 -9
  153. package/src/lib/components/tablev2/Tablev2.test.tsx +36 -37
  154. package/src/lib/components/tabsv2/ScrollButton.tsx +2 -2
  155. package/src/lib/components/tabsv2/Tabsv2.component.tsx +6 -6
  156. package/src/lib/components/text/Text.component.tsx +4 -5
  157. package/src/lib/components/textarea/TextArea.component.tsx +3 -2
  158. package/src/lib/components/textbadge/TextBadge.component.tsx +0 -1
  159. package/src/lib/components/toast/Toast.component.tsx +1 -1
  160. package/src/lib/components/toast/ToastProvider.tsx +17 -7
  161. package/src/lib/components/vegachartv2/SyncedCursorCharts.tsx +5 -7
  162. package/src/lib/components/vegachartv2/VegaChartV2.component.tsx +2 -2
  163. package/src/lib/icons/branding.tsx +0 -2
  164. package/src/lib/icons/scality-loading.tsx +0 -2
  165. package/src/lib/index.ts +1 -0
  166. package/src/lib/next.ts +6 -0
  167. package/src/lib/style/theme.ts +53 -1
  168. package/stories/BarChart/barchart.stories.tsx +822 -0
  169. package/stories/areachart.stories.tsx +0 -1
  170. package/stories/format.mdx +4 -2
  171. package/stories/linetimeseriechart.stories.tsx +485 -0
  172. package/stories/tablev2.stories.tsx +41 -0
  173. package/tsconfig.json +5 -2
@@ -0,0 +1,337 @@
1
+ import { DAY_MONTH_FORMATER, TIME_FORMATER } from '../date/FormattedDateTime';
2
+ import { chartColors } from '../../style/theme';
3
+ import { useChartLegend } from '../chartlegend/ChartLegendWrapper';
4
+ export const getRoundReferenceValue = (value) => {
5
+ if (value <= 0)
6
+ return 10; // Default for zero or negative values
7
+ // Get the magnitude (10^n where n is the number of digits - 1)
8
+ const magnitude = Math.pow(10, Math.floor(Math.log10(value)));
9
+ // Normalized value between 1 and 10
10
+ const normalized = value / magnitude;
11
+ // Round to nice numbers based on normalized value
12
+ if (normalized <= 1)
13
+ return magnitude;
14
+ if (normalized <= 2.5)
15
+ return 2.5 * magnitude;
16
+ if (normalized <= 5)
17
+ return 5 * magnitude;
18
+ return 10 * magnitude;
19
+ };
20
+ export const getMaxBarValue = (data, stacked) => {
21
+ const values = data.map((item) => {
22
+ // If stacked, we need to filter out category and sum the values in the same object
23
+ if (stacked) {
24
+ // Get objects keys except category
25
+ const filterOutCategory = Object.keys(item).filter((key) => key !== 'category');
26
+ // Sum the values in the same object (corresponding to one bar) based on the keys
27
+ const sumValues = filterOutCategory.reduce((acc, curr) => {
28
+ return acc + Number(item[curr]);
29
+ }, 0);
30
+ return sumValues;
31
+ }
32
+ //filter out the category key
33
+ const numberValues = Object.keys(item)
34
+ .filter((key) => key !== 'category')
35
+ .map((key) => Number(item[key]));
36
+ // Get the max value among the values in the object (corresponding to one bar)
37
+ return Math.max(...numberValues);
38
+ });
39
+ return Math.max(...values);
40
+ };
41
+ /**
42
+ * Generates time ranges between start and end dates based on the given interval
43
+ * @param startDate - Start date
44
+ * @param endDate - End date
45
+ * @param interval - Interval in milliseconds
46
+ * @returns Array of time ranges with start and end properties as Date objects
47
+ */
48
+ const generateTimeRanges = (startDate, endDate, interval) => {
49
+ const ranges = [];
50
+ if (!startDate || !endDate || !interval) {
51
+ return ranges;
52
+ }
53
+ let currentDate = new Date(startDate.getTime());
54
+ while (currentDate.getTime() <= endDate.getTime()) {
55
+ const rangeEnd = new Date(currentDate.getTime() + interval);
56
+ ranges.push({
57
+ start: new Date(currentDate.getTime()),
58
+ end: rangeEnd,
59
+ });
60
+ currentDate = new Date(currentDate.getTime() + interval);
61
+ }
62
+ return ranges;
63
+ };
64
+ /**
65
+ * Formats a date based on the interval
66
+ * @param date - Date object
67
+ * @param interval - Interval in milliseconds
68
+ * @returns Formatted string
69
+ */
70
+ const formatDate = (date, interval) => {
71
+ if (interval > 24 * 60 * 60 * 1000) {
72
+ return (DAY_MONTH_FORMATER.format(date).replace(/[ ,]/g, '') +
73
+ ' ' +
74
+ TIME_FORMATER.format(date));
75
+ }
76
+ else if (interval === 24 * 60 * 60 * 1000) {
77
+ // Daily or longer intervals - use day format
78
+ return DAY_MONTH_FORMATER.format(date).replace(/[ ,]/g, '');
79
+ }
80
+ else if (interval >= 60 * 1000) {
81
+ //Handle hourly and minute intervals - use minute format
82
+ return TIME_FORMATER.format(date);
83
+ }
84
+ else {
85
+ // Second intervals or less - use full timestamp
86
+ return date.toISOString();
87
+ }
88
+ };
89
+ /**
90
+ * Finds the time range that contains the given date
91
+ * @param date - Data point date
92
+ * @param ranges - Array of time ranges
93
+ * @returns The range that contains the date, or null if not found
94
+ */
95
+ const findRangeForDate = (date, ranges) => {
96
+ const timestamp = date.getTime();
97
+ return (ranges.find((range) => timestamp >= range.start.getTime() && timestamp < range.end.getTime()) || null);
98
+ };
99
+ /**
100
+ * Transforms time-based data into chart format
101
+ */
102
+ export const transformTimeData = (bars, type, barDataKeys) => {
103
+ const timeRanges = generateTimeRanges(type.timeRange.startDate, type.timeRange.endDate, type.timeRange.interval);
104
+ const categoryMap = new Map();
105
+ // Initialize all ranges with zeros
106
+ timeRanges.forEach((range) => {
107
+ const categoryDisplay = formatDate(range.start, type.timeRange.interval);
108
+ const initialData = {
109
+ category: categoryDisplay,
110
+ };
111
+ barDataKeys.forEach((dataKey) => {
112
+ initialData[dataKey] = 0;
113
+ });
114
+ categoryMap.set(range.start.getTime(), initialData);
115
+ });
116
+ // Populate with actual data
117
+ bars.forEach((bar) => {
118
+ bar.data.forEach(([dateValue, value]) => {
119
+ // Convert to Date if it's not already a Date object
120
+ const date = dateValue instanceof Date
121
+ ? dateValue
122
+ : new Date(dateValue);
123
+ const range = findRangeForDate(date, timeRanges);
124
+ if (range) {
125
+ const existingData = categoryMap.get(range.start.getTime());
126
+ existingData[bar.label] = value;
127
+ }
128
+ });
129
+ });
130
+ return Array.from(categoryMap.values());
131
+ };
132
+ /**
133
+ * Transforms category-based data into chart format
134
+ */
135
+ export const transformCategoryData = (bars, barDataKeys) => {
136
+ const categoryMap = new Map();
137
+ bars.forEach((bar) => {
138
+ bar.data.forEach(([key, value]) => {
139
+ const categoryKey = String(key);
140
+ if (!categoryMap.has(categoryKey)) {
141
+ const newData = {
142
+ category: categoryKey,
143
+ };
144
+ barDataKeys.forEach((dataKey) => {
145
+ newData[dataKey] = 0;
146
+ });
147
+ categoryMap.set(categoryKey, newData);
148
+ }
149
+ const existingData = categoryMap.get(categoryKey);
150
+ existingData[bar.label] = value;
151
+ });
152
+ });
153
+ return Array.from(categoryMap.values());
154
+ };
155
+ /**
156
+ * Applies custom sorting to chart data
157
+ */
158
+ export const applySortingToData = (data, barDataKeys, defaultSort) => {
159
+ const points = data.map((item) => {
160
+ const point = { category: item.category };
161
+ barDataKeys.forEach((dataKey) => {
162
+ point[dataKey] = Number(item[dataKey]) || 0;
163
+ });
164
+ return point;
165
+ });
166
+ points.sort(defaultSort);
167
+ return points.map((point) => {
168
+ const dataItem = {
169
+ category: point.category,
170
+ };
171
+ barDataKeys.forEach((dataKey) => {
172
+ dataItem[dataKey] = point[dataKey];
173
+ });
174
+ return dataItem;
175
+ });
176
+ };
177
+ const getRechartsBarsAndBarDataKeys = (bars, colorSet, stacked) => {
178
+ const rechartsBars = [];
179
+ const barDataKeys = [];
180
+ bars.forEach((bar) => {
181
+ const colorName = colorSet[bar.label];
182
+ const rechartsBar = {
183
+ dataKey: bar.label,
184
+ fill: chartColors[colorName] || colorName,
185
+ stackId: stacked ? 'stacked' : undefined,
186
+ };
187
+ rechartsBars.push(rechartsBar);
188
+ barDataKeys.push(bar.label);
189
+ });
190
+ return {
191
+ rechartsBars,
192
+ barDataKeys,
193
+ };
194
+ };
195
+ /**
196
+ * Converts prometheus data to recharts data format
197
+ * @param bars - The bars to convert
198
+ * @param type - The chart type (category or time)
199
+ * @returns Recharts data format
200
+ */
201
+ export const formatPrometheusDataToRechartsDataAndBars = (bars, type, colorSet, stacked, defaultSort) => {
202
+ const { rechartsBars, barDataKeys } = getRechartsBarsAndBarDataKeys(bars, colorSet, stacked);
203
+ let data = type !== 'category' && type.type === 'time'
204
+ ? transformTimeData(bars, type, barDataKeys)
205
+ : transformCategoryData(bars, barDataKeys);
206
+ if (type === 'category' && defaultSort) {
207
+ data = applySortingToData(data, barDataKeys, defaultSort);
208
+ }
209
+ const sortedRechartsBars = sortStackedBars(rechartsBars, data, stacked);
210
+ return {
211
+ rechartsBars: sortedRechartsBars,
212
+ data,
213
+ };
214
+ };
215
+ export const computeUnitLabelAndRoundReferenceValue = (data, maxValue, unitRange) => {
216
+ if (!unitRange) {
217
+ const roundReferenceValue = getRoundReferenceValue(maxValue);
218
+ return { unitLabel: '', roundReferenceValue, rechartsData: data };
219
+ }
220
+ const { valueBase, unitLabel } = getUnitLabel(unitRange !== null && unitRange !== void 0 ? unitRange : [], maxValue);
221
+ const topValue = Math.ceil(maxValue / valueBase / 10) * 10;
222
+ const roundReferenceValue = getRoundReferenceValue(topValue);
223
+ const rechartsData = data.map((dataPoint) => {
224
+ const normalizedDataPoint = { ...dataPoint };
225
+ Object.entries(dataPoint).forEach(([key, value]) => {
226
+ if (key !== 'category' && typeof value === 'number') {
227
+ normalizedDataPoint[key] = value / valueBase;
228
+ }
229
+ });
230
+ return normalizedDataPoint;
231
+ });
232
+ return { unitLabel, roundReferenceValue, rechartsData };
233
+ };
234
+ /**
235
+ * Return the unit label base on the current dataset, and the valueBase which is used to convert the data
236
+ * @param {any} unitRange
237
+ * @param {any} maxValue the maximum value among the data set
238
+ * @returns {any}
239
+ */
240
+ export function getUnitLabel(unitRange, maxValue) {
241
+ // first sort the unitRange
242
+ unitRange.sort((unitA, unitB) => {
243
+ return unitA.threshold - unitB.threshold;
244
+ });
245
+ let index = unitRange.findIndex((range) => range.threshold > maxValue);
246
+ // last unit
247
+ if (index === -1) {
248
+ index = unitRange.length;
249
+ }
250
+ if (index === 0) {
251
+ return {
252
+ valueBase: unitRange[index].threshold,
253
+ unitLabel: unitRange[index].label,
254
+ };
255
+ }
256
+ return {
257
+ // if the threshold is 0, we use 1 as the value base to avoid division by 0
258
+ valueBase: unitRange[index - 1].threshold || 1,
259
+ unitLabel: unitRange[index - 1].label,
260
+ };
261
+ }
262
+ // Sort stacked bars by their average values in descending order
263
+ // This ensures the largest bars appear at the bottom of the stack
264
+ export const sortStackedBars = (rechartsBars, data, stacked) => {
265
+ if (!stacked) {
266
+ return rechartsBars;
267
+ }
268
+ const barAverages = rechartsBars.map((bar) => {
269
+ const values = data
270
+ .map((item) => Number(item[bar.dataKey]) || 0)
271
+ .filter((value) => !isNaN(value));
272
+ const average = values.length > 0 ? values.reduce((a, b) => a + b, 0) / values.length : 0;
273
+ return { ...bar, average };
274
+ });
275
+ // Sort by average in descending order (largest first, which will be at bottom in stack)
276
+ barAverages.sort((a, b) => b.average - a.average);
277
+ // Remove the average property and keep only the bar data
278
+ return barAverages.map(({ average, ...bar }) => bar);
279
+ };
280
+ export const renderTooltipContent = (props, tooltip, hoveredValue) => {
281
+ const { active, payload, label } = props;
282
+ if (!active || !tooltip) {
283
+ return null;
284
+ }
285
+ const tooltipValues = payload.map((item) => ({
286
+ label: item.name,
287
+ value: item.value,
288
+ isHovered: item.name === hoveredValue,
289
+ }));
290
+ const currentPoint = {
291
+ category: label,
292
+ values: tooltipValues,
293
+ };
294
+ return tooltip(currentPoint);
295
+ };
296
+ /**
297
+ * Filters both chart data and recharts bars to only include selected resources from legend
298
+ * @param data - Array of chart data objects with category and resource values
299
+ * @param rechartsBars - Array of recharts bar configurations
300
+ * @param selectedResources - Array of selected resource names
301
+ * @returns Object containing filtered data and recharts bars
302
+ */
303
+ export const filterChartDataAndBarsByLegendSelection = (data, rechartsBars, selectedResources) => {
304
+ // If no resources are selected, show all data and bars (default behavior)
305
+ if (selectedResources.length === 0) {
306
+ return { filteredData: data, filteredRechartsBars: rechartsBars };
307
+ }
308
+ // Filter recharts bars
309
+ const filteredRechartsBars = rechartsBars.filter((bar) => selectedResources.includes(bar.dataKey));
310
+ // Filter data to only include selected resources
311
+ const filteredData = data.map((item) => {
312
+ const filteredItem = {
313
+ category: item.category,
314
+ };
315
+ selectedResources.forEach((resource) => {
316
+ if (resource in item) {
317
+ filteredItem[resource] = item[resource];
318
+ }
319
+ });
320
+ return filteredItem;
321
+ });
322
+ return { filteredData, filteredRechartsBars };
323
+ };
324
+ export const useChartData = (bars, type, colorSet, stacked, defaultSort, unitRange) => {
325
+ const { selectedResources } = useChartLegend();
326
+ const { data, rechartsBars } = formatPrometheusDataToRechartsDataAndBars(bars, type, colorSet, stacked, defaultSort);
327
+ // Filter both data and bars to only include selected resources for accurate maxValue calculation
328
+ const { filteredData, filteredRechartsBars } = filterChartDataAndBarsByLegendSelection(data, rechartsBars, selectedResources);
329
+ const maxValue = getMaxBarValue(filteredData, stacked);
330
+ const { unitLabel, roundReferenceValue, rechartsData } = computeUnitLabelAndRoundReferenceValue(filteredData, maxValue, unitRange);
331
+ return {
332
+ rechartsBars: filteredRechartsBars,
333
+ unitLabel,
334
+ roundReferenceValue,
335
+ rechartsData,
336
+ };
337
+ };
@@ -1,4 +1,4 @@
1
- import React, { ButtonHTMLAttributes } from 'react';
1
+ import { ButtonHTMLAttributes } from 'react';
2
2
  import { Loader } from '../loader/Loader.component';
3
3
  import { Props as TooltipProps } from '../tooltip/Tooltip.component';
4
4
  export declare const FocusVisibleStyle: import("styled-components").FlattenInterpolation<import("styled-components").ThemeProps<import("styled-components").DefaultTheme>>;
@@ -1 +1 @@
1
- {"version":3,"file":"Buttonv2.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/buttonv2/Buttonv2.component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAIpD,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAW,KAAK,IAAI,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE9E,eAAO,MAAM,iBAAiB,oIAI7B,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,IAAI,CACtB,oBAAoB,CAAC,iBAAiB,CAAC,EACvC,MAAM,GAAG,OAAO,CACjB,GAAG;IACF,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;IACzD,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;IAC/D,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IACzC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AACF,eAAO,MAAM,YAAY,+GAqJxB,CAAC;AACF,eAAO,MAAM,WAAW,0GAIvB,CAAC;AACF,eAAO,MAAM,UAAU;WAAwB,KAAK,CAAC,SAAS;SAS7D,CAAC;AAEF,eAAO,MAAM,YAAY;;;SAaxB,CAAC;AAEF,iBAAS,MAAM,CAAC,EACd,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,OAAO,EACP,OAAO,EACP,SAAS,EACT,GAAG,IAAI,EACR,EAAE,KAAK,2CAqDP;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
1
+ {"version":3,"file":"Buttonv2.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/buttonv2/Buttonv2.component.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAI7C,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAW,KAAK,IAAI,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE9E,eAAO,MAAM,iBAAiB,oIAI7B,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,IAAI,CACtB,oBAAoB,CAAC,iBAAiB,CAAC,EACvC,MAAM,GAAG,OAAO,CACjB,GAAG;IACF,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;IACzD,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;IAC/D,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IACzC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AACF,eAAO,MAAM,YAAY,+GAqJxB,CAAC;AACF,eAAO,MAAM,WAAW,0GAIvB,CAAC;AACF,eAAO,MAAM,UAAU;WAAwB,KAAK,CAAC,SAAS;SAS7D,CAAC;AAEF,eAAO,MAAM,YAAY;;;SAaxB,CAAC;AAEF,iBAAS,MAAM,CAAC,EACd,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,OAAO,EACP,OAAO,EACP,SAAS,EACT,GAAG,IAAI,EACR,EAAE,KAAK,2CAqDP;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ type ChartLegendProps = {
2
+ shape: 'line' | 'rectangle';
3
+ disabled?: boolean;
4
+ direction?: 'horizontal' | 'vertical';
5
+ };
6
+ export declare const ChartLegend: ({ shape, disabled, direction, }: ChartLegendProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
8
+ //# sourceMappingURL=ChartLegend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChartLegend.d.ts","sourceRoot":"","sources":["../../../src/lib/components/chartlegend/ChartLegend.tsx"],"names":[],"mappings":"AAMA,KAAK,gBAAgB,GAAG;IACtB,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;CACvC,CAAC;AAkDF,eAAO,MAAM,WAAW,oCAIrB,gBAAgB,4CAgDlB,CAAC"}
@@ -0,0 +1,65 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import styled from 'styled-components';
3
+ import { useChartLegend } from './ChartLegendWrapper';
4
+ import { Text } from '../text/Text.component';
5
+ import { chartColors } from '../../style/theme';
6
+ import { useCallback } from 'react';
7
+ const Legend = styled.div `
8
+ display: flex;
9
+ flex-direction: ${({ direction }) => direction === 'horizontal' ? 'row' : 'column'};
10
+ gap: ${({ direction }) => (direction === 'horizontal' ? '16px' : '8px')};
11
+ flex-wrap: wrap;
12
+ `;
13
+ const LegendItem = styled.div `
14
+ display: flex;
15
+ align-items: center;
16
+ gap: 8px;
17
+ cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')};
18
+ opacity: ${({ selected, disabled }) => (disabled ? 0.5 : selected ? 1 : 0.7)};
19
+ transition: opacity 0.2s ease;
20
+
21
+ &:hover {
22
+ opacity: ${({ disabled }) => (disabled ? 0.5 : 1)};
23
+ }
24
+ `;
25
+ const LegendShape = styled.div `
26
+ ${({ shape, color, chartColors }) => {
27
+ if (shape === 'line') {
28
+ return `
29
+ width: 20px;
30
+ height: 2px;
31
+ background-color: ${chartColors[color] || color};
32
+ `;
33
+ }
34
+ else if (shape === 'rectangle') {
35
+ return `
36
+ width: 12px;
37
+ height: 12px;
38
+ background-color: ${chartColors[color] || color};
39
+ border-radius: 2px;
40
+ `;
41
+ }
42
+ else {
43
+ console.error('The shape is not valid. Please use "line" or "rectangle".');
44
+ }
45
+ }}
46
+ `;
47
+ export const ChartLegend = ({ shape, disabled = false, direction = 'horizontal', }) => {
48
+ const { listResources, getColor, isSelected, addSelectedResource, removeSelectedResource, } = useChartLegend();
49
+ const resources = listResources();
50
+ const handleLegendClick = useCallback((resource) => {
51
+ if (disabled)
52
+ return;
53
+ if (isSelected(resource)) {
54
+ removeSelectedResource(resource);
55
+ }
56
+ else {
57
+ addSelectedResource(resource);
58
+ }
59
+ }, [disabled, isSelected, addSelectedResource, removeSelectedResource]);
60
+ return (_jsx(Legend, { direction: direction, children: resources.map((resource) => {
61
+ const color = getColor(resource);
62
+ const selected = isSelected(resource);
63
+ return (_jsxs(LegendItem, { disabled: disabled, selected: selected, onClick: () => handleLegendClick(resource), children: [_jsx(LegendShape, { color: color, shape: shape, chartColors: chartColors }), _jsx(Text, { variant: "Basic", children: resource })] }, resource));
64
+ }) }));
65
+ };
@@ -0,0 +1,17 @@
1
+ import { ReactNode } from 'react';
2
+ import { ChartColors } from '../../style/theme';
3
+ export type ChartLegendState = {
4
+ selectedResources: string[];
5
+ addSelectedResource: (resource: string) => void;
6
+ removeSelectedResource: (resource: string) => void;
7
+ isSelected: (resource: string) => boolean;
8
+ getColor: (resource: string) => string | undefined;
9
+ listResources: () => string[];
10
+ };
11
+ export type ChartLegendWrapperProps = {
12
+ children: ReactNode;
13
+ colorSet: Record<string, ChartColors | string>;
14
+ };
15
+ export declare const ChartLegendWrapper: ({ children, colorSet, }: ChartLegendWrapperProps) => import("react/jsx-runtime").JSX.Element;
16
+ export declare const useChartLegend: () => ChartLegendState;
17
+ //# sourceMappingURL=ChartLegendWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChartLegendWrapper.d.ts","sourceRoot":"","sources":["../../../src/lib/components/chartlegend/ChartLegendWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuC,SAAS,EAAwB,MAAM,OAAO,CAAC;AAC7F,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,mBAAmB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,sBAAsB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IAC1C,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IACnD,aAAa,EAAE,MAAM,MAAM,EAAE,CAAC;CAC/B,CAAC;AAIF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC,CAAC;CAChD,CAAC;AAEF,eAAO,MAAM,kBAAkB,4BAG5B,uBAAuB,4CAqDzB,CAAC;AAGF,eAAO,MAAM,cAAc,wBAM1B,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useState, useMemo, useCallback } from 'react';
3
+ const ChartLegendContext = createContext(null);
4
+ export const ChartLegendWrapper = ({ children, colorSet, }) => {
5
+ const [selectedResources, setSelectedResources] = useState([]);
6
+ const addSelectedResource = useCallback((resource) => {
7
+ setSelectedResources((prev) => prev.includes(resource) ? prev : [...prev, resource]);
8
+ }, []);
9
+ const removeSelectedResource = useCallback((resource) => {
10
+ setSelectedResources((prev) => prev.filter((r) => r !== resource));
11
+ }, []);
12
+ const isSelected = useCallback((resource) => {
13
+ return selectedResources.includes(resource);
14
+ }, [selectedResources]);
15
+ const getColor = useCallback((resource) => {
16
+ const color = colorSet[resource];
17
+ if (!color) {
18
+ console.warn(`ChartLegendWrapper: No color defined for resource "${resource}"`);
19
+ return undefined;
20
+ }
21
+ return color;
22
+ }, [colorSet]);
23
+ const listResources = useCallback(() => {
24
+ return Object.keys(colorSet);
25
+ }, [colorSet]);
26
+ const chartLegendState = useMemo(() => ({
27
+ selectedResources,
28
+ addSelectedResource,
29
+ removeSelectedResource,
30
+ isSelected,
31
+ getColor,
32
+ listResources,
33
+ }), [
34
+ selectedResources,
35
+ addSelectedResource,
36
+ removeSelectedResource,
37
+ isSelected,
38
+ getColor,
39
+ listResources,
40
+ ]);
41
+ return (_jsx(ChartLegendContext.Provider, { value: chartLegendState, children: children }));
42
+ };
43
+ // Hook for accessing legend state in custom components
44
+ export const useChartLegend = () => {
45
+ const context = useContext(ChartLegendContext);
46
+ if (!context) {
47
+ throw new Error('useChartLegend must be used within a ChartLegendWrapper');
48
+ }
49
+ return context;
50
+ };
@@ -5,7 +5,8 @@ type Props = {
5
5
  tooltipStyle?: $PropertyType<TooltipProps, 'overlayStyle'>;
6
6
  tooltipPlacement?: $PropertyType<TooltipProps, 'placement'>;
7
7
  lineClamp?: number;
8
+ centered?: boolean;
8
9
  };
9
- declare function ConstrainedText({ text, tooltipStyle, tooltipPlacement, lineClamp, }: Props): JSX.Element;
10
+ declare function ConstrainedText({ text, tooltipStyle, tooltipPlacement, lineClamp, centered, }: Props): JSX.Element;
10
11
  export { ConstrainedText };
11
12
  //# sourceMappingURL=Constrainedtext.component.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Constrainedtext.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/constrainedtext/Constrainedtext.component.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAK9C,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAGrE,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IACpD,YAAY,CAAC,EAAE,aAAa,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IAC3D,gBAAgB,CAAC,EAAE,aAAa,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAiDF,iBAAS,eAAe,CAAC,EACvB,IAAI,EACJ,YAAY,EACZ,gBAAgB,EAChB,SAAa,GACd,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CA2BrB;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"Constrainedtext.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/constrainedtext/Constrainedtext.component.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAK9C,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAGrE,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IACpD,YAAY,CAAC,EAAE,aAAa,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IAC3D,gBAAgB,CAAC,EAAE,aAAa,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAwDF,iBAAS,eAAe,CAAC,EACvB,IAAI,EACJ,YAAY,EACZ,gBAAgB,EAChB,SAAa,EACb,QAAgB,GACjB,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CAqCrB;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -9,6 +9,7 @@ import { Text } from '../text/Text.component';
9
9
  const ConstrainedTextContainer = styled.div `
10
10
  overflow: hidden;
11
11
  text-overflow: ellipsis;
12
+ text-align: ${(props) => (props.centered ? 'center' : 'left')};
12
13
 
13
14
  ${(props) => props.lineClamp > 1
14
15
  ? `
@@ -34,14 +35,14 @@ function isEllipsisActive(element) {
34
35
  (element.offsetWidth < element.scrollWidth ||
35
36
  element.offsetHeight < element.scrollHeight));
36
37
  }
37
- function getConstrainedTextContainer(constrainedTextRef, lineClamp, text) {
38
- return (_jsx(ConstrainedTextContainer, { ref: constrainedTextRef, className: "sc-constrainedtext", lineClamp: lineClamp, children: text }));
38
+ function getConstrainedTextContainer(constrainedTextRef, lineClamp, text, centered) {
39
+ return (_jsx(ConstrainedTextContainer, { ref: constrainedTextRef, className: "sc-constrainedtext", lineClamp: lineClamp, centered: centered, children: text }));
39
40
  }
40
- function ConstrainedText({ text, tooltipStyle, tooltipPlacement, lineClamp = 1, }) {
41
+ function ConstrainedText({ text, tooltipStyle, tooltipPlacement, lineClamp = 1, centered = false, }) {
41
42
  const [displayToolTip, setDisplayToolTip] = useState(false);
42
43
  const constrainedTextRef = useCallback((element) => {
43
44
  element && text && setDisplayToolTip(isEllipsisActive(element));
44
45
  }, [text]);
45
- return (_jsx(BlockTooltip, { children: displayToolTip ? (_jsx(Tooltip, { overlay: text, overlayStyle: tooltipStyle, placement: tooltipPlacement, children: _jsx(Text, { children: getConstrainedTextContainer(constrainedTextRef, lineClamp, text) }) })) : (_jsx(Text, { children: getConstrainedTextContainer(constrainedTextRef, lineClamp, text) })) }));
46
+ return (_jsx(BlockTooltip, { children: displayToolTip ? (_jsx(Tooltip, { overlay: text, overlayStyle: tooltipStyle, placement: tooltipPlacement, children: _jsx(Text, { children: getConstrainedTextContainer(constrainedTextRef, lineClamp, text, centered) }) })) : (_jsx(Text, { children: getConstrainedTextContainer(constrainedTextRef, lineClamp, text, centered) })) }));
46
47
  }
47
48
  export { ConstrainedText };
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import { CoreUITheme } from '../../style/theme';
3
2
  type Props = {
4
3
  theme: CoreUITheme;
@@ -1 +1 @@
1
- {"version":3,"file":"CoreUiThemeProvider.d.ts","sourceRoot":"","sources":["../../../src/lib/components/coreuithemeprovider/CoreUiThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAmB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEjE,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,QAAA,MAAM,mBAAmB,wBAAyB,KAAK,4CAStD,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
1
+ {"version":3,"file":"CoreUiThemeProvider.d.ts","sourceRoot":"","sources":["../../../src/lib/components/coreuithemeprovider/CoreUiThemeProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAmB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEjE,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,QAAA,MAAM,mBAAmB,wBAAyB,KAAK,4CAStD,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
@@ -1,8 +1,11 @@
1
1
  export declare const DATE_FORMATER: Intl.DateTimeFormat;
2
+ export declare const DAY_MONTH_FORMATER: Intl.DateTimeFormat;
2
3
  export declare const TIME_SECOND_FORMATER: Intl.DateTimeFormat;
3
4
  export declare const TIME_FORMATER: Intl.DateTimeFormat;
5
+ export declare const DAY_MONTH_ABBREVIATED_HOUR_MINUTE_SECOND: Intl.DateTimeFormat;
6
+ export declare const DAY_MONTH_ABBREVIATED_HOUR_MINUTE: Intl.DateTimeFormat;
4
7
  type FormattedDateTimeProps = {
5
- format: 'date' | 'date-time' | 'date-time-second' | 'time' | 'time-second' | 'relative';
8
+ format: 'date' | 'date-time' | 'date-time-second' | 'time' | 'time-second' | 'relative' | 'day-month-abbreviated-hour-minute' | 'day-month-abbreviated-hour-minute-second';
6
9
  value: Date;
7
10
  };
8
11
  export declare const FormattedDateTime: ({ format, value, }: FormattedDateTimeProps) => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"FormattedDateTime.d.ts","sourceRoot":"","sources":["../../../src/lib/components/date/FormattedDateTime.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,qBAKxB,CAAC;AAEH,eAAO,MAAM,oBAAoB,qBAK/B,CAAC;AAEH,eAAO,MAAM,aAAa,qBAIxB,CAAC;AAEH,KAAK,sBAAsB,GAAG;IAC5B,MAAM,EACF,MAAM,GACN,WAAW,GACX,kBAAkB,GAClB,MAAM,GACN,aAAa,GACb,UAAU,CAAC;IACf,KAAK,EAAE,IAAI,CAAC;CACb,CAAC;AAaF,eAAO,MAAM,iBAAiB,uBAG3B,sBAAsB,4CAqGxB,CAAC"}
1
+ {"version":3,"file":"FormattedDateTime.d.ts","sourceRoot":"","sources":["../../../src/lib/components/date/FormattedDateTime.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,qBAKxB,CAAC;AAEH,eAAO,MAAM,kBAAkB,qBAI7B,CAAC;AAEH,eAAO,MAAM,oBAAoB,qBAK/B,CAAC;AAEH,eAAO,MAAM,aAAa,qBAIxB,CAAC;AAEH,eAAO,MAAM,wCAAwC,qBAUpD,CAAC;AAEF,eAAO,MAAM,iCAAiC,qBAM5C,CAAC;AAEH,KAAK,sBAAsB,GAAG;IAC5B,MAAM,EACF,MAAM,GACN,WAAW,GACX,kBAAkB,GAClB,MAAM,GACN,aAAa,GACb,UAAU,GACV,mCAAmC,GACnC,0CAA0C,CAAC;IAC/C,KAAK,EAAE,IAAI,CAAC;CACb,CAAC;AAaF,eAAO,MAAM,iBAAiB,uBAG3B,sBAAsB,4CAiHxB,CAAC"}
@@ -7,6 +7,11 @@ export const DATE_FORMATER = Intl.DateTimeFormat('fr-CA', {
7
7
  day: '2-digit',
8
8
  hour12: false,
9
9
  });
10
+ export const DAY_MONTH_FORMATER = Intl.DateTimeFormat('en-GB', {
11
+ weekday: 'short',
12
+ day: '2-digit',
13
+ month: 'short',
14
+ });
10
15
  export const TIME_SECOND_FORMATER = Intl.DateTimeFormat('en-GB', {
11
16
  hour12: false,
12
17
  hour: '2-digit',
@@ -18,6 +23,21 @@ export const TIME_FORMATER = Intl.DateTimeFormat('en-GB', {
18
23
  hour: '2-digit',
19
24
  minute: '2-digit',
20
25
  });
26
+ export const DAY_MONTH_ABBREVIATED_HOUR_MINUTE_SECOND = Intl.DateTimeFormat('en-GB', {
27
+ day: 'numeric',
28
+ month: 'short',
29
+ hour: '2-digit',
30
+ minute: '2-digit',
31
+ second: '2-digit',
32
+ hour12: false,
33
+ });
34
+ export const DAY_MONTH_ABBREVIATED_HOUR_MINUTE = Intl.DateTimeFormat('en-GB', {
35
+ day: 'numeric',
36
+ month: 'short',
37
+ hour: '2-digit',
38
+ minute: '2-digit',
39
+ hour12: false,
40
+ });
21
41
  const isItFutureOrIsItPast = (timeDiff, stringToBeFormatted) => {
22
42
  if (timeDiff > 0) {
23
43
  return `${stringToBeFormatted} ago`;
@@ -59,7 +79,10 @@ export const FormattedDateTime = ({ format, value, }) => {
59
79
  return (_jsx(Tooltip, { overlay: _jsx(FormattedDateTime, { format: "date-time-second", value: value }), children: isItFutureOrIsItPast(minuteDiff, `${Math.abs(minuteDiff)} minute${Math.abs(minuteDiff) > 1 ? 's' : ''}`) }));
60
80
  }
61
81
  return (_jsx(Tooltip, { overlay: _jsx(FormattedDateTime, { format: "date-time-second", value: value }), children: "few seconds ago" }));
62
- //TO FINISH
82
+ case 'day-month-abbreviated-hour-minute':
83
+ return (_jsx(_Fragment, { children: DAY_MONTH_ABBREVIATED_HOUR_MINUTE.format(value).replace(',', '') }));
84
+ case 'day-month-abbreviated-hour-minute-second':
85
+ return (_jsx(_Fragment, { children: DAY_MONTH_ABBREVIATED_HOUR_MINUTE_SECOND.format(value).replace(',', '') }));
63
86
  default:
64
87
  return _jsx(_Fragment, {});
65
88
  }
@@ -137,4 +137,16 @@ describe('FormatttedDateTime', () => {
137
137
  //V
138
138
  expect(screen.getByText('2022-12-12 11:57:26')).toBeInTheDocument();
139
139
  });
140
+ it('should display the date in the expected format of the xaxis tick in the chart', () => {
141
+ //S
142
+ render(_jsx(FormattedDateTime, { format: "day-month-abbreviated-hour-minute", value: new Date('2022-10-06T18:33:00Z') }));
143
+ //V
144
+ expect(screen.getByText('6 Oct 18:33')).toBeInTheDocument();
145
+ });
146
+ it('should display the date in the expected format of date in the chart', () => {
147
+ //S
148
+ render(_jsx(FormattedDateTime, { format: "day-month-abbreviated-hour-minute-second", value: new Date('2022-10-06T18:33:00Z') }));
149
+ //V
150
+ expect(screen.getByText('6 Oct 18:33:00')).toBeInTheDocument();
151
+ });
140
152
  });
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
1
  type Props = {
3
2
  children: Node | React.ReactNode;
4
3
  useDiv?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"Emptytable.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/emptytable/Emptytable.component.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC;IACjC,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAuDF,iBAAS,UAAU,CAAC,KAAK,EAAE,KAAK,2CAY/B;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"Emptytable.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/emptytable/Emptytable.component.tsx"],"names":[],"mappings":"AAMA,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC;IACjC,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAuDF,iBAAS,UAAU,CAAC,KAAK,EAAE,KAAK,2CAY/B;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}