@centreon/ui 24.4.55 → 24.4.57
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/package.json +3 -3
- package/src/Graph/BarStack/BarStack.stories.tsx +5 -5
- package/src/Graph/BarStack/BarStack.styles.ts +3 -2
- package/src/Graph/BarStack/ResponsiveBarStack.tsx +41 -27
- package/src/Graph/BarStack/models.ts +1 -0
- package/src/Graph/BarStack/useResponsiveBarStack.ts +3 -5
- package/src/Graph/PieChart/ResponsivePie.tsx +7 -4
- package/src/Graph/PieChart/models.ts +1 -0
- package/src/Graph/PieChart/useResponsivePie.ts +1 -2
- package/src/api/index.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@centreon/ui",
|
|
3
|
-
"version": "24.4.
|
|
3
|
+
"version": "24.4.57",
|
|
4
4
|
"description": "Centreon UI Components",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@storybook/preview-api": "^7.0.9",
|
|
67
67
|
"@storybook/react": "^7.0.9",
|
|
68
68
|
"@storybook/react-vite": "^7.0.9",
|
|
69
|
-
"@storybook/test-runner": "^0.
|
|
69
|
+
"@storybook/test-runner": "^0.16.0",
|
|
70
70
|
"@storybook/testing-library": "^0.1.0",
|
|
71
71
|
"@storybook/theming": "^7.0.9",
|
|
72
72
|
"@testing-library/cypress": "^8.0.7",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
"@mui/material": "5.x",
|
|
146
146
|
"@mui/styles": "5.x",
|
|
147
147
|
"@tanstack/react-query": "5.x",
|
|
148
|
-
"axios": "
|
|
148
|
+
"axios": ">= 1.6.4",
|
|
149
149
|
"dayjs": "1.x",
|
|
150
150
|
"formik": "2.x",
|
|
151
151
|
"jotai": "2.x",
|
|
@@ -58,11 +58,6 @@ export const WithoutTitle: Story = {
|
|
|
58
58
|
render: Template
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
export const WithPencentage: Story = {
|
|
62
|
-
args: { data, title: 'hosts', unit: 'percentage' },
|
|
63
|
-
render: Template
|
|
64
|
-
};
|
|
65
|
-
|
|
66
61
|
export const WithoutLegend: Story = {
|
|
67
62
|
args: { data, displayLegend: false, title: 'hosts' },
|
|
68
63
|
|
|
@@ -74,6 +69,11 @@ export const withDisplayedValues: Story = {
|
|
|
74
69
|
render: Template
|
|
75
70
|
};
|
|
76
71
|
|
|
72
|
+
export const WithPencentage: Story = {
|
|
73
|
+
args: { data, displayValues: true, title: 'hosts', unit: 'percentage' },
|
|
74
|
+
render: Template
|
|
75
|
+
};
|
|
76
|
+
|
|
77
77
|
export const WithTooltip: Story = {
|
|
78
78
|
args: { TooltipContent, data, title: 'hosts' },
|
|
79
79
|
render: Template
|
|
@@ -16,7 +16,7 @@ export const useBarStackStyles = makeStyles()((theme) => ({
|
|
|
16
16
|
svgContainer: {
|
|
17
17
|
alignItems: 'center',
|
|
18
18
|
backgroundColor: theme.palette.background.panelGroups,
|
|
19
|
-
borderRadius: theme.
|
|
19
|
+
borderRadius: theme.spacing(1.25),
|
|
20
20
|
display: 'flex',
|
|
21
21
|
justifyContent: 'center'
|
|
22
22
|
},
|
|
@@ -31,6 +31,7 @@ export const useBarStackStyles = makeStyles()((theme) => ({
|
|
|
31
31
|
fontSize: theme.typography.h6.fontSize,
|
|
32
32
|
fontWeight: theme.typography.fontWeightMedium,
|
|
33
33
|
margin: 0,
|
|
34
|
-
padding: 0
|
|
34
|
+
padding: 0,
|
|
35
|
+
textAlign: 'center'
|
|
35
36
|
}
|
|
36
37
|
}));
|
|
@@ -5,6 +5,7 @@ import { Group } from '@visx/group';
|
|
|
5
5
|
import numeral from 'numeral';
|
|
6
6
|
import { Text } from '@visx/text';
|
|
7
7
|
import { useTranslation } from 'react-i18next';
|
|
8
|
+
import { equals } from 'ramda';
|
|
8
9
|
|
|
9
10
|
import { Typography } from '@mui/material';
|
|
10
11
|
|
|
@@ -12,7 +13,7 @@ import { Tooltip } from '../../components';
|
|
|
12
13
|
import { LegendProps } from '../Legend/models';
|
|
13
14
|
import { Legend as LegendComponent } from '../Legend';
|
|
14
15
|
import { getValueByUnit } from '../common/utils';
|
|
15
|
-
import { labelNoDataFound } from '../translatedLabels';
|
|
16
|
+
import { labelNoDataFound as defaultlabelNoDataFound } from '../translatedLabels';
|
|
16
17
|
|
|
17
18
|
import { BarStackProps } from './models';
|
|
18
19
|
import { useBarStackStyles } from './BarStack.styles';
|
|
@@ -35,7 +36,8 @@ const BarStack = ({
|
|
|
35
36
|
unit = 'number',
|
|
36
37
|
displayValues,
|
|
37
38
|
variant = 'vertical',
|
|
38
|
-
legendDirection = 'column'
|
|
39
|
+
legendDirection = 'column',
|
|
40
|
+
labelNoDataFound = defaultlabelNoDataFound
|
|
39
41
|
}: BarStackProps & { height: number; width: number }): JSX.Element => {
|
|
40
42
|
const { t } = useTranslation();
|
|
41
43
|
const { classes } = useBarStackStyles();
|
|
@@ -90,7 +92,7 @@ const BarStack = ({
|
|
|
90
92
|
>
|
|
91
93
|
{title && (
|
|
92
94
|
<div className={classes.title} data-testid="Title" ref={titleRef}>
|
|
93
|
-
{`${numeral(total).format('0a').toUpperCase()} `} {title}
|
|
95
|
+
{`${numeral(total).format('0a').toUpperCase()} `} {t(title)}
|
|
94
96
|
</div>
|
|
95
97
|
)}
|
|
96
98
|
<div
|
|
@@ -117,6 +119,20 @@ const BarStack = ({
|
|
|
117
119
|
{(barStacks) =>
|
|
118
120
|
barStacks.map((barStack) =>
|
|
119
121
|
barStack.bars.map((bar) => {
|
|
122
|
+
const shouldDisplayValues = (): boolean => {
|
|
123
|
+
if (bar.height < 10) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
(equals(unit, 'number') && bar.width > 10) ||
|
|
129
|
+
(equals(unit, 'percentage') && bar.width > 25)
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const TextX = bar.x + bar.width / 2;
|
|
134
|
+
const TextY = bar.y + bar.height / 2;
|
|
135
|
+
|
|
120
136
|
const onClick = (): void => {
|
|
121
137
|
onSingleBarClick?.(bar);
|
|
122
138
|
};
|
|
@@ -144,40 +160,38 @@ const BarStack = ({
|
|
|
144
160
|
isVerticalBar ? 'right-start' : 'bottom-start'
|
|
145
161
|
}
|
|
146
162
|
>
|
|
147
|
-
<g data-testid={bar.key}>
|
|
163
|
+
<g data-testid={bar.key} onClick={onClick}>
|
|
148
164
|
<rect
|
|
165
|
+
cursor="pointer"
|
|
149
166
|
fill={bar.color}
|
|
150
167
|
height={
|
|
151
168
|
isVerticalBar ? bar.height - 1 : bar.height
|
|
152
169
|
}
|
|
153
170
|
key={`bar-stack-${barStack.index}-${bar.index}`}
|
|
154
|
-
ry={
|
|
171
|
+
ry={10}
|
|
155
172
|
width={isVerticalBar ? bar.width : bar.width - 1}
|
|
156
173
|
x={bar.x}
|
|
157
174
|
y={bar.y}
|
|
158
|
-
onClick={onClick}
|
|
159
175
|
/>
|
|
160
|
-
{displayValues &&
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
</Text>
|
|
180
|
-
)}
|
|
176
|
+
{displayValues && shouldDisplayValues() && (
|
|
177
|
+
<Text
|
|
178
|
+
cursor="pointer"
|
|
179
|
+
data-testid="value"
|
|
180
|
+
fill="#000"
|
|
181
|
+
fontSize={12}
|
|
182
|
+
fontWeight={600}
|
|
183
|
+
textAnchor="middle"
|
|
184
|
+
verticalAnchor="middle"
|
|
185
|
+
x={TextX}
|
|
186
|
+
y={TextY}
|
|
187
|
+
>
|
|
188
|
+
{getValueByUnit({
|
|
189
|
+
total,
|
|
190
|
+
unit,
|
|
191
|
+
value: barStack.bars[0].bar.data[barStack.key]
|
|
192
|
+
})}
|
|
193
|
+
</Text>
|
|
194
|
+
)}
|
|
181
195
|
</g>
|
|
182
196
|
</Tooltip>
|
|
183
197
|
);
|
|
@@ -55,7 +55,7 @@ const useResponsiveBarStack = ({
|
|
|
55
55
|
const verticalGap = heightOfTitle > 0 ? 8 : 0;
|
|
56
56
|
|
|
57
57
|
const svgWrapperWidth = isVerticalBar
|
|
58
|
-
? size +
|
|
58
|
+
? size + 36
|
|
59
59
|
: width - widthOfLegend - horizontalGap;
|
|
60
60
|
|
|
61
61
|
const svgContainerSize = {
|
|
@@ -72,8 +72,7 @@ const useResponsiveBarStack = ({
|
|
|
72
72
|
|
|
73
73
|
const yScale = isVerticalBar
|
|
74
74
|
? scaleLinear({
|
|
75
|
-
domain: [0, total]
|
|
76
|
-
nice: true
|
|
75
|
+
domain: [0, total]
|
|
77
76
|
})
|
|
78
77
|
: scaleBand({
|
|
79
78
|
domain: [0, 0],
|
|
@@ -86,8 +85,7 @@ const useResponsiveBarStack = ({
|
|
|
86
85
|
padding: 0
|
|
87
86
|
})
|
|
88
87
|
: scaleLinear({
|
|
89
|
-
domain: [0, total]
|
|
90
|
-
nice: true
|
|
88
|
+
domain: [0, total]
|
|
91
89
|
});
|
|
92
90
|
|
|
93
91
|
const keys = pluck('label', data);
|
|
@@ -13,7 +13,7 @@ import { Tooltip } from '../../components';
|
|
|
13
13
|
import { Legend as LegendComponent } from '../Legend';
|
|
14
14
|
import { LegendProps } from '../Legend/models';
|
|
15
15
|
import { getValueByUnit } from '../common/utils';
|
|
16
|
-
import { labelNoDataFound } from '../translatedLabels';
|
|
16
|
+
import { labelNoDataFound as defaultlabelNoDataFound } from '../translatedLabels';
|
|
17
17
|
|
|
18
18
|
import { PieProps } from './models';
|
|
19
19
|
import { usePieStyles } from './PieChart.styles';
|
|
@@ -54,7 +54,8 @@ const ResponsivePie = ({
|
|
|
54
54
|
onArcClick,
|
|
55
55
|
displayValues,
|
|
56
56
|
TooltipContent,
|
|
57
|
-
legendDirection = 'column'
|
|
57
|
+
legendDirection = 'column',
|
|
58
|
+
labelNoDataFound = defaultlabelNoDataFound
|
|
58
59
|
}: PieProps & { height: number; width: number }): JSX.Element => {
|
|
59
60
|
const { t } = useTranslation();
|
|
60
61
|
const theme = useTheme();
|
|
@@ -109,7 +110,7 @@ const ResponsivePie = ({
|
|
|
109
110
|
>
|
|
110
111
|
{equals(variant, 'pie') && title && (
|
|
111
112
|
<div className={classes.title} data-testid="Title" ref={titleRef}>
|
|
112
|
-
{`${numeral(total).format('0a').toUpperCase()} `} {title}
|
|
113
|
+
{`${numeral(total).format('0a').toUpperCase()} `} {t(title)}
|
|
113
114
|
</div>
|
|
114
115
|
)}
|
|
115
116
|
<div
|
|
@@ -178,6 +179,7 @@ const ResponsivePie = ({
|
|
|
178
179
|
>
|
|
179
180
|
<g data-testid={arc.data.label} onClick={onClick}>
|
|
180
181
|
<path
|
|
182
|
+
cursor="pointer"
|
|
181
183
|
d={pie.path(arc) as string}
|
|
182
184
|
fill={arc.data.color}
|
|
183
185
|
/>
|
|
@@ -189,6 +191,7 @@ const ResponsivePie = ({
|
|
|
189
191
|
dy=".33em"
|
|
190
192
|
fill="#000"
|
|
191
193
|
fontSize={12}
|
|
194
|
+
fontWeight={600}
|
|
192
195
|
pointerEvents="none"
|
|
193
196
|
textAnchor="middle"
|
|
194
197
|
x={x}
|
|
@@ -224,7 +227,7 @@ const ResponsivePie = ({
|
|
|
224
227
|
fill={theme.palette.text.primary}
|
|
225
228
|
textAnchor="middle"
|
|
226
229
|
>
|
|
227
|
-
{title}
|
|
230
|
+
{t(title)}
|
|
228
231
|
</Text>
|
|
229
232
|
</>
|
|
230
233
|
)}
|
|
@@ -41,12 +41,11 @@ export const useResponsivePie = ({
|
|
|
41
41
|
const horizontalGap = widthOfLegend > 0 ? 16 : 0;
|
|
42
42
|
const verticalGap = heightOfTitle > 0 ? 8 : 0;
|
|
43
43
|
|
|
44
|
-
const svgWrapperWidth = width - widthOfLegend - horizontalGap;
|
|
45
|
-
|
|
46
44
|
const svgContainerSize = Math.min(
|
|
47
45
|
height - heightOfTitle - verticalGap,
|
|
48
46
|
width - widthOfLegend - horizontalGap
|
|
49
47
|
);
|
|
48
|
+
const svgWrapperWidth = svgContainerSize;
|
|
50
49
|
|
|
51
50
|
const outerRadius = Math.min(32, svgContainerSize / 6);
|
|
52
51
|
|
package/src/api/index.ts
CHANGED
|
@@ -30,7 +30,7 @@ const patchData =
|
|
|
30
30
|
<TData, TResult>(cancelToken: CancelToken) =>
|
|
31
31
|
({ endpoint, data }: RequestWithData<TData>): Promise<TResult> =>
|
|
32
32
|
axios
|
|
33
|
-
.patch(endpoint, data, {
|
|
33
|
+
.patch(endpoint, JSON.stringify(data), {
|
|
34
34
|
cancelToken,
|
|
35
35
|
headers: contentTypeHeaders
|
|
36
36
|
})
|
|
@@ -40,7 +40,7 @@ const postData =
|
|
|
40
40
|
<TData, TResult>(cancelToken: CancelToken) =>
|
|
41
41
|
({ endpoint, data }: RequestWithData<TData>): Promise<TResult> =>
|
|
42
42
|
axios
|
|
43
|
-
.post(endpoint, data, {
|
|
43
|
+
.post(endpoint, JSON.stringify(data), {
|
|
44
44
|
cancelToken,
|
|
45
45
|
headers: contentTypeHeaders
|
|
46
46
|
})
|
|
@@ -50,7 +50,7 @@ const putData =
|
|
|
50
50
|
<TData, TResult>(cancelToken: CancelToken) =>
|
|
51
51
|
({ endpoint, data }: RequestWithData<TData>): Promise<TResult> =>
|
|
52
52
|
axios
|
|
53
|
-
.put(endpoint, data, {
|
|
53
|
+
.put(endpoint, JSON.stringify(data), {
|
|
54
54
|
cancelToken,
|
|
55
55
|
headers: contentTypeHeaders
|
|
56
56
|
})
|