@centreon/ui 24.6.4 → 24.6.5

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.6.4",
3
+ "version": "24.6.5",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -1,7 +1,7 @@
1
- import { MutableRefObject, useMemo, useRef, useState } from 'react';
1
+ import { MutableRefObject, useEffect, useMemo, useRef, useState } from 'react';
2
2
 
3
3
  import { Tooltip } from '@visx/visx';
4
- import { equals, flatten, isNil, pluck } from 'ramda';
4
+ import { equals, flatten, isNil, pluck, reject } from 'ramda';
5
5
 
6
6
  import { ClickAwayListener, Fade, Skeleton, useTheme } from '@mui/material';
7
7
 
@@ -19,10 +19,15 @@ import BaseChart from '../common/BaseChart/BaseChart';
19
19
  import { useComputeBaseChartDimensions } from '../common/BaseChart/useComputeBaseChartDimensions';
20
20
  import ChartSvgWrapper from '../common/BaseChart/ChartSvgWrapper';
21
21
  import Thresholds from '../common/Thresholds/Thresholds';
22
+ import { useDeepCompare } from '../../utils';
22
23
 
23
24
  import Lines from './BasicComponents/Lines';
24
- import { canDisplayThreshold } from './BasicComponents/Lines/Threshold/models';
25
- import useFilterLines from './BasicComponents/useFilterLines';
25
+ import {
26
+ canDisplayThreshold,
27
+ findLineOfOriginMetricThreshold,
28
+ lowerLineName,
29
+ upperLineName
30
+ } from './BasicComponents/Lines/Threshold/models';
26
31
  import InteractionWithGraph from './InteractiveComponents';
27
32
  import GraphTooltip from './InteractiveComponents/Tooltip';
28
33
  import useGraphTooltip from './InteractiveComponents/Tooltip/useGraphTooltip';
@@ -47,6 +52,23 @@ const baseStyles = {
47
52
  textAlign: 'center'
48
53
  };
49
54
 
55
+ const filterLines = (lines: Array<Line>, displayThreshold): Array<Line> => {
56
+ if (!displayThreshold) {
57
+ return lines;
58
+ }
59
+ const lineOriginMetric = findLineOfOriginMetricThreshold(lines);
60
+
61
+ const findLinesUpperLower = lines.map((line) =>
62
+ equals(line.name, lowerLineName) || equals(line.name, upperLineName)
63
+ ? line
64
+ : null
65
+ );
66
+
67
+ const linesUpperLower = reject((element) => !element, findLinesUpperLower);
68
+
69
+ return [...lineOriginMetric, ...linesUpperLower] as Array<Line>;
70
+ };
71
+
50
72
  const LineChart = ({
51
73
  graphData,
52
74
  height = 500,
@@ -72,7 +94,11 @@ const LineChart = ({
72
94
 
73
95
  const theme = useTheme();
74
96
 
75
- const [linesGraph, setLinesGraph] = useState<Array<Line> | null>(null);
97
+ const { title, timeSeries, baseAxis, lines } = graphData;
98
+
99
+ const [linesGraph, setLinesGraph] = useState<Array<Line>>(
100
+ filterLines(lines, canDisplayThreshold(shapeLines?.areaThresholdLines))
101
+ );
76
102
  const graphSvgRef = useRef<SVGSVGElement | null>(null);
77
103
 
78
104
  const { isInViewport } = useIntersection({ element: graphRef?.current });
@@ -86,21 +112,12 @@ const LineChart = ({
86
112
  showTooltip: showThresholdTooltip
87
113
  } = Tooltip.useTooltip();
88
114
 
89
- const { title, timeSeries, baseAxis, lines } = graphData;
90
-
91
115
  const thresholdValues = flatten([
92
116
  pluck('value', thresholds?.warning || []),
93
117
  pluck('value', thresholds?.critical || [])
94
118
  ]);
95
119
 
96
- const { displayedLines } = useFilterLines({
97
- displayThreshold: canDisplayThreshold(shapeLines?.areaThresholdLines),
98
- lines,
99
- linesGraph,
100
- setLinesGraph
101
- });
102
-
103
- const [, secondUnit] = getUnits(displayedLines);
120
+ const [, secondUnit] = getUnits(linesGraph);
104
121
 
105
122
  const { legendRef, graphWidth, graphHeight } = useComputeBaseChartDimensions({
106
123
  hasSecondUnit: Boolean(secondUnit),
@@ -119,6 +136,11 @@ const LineChart = ({
119
136
  [timeSeries, graphWidth]
120
137
  );
121
138
 
139
+ const displayedLines = useMemo(
140
+ () => linesGraph.filter(({ display }) => display),
141
+ [linesGraph]
142
+ );
143
+
122
144
  const leftScale = useMemo(
123
145
  () =>
124
146
  getLeftScale({
@@ -164,6 +186,15 @@ const LineChart = ({
164
186
  ]
165
187
  );
166
188
 
189
+ useEffect(
190
+ () => {
191
+ setLinesGraph(
192
+ filterLines(lines, canDisplayThreshold(shapeLines?.areaThresholdLines))
193
+ );
194
+ },
195
+ useDeepCompare([lines])
196
+ );
197
+
167
198
  const graphTooltipData = useGraphTooltip({
168
199
  graphWidth,
169
200
  timeSeries,
@@ -204,7 +235,7 @@ const LineChart = ({
204
235
  }}
205
236
  legendRef={legendRef}
206
237
  limitLegend={limitLegend}
207
- lines={displayedLines}
238
+ lines={linesGraph}
208
239
  setLines={setLinesGraph}
209
240
  title={title}
210
241
  >
@@ -269,7 +300,7 @@ const LineChart = ({
269
300
  graphSvgRef,
270
301
  graphWidth,
271
302
  leftScale,
272
- lines: displayedLines,
303
+ lines: linesGraph,
273
304
  rightScale,
274
305
  timeSeries,
275
306
  xScale