@centreon/ui 24.8.7 → 24.9.1

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.8.7",
3
+ "version": "24.9.1",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -1,18 +1,18 @@
1
1
  import { equals, isNil } from 'ramda';
2
2
 
3
- import { TimeValue } from '../../../../common/timeSeries/models';
3
+ import type { TimeValue } from '../../../../common/timeSeries/models';
4
4
  import { displayArea } from '../../../helpers/index';
5
5
  import {
6
- PatternThreshold,
6
+ type PatternThreshold,
7
7
  ThresholdType,
8
- VariationThreshold
8
+ type VariationThreshold
9
9
  } from '../../../models';
10
10
 
11
11
  import BasicThreshold from './BasicThreshold';
12
12
  import Circle from './Circle';
13
13
  import ThresholdWithPatternLines from './ThresholdWithPatternLines';
14
14
  import ThresholdWithVariation from './ThresholdWithVariation';
15
- import { WrapperThresholdLinesModel } from './models';
15
+ import type { WrapperThresholdLinesModel } from './models';
16
16
  import useScaleThreshold from './useScaleThreshold';
17
17
 
18
18
  interface Props extends WrapperThresholdLinesModel {
@@ -52,14 +52,14 @@ const WrapperThresholdLines = ({
52
52
  timeSeries
53
53
  };
54
54
 
55
- const thresholdLines = areaThresholdLines?.map((item, index) => {
55
+ const thresholdLines = areaThresholdLines?.map((item) => {
56
56
  const { type, id } = item;
57
57
 
58
58
  if (equals(type, ThresholdType.basic)) {
59
59
  return [
60
60
  {
61
61
  Component: BasicThreshold,
62
- key: index,
62
+ key: id,
63
63
  props: { ...commonProps, getY0, getY1, id }
64
64
  }
65
65
  ];
@@ -73,7 +73,7 @@ const WrapperThresholdLines = ({
73
73
  return [
74
74
  {
75
75
  Component: ThresholdWithVariation,
76
- key: index,
76
+ key: dataVariation.id,
77
77
  props: {
78
78
  factors: dataVariation.factors,
79
79
  ...commonProps,
@@ -101,13 +101,13 @@ const WrapperThresholdLines = ({
101
101
 
102
102
  const { data: pattern } = dataPattern;
103
103
 
104
- return pattern.map((element, ind) => ({
104
+ return pattern.map((element, index) => ({
105
105
  Component: ThresholdWithPatternLines,
106
- key: ind,
106
+ key: index,
107
107
  props: {
108
108
  data: element,
109
109
  graphHeight,
110
- key: ind,
110
+ key: index,
111
111
  orientation: dataPattern?.orientation,
112
112
  xScale,
113
113
  yScalesPerUnit
@@ -1,8 +1,8 @@
1
- import { ScaleLinear } from 'd3-scale';
1
+ import type { ScaleLinear } from 'd3-scale';
2
2
  import { equals, reject } from 'ramda';
3
3
 
4
- import { Line, TimeValue } from '../../../../common/timeSeries/models';
5
- import { GlobalAreaLines, ThresholdType } from '../../../models';
4
+ import type { Line, TimeValue } from '../../../../common/timeSeries/models';
5
+ import { type GlobalAreaLines, ThresholdType } from '../../../models';
6
6
 
7
7
  export interface Data {
8
8
  lineColor: string;
@@ -95,7 +95,7 @@ export const findLineOfOriginMetricThreshold = (
95
95
 
96
96
  const originMetric = metrics.find((element) => element);
97
97
 
98
- return reject((line: Line) => !equals(line.name, originMetric), lines);
98
+ return reject((line: Line) => !equals(line.metric, originMetric), lines);
99
99
  };
100
100
 
101
101
  export const canDisplayThreshold = (
@@ -1,6 +1,6 @@
1
- import { MutableRefObject } from 'react';
1
+ import type { MutableRefObject } from 'react';
2
2
 
3
- import { ScaleLinear } from 'd3-scale';
3
+ import type { ScaleLinear } from 'd3-scale';
4
4
  import { isNil } from 'ramda';
5
5
 
6
6
  import {
@@ -8,14 +8,14 @@ import {
8
8
  getTimeSeriesForLines,
9
9
  getYScale
10
10
  } from '../../../common/timeSeries';
11
- import { Line, TimeValue } from '../../../common/timeSeries/models';
11
+ import type { Line, TimeValue } from '../../../common/timeSeries/models';
12
12
  import { getPointRadius } from '../../../common/utils';
13
13
  import GuidingLines from '../../InteractiveComponents/AnchorPoint/GuidingLines';
14
14
  import RegularAnchorPoint, {
15
15
  getYAnchorPoint
16
16
  } from '../../InteractiveComponents/AnchorPoint/RegularAnchorPoint';
17
17
  import { displayArea } from '../../helpers/index';
18
- import { DisplayAnchor, GlobalAreaLines } from '../../models';
18
+ import type { DisplayAnchor, GlobalAreaLines } from '../../models';
19
19
 
20
20
  import Point from './Point';
21
21
  import RegularLine from './RegularLines';
@@ -1,5 +1,13 @@
1
1
  import { makeStyles } from 'tss-react/mui';
2
2
 
3
3
  export const useChartStyles = makeStyles()({
4
- tooltipChildren: { height: '100%', width: '100%' }
4
+ baseWrapper: {
5
+ position: 'relative'
6
+ },
7
+ tooltipChildren: { height: '100%', width: '100%' },
8
+ wrapperContainer: {
9
+ height: '100%',
10
+ width: '100%',
11
+ overflow: 'hidden'
12
+ }
5
13
  });
@@ -1,4 +1,10 @@
1
- import { MutableRefObject, useEffect, useMemo, useRef, useState } from 'react';
1
+ import {
2
+ type MutableRefObject,
3
+ useEffect,
4
+ useMemo,
5
+ useRef,
6
+ useState
7
+ } from 'react';
2
8
 
3
9
  import { useAtom } from 'jotai';
4
10
  import { equals, flatten, isNil, pluck, reject } from 'ramda';
@@ -11,14 +17,14 @@ import BaseChart from '../common/BaseChart/BaseChart';
11
17
  import ChartSvgWrapper from '../common/BaseChart/ChartSvgWrapper';
12
18
  import { useComputeBaseChartDimensions } from '../common/BaseChart/useComputeBaseChartDimensions';
13
19
  import Thresholds from '../common/Thresholds/Thresholds';
14
- import { Thresholds as ThresholdsModel } from '../common/models';
20
+ import type { Thresholds as ThresholdsModel } from '../common/models';
15
21
  import {
16
22
  getUnits,
17
23
  getXScale,
18
24
  getXScaleBand,
19
25
  getYScalePerUnit
20
26
  } from '../common/timeSeries';
21
- import { Line } from '../common/timeSeries/models';
27
+ import type { Line } from '../common/timeSeries/models';
22
28
 
23
29
  import Lines from './BasicComponents/Lines';
24
30
  import {
@@ -34,7 +40,12 @@ import GraphTooltip from './InteractiveComponents/Tooltip';
34
40
  import useGraphTooltip from './InteractiveComponents/Tooltip/useGraphTooltip';
35
41
  import { margin } from './common';
36
42
  import { thresholdTooltipAtom } from './graphAtoms';
37
- import { Data, GlobalAreaLines, GraphInterval, LineChartProps } from './models';
43
+ import type {
44
+ Data,
45
+ GlobalAreaLines,
46
+ GraphInterval,
47
+ LineChartProps
48
+ } from './models';
38
49
  import { useIntersection } from './useChartIntersection';
39
50
 
40
51
  interface Props extends LineChartProps {
@@ -95,6 +106,7 @@ const Chart = ({
95
106
  const [linesGraph, setLinesGraph] = useState<Array<Line>>(
96
107
  filterLines(lines, canDisplayThreshold(shapeLines?.areaThresholdLines))
97
108
  );
109
+
98
110
  const graphSvgRef = useRef<SVGSVGElement | null>(null);
99
111
 
100
112
  const [thresholdTooltip, setThresholdTooltip] = useAtom(thresholdTooltipAtom);
@@ -190,7 +202,7 @@ const Chart = ({
190
202
  filterLines(lines, canDisplayThreshold(shapeLines?.areaThresholdLines))
191
203
  );
192
204
  },
193
- useDeepCompare([lines])
205
+ useDeepCompare([lines, shapeLines?.areaThresholdLines])
194
206
  );
195
207
 
196
208
  const graphTooltipData = useGraphTooltip({
@@ -219,7 +231,7 @@ const Chart = ({
219
231
 
220
232
  return (
221
233
  <ClickAwayListener onClickAway={graphTooltipData?.hideTooltip}>
222
- <>
234
+ <div className={classes.baseWrapper}>
223
235
  <BaseChart
224
236
  base={baseAxis}
225
237
  graphWidth={graphWidth}
@@ -329,7 +341,7 @@ const Chart = ({
329
341
  </GraphValueTooltip>
330
342
  </BaseChart>
331
343
  {displayTooltip && <GraphTooltip {...tooltip} {...graphTooltipData} />}
332
- </>
344
+ </div>
333
345
  </ClickAwayListener>
334
346
  );
335
347
  };
@@ -1,7 +1,7 @@
1
- import { MutableRefObject } from 'react';
1
+ import type { MutableRefObject } from 'react';
2
2
 
3
3
  import { Event } from '@visx/visx';
4
- import { ScaleLinear, ScaleTime } from 'd3-scale';
4
+ import type { ScaleLinear, ScaleTime } from 'd3-scale';
5
5
  import { useSetAtom } from 'jotai';
6
6
  import {
7
7
  all,
@@ -28,9 +28,9 @@ import {
28
28
  getTimeValue,
29
29
  getYScale
30
30
  } from '../../common/timeSeries';
31
- import { Line, TimeValue } from '../../common/timeSeries/models';
31
+ import type { Line, TimeValue } from '../../common/timeSeries/models';
32
32
  import { margin } from '../common';
33
- import {
33
+ import type {
34
34
  AnnotationEvent,
35
35
  GraphInterval,
36
36
  InteractedZone,
@@ -38,12 +38,12 @@ import {
38
38
  } from '../models';
39
39
 
40
40
  import Annotations from './Annotations';
41
- import { TimelineEvent } from './Annotations/models';
41
+ import type { TimelineEvent } from './Annotations/models';
42
42
  import Bar from './Bar';
43
43
  import TimeShiftZones from './TimeShiftZones';
44
44
  import ZoomPreview from './ZoomPreview';
45
45
  import {
46
- MousePosition,
46
+ type MousePosition,
47
47
  changeMousePositionDerivedAtom,
48
48
  eventMouseDownAtom,
49
49
  eventMouseLeaveAtom,
@@ -91,7 +91,6 @@ const InteractionWithGraph = ({
91
91
  const setEventMouseLeave = useSetAtom(eventMouseLeaveAtom);
92
92
  const changeMousePosition = useSetAtom(changeMousePositionDerivedAtom);
93
93
  const setGraphTooltipData = useSetAtom(graphTooltipDataAtom);
94
-
95
94
  const {
96
95
  graphHeight,
97
96
  graphWidth,
@@ -246,7 +245,7 @@ const InteractionWithGraph = ({
246
245
  {displayEventAnnotations && (
247
246
  <Annotations
248
247
  data={annotationData?.data as Array<TimelineEvent>}
249
- graphHeight={graphHeight}
248
+ graphHeight={graphHeight - margin.bottom}
250
249
  graphSvgRef={graphSvgRef}
251
250
  graphWidth={graphWidth}
252
251
  xScale={xScale}
@@ -1,4 +1,4 @@
1
- import { MutableRefObject, memo, useRef } from 'react';
1
+ import { type MutableRefObject, memo, useEffect, useRef } from 'react';
2
2
 
3
3
  import dayjs from 'dayjs';
4
4
  import 'dayjs/locale/en';
@@ -8,15 +8,15 @@ import 'dayjs/locale/pt';
8
8
  import localizedFormat from 'dayjs/plugin/localizedFormat';
9
9
  import timezonePlugin from 'dayjs/plugin/timezone';
10
10
  import utcPlugin from 'dayjs/plugin/utc';
11
- import { equals } from 'ramda';
12
11
 
13
12
  import { ParentSize } from '../..';
14
13
  import Loading from '../../LoadingSkeleton';
15
- import { LineChartData, Thresholds } from '../common/models';
14
+ import type { LineChartData, Thresholds } from '../common/models';
16
15
 
17
16
  import Chart from './Chart';
17
+ import { useChartStyles } from './Chart.styles';
18
18
  import LoadingSkeleton from './LoadingSkeleton';
19
- import { GlobalAreaLines, LineChartProps } from './models';
19
+ import type { GlobalAreaLines, LineChartProps } from './models';
20
20
  import useChartData from './useChartData';
21
21
 
22
22
  dayjs.extend(localizedFormat);
@@ -32,6 +32,8 @@ interface Props extends Partial<LineChartProps> {
32
32
  start: string;
33
33
  thresholdUnit?: string;
34
34
  thresholds?: Thresholds;
35
+ getRef?: (ref: MutableRefObject<HTMLDivElement | null>) => void;
36
+ containerStyle?: string;
35
37
  }
36
38
 
37
39
  const WrapperChart = ({
@@ -61,11 +63,19 @@ const WrapperChart = ({
61
63
  barStyle,
62
64
  thresholds,
63
65
  thresholdUnit,
64
- limitLegend
66
+ limitLegend,
67
+ getRef,
68
+ ...rest
65
69
  }: Props): JSX.Element | null => {
70
+ const { classes, cx } = useChartStyles();
71
+
66
72
  const { adjustedData } = useChartData({ data, end, start });
67
73
  const lineChartRef = useRef<HTMLDivElement | null>(null);
68
74
 
75
+ useEffect(() => {
76
+ getRef?.(lineChartRef);
77
+ }, [lineChartRef?.current]);
78
+
69
79
  if (loading && !adjustedData) {
70
80
  return (
71
81
  <LoadingSkeleton
@@ -82,7 +92,7 @@ const WrapperChart = ({
82
92
  return (
83
93
  <div
84
94
  ref={lineChartRef as MutableRefObject<HTMLDivElement>}
85
- style={{ height: '100%', overflow: 'hidden', width: '100%' }}
95
+ className={cx(classes.wrapperContainer, rest?.containerStyle)}
86
96
  >
87
97
  <ParentSize>
88
98
  {({
@@ -118,4 +128,4 @@ const WrapperChart = ({
118
128
  );
119
129
  };
120
130
 
121
- export default memo(WrapperChart, equals);
131
+ export default memo(WrapperChart);
@@ -1,18 +1,22 @@
1
- import { ReactNode } from 'react';
1
+ import type { ReactNode } from 'react';
2
2
 
3
- import { ScaleLinear } from 'd3-scale';
3
+ import type { ScaleLinear } from 'd3-scale';
4
4
 
5
- import { BarStyle } from '../BarChart/models';
6
- import { AxisX, Axis as AxisYLeft, AxisYRight } from '../common/Axes/models';
7
- import { LineChartData } from '../common/models';
8
- import { Line, TimeValue } from '../common/timeSeries/models';
5
+ import type { BarStyle } from '../BarChart/models';
6
+ import type {
7
+ AxisX,
8
+ Axis as AxisYLeft,
9
+ AxisYRight
10
+ } from '../common/Axes/models';
11
+ import type { LineChartData } from '../common/models';
12
+ import type { Line, TimeValue } from '../common/timeSeries/models';
9
13
 
10
- import { FactorsVariation } from './BasicComponents/Lines/Threshold/models';
11
- import {
14
+ import type { FactorsVariation } from './BasicComponents/Lines/Threshold/models';
15
+ import type {
12
16
  AreaRegularLines,
13
17
  AreaStackedLines
14
18
  } from './BasicComponents/Lines/models';
15
- import { TimelineEvent } from './InteractiveComponents/Annotations/models';
19
+ import type { TimelineEvent } from './InteractiveComponents/Annotations/models';
16
20
 
17
21
  export interface LineChartEndpoint {
18
22
  baseUrl: string;
@@ -138,16 +142,18 @@ export interface PatternThreshold {
138
142
  data: Array<LineChartData>;
139
143
  orientation?: Array<PatternOrientation>;
140
144
  type: ThresholdType.pattern;
145
+ id: string;
141
146
  }
142
147
  export interface VariationThreshold {
143
148
  displayCircles?: boolean;
144
149
  factors: FactorsVariation;
145
150
  getCountDisplayedCircles?: (value: number) => void;
146
151
  type: ThresholdType.variation;
152
+ id: string;
147
153
  }
148
154
 
149
155
  export interface BasicThreshold {
150
- id?: string;
156
+ id: string;
151
157
  type: ThresholdType.basic;
152
158
  }
153
159
 
@@ -13,11 +13,11 @@ import {
13
13
  toLower
14
14
  } from 'ramda';
15
15
 
16
- import { LineChartData } from '../common/models';
16
+ import type { LineChartData } from '../common/models';
17
17
  import { emphasizeCurveColor } from '../common/utils';
18
18
 
19
19
  import { adjustGraphData } from './helpers';
20
- import { Data } from './models';
20
+ import type { Data } from './models';
21
21
 
22
22
  interface GraphDataResult {
23
23
  adjustedData?: Data;
@@ -9,6 +9,7 @@ import {
9
9
  findIndex,
10
10
  gt,
11
11
  gte,
12
+ identity,
12
13
  includes,
13
14
  isNil,
14
15
  last,
@@ -75,9 +76,9 @@ const getVisibleColumns = ({
75
76
  return columns;
76
77
  }
77
78
 
78
- return selectedColumnIds.map((id) =>
79
- columns.find(propEq(id, 'id'))
80
- ) as Array<Column>;
79
+ return selectedColumnIds
80
+ .map((id) => columns.find(propEq(id, 'id')))
81
+ .filter(identity) as Array<Column>;
81
82
  };
82
83
 
83
84
  interface CustomStyle {
@@ -9,12 +9,12 @@ import timezonePlugin from 'dayjs/plugin/timezone';
9
9
  import utcPlugin from 'dayjs/plugin/utc';
10
10
  import { lt } from 'ramda';
11
11
 
12
- import { Paper, Theme, useMediaQuery } from '@mui/material';
12
+ import { Paper, type Theme, useMediaQuery } from '@mui/material';
13
13
 
14
14
  import CustomTimePeriod from './CustomTimePeriod';
15
15
  import SelectedTimePeriod from './SelectedTimePeriod';
16
16
  import { useStyles } from './TimePeriods.styles';
17
- import { WrapperTimePeriodProps } from './models';
17
+ import type { WrapperTimePeriodProps } from './models';
18
18
  import useTimePeriod from './useTimePeriod';
19
19
 
20
20
  dayjs.extend(isSameOrAfter);
@@ -11,8 +11,9 @@ import utcPlugin from 'dayjs/plugin/utc';
11
11
  import { ParentSize } from '..';
12
12
  import LoadingSkeleton from '../LoadingSkeleton';
13
13
 
14
+ import { memo } from 'react';
14
15
  import TimePeriods from './TimePeriods';
15
- import { WrapperTimePeriodProps } from './models';
16
+ import type { WrapperTimePeriodProps } from './models';
16
17
 
17
18
  dayjs.extend(isSameOrAfter);
18
19
  dayjs.extend(utcPlugin);
@@ -34,4 +35,4 @@ const WrapperTimePeriods = ({
34
35
  </ParentSize>
35
36
  );
36
37
 
37
- export default WrapperTimePeriods;
38
+ export default memo(WrapperTimePeriods);
@@ -1,4 +1,4 @@
1
- import { ReactNode } from 'react';
1
+ import type { ReactNode } from 'react';
2
2
 
3
3
  import dayjs from 'dayjs';
4
4
 
@@ -98,7 +98,7 @@ export interface EndStartInterval {
98
98
  start: string;
99
99
  }
100
100
 
101
- interface Parameters extends EndStartInterval {
101
+ export interface Parameters extends EndStartInterval {
102
102
  timelineEventsLimit: number;
103
103
  }
104
104
 
package/src/index.ts CHANGED
@@ -158,7 +158,6 @@ export { default as FluidTypography } from './Typography/FluidTypography';
158
158
  export { default as EllipsisTypography } from './Typography/EllipsisTypography';
159
159
  export * from './Dashboard';
160
160
  export * from './Graph';
161
-
162
161
  export { default as TimePeriods } from './TimePeriods';
163
162
  export { default as SimpleCustomTimePeriod } from './TimePeriods/CustomTimePeriod/SimpleCustomTimePeriod';
164
163
  export { default as DateTimePickerInput } from './TimePeriods/DateTimePickerInput';
@@ -26,4 +26,5 @@ export * from './resourcesStatusURL';
26
26
  export * from '../Graph/Chart/helpers';
27
27
  export * from '../Graph/Chart/InteractiveComponents/TimeShiftZones/useTimeShiftZones';
28
28
  export * from '../TimePeriods/helpers';
29
+ export { lastDayPeriod, type Parameters } from '../TimePeriods/models';
29
30
  export * from './useLocaleTimezoneDate/useLocaleTimezoneDate';