@scality/core-ui 0.162.0 → 0.164.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/dist/components/barchartv2/Barchart.component.d.ts +9 -3
- package/dist/components/barchartv2/Barchart.component.d.ts.map +1 -1
- package/dist/components/barchartv2/Barchart.component.js +22 -5
- package/dist/components/barchartv2/utils.d.ts +26 -3
- package/dist/components/barchartv2/utils.d.ts.map +1 -1
- package/dist/components/barchartv2/utils.js +76 -22
- package/dist/components/chartlegend/ChartLegend.d.ts +8 -0
- package/dist/components/chartlegend/ChartLegend.d.ts.map +1 -0
- package/dist/components/chartlegend/ChartLegend.js +65 -0
- package/dist/components/chartlegend/ChartLegendWrapper.d.ts +17 -0
- package/dist/components/chartlegend/ChartLegendWrapper.d.ts.map +1 -0
- package/dist/components/chartlegend/ChartLegendWrapper.js +50 -0
- package/dist/components/date/FormattedDateTime.d.ts +3 -1
- package/dist/components/date/FormattedDateTime.d.ts.map +1 -1
- package/dist/components/date/FormattedDateTime.js +19 -1
- package/dist/components/date/FormattedDateTime.spec.js +12 -0
- package/dist/components/icon/Icon.component.d.ts +5 -5
- package/dist/components/icon/Icon.component.d.ts.map +1 -1
- package/dist/components/icon/Icon.component.js +33 -31
- package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts +33 -0
- package/dist/components/linetimeseriechart/linetimeseriechart.component.d.ts.map +1 -0
- package/dist/components/linetimeseriechart/linetimeseriechart.component.js +249 -0
- package/dist/components/selectv2/Selectv2.component.d.ts.map +1 -1
- package/dist/components/selectv2/Selectv2.component.js +11 -6
- package/dist/components/steppers/Stepper.component.d.ts.map +1 -1
- package/dist/components/steppers/Stepper.component.js +9 -8
- package/dist/components/toast/ToastProvider.d.ts.map +1 -1
- package/dist/components/toast/ToastProvider.js +4 -5
- package/dist/components/vegachartv2/SyncedCursorCharts.d.ts.map +1 -1
- package/dist/components/vegachartv2/SyncedCursorCharts.js +3 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/next.d.ts +2 -0
- package/dist/next.d.ts.map +1 -1
- package/dist/next.js +2 -0
- package/dist/style/theme.d.ts +1 -0
- package/dist/style/theme.d.ts.map +1 -1
- package/dist/style/theme.js +28 -0
- package/package.json +2 -2
- package/src/lib/components/accordion/Accordion.test.tsx +8 -16
- package/src/lib/components/barchartv2/Barchart.component.test.tsx +117 -111
- package/src/lib/components/barchartv2/Barchart.component.tsx +54 -7
- package/src/lib/components/barchartv2/utils.test.ts +127 -2
- package/src/lib/components/barchartv2/utils.ts +103 -19
- package/src/lib/components/chartlegend/ChartLegend.tsx +113 -0
- package/src/lib/components/chartlegend/ChartLegendWrapper.tsx +85 -0
- package/src/lib/components/date/FormattedDateTime.spec.tsx +24 -0
- package/src/lib/components/date/FormattedDateTime.tsx +36 -2
- package/src/lib/components/healthselectorv2/HealthSelector.component.test.tsx +10 -10
- package/src/lib/components/icon/Icon.component.tsx +48 -60
- package/src/lib/components/infomessage/InfoMessageUtils.test.tsx +0 -1
- package/src/lib/components/inlineinput/InlineInput.test.tsx +28 -22
- package/src/lib/components/inputlist/InputList.test.tsx +22 -21
- package/src/lib/components/linetemporalchart/ChartUtil.test.ts +5 -4
- package/src/lib/components/linetimeseriechart/linetimeseriechart.component.tsx +502 -0
- package/src/lib/components/searchinput/SearchInput.test.tsx +3 -7
- package/src/lib/components/selectv2/Selectv2.component.tsx +13 -5
- package/src/lib/components/selectv2/selectv2.test.tsx +70 -61
- package/src/lib/components/steppers/Stepper.component.tsx +10 -8
- package/src/lib/components/tablev2/TableSync.test.tsx +8 -12
- package/src/lib/components/tablev2/TableUtils.test.ts +6 -3
- package/src/lib/components/tablev2/Tablev2.test.tsx +38 -40
- package/src/lib/components/toast/ToastProvider.tsx +14 -6
- package/src/lib/components/toggle/Toggle.test.tsx +1 -1
- package/src/lib/components/vegachartv2/SyncedCursorCharts.tsx +5 -7
- package/src/lib/index.ts +1 -0
- package/src/lib/next.ts +2 -0
- package/src/lib/style/theme.ts +29 -0
- package/stories/BarChart/barchart.stories.tsx +387 -129
- package/stories/format.mdx +4 -2
- package/stories/linetimeseriechart.stories.tsx +485 -0
- package/tsconfig.json +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ChartColors } from '../../style/theme';
|
|
2
1
|
import { UnitRange } from './utils';
|
|
3
2
|
export type TimeType = {
|
|
4
3
|
type: 'time';
|
|
@@ -38,18 +37,25 @@ export type BarchartSortFn<T extends BarchartBars> = (pointA: Record<T[number]['
|
|
|
38
37
|
}) => 1 | -1 | 0;
|
|
39
38
|
export type BarchartProps<T extends BarchartBars> = {
|
|
40
39
|
type: 'category' | TimeType;
|
|
41
|
-
bars
|
|
42
|
-
colorSet: Record<T[number]['label'], ChartColors | (string & {})>;
|
|
40
|
+
bars?: T;
|
|
43
41
|
tooltip?: BarchartTooltipFn<T>;
|
|
44
42
|
defaultSort?: BarchartSortFn<T>;
|
|
45
43
|
unitRange?: UnitRange;
|
|
46
44
|
helpTooltip?: string;
|
|
47
45
|
stacked?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Sort the bars by default or by legend order
|
|
48
|
+
* legend will sort the bars by the order of the colorSet property of the ChartLegendWrapper component
|
|
49
|
+
* default will sort the bars by average values in descending order (biggest values will be at bottom)
|
|
50
|
+
* @default 'default'
|
|
51
|
+
*/
|
|
52
|
+
stackedBarSort?: 'default' | 'legend';
|
|
48
53
|
title?: string;
|
|
49
54
|
secondaryTitle?: string;
|
|
50
55
|
rightTitle?: React.ReactNode;
|
|
51
56
|
height?: number;
|
|
52
57
|
isLoading?: boolean;
|
|
58
|
+
isError?: boolean;
|
|
53
59
|
};
|
|
54
60
|
export declare const Barchart: <T extends BarchartBars>(props: BarchartProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
55
61
|
//# sourceMappingURL=Barchart.component.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Barchart.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/Barchart.component.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Barchart.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/Barchart.component.tsx"],"names":[],"mappings":"AAoBA,OAAO,EAAwB,SAAS,EAAgB,MAAM,SAAS,CAAC;AAkBxE,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE;QACT,SAAS,EAAE,IAAI,CAAC;QAChB,OAAO,EAAE,IAAI,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,CAAC;AACF,MAAM,MAAM,KAAK,GAAG;IAClB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,SAAS;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC;CACvE,EAAE,CAAC;AAEJ,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,YAAY,IAAI,CAAC,YAAY,EAAE;IACrE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,MAAM,EAAE;QAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;CAC5E,KAAK,KAAK,CAAC,SAAS,CAAC;AAEtB,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,YAAY,IAAI,CACnD,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG;IAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EAC1E,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG;IAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,KACvE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAEhB,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,YAAY,IAAI;IAClD,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC5B,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC/B,WAAW,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAChC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAgIF,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,YAAY,SAAS,aAAa,CAAC,CAAC,CAAC,4CAwIvE,CAAC"}
|
|
@@ -10,10 +10,11 @@ import { IconHelp } from '../iconhelper/IconHelper';
|
|
|
10
10
|
import { Loader } from '../loader/Loader.component';
|
|
11
11
|
import { Text } from '../text/Text.component';
|
|
12
12
|
import { renderTooltipContent, useChartData } from './utils';
|
|
13
|
+
import { useChartLegend } from '../chartlegend/ChartLegendWrapper';
|
|
13
14
|
const CHART_CONSTANTS = {
|
|
14
15
|
TICK_WIDTH_OFFSET: 5,
|
|
15
16
|
BAR_SIZE: 12,
|
|
16
|
-
MIN_POINT_SIZE:
|
|
17
|
+
MIN_POINT_SIZE: 3,
|
|
17
18
|
DEFAULT_HEIGHT: 200,
|
|
18
19
|
CHART_MARGIN: {
|
|
19
20
|
left: 0,
|
|
@@ -46,6 +47,13 @@ const ChartHeader = ({ title, secondaryTitle, helpTooltip, rightTitle, }) => {
|
|
|
46
47
|
marginLeft: spacing.r8,
|
|
47
48
|
}, children: secondaryTitle }))] }), rightTitle && _jsx(Text, { children: rightTitle })] }));
|
|
48
49
|
};
|
|
50
|
+
const Error = ({ height }) => {
|
|
51
|
+
return (_jsx(Box, { height: height, style: {
|
|
52
|
+
alignItems: 'center',
|
|
53
|
+
justifyContent: 'center',
|
|
54
|
+
display: 'flex',
|
|
55
|
+
}, children: _jsx(Text, { children: "Chart data is not available" }) }));
|
|
56
|
+
};
|
|
49
57
|
const Loading = ({ height }) => {
|
|
50
58
|
return (_jsx(Box, { height: height, style: {
|
|
51
59
|
alignItems: 'center',
|
|
@@ -56,12 +64,21 @@ const Loading = ({ height }) => {
|
|
|
56
64
|
/* ---------------------------------- MAIN COMPONENT ---------------------------------- */
|
|
57
65
|
export const Barchart = (props) => {
|
|
58
66
|
const theme = useTheme();
|
|
67
|
+
const { getColor } = useChartLegend();
|
|
59
68
|
const [hoveredValue, setHoveredValue] = useState();
|
|
60
|
-
const { height = CHART_CONSTANTS.DEFAULT_HEIGHT, bars, type = 'category',
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
const { height = CHART_CONSTANTS.DEFAULT_HEIGHT, bars, type = 'category', unitRange, stacked, stackedBarSort = 'default', defaultSort, tooltip, title, secondaryTitle, helpTooltip, rightTitle, isLoading, isError, } = props;
|
|
70
|
+
// Create colorSet from ChartLegendWrapper
|
|
71
|
+
const colorSet = bars === null || bars === void 0 ? void 0 : bars.reduce((acc, bar) => {
|
|
72
|
+
const color = getColor(bar.label);
|
|
73
|
+
if (color) {
|
|
74
|
+
acc[bar.label] = color;
|
|
75
|
+
}
|
|
76
|
+
return acc;
|
|
77
|
+
}, {});
|
|
78
|
+
const { rechartsBars, unitLabel, roundReferenceValue, rechartsData } = useChartData(bars || [], type, colorSet || {}, stacked, defaultSort, unitRange, stackedBarSort);
|
|
79
|
+
return (_jsxs(Stack, { direction: "vertical", gap: "r8", children: [_jsx(ChartHeader, { title: title, secondaryTitle: secondaryTitle, helpTooltip: helpTooltip, rightTitle: rightTitle }), isError || (!bars && !isLoading) ? (_jsx(Error, { height: height })) : isLoading ? (_jsx(Loading, { height: height })) : (_jsx(StyledResponsiveContainer, { width: "100%", height: height, children: _jsxs(BarChart, { data: rechartsData, accessibilityLayer: true, barSize: CHART_CONSTANTS.BAR_SIZE, height: height, margin: CHART_CONSTANTS.CHART_MARGIN, children: [_jsx(CartesianGrid, { vertical: false, horizontal: false, fill: theme.backgroundLevel1 }), rechartsBars.map((bar) => {
|
|
63
80
|
const { fill, dataKey, stackId } = bar;
|
|
64
|
-
return (_jsx(Bar, { dataKey: dataKey, fill: chartColors[fill] || fill, minPointSize: CHART_CONSTANTS.MIN_POINT_SIZE, stackId: stackId, onMouseOver: () => setHoveredValue(dataKey), onMouseLeave: () => setHoveredValue(undefined) }, dataKey));
|
|
81
|
+
return (_jsx(Bar, { dataKey: dataKey, fill: chartColors[fill] || fill, minPointSize: stacked ? 0 : CHART_CONSTANTS.MIN_POINT_SIZE, stackId: stackId, onMouseOver: () => setHoveredValue(dataKey), onMouseLeave: () => setHoveredValue(undefined) }, dataKey));
|
|
65
82
|
}), _jsx(YAxis, { tickCount: 1, unit: ` ${unitLabel}`, domain: [0, roundReferenceValue], tickFormatter: (value) => new Intl.NumberFormat('fr-FR').format(value.toFixed(0)) // Add a space as thousand separator
|
|
66
83
|
, axisLine: false, tick: {
|
|
67
84
|
fill: theme.textSecondary,
|
|
@@ -38,7 +38,7 @@ export declare const applySortingToData: <T extends BarchartBars>(data: {
|
|
|
38
38
|
* @param type - The chart type (category or time)
|
|
39
39
|
* @returns Recharts data format
|
|
40
40
|
*/
|
|
41
|
-
export declare const formatPrometheusDataToRechartsDataAndBars: <T extends BarchartBars>(bars: T, type: BarchartProps<T>["type"], colorSet: Record<
|
|
41
|
+
export declare const formatPrometheusDataToRechartsDataAndBars: <T extends BarchartBars>(bars: T, type: BarchartProps<T>["type"], colorSet: Record<string, ChartColors | string>, stacked?: boolean, defaultSort?: BarchartProps<T>["defaultSort"], legendOrder?: string[]) => {
|
|
42
42
|
data: {
|
|
43
43
|
[key: string]: string | number;
|
|
44
44
|
}[];
|
|
@@ -76,13 +76,36 @@ export declare const sortStackedBars: (rechartsBars: {
|
|
|
76
76
|
stackId?: string;
|
|
77
77
|
}[], data: {
|
|
78
78
|
[key: string]: string | number;
|
|
79
|
-
}[], stacked?: boolean) => {
|
|
79
|
+
}[], stacked?: boolean, legendOrder?: string[]) => {
|
|
80
80
|
dataKey: string;
|
|
81
81
|
fill: string;
|
|
82
82
|
stackId?: string;
|
|
83
83
|
}[];
|
|
84
84
|
export declare const renderTooltipContent: <T extends BarchartBars>(props: TooltipContentProps<number, string>, tooltip: BarchartTooltipFn<T> | undefined, hoveredValue: string | undefined) => import("react").ReactNode;
|
|
85
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Filters both chart data and recharts bars to only include selected resources from legend
|
|
87
|
+
* @param data - Array of chart data objects with category and resource values
|
|
88
|
+
* @param rechartsBars - Array of recharts bar configurations
|
|
89
|
+
* @param selectedResources - Array of selected resource names
|
|
90
|
+
* @returns Object containing filtered data and recharts bars
|
|
91
|
+
*/
|
|
92
|
+
export declare const filterChartDataAndBarsByLegendSelection: (data: {
|
|
93
|
+
[key: string]: string | number;
|
|
94
|
+
}[], rechartsBars: {
|
|
95
|
+
dataKey: string;
|
|
96
|
+
fill: string;
|
|
97
|
+
stackId?: string;
|
|
98
|
+
}[], selectedResources: string[]) => {
|
|
99
|
+
filteredData: {
|
|
100
|
+
[key: string]: string | number;
|
|
101
|
+
}[];
|
|
102
|
+
filteredRechartsBars: {
|
|
103
|
+
dataKey: string;
|
|
104
|
+
fill: string;
|
|
105
|
+
stackId?: string;
|
|
106
|
+
}[];
|
|
107
|
+
};
|
|
108
|
+
export declare const useChartData: <T extends BarchartBars>(bars: T, type: BarchartProps<T>["type"], colorSet: Record<string, ChartColors | string>, stacked?: boolean, defaultSort?: BarchartProps<T>["defaultSort"], unitRange?: UnitRange, stackedBarSort?: "default" | "legend") => {
|
|
86
109
|
rechartsBars: {
|
|
87
110
|
dataKey: string;
|
|
88
111
|
fill: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,YAAY,EACZ,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/components/barchartv2/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,YAAY,EACZ,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG7D,eAAO,MAAM,sBAAsB,UAAW,MAAM,KAAG,MAkBtD,CAAC;AAEF,eAAO,MAAM,cAAc,SACnB;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;CAAE,EAAE,YAChC,OAAO,WAuBlB,CAAC;AA2EF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI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CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,cACjC,SAAS,mBACJ,SAAS,GAAG,QAAQ;;iBApCZ,MAAM;cAAQ,MAAM;kBAAY,MAAM;;;;;CAuEhE,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DAY_MONTH_FORMATER, TIME_FORMATER } from '../date/FormattedDateTime';
|
|
2
2
|
import { chartColors } from '../../style/theme';
|
|
3
|
+
import { useChartLegend } from '../chartlegend/ChartLegendWrapper';
|
|
3
4
|
export const getRoundReferenceValue = (value) => {
|
|
4
5
|
if (value <= 0)
|
|
5
6
|
return 10; // Default for zero or negative values
|
|
@@ -8,13 +9,17 @@ export const getRoundReferenceValue = (value) => {
|
|
|
8
9
|
// Normalized value between 1 and 10
|
|
9
10
|
const normalized = value / magnitude;
|
|
10
11
|
// Round to nice numbers based on normalized value
|
|
12
|
+
let result;
|
|
11
13
|
if (normalized <= 1)
|
|
12
|
-
|
|
13
|
-
if (normalized <= 2.5)
|
|
14
|
-
|
|
15
|
-
if (normalized <= 5)
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
result = magnitude;
|
|
15
|
+
else if (normalized <= 2.5)
|
|
16
|
+
result = 2.5 * magnitude;
|
|
17
|
+
else if (normalized <= 5)
|
|
18
|
+
result = 5 * magnitude;
|
|
19
|
+
else
|
|
20
|
+
result = 10 * magnitude;
|
|
21
|
+
// Ensure minimum value of 5 for better chart appearance
|
|
22
|
+
return Math.max(result, 5);
|
|
18
23
|
};
|
|
19
24
|
export const getMaxBarValue = (data, stacked) => {
|
|
20
25
|
const values = data.map((item) => {
|
|
@@ -33,9 +38,9 @@ export const getMaxBarValue = (data, stacked) => {
|
|
|
33
38
|
.filter((key) => key !== 'category')
|
|
34
39
|
.map((key) => Number(item[key]));
|
|
35
40
|
// Get the max value among the values in the object (corresponding to one bar)
|
|
36
|
-
return Math.max(...numberValues);
|
|
41
|
+
return Math.max(...numberValues, 0); // Ensure we don't get -Infinity
|
|
37
42
|
});
|
|
38
|
-
return Math.max(...values);
|
|
43
|
+
return Math.max(...values, 0);
|
|
39
44
|
};
|
|
40
45
|
/**
|
|
41
46
|
* Generates time ranges between start and end dates based on the given interval
|
|
@@ -46,9 +51,6 @@ export const getMaxBarValue = (data, stacked) => {
|
|
|
46
51
|
*/
|
|
47
52
|
const generateTimeRanges = (startDate, endDate, interval) => {
|
|
48
53
|
const ranges = [];
|
|
49
|
-
if (!startDate || !endDate || !interval) {
|
|
50
|
-
return ranges;
|
|
51
|
-
}
|
|
52
54
|
let currentDate = new Date(startDate.getTime());
|
|
53
55
|
while (currentDate.getTime() <= endDate.getTime()) {
|
|
54
56
|
const rangeEnd = new Date(currentDate.getTime() + interval);
|
|
@@ -197,7 +199,7 @@ const getRechartsBarsAndBarDataKeys = (bars, colorSet, stacked) => {
|
|
|
197
199
|
* @param type - The chart type (category or time)
|
|
198
200
|
* @returns Recharts data format
|
|
199
201
|
*/
|
|
200
|
-
export const formatPrometheusDataToRechartsDataAndBars = (bars, type, colorSet, stacked, defaultSort) => {
|
|
202
|
+
export const formatPrometheusDataToRechartsDataAndBars = (bars, type, colorSet, stacked, defaultSort, legendOrder) => {
|
|
201
203
|
const { rechartsBars, barDataKeys } = getRechartsBarsAndBarDataKeys(bars, colorSet, stacked);
|
|
202
204
|
let data = type !== 'category' && type.type === 'time'
|
|
203
205
|
? transformTimeData(bars, type, barDataKeys)
|
|
@@ -205,7 +207,7 @@ export const formatPrometheusDataToRechartsDataAndBars = (bars, type, colorSet,
|
|
|
205
207
|
if (type === 'category' && defaultSort) {
|
|
206
208
|
data = applySortingToData(data, barDataKeys, defaultSort);
|
|
207
209
|
}
|
|
208
|
-
const sortedRechartsBars = sortStackedBars(rechartsBars, data, stacked);
|
|
210
|
+
const sortedRechartsBars = sortStackedBars(rechartsBars, data, stacked, legendOrder);
|
|
209
211
|
return {
|
|
210
212
|
rechartsBars: sortedRechartsBars,
|
|
211
213
|
data,
|
|
@@ -216,7 +218,7 @@ export const computeUnitLabelAndRoundReferenceValue = (data, maxValue, unitRange
|
|
|
216
218
|
const roundReferenceValue = getRoundReferenceValue(maxValue);
|
|
217
219
|
return { unitLabel: '', roundReferenceValue, rechartsData: data };
|
|
218
220
|
}
|
|
219
|
-
const { valueBase, unitLabel } = getUnitLabel(unitRange
|
|
221
|
+
const { valueBase, unitLabel } = getUnitLabel(unitRange, maxValue);
|
|
220
222
|
const topValue = Math.ceil(maxValue / valueBase / 10) * 10;
|
|
221
223
|
const roundReferenceValue = getRoundReferenceValue(topValue);
|
|
222
224
|
const rechartsData = data.map((dataPoint) => {
|
|
@@ -258,12 +260,31 @@ export function getUnitLabel(unitRange, maxValue) {
|
|
|
258
260
|
unitLabel: unitRange[index - 1].label,
|
|
259
261
|
};
|
|
260
262
|
}
|
|
261
|
-
// Sort stacked bars by their average values in descending order
|
|
262
|
-
// This ensures the largest bars appear at the bottom of the stack
|
|
263
|
-
export const sortStackedBars = (rechartsBars, data, stacked) => {
|
|
263
|
+
// Sort stacked bars by their average values in descending order or by legend order
|
|
264
|
+
// This ensures the largest bars appear at the bottom of the stack (default) or follow legend order
|
|
265
|
+
export const sortStackedBars = (rechartsBars, data, stacked, legendOrder) => {
|
|
264
266
|
if (!stacked) {
|
|
265
267
|
return rechartsBars;
|
|
266
268
|
}
|
|
269
|
+
// If legend order is provided, sort by legend order
|
|
270
|
+
if (legendOrder && legendOrder.length > 0) {
|
|
271
|
+
return [...rechartsBars].sort((a, b) => {
|
|
272
|
+
const indexA = legendOrder.indexOf(a.dataKey);
|
|
273
|
+
const indexB = legendOrder.indexOf(b.dataKey);
|
|
274
|
+
// If both items are in legend order, sort by their position
|
|
275
|
+
if (indexA !== -1 && indexB !== -1) {
|
|
276
|
+
return indexA - indexB;
|
|
277
|
+
}
|
|
278
|
+
// If only one item is in legend order, prioritize it
|
|
279
|
+
if (indexA !== -1)
|
|
280
|
+
return -1;
|
|
281
|
+
if (indexB !== -1)
|
|
282
|
+
return 1;
|
|
283
|
+
// If neither is in legend order, maintain original order
|
|
284
|
+
return 0;
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
// Default behavior: sort by average values
|
|
267
288
|
const barAverages = rechartsBars.map((bar) => {
|
|
268
289
|
const values = data
|
|
269
290
|
.map((item) => Number(item[bar.dataKey]) || 0)
|
|
@@ -292,12 +313,45 @@ export const renderTooltipContent = (props, tooltip, hoveredValue) => {
|
|
|
292
313
|
};
|
|
293
314
|
return tooltip(currentPoint);
|
|
294
315
|
};
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
316
|
+
/**
|
|
317
|
+
* Filters both chart data and recharts bars to only include selected resources from legend
|
|
318
|
+
* @param data - Array of chart data objects with category and resource values
|
|
319
|
+
* @param rechartsBars - Array of recharts bar configurations
|
|
320
|
+
* @param selectedResources - Array of selected resource names
|
|
321
|
+
* @returns Object containing filtered data and recharts bars
|
|
322
|
+
*/
|
|
323
|
+
export const filterChartDataAndBarsByLegendSelection = (data, rechartsBars, selectedResources) => {
|
|
324
|
+
// If no resources are selected, show all data and bars (default behavior)
|
|
325
|
+
if (selectedResources.length === 0) {
|
|
326
|
+
return { filteredData: data, filteredRechartsBars: rechartsBars };
|
|
327
|
+
}
|
|
328
|
+
// Filter recharts bars
|
|
329
|
+
const filteredRechartsBars = rechartsBars.filter((bar) => selectedResources.includes(bar.dataKey));
|
|
330
|
+
// Filter data to only include selected resources
|
|
331
|
+
const filteredData = data.map((item) => {
|
|
332
|
+
const filteredItem = {
|
|
333
|
+
category: item.category,
|
|
334
|
+
};
|
|
335
|
+
selectedResources.forEach((resource) => {
|
|
336
|
+
if (resource in item) {
|
|
337
|
+
filteredItem[resource] = item[resource];
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
return filteredItem;
|
|
341
|
+
});
|
|
342
|
+
return { filteredData, filteredRechartsBars };
|
|
343
|
+
};
|
|
344
|
+
export const useChartData = (bars, type, colorSet, stacked, defaultSort, unitRange, stackedBarSort) => {
|
|
345
|
+
const { selectedResources, listResources } = useChartLegend();
|
|
346
|
+
// Get legend order when stackedBarSort is 'legend'
|
|
347
|
+
const legendOrder = stackedBarSort === 'legend' ? listResources() : undefined;
|
|
348
|
+
const { data, rechartsBars } = formatPrometheusDataToRechartsDataAndBars(bars, type, colorSet, stacked, defaultSort, legendOrder);
|
|
349
|
+
// Filter both data and bars to only include selected resources for accurate maxValue calculation
|
|
350
|
+
const { filteredData, filteredRechartsBars } = filterChartDataAndBarsByLegendSelection(data, rechartsBars, selectedResources);
|
|
351
|
+
const maxValue = getMaxBarValue(filteredData, stacked);
|
|
352
|
+
const { unitLabel, roundReferenceValue, rechartsData } = computeUnitLabelAndRoundReferenceValue(filteredData, maxValue, unitRange);
|
|
299
353
|
return {
|
|
300
|
-
rechartsBars,
|
|
354
|
+
rechartsBars: filteredRechartsBars,
|
|
301
355
|
unitLabel,
|
|
302
356
|
roundReferenceValue,
|
|
303
357
|
rechartsData,
|
|
@@ -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
|
+
};
|
|
@@ -2,8 +2,10 @@ export declare const DATE_FORMATER: Intl.DateTimeFormat;
|
|
|
2
2
|
export declare const DAY_MONTH_FORMATER: Intl.DateTimeFormat;
|
|
3
3
|
export declare const TIME_SECOND_FORMATER: Intl.DateTimeFormat;
|
|
4
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;
|
|
5
7
|
type FormattedDateTimeProps = {
|
|
6
|
-
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';
|
|
7
9
|
value: Date;
|
|
8
10
|
};
|
|
9
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,kBAAkB,qBAI7B,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;
|
|
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"}
|
|
@@ -23,6 +23,21 @@ export const TIME_FORMATER = Intl.DateTimeFormat('en-GB', {
|
|
|
23
23
|
hour: '2-digit',
|
|
24
24
|
minute: '2-digit',
|
|
25
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
|
+
});
|
|
26
41
|
const isItFutureOrIsItPast = (timeDiff, stringToBeFormatted) => {
|
|
27
42
|
if (timeDiff > 0) {
|
|
28
43
|
return `${stringToBeFormatted} ago`;
|
|
@@ -64,7 +79,10 @@ export const FormattedDateTime = ({ format, value, }) => {
|
|
|
64
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' : ''}`) }));
|
|
65
80
|
}
|
|
66
81
|
return (_jsx(Tooltip, { overlay: _jsx(FormattedDateTime, { format: "date-time-second", value: value }), children: "few seconds ago" }));
|
|
67
|
-
|
|
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(',', '') }));
|
|
68
86
|
default:
|
|
69
87
|
return _jsx(_Fragment, {});
|
|
70
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
|
});
|
|
@@ -128,13 +128,13 @@ export declare const iconTable: {
|
|
|
128
128
|
Mail: string;
|
|
129
129
|
};
|
|
130
130
|
export declare const customIcons: {
|
|
131
|
-
'Remote-user': ({ ariaLabel, color, size }: {
|
|
132
|
-
|
|
131
|
+
'Remote-user': ({ "aria-label": ariaLabel, color, size }: {
|
|
132
|
+
"aria-label": any;
|
|
133
133
|
color: any;
|
|
134
134
|
size: any;
|
|
135
135
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
136
|
-
'Remote-group': ({ ariaLabel, color, size }: {
|
|
137
|
-
|
|
136
|
+
'Remote-group': ({ "aria-label": ariaLabel, color, size }: {
|
|
137
|
+
"aria-label": any;
|
|
138
138
|
color: any;
|
|
139
139
|
size: any;
|
|
140
140
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -148,7 +148,7 @@ type Props = {
|
|
|
148
148
|
ariaLabel?: string;
|
|
149
149
|
withWrapper?: boolean;
|
|
150
150
|
style?: CSSProperties;
|
|
151
|
-
onClick?: (event: MouseEvent) => void;
|
|
151
|
+
onClick?: (event: React.MouseEvent) => void;
|
|
152
152
|
title?: string;
|
|
153
153
|
};
|
|
154
154
|
export declare const IconWrapper: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/icon/Icon.component.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAE7D,OAAO,EACL,aAAa,EAKd,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Icon.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/icon/Icon.component.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAE7D,OAAO,EACL,aAAa,EAKd,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6HrB,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;;;;;CAOvB,CAAC;AAaF,MAAM,MAAM,QAA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