@centreon/ui 25.10.10 → 25.10.12

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": "25.10.10",
3
+ "version": "25.10.12",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -1,22 +1,23 @@
1
- import { RefCallback, memo, useEffect } from 'react';
1
+ import dayjs from "dayjs";
2
+ import { memo, type RefCallback, useEffect, useRef } from "react";
3
+ import "dayjs/locale/en";
4
+ import "dayjs/locale/es";
5
+ import "dayjs/locale/fr";
6
+ import "dayjs/locale/pt";
2
7
 
3
- import dayjs from 'dayjs';
4
- import 'dayjs/locale/en';
5
- import 'dayjs/locale/es';
6
- import 'dayjs/locale/fr';
7
- import 'dayjs/locale/pt';
8
- import localizedFormat from 'dayjs/plugin/localizedFormat';
9
- import timezonePlugin from 'dayjs/plugin/timezone';
10
- import utcPlugin from 'dayjs/plugin/utc';
11
- import Loading from '../../LoadingSkeleton';
12
- import type { LineChartData, Thresholds } from '../common/models';
8
+ import { NoData } from "@centreon/ui";
13
9
 
14
- import useResizeObserver from 'use-resize-observer';
15
- import Chart from './Chart';
16
- import { useChartStyles } from './Chart.styles';
17
- import LoadingSkeleton from './LoadingSkeleton';
18
- import type { GlobalAreaLines, LineChartProps } from './models';
19
- import useChartData from './useChartData';
10
+ import localizedFormat from "dayjs/plugin/localizedFormat";
11
+ import timezonePlugin from "dayjs/plugin/timezone";
12
+ import utcPlugin from "dayjs/plugin/utc";
13
+ import useResizeObserver from "use-resize-observer";
14
+ import Loading from "../../LoadingSkeleton";
15
+ import type { LineChartData, Thresholds } from "../common/models";
16
+ import Chart from "./Chart";
17
+ import { useChartStyles } from "./Chart.styles";
18
+ import LoadingSkeleton from "./LoadingSkeleton";
19
+ import type { GlobalAreaLines, LineChartProps } from "./models";
20
+ import useChartData from "./useChartData";
20
21
 
21
22
  dayjs.extend(localizedFormat);
22
23
  dayjs.extend(utcPlugin);
@@ -31,7 +32,7 @@ interface Props extends Partial<LineChartProps> {
31
32
  start: string;
32
33
  thresholdUnit?: string;
33
34
  thresholds?: Thresholds;
34
- getRef?: (ref: RefCallback<Element>) => void;
35
+ getRef?: (ref: React.RefObject<HTMLDivElement | null>) => void;
35
36
  containerStyle?: string;
36
37
  transformMatrix?: {
37
38
  fx?: (pointX: number) => number;
@@ -52,14 +53,14 @@ const WrapperChart = ({
52
53
  loading,
53
54
  timeShiftZones,
54
55
  tooltip = {
55
- mode: 'all',
56
- sortOrder: 'name'
56
+ mode: "all",
57
+ sortOrder: "name",
57
58
  },
58
59
  annotationEvent,
59
60
  legend = {
60
61
  display: true,
61
- mode: 'grid',
62
- placement: 'bottom'
62
+ mode: "grid",
63
+ placement: "bottom",
63
64
  },
64
65
  header,
65
66
  lineStyle,
@@ -76,17 +77,26 @@ const WrapperChart = ({
76
77
  ...rest
77
78
  }: Props): JSX.Element | null => {
78
79
  const { classes, cx } = useChartStyles();
79
-
80
80
  const { adjustedData } = useChartData({ data, end, start });
81
+
82
+ const containerRef = useRef<HTMLDivElement | null>(null);
83
+
81
84
  const {
82
- ref,
85
+ ref: resizeObserverRef,
83
86
  width: responsiveWidth,
84
- height: responsiveHeight
87
+ height: responsiveHeight,
85
88
  } = useResizeObserver();
86
89
 
87
- useEffect(() => {
88
- getRef?.(ref);
89
- }, [ref?.current]);
90
+ const combinedRef = (element: HTMLDivElement | null) => {
91
+ if (containerRef.current !== element) {
92
+ containerRef.current = element;
93
+ if (element) {
94
+ getRef?.(containerRef);
95
+ }
96
+ }
97
+ resizeObserverRef(element);
98
+ };
99
+
90
100
 
91
101
  if (loading && !adjustedData) {
92
102
  return (
@@ -97,13 +107,17 @@ const WrapperChart = ({
97
107
  );
98
108
  }
99
109
 
110
+ if (!adjustedData) {
111
+ return <NoData />;
112
+ }
113
+
100
114
  return (
101
115
  <div
102
- ref={ref}
116
+ ref={combinedRef}
103
117
  className={cx(classes.wrapperContainer, rest?.containerStyle)}
104
118
  >
105
119
  {!responsiveHeight ? (
106
- <Loading height={height || '100%'} width={width} />
120
+ <Loading height={height || "100%"} width={width} />
107
121
  ) : (
108
122
  <Chart
109
123
  annotationEvent={annotationEvent}
@@ -112,7 +126,7 @@ const WrapperChart = ({
112
126
  displayAnchor={displayAnchor}
113
127
  graphData={adjustedData}
114
128
  graphInterval={{ end, start }}
115
- graphRef={ref}
129
+ graphRef={containerRef}
116
130
  header={header}
117
131
  height={height || responsiveHeight || 0}
118
132
  legend={legend}
@@ -7,3 +7,4 @@ export const labelDowntime = 'Downtime';
7
7
  export const labelMin = 'Min';
8
8
  export const labelMax = 'Max';
9
9
  export const labelAvg = 'Avg';
10
+ export const labelNoDataForThisPeriod = 'No data available for this period';
@@ -0,0 +1,18 @@
1
+ import { Typography } from '@mui/material';
2
+
3
+ import { useTranslation } from 'react-i18next';
4
+
5
+ import { labelNoDataForThisPeriod } from '../../Chart/translatedLabels';
6
+
7
+ const NoData = () => {
8
+ const { t } = useTranslation();
9
+ return (
10
+ <div className={'flex items-center justify-center h-full'}>
11
+ <Typography align="center" variant="body1">
12
+ {t(labelNoDataForThisPeriod)}
13
+ </Typography>
14
+ </div>
15
+ );
16
+ };
17
+
18
+ export default NoData;
@@ -1,20 +1,20 @@
1
- export type { ParentSizeProps } from '@visx/responsive/lib/components/ParentSize';
2
- export { default as LineChart } from './Chart';
3
- export { default as ThresholdLines } from './Chart/BasicComponents/Lines/Threshold';
4
- export { default as useLineChartData } from './Chart/useChartData';
5
- export { default as BarChart } from './BarChart/BarChart';
6
- export { Gauge } from './Gauge';
7
- export { SingleBar } from './SingleBar';
8
- export { Text as GraphText } from './Text';
9
- export { default as Header } from './common/BaseChart/Header';
10
-
11
- export { HeatMap } from './HeatMap';
12
- export { BarStack } from './BarStack';
13
- export { PieChart } from './PieChart';
14
- export { Timeline } from './Timeline';
15
- export * from './Tree';
16
- export type { LineChartData, Threshold, Thresholds } from './common/models';
17
- export * from './common/timeSeries';
18
- export type { Metric } from './common/timeSeries/models';
19
- export * from './Chart/models';
20
- export * from './PieChart/models';
1
+ export type { ParentSizeProps } from "@visx/responsive/lib/components/ParentSize";
2
+ export { default as BarChart } from "./BarChart/BarChart";
3
+ export { BarStack } from "./BarStack";
4
+ export { default as LineChart } from "./Chart";
5
+ export { default as ThresholdLines } from "./Chart/BasicComponents/Lines/Threshold";
6
+ export * from "./Chart/models";
7
+ export { default as useLineChartData } from "./Chart/useChartData";
8
+ export { default as Header } from "./common/BaseChart/Header";
9
+ export { default as NoData } from "./common/Error/NoData";
10
+ export type { LineChartData, Threshold, Thresholds } from "./common/models";
11
+ export * from "./common/timeSeries";
12
+ export type { Metric } from "./common/timeSeries/models";
13
+ export { Gauge } from "./Gauge";
14
+ export { HeatMap } from "./HeatMap";
15
+ export { PieChart } from "./PieChart";
16
+ export * from "./PieChart/models";
17
+ export { SingleBar } from "./SingleBar";
18
+ export { Text as GraphText } from "./Text";
19
+ export { Timeline } from "./Timeline";
20
+ export * from "./Tree";