@centreon/ui 24.11.23 → 24.11.25

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.11.23",
3
+ "version": "24.11.25",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -1,4 +1,4 @@
1
- import { useMemo } from 'react';
1
+ import { useMemo, useRef } from 'react';
2
2
 
3
3
  import { scaleLinear } from '@visx/scale';
4
4
  import { T, equals, gt, lt } from 'ramda';
@@ -13,6 +13,7 @@ import { HeatMapProps } from './model';
13
13
  const gap = 8;
14
14
  const maxTileSize = 120;
15
15
  const smallestTileSize = 44;
16
+ const toleratedRangeWidth = 10;
16
17
 
17
18
  const ResponsiveHeatMap = <TData,>({
18
19
  width,
@@ -28,6 +29,7 @@ const ResponsiveHeatMap = <TData,>({
28
29
  width: number;
29
30
  }): JSX.Element | null => {
30
31
  const { classes, cx } = useHeatMapStyles();
32
+ const previousTileSize = useRef(0);
31
33
 
32
34
  const tileSize = useMemo(() => {
33
35
  const scaleWidth = scaleLinear({
@@ -44,6 +46,13 @@ const ResponsiveHeatMap = <TData,>({
44
46
  const theoricalTotalTilesWidth =
45
47
  tilesLength * tileWidth + (tilesLength - 1) * gap;
46
48
 
49
+ const canUpdateTileSize =
50
+ Math.abs(tileWidth - previousTileSize.current) > toleratedRangeWidth;
51
+
52
+ if (!canUpdateTileSize) {
53
+ return previousTileSize.current;
54
+ }
55
+
47
56
  if (
48
57
  (lt(height, maxTileSize) ||
49
58
  (lt(width, 680) && gt(maxTotalTilesWidth, width))) &&
@@ -60,6 +69,8 @@ const ResponsiveHeatMap = <TData,>({
60
69
  }, [width, tiles, height]);
61
70
 
62
71
  const isSmallestSize = equals(tileSize, smallestTileSize);
72
+ const isMediumSize = !isSmallestSize && lt(tileSize, 90);
73
+ previousTileSize.current = tileSize;
63
74
 
64
75
  if (equals(width, 0)) {
65
76
  return null;
@@ -100,7 +111,14 @@ const ResponsiveHeatMap = <TData,>({
100
111
  position="right-start"
101
112
  >
102
113
  <div className={classes.heatMapTileContent}>
103
- {children({ backgroundColor, data, id, isSmallestSize })}
114
+ {children({
115
+ backgroundColor,
116
+ data,
117
+ id,
118
+ isSmallestSize,
119
+ tileSize,
120
+ isMediumSize
121
+ })}
104
122
  </div>
105
123
  </Tooltip>
106
124
  </Box>
@@ -1,4 +1,4 @@
1
- import { ReactElement } from 'react';
1
+ import type { ReactElement } from 'react';
2
2
 
3
3
  interface Tile<TData> {
4
4
  backgroundColor: string;
@@ -11,6 +11,8 @@ interface ChildrenProps<TData> {
11
11
  data: TData;
12
12
  id: string;
13
13
  isSmallestSize: boolean;
14
+ isMediumSize?: boolean;
15
+ tileSize?: number;
14
16
  }
15
17
 
16
18
  export interface HeatMapProps<TData> {
@@ -19,7 +21,9 @@ export interface HeatMapProps<TData> {
19
21
  backgroundColor,
20
22
  id,
21
23
  data,
22
- isSmallestSize
24
+ isSmallestSize,
25
+ tileSize,
26
+ isMediumSize
23
27
  }: ChildrenProps<TData>) => ReactElement | boolean | null;
24
28
  displayTooltipCondition?: (data: TData) => boolean;
25
29
  tileSizeFixed?: boolean;
@@ -55,7 +55,7 @@ const ConnectedAutocompleteField = (
55
55
  field,
56
56
  labelKey,
57
57
  open,
58
- conditionField = 'id',
58
+ conditionField = 'name',
59
59
  searchConditions = [],
60
60
  getRenderedOptionText = (option): string => option.name?.toString(),
61
61
  getRequestHeaders,