@centreon/ui 26.3.17 → 26.3.19
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 +1 -1
- package/src/Form/storiesData.tsx +2 -1
- package/src/Graph/BarChart/ResponsiveBarChart.tsx +5 -5
- package/src/Graph/Chart/Chart.tsx +5 -2
- package/src/Graph/Chart/useChartData.ts +23 -2
- package/src/Graph/common/Axes/index.tsx +1 -1
- package/src/Graph/common/BaseChart/ChartSvgWrapper.tsx +23 -16
- package/src/Graph/common/Grids/index.tsx +4 -4
- package/src/Graph/common/timeSeries/index.ts +44 -24
- package/src/InputField/Select/Autocomplete/index.tsx +5 -1
- package/src/InputField/Text/index.tsx +4 -1
- package/src/utils/useViewportIntersection.ts +6 -3
package/package.json
CHANGED
package/src/Form/storiesData.tsx
CHANGED
|
@@ -327,7 +327,8 @@ export const basicFormInputs: Array<InputProps> = [
|
|
|
327
327
|
{
|
|
328
328
|
connectedAutocomplete: {
|
|
329
329
|
additionalConditionParameters: [],
|
|
330
|
-
endpoint: 'endpoint'
|
|
330
|
+
endpoint: 'endpoint',
|
|
331
|
+
helperText: 'Hello I am testing'
|
|
331
332
|
},
|
|
332
333
|
fieldName: 'group',
|
|
333
334
|
label: 'Group (Single connected autocomplete)',
|
|
@@ -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
|
|
226
|
-
const
|
|
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
|
|
47
|
-
)(
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
|
10
|
+
leftScale?: ScaleLinear<number, number>;
|
|
11
11
|
width: number;
|
|
12
|
-
xScale
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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);
|
|
@@ -18,7 +18,8 @@ import {
|
|
|
18
18
|
type ForwardedRef,
|
|
19
19
|
forwardRef,
|
|
20
20
|
type HTMLAttributes,
|
|
21
|
-
type ReactElement
|
|
21
|
+
type ReactElement,
|
|
22
|
+
ReactNode
|
|
22
23
|
} from 'react';
|
|
23
24
|
import { useTranslation } from 'react-i18next';
|
|
24
25
|
|
|
@@ -32,6 +33,7 @@ import { useAutoCompleteStyles } from './autoComplete.styles';
|
|
|
32
33
|
export type Props = {
|
|
33
34
|
autoFocus?: boolean;
|
|
34
35
|
autoSize?: boolean;
|
|
36
|
+
helperText?: ReactNode;
|
|
35
37
|
autoSizeCustomPadding?: number;
|
|
36
38
|
autoSizeDefaultWidth?: number;
|
|
37
39
|
dataTestId?: string;
|
|
@@ -95,6 +97,7 @@ const AutocompleteField = forwardRef(
|
|
|
95
97
|
displayPopupIcon = true,
|
|
96
98
|
autoFocus = false,
|
|
97
99
|
hideInput = false,
|
|
100
|
+
helperText,
|
|
98
101
|
dataTestId,
|
|
99
102
|
autoSize = false,
|
|
100
103
|
autoSizeDefaultWidth = 0,
|
|
@@ -151,6 +154,7 @@ const AutocompleteField = forwardRef(
|
|
|
151
154
|
}}
|
|
152
155
|
error={error}
|
|
153
156
|
externalValueForAutoSize={autocompleteProps?.value?.name}
|
|
157
|
+
helperText={helperText}
|
|
154
158
|
label={label}
|
|
155
159
|
onChange={onTextChange}
|
|
156
160
|
placeholder={isNil(placeholder) ? t(searchLabel) : placeholder}
|
|
@@ -123,6 +123,7 @@ const TextField = forwardRef(
|
|
|
123
123
|
type,
|
|
124
124
|
textFieldSlotsAndSlotProps,
|
|
125
125
|
forceUncontrolled,
|
|
126
|
+
helperText,
|
|
126
127
|
...rest
|
|
127
128
|
}: TextProps,
|
|
128
129
|
ref: React.ForwardedRef<HTMLDivElement>
|
|
@@ -160,7 +161,9 @@ const TextField = forwardRef(
|
|
|
160
161
|
<MuiTextField
|
|
161
162
|
data-testid={dataTestId}
|
|
162
163
|
error={!isNil(error)}
|
|
163
|
-
helperText={
|
|
164
|
+
helperText={
|
|
165
|
+
(displayErrorInTooltip ? undefined : error) || helperText
|
|
166
|
+
}
|
|
164
167
|
id={getNormalizedId(dataTestId || '')}
|
|
165
168
|
label={label}
|
|
166
169
|
onChange={changeInputValue}
|
|
@@ -18,11 +18,14 @@ export const useViewportIntersection = (
|
|
|
18
18
|
const [element, setElement] = useState<HTMLElement | null>(null);
|
|
19
19
|
|
|
20
20
|
const observer = useRef<IntersectionObserver | null>(null);
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
const sanitizedOptions = {
|
|
23
23
|
...options,
|
|
24
|
-
root:
|
|
25
|
-
|
|
24
|
+
root:
|
|
25
|
+
options?.root instanceof HTMLElement
|
|
26
|
+
? `${options.root.tagName}_${options.root.className}`
|
|
27
|
+
: null
|
|
28
|
+
};
|
|
26
29
|
|
|
27
30
|
useEffect(() => {
|
|
28
31
|
if (observer.current) {
|