@centreon/ui 26.3.16 → 26.3.18

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": "26.3.16",
3
+ "version": "26.3.18",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -145,6 +145,7 @@ const ConnectedAutocomplete = ({
145
145
  getEndpoint={getEndpoint}
146
146
  getOptionLabel={connectedAutocomplete?.getOptionLabel}
147
147
  getRenderedOptionText={connectedAutocomplete?.getRenderedOptionText}
148
+ helperText={connectedAutocomplete?.helperText}
148
149
  initialPage={1}
149
150
  isOptionEqualToValue={isOptionEqualToValue}
150
151
  label={t(label)}
@@ -63,6 +63,7 @@ export interface InputProps {
63
63
  filterKey?: string;
64
64
  getRenderedOptionText?: (option) => string | JSX.Element;
65
65
  getOptionLabel?: (option) => string;
66
+ helperText?: string;
66
67
  optionProperty?: string;
67
68
  disableSelectAll?: boolean;
68
69
  limitTags?: number;
@@ -95,7 +95,7 @@ const ResponsiveBarChart = ({
95
95
 
96
96
  const { classes, cx } = useTooltipStyles();
97
97
 
98
- const [linesGraph, setLinesGraph] = useState<Array<Line>>(lines);
98
+ const [linesGraph, setLinesGraph] = useState<Array<Line>>(lines || []);
99
99
  const graphSvgRef = useRef<SVGSVGElement | null>(null);
100
100
 
101
101
  const [tooltipData, setTooltipData] = useAtom(tooltipDataAtom);
@@ -109,7 +109,7 @@ const ResponsiveBarChart = ({
109
109
  );
110
110
 
111
111
  const [firstUnit, secondUnit] = getUnits(displayedLines);
112
- const allUnits = getUnits(lines);
112
+ const allUnits = getUnits(lines || []);
113
113
 
114
114
  const { maxLeftAxisCharacters, maxRightAxisCharacters } =
115
115
  useComputeYAxisMaxCharacters({
@@ -200,13 +200,13 @@ const ResponsiveBarChart = ({
200
200
  ]
201
201
  );
202
202
 
203
- const leftScale = yScalesPerUnit[firstUnit];
204
- const rightScale = yScalesPerUnit[secondUnit];
203
+ const leftScale = yScalesPerUnit[firstUnit ?? allUnits[0]];
204
+ const rightScale = yScalesPerUnit[secondUnit ?? allUnits[1]];
205
205
  const pixelsToShift = computPixelsToShiftMouse(xScaleLinear);
206
206
 
207
207
  useEffect(
208
208
  () => {
209
- setLinesGraph(lines);
209
+ setLinesGraph(lines || []);
210
210
  },
211
211
  useDeepCompare([lines])
212
212
  );
@@ -222,8 +222,11 @@ const Chart = ({
222
222
  ]
223
223
  );
224
224
 
225
- const leftScale = yScalesPerUnit[axis?.axisYLeft?.unit ?? firstUnit];
226
- const rightScale = yScalesPerUnit[axis?.axisYRight?.unit ?? secondUnit];
225
+ const fallbackLeftUnit = axis?.axisYLeft?.unit ?? firstUnit ?? allUnits[0];
226
+ const fallbackRightUnit = axis?.axisYRight?.unit ?? secondUnit ?? allUnits[1];
227
+
228
+ const leftScale = yScalesPerUnit[fallbackLeftUnit];
229
+ const rightScale = yScalesPerUnit[fallbackRightUnit];
227
230
 
228
231
  const linesDisplayedAsLine = useMemo(
229
232
  () =>
@@ -29,6 +29,15 @@ interface Props {
29
29
  }
30
30
 
31
31
  const getBoolean = (value) => Boolean(Number(value));
32
+ const defaultDsData = {
33
+ ds_color_line: '#000000',
34
+ ds_filled: false,
35
+ ds_invert: false,
36
+ ds_legend: '',
37
+ ds_order: '0',
38
+ ds_stack: '0',
39
+ ds_transparency: 80
40
+ };
32
41
 
33
42
  const useGraphData = ({ data }: Props): GraphDataResult => {
34
43
  const adjustedDataRef = useRef<Data>();
@@ -42,9 +51,21 @@ const useGraphData = ({ data }: Props): GraphDataResult => {
42
51
  return undefined;
43
52
  }
44
53
 
54
+ const metricsWithValidDsData = (data?.metrics || []).map((metric) => ({
55
+ ...metric,
56
+ ds_data: {
57
+ ...defaultDsData,
58
+ ...(metric?.ds_data || {}),
59
+ ds_color_area:
60
+ metric?.ds_data?.ds_color_area ??
61
+ metric?.ds_data?.ds_color_line ??
62
+ defaultDsData.ds_color_line
63
+ }
64
+ }));
65
+
45
66
  const metricsGroupedByColor = groupBy(
46
- (metric) => metric.ds_data.ds_color_line
47
- )(data?.metrics || []);
67
+ (metric) => metric.ds_data?.ds_color_line || '#000000'
68
+ )(metricsWithValidDsData);
48
69
 
49
70
  const newMetrics = Object.entries(metricsGroupedByColor).map(
50
71
  ([color, value]) => {
@@ -58,7 +58,7 @@ const Axes = ({
58
58
  const formatAxisTick = (tick): string =>
59
59
  format({ date: new Date(tick), formatString: tickFormat });
60
60
 
61
- const displayAxisRight = !isNil(secondUnit);
61
+ const displayAxisRight = !isNil(secondUnit) && !isNil(rightScale);
62
62
 
63
63
  const AxisBottom = isHorizontal ? Axis.AxisBottom : Axis.AxisLeft;
64
64
  const AxisLeft = isHorizontal ? Axis.AxisLeft : Axis.AxisTop;
@@ -52,6 +52,11 @@ const ChartSvgWrapper = ({
52
52
  title
53
53
  }: Props): ReactElement => {
54
54
  const isHorizontal = equals(orientation, 'horizontal');
55
+ const hasValidLeftScale = Boolean(leftScale);
56
+ const hasValidXScale = Boolean(xScale);
57
+ const canRenderAxes = hasValidLeftScale && hasValidXScale;
58
+ const canRenderGridRows = Boolean(isHorizontal ? leftScale : xScale);
59
+ const canRenderGridColumns = Boolean(isHorizontal ? xScale : leftScale);
55
60
 
56
61
  const marginTop = useMarginTop({ title, units: allUnits });
57
62
 
@@ -70,7 +75,7 @@ const ChartSvgWrapper = ({
70
75
  })}
71
76
  top={marginTop}
72
77
  >
73
- {showGridLines && (
78
+ {showGridLines && (canRenderGridRows || canRenderGridColumns) && (
74
79
  <Grids
75
80
  gridLinesType={gridLinesType}
76
81
  height={graphHeight - margin.bottom}
@@ -79,21 +84,23 @@ const ChartSvgWrapper = ({
79
84
  xScale={isHorizontal ? xScale : leftScale}
80
85
  />
81
86
  )}
82
- <Axes
83
- allUnits={allUnits}
84
- data={{
85
- baseAxis: base,
86
- lines: displayedLines,
87
- timeSeries,
88
- ...axis
89
- }}
90
- height={graphHeight}
91
- leftScale={leftScale}
92
- orientation={orientation}
93
- rightScale={rightScale}
94
- width={graphWidth}
95
- xScale={xScale}
96
- />
87
+ {canRenderAxes && (
88
+ <Axes
89
+ allUnits={allUnits}
90
+ data={{
91
+ baseAxis: base,
92
+ lines: displayedLines,
93
+ timeSeries,
94
+ ...axis
95
+ }}
96
+ height={graphHeight}
97
+ leftScale={leftScale}
98
+ orientation={orientation}
99
+ rightScale={rightScale}
100
+ width={graphWidth}
101
+ xScale={xScale}
102
+ />
103
+ )}
97
104
  {children}
98
105
  </Group.Group>
99
106
  </svg>
@@ -7,9 +7,9 @@ import type { ChartAxis } from '../../Chart/models';
7
7
 
8
8
  interface Props extends Pick<ChartAxis, 'gridLinesType'> {
9
9
  height: number;
10
- leftScale: ScaleLinear<number, number>;
10
+ leftScale?: ScaleLinear<number, number>;
11
11
  width: number;
12
- xScale: ScaleLinear<number, number>;
12
+ xScale?: ScaleLinear<number, number>;
13
13
  }
14
14
 
15
15
  const Grids = ({
@@ -30,10 +30,10 @@ const Grids = ({
30
30
 
31
31
  return (
32
32
  <g>
33
- {displayRows && (
33
+ {displayRows && leftScale && (
34
34
  <Grid.GridRows height={height} scale={leftScale} width={width} />
35
35
  )}
36
- {displayColumns && (
36
+ {displayColumns && xScale && (
37
37
  <Grid.GridColumns height={height} scale={xScale} width={width} />
38
38
  )}
39
39
  </g>
@@ -54,6 +54,17 @@ interface TimeTickWithMetrics {
54
54
  timeTick: string;
55
55
  }
56
56
 
57
+ const defaultDsData = {
58
+ ds_color_line: '#000000',
59
+ ds_filled: false,
60
+ ds_invert: false,
61
+ ds_legend: '',
62
+ ds_order: '0',
63
+ ds_stack: '0',
64
+ ds_stack_key: null,
65
+ ds_transparency: 80
66
+ };
67
+
57
68
  const toTimeTickWithMetrics = ({
58
69
  metrics,
59
70
  times
@@ -120,30 +131,39 @@ const toLine = ({
120
131
  maximum_value,
121
132
  metric_id,
122
133
  displayAs
123
- }: Metric): Line => ({
124
- areaColor: ds_data.ds_color_area,
125
- average_value,
126
- color: ds_data.ds_color_line,
127
- display: true,
128
- displayAs,
129
- filled: ds_data.ds_filled,
130
- highlight: undefined,
131
- invert: ds_data.ds_invert,
132
- legend: ds_data.ds_legend,
133
- lineColor: ds_data.ds_color_line,
134
- maximum_value,
135
- metric,
136
- metric_id,
137
- minimum_value,
138
- name: legend,
139
- stackKey: ds_data.ds_stack_key || null,
140
- stackOrder:
141
- equals(ds_data.ds_stack, '1') || equals(ds_data.ds_stack, true)
142
- ? Number.parseInt(ds_data.ds_order || '0', 10)
143
- : null,
144
- transparency: ds_data.ds_transparency,
145
- unit
146
- });
134
+ }: Metric): Line => {
135
+ const safeDsData = {
136
+ ...defaultDsData,
137
+ ...(ds_data || {}),
138
+ ds_color_area:
139
+ ds_data?.ds_color_area ?? ds_data?.ds_color_line ?? defaultDsData.ds_color_line
140
+ };
141
+
142
+ return {
143
+ areaColor: safeDsData.ds_color_area,
144
+ average_value,
145
+ color: safeDsData.ds_color_line,
146
+ display: true,
147
+ displayAs,
148
+ filled: safeDsData.ds_filled,
149
+ highlight: undefined,
150
+ invert: safeDsData.ds_invert,
151
+ legend: safeDsData.ds_legend,
152
+ lineColor: safeDsData.ds_color_line,
153
+ maximum_value,
154
+ metric,
155
+ metric_id,
156
+ minimum_value,
157
+ name: legend,
158
+ stackKey: safeDsData.ds_stack_key || null,
159
+ stackOrder:
160
+ equals(safeDsData.ds_stack, '1') || equals(safeDsData.ds_stack, true)
161
+ ? Number.parseInt(safeDsData.ds_order || '0', 10)
162
+ : null,
163
+ transparency: safeDsData.ds_transparency,
164
+ unit
165
+ };
166
+ };
147
167
 
148
168
  const getLineData = (graphData: LineChartData): Array<Line> =>
149
169
  map(toLine, graphData.metrics);