@centreon/ui 24.7.9 → 24.7.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centreon/ui",
3
- "version": "24.7.9",
3
+ "version": "24.7.11",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -106,8 +106,10 @@
106
106
  "vite-plugin-svgr": "^4.2.0",
107
107
  "vite-plugin-turbosnap": "^1.0.3"
108
108
  },
109
+ "peerDependencies": {
110
+ "@centreon/ui-context": "file:../ui-context"
111
+ },
109
112
  "dependencies": {
110
- "@centreon/ui-context": "file:../ui-context",
111
113
  "@lexical/html": "^0.16.1",
112
114
  "@lexical/link": "^0.16.1",
113
115
  "@lexical/list": "^0.16.1",
@@ -33,7 +33,8 @@ const ResponsiveBarStack = ({
33
33
  unit = 'number',
34
34
  displayValues,
35
35
  variant = 'vertical',
36
- legendDirection = 'column'
36
+ legendDirection = 'column',
37
+ tooltipProps = {}
37
38
  }: BarStackProps & { height: number; width: number }): JSX.Element => {
38
39
  const { t } = useTranslation();
39
40
  const { classes, cx } = useBarStackStyles();
@@ -143,6 +144,7 @@ const ResponsiveBarStack = ({
143
144
  title={title}
144
145
  total={total}
145
146
  value={barStack.bars[0].bar.data[barStack.key]}
147
+ {...tooltipProps}
146
148
  />
147
149
  )
148
150
  }
@@ -14,6 +14,7 @@ export type BarStackProps = {
14
14
  onSingleBarClick?: (barData) => void;
15
15
  size?: number;
16
16
  title?: string;
17
+ tooltipProps?: object;
17
18
  unit?: 'percentage' | 'number';
18
19
  variant?: 'vertical' | 'horizontal';
19
20
  };
@@ -1,8 +1,8 @@
1
1
  import { lt } from 'ramda';
2
2
  import { makeStyles } from 'tss-react/mui';
3
3
 
4
- export const usePieStyles = makeStyles<{ svgSize: number }>()(
5
- (theme, { svgSize }) => ({
4
+ export const usePieStyles = makeStyles<{ reverse: boolean; svgSize: number }>()(
5
+ (theme, { reverse, svgSize }) => ({
6
6
  container: {
7
7
  alignItems: 'center',
8
8
  display: 'flex',
@@ -25,7 +25,7 @@ export const usePieStyles = makeStyles<{ svgSize: number }>()(
25
25
  svgWrapper: {
26
26
  alignItems: 'center',
27
27
  display: 'flex',
28
- flexDirection: 'column',
28
+ flexDirection: reverse ? 'column-reverse' : 'column',
29
29
  gap: theme.spacing(1),
30
30
  justifyContent: 'center'
31
31
  },
@@ -18,7 +18,7 @@ import { PieProps } from './models';
18
18
  import { usePieStyles } from './PieChart.styles';
19
19
  import { useResponsivePie } from './useResponsivePie';
20
20
 
21
- const DefaultLengd = ({ scale, direction }: LegendProps): JSX.Element => (
21
+ const DefaultLegend = ({ scale, direction }: LegendProps): JSX.Element => (
22
22
  <LegendComponent direction={direction} scale={scale} />
23
23
  );
24
24
 
@@ -42,18 +42,25 @@ const getTooltipPlacement = ({ radianX, radianY }): Placement => {
42
42
 
43
43
  const ResponsivePie = ({
44
44
  title,
45
+ titlePosition,
46
+ displayTitle = true,
45
47
  variant = 'pie',
46
48
  width,
47
49
  height,
48
50
  data,
49
51
  unit = 'number',
50
- Legend = DefaultLengd,
52
+ Legend = DefaultLegend,
51
53
  displayLegend = true,
54
+ displayTotal = true,
52
55
  innerRadius: defaultInnerRadius = 40,
56
+ innerRadiusNoLimit = false,
53
57
  onArcClick,
58
+ padAngle = 0,
54
59
  displayValues,
55
60
  TooltipContent,
56
- legendDirection = 'column'
61
+ legendDirection = 'column',
62
+ tooltipProps = {},
63
+ opacity = 1
57
64
  }: PieProps & { height: number; width: number }): JSX.Element => {
58
65
  const { t } = useTranslation();
59
66
  const theme = useTheme();
@@ -73,6 +80,7 @@ const ResponsivePie = ({
73
80
  data,
74
81
  defaultInnerRadius,
75
82
  height,
83
+ innerRadiusNoLimit,
76
84
  legendRef,
77
85
  titleRef,
78
86
  unit,
@@ -84,7 +92,10 @@ const ResponsivePie = ({
84
92
  const isSmall = lt(width, 130);
85
93
  const mustDisplayLegend = isTooSmallForLegend ? false : displayLegend;
86
94
 
87
- const { classes } = usePieStyles({ svgSize });
95
+ const { classes } = usePieStyles({
96
+ reverse: equals(titlePosition, 'bottom'),
97
+ svgSize
98
+ });
88
99
 
89
100
  return (
90
101
  <div
@@ -99,11 +110,16 @@ const ResponsivePie = ({
99
110
  minHeight: equals(variant, 'donut') && isSmall ? 'auto' : height
100
111
  }}
101
112
  >
102
- {(equals(variant, 'pie') || isSmall) && title && (
103
- <div className={classes.title} data-testid="Title" ref={titleRef}>
104
- {`${numeral(total).format('0a').toUpperCase()} `} {t(title)}
105
- </div>
106
- )}
113
+ {(equals(variant, 'pie') ||
114
+ isSmall ||
115
+ (equals(variant, 'donut') && equals(titlePosition, 'bottom'))) &&
116
+ title &&
117
+ displayTitle && (
118
+ <div className={classes.title} data-testid="Title" ref={titleRef}>
119
+ {`${displayTotal ? numeral(total).format('0a').toUpperCase() : ''} `}
120
+ {t(title)}
121
+ </div>
122
+ )}
107
123
  <div
108
124
  className={classes.svgContainer}
109
125
  data-testid="pieChart"
@@ -122,9 +138,14 @@ const ResponsivePie = ({
122
138
  cornerRadius={4}
123
139
  data={data}
124
140
  innerRadius={() => {
125
- return equals(variant, 'pie') ? 0 : half - innerRadius;
141
+ const iRadius = innerRadiusNoLimit
142
+ ? innerRadius
143
+ : half - innerRadius;
144
+
145
+ return equals(variant, 'pie') ? 0 : iRadius;
126
146
  }}
127
147
  outerRadius={half}
148
+ padAngle={padAngle}
128
149
  pieValue={(items) => items.value}
129
150
  >
130
151
  {(pie) => {
@@ -163,6 +184,7 @@ const ResponsivePie = ({
163
184
  title={title}
164
185
  total={total}
165
186
  value={arc.data.value}
187
+ {...tooltipProps}
166
188
  />
167
189
  )
168
190
  }
@@ -185,6 +207,7 @@ const ResponsivePie = ({
185
207
  data-testid="value"
186
208
  dy=".33em"
187
209
  fill="#000"
210
+ fillOpacity={opacity}
188
211
  fontSize={12}
189
212
  fontWeight={600}
190
213
  pointerEvents="none"
@@ -205,27 +228,31 @@ const ResponsivePie = ({
205
228
  });
206
229
  }}
207
230
  </Pie>
208
- {equals(variant, 'donut') && !isSmall && title && (
209
- <>
210
- <Text
211
- className={classes.title}
212
- dy={lt(svgSize, 150) ? -10 : -15}
213
- fill={theme.palette.text.primary}
214
- textAnchor="middle"
215
- >
216
- {numeral(total).format('0a').toUpperCase()}
217
- </Text>
218
- <Text
219
- className={classes.title}
220
- data-testid="Title"
221
- dy={lt(svgSize, 150) ? 10 : 15}
222
- fill={theme.palette.text.primary}
223
- textAnchor="middle"
224
- >
225
- {t(title)}
226
- </Text>
227
- </>
228
- )}
231
+ {equals(variant, 'donut') &&
232
+ !isSmall &&
233
+ title &&
234
+ displayTitle &&
235
+ !equals(titlePosition, 'bottom') && (
236
+ <>
237
+ <Text
238
+ className={classes.title}
239
+ dy={lt(svgSize, 150) ? -10 : -15}
240
+ fill={theme.palette.text.primary}
241
+ textAnchor="middle"
242
+ >
243
+ {numeral(total).format('0a').toUpperCase()}
244
+ </Text>
245
+ <Text
246
+ className={classes.title}
247
+ data-testid="Title"
248
+ dy={lt(svgSize, 150) ? 10 : 15}
249
+ fill={theme.palette.text.primary}
250
+ textAnchor="middle"
251
+ >
252
+ {t(title)}
253
+ </Text>
254
+ </>
255
+ )}
229
256
  </Group>
230
257
  </svg>
231
258
  </div>
@@ -9,11 +9,18 @@ export interface PieProps {
9
9
  TooltipContent?: (arcData) => JSX.Element | boolean | null;
10
10
  data: Array<ArcType>;
11
11
  displayLegend?: boolean;
12
+ displayTitle?: boolean;
13
+ displayTotal?: boolean;
12
14
  displayValues?: boolean;
13
15
  innerRadius?: number;
16
+ innerRadiusNoLimit?: boolean;
14
17
  legendDirection?: 'row' | 'column';
15
- onArcClick?: (ardata) => void;
18
+ onArcClick?: (arcData) => void;
19
+ opacity: number;
20
+ padAngle?: number;
16
21
  title?: string;
22
+ titlePosition?: 'default' | 'bottom';
23
+ tooltipProps?: object;
17
24
  unit?: 'percentage' | 'number';
18
25
  variant?: 'pie' | 'donut';
19
26
  }
@@ -9,6 +9,7 @@ interface ResponsivePieProps {
9
9
  data: Array<ArcType>;
10
10
  defaultInnerRadius: number;
11
11
  height: number;
12
+ innerRadiusNoLimit: boolean;
12
13
  legendRef;
13
14
  titleRef;
14
15
  unit: 'percentage' | 'number';
@@ -31,7 +32,8 @@ export const useResponsivePie = ({
31
32
  width,
32
33
  data,
33
34
  unit,
34
- defaultInnerRadius
35
+ defaultInnerRadius,
36
+ innerRadiusNoLimit
35
37
  }: ResponsivePieProps): ResponsivePieState => {
36
38
  const heightOfTitle = titleRef.current?.offsetHeight || 0;
37
39
  const widthOfLegend = legendRef.current?.offsetWidth || 0;
@@ -52,7 +54,11 @@ export const useResponsivePie = ({
52
54
 
53
55
  const total = Math.floor(data.reduce((acc, { value }) => acc + value, 0));
54
56
 
55
- const innerRadius = Math.min(defaultInnerRadius, svgSize / 5);
57
+ let innerRadius = Math.min(defaultInnerRadius, svgSize / 5);
58
+
59
+ if (innerRadiusNoLimit) {
60
+ innerRadius = half * defaultInnerRadius * 0.01;
61
+ }
56
62
 
57
63
  const legendScale = {
58
64
  domain: data.map(({ value }) => getValueByUnit({ total, unit, value })),
@@ -60,7 +60,12 @@ export const useInfiniteScrollListing = <T>({
60
60
  customQueryParameters,
61
61
  parameters: { limit, page: params?.page || page, ...parameters }
62
62
  }),
63
- getQueryKey: () => [queryKeyName, page],
63
+ getQueryKey: () => [
64
+ queryKeyName,
65
+ page,
66
+ JSON.stringify(parameters),
67
+ JSON.stringify(customQueryParameters)
68
+ ],
64
69
  isPaginated: true,
65
70
  queryOptions: {
66
71
  enabled,