@centreon/ui 23.10.61 → 23.10.63
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/Graph/Gauge/AnimatedPie.tsx +31 -20
- package/src/Graph/Gauge/Gauge.stories.tsx +97 -6
- package/src/Graph/Gauge/Gauge.tsx +4 -15
- package/src/Graph/Gauge/PieData.tsx +8 -24
- package/src/Graph/Gauge/ResponsiveGauge.tsx +11 -14
- package/src/Graph/Gauge/Thresholds.tsx +109 -56
- package/src/Graph/Gauge/models.ts +2 -3
- package/src/Graph/LineChart/BasicComponents/ThresholdLine.tsx +64 -0
- package/src/Graph/LineChart/BasicComponents/Thresholds.tsx +77 -0
- package/src/Graph/LineChart/BasicComponents/useFilterLines.ts +9 -7
- package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/index.tsx +2 -4
- package/src/Graph/LineChart/InteractiveComponents/interactionWithGraphAtoms.ts +1 -0
- package/src/Graph/LineChart/Legend/index.tsx +9 -4
- package/src/Graph/LineChart/Legend/useInteractiveValues.ts +13 -4
- package/src/Graph/LineChart/Legend/useLegend.ts +10 -13
- package/src/Graph/LineChart/LineChart.tsx +73 -8
- package/src/Graph/LineChart/graphAtoms.ts +0 -3
- package/src/Graph/LineChart/index.stories.tsx +101 -6
- package/src/Graph/LineChart/index.tsx +13 -3
- package/src/Graph/SingleBar/ResponsiveSingleBar.tsx +10 -8
- package/src/Graph/SingleBar/SingleBar.stories.tsx +119 -6
- package/src/Graph/SingleBar/ThresholdLine.tsx +74 -0
- package/src/Graph/SingleBar/Thresholds.tsx +28 -82
- package/src/Graph/SingleBar/models.ts +2 -4
- package/src/Graph/Text/Text.tsx +20 -16
- package/src/Graph/common/models.ts +12 -0
- package/src/Graph/common/timeSeries/index.ts +41 -8
- package/src/Graph/common/timeSeries/models.ts +3 -1
- package/src/Graph/common/utils.ts +59 -6
- package/src/api/useGraphQuery/index.ts +52 -21
- package/src/components/Modal/Modal.styles.ts +1 -2
- package/src/utils/index.ts +1 -0
- package/src/utils/useRefreshInterval.ts +21 -0
- package/src/utils/useThresholds.ts +0 -0
|
@@ -1,20 +1,73 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
T,
|
|
3
|
+
always,
|
|
4
|
+
cond,
|
|
5
|
+
equals,
|
|
6
|
+
gt,
|
|
7
|
+
gte,
|
|
8
|
+
head,
|
|
9
|
+
length,
|
|
10
|
+
lt,
|
|
11
|
+
lte,
|
|
12
|
+
pluck
|
|
13
|
+
} from 'ramda';
|
|
2
14
|
|
|
3
15
|
import { Theme } from '@mui/material';
|
|
4
16
|
|
|
17
|
+
import { Thresholds } from './models';
|
|
18
|
+
|
|
5
19
|
interface GetColorFromDataAndThresholdsProps {
|
|
6
20
|
data: number;
|
|
7
21
|
theme: Theme;
|
|
8
|
-
thresholds:
|
|
22
|
+
thresholds: Thresholds;
|
|
9
23
|
}
|
|
10
24
|
|
|
11
25
|
export const getColorFromDataAndTresholds = ({
|
|
12
26
|
data,
|
|
13
27
|
thresholds,
|
|
14
28
|
theme
|
|
15
|
-
}: GetColorFromDataAndThresholdsProps): string =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
}: GetColorFromDataAndThresholdsProps): string => {
|
|
30
|
+
if (!thresholds.enabled) {
|
|
31
|
+
return theme.palette.success.main;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const criticalValues = pluck('value', thresholds.critical).sort();
|
|
35
|
+
const warningValues = pluck('value', thresholds.warning).sort();
|
|
36
|
+
|
|
37
|
+
if (
|
|
38
|
+
equals(length(criticalValues), 2) &&
|
|
39
|
+
lte(criticalValues[0], data) &&
|
|
40
|
+
gte(criticalValues[1], data)
|
|
41
|
+
) {
|
|
42
|
+
return theme.palette.error.main;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (
|
|
46
|
+
equals(length(warningValues), 2) &&
|
|
47
|
+
lte(warningValues[0], data) &&
|
|
48
|
+
gte(warningValues[1], data)
|
|
49
|
+
) {
|
|
50
|
+
return theme.palette.warning.main;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (equals(length(warningValues), 2)) {
|
|
54
|
+
return theme.palette.success.main;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const criticalValue = head(criticalValues) as number;
|
|
58
|
+
const warningValue = head(warningValues) as number;
|
|
59
|
+
|
|
60
|
+
if (gt(warningValue, criticalValue)) {
|
|
61
|
+
return cond([
|
|
62
|
+
[lt(warningValue), always(theme.palette.success.main)],
|
|
63
|
+
[lt(criticalValue), always(theme.palette.warning.main)],
|
|
64
|
+
[T, always(theme.palette.error.main)]
|
|
65
|
+
])(data);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return cond([
|
|
69
|
+
[gt(warningValue), always(theme.palette.success.main)],
|
|
70
|
+
[gt(criticalValue), always(theme.palette.warning.main)],
|
|
19
71
|
[T, always(theme.palette.error.main)]
|
|
20
72
|
])(data);
|
|
73
|
+
};
|
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { equals, flatten, has, isEmpty, join, pipe, pluck } from 'ramda';
|
|
2
2
|
import dayjs from 'dayjs';
|
|
3
3
|
|
|
4
4
|
import { LineChartData, useFetchQuery } from '../..';
|
|
5
5
|
|
|
6
6
|
import { ServiceMetric } from './models';
|
|
7
7
|
|
|
8
|
+
interface CustomTimePeriod {
|
|
9
|
+
end: string;
|
|
10
|
+
start: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
interface UseMetricsQueryProps {
|
|
9
14
|
baseEndpoint: string;
|
|
10
15
|
metrics: Array<ServiceMetric>;
|
|
11
16
|
refreshInterval?: number | false;
|
|
12
|
-
timePeriod?:
|
|
17
|
+
timePeriod?: {
|
|
18
|
+
end?: string | null;
|
|
19
|
+
start?: string | null;
|
|
20
|
+
timePeriodType: number;
|
|
21
|
+
};
|
|
13
22
|
}
|
|
14
23
|
|
|
15
24
|
interface UseMetricsQueryState {
|
|
@@ -20,24 +29,24 @@ interface UseMetricsQueryState {
|
|
|
20
29
|
start: string;
|
|
21
30
|
}
|
|
22
31
|
|
|
23
|
-
enum TimePeriod {
|
|
24
|
-
lastDay = 'last_day'
|
|
25
|
-
}
|
|
26
|
-
|
|
27
32
|
const getStartEndFromTimePeriod = (
|
|
28
|
-
timePeriod:
|
|
33
|
+
timePeriod: number
|
|
29
34
|
): { end: string; start: string } => {
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
end: dayjs().toISOString(),
|
|
35
|
-
start: dayjs().subtract(1, 'day').toISOString()
|
|
36
|
-
})
|
|
37
|
-
]
|
|
38
|
-
])(timePeriod);
|
|
35
|
+
return {
|
|
36
|
+
end: dayjs().toISOString(),
|
|
37
|
+
start: dayjs().subtract(timePeriod, 'hour').toISOString()
|
|
38
|
+
};
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
const isCustomTimePeriod = (
|
|
42
|
+
timePeriod:
|
|
43
|
+
| number
|
|
44
|
+
| {
|
|
45
|
+
end?: string | null;
|
|
46
|
+
start?: string | null;
|
|
47
|
+
}
|
|
48
|
+
): boolean => has('end', timePeriod) && has('start', timePeriod);
|
|
49
|
+
|
|
41
50
|
interface PerformanceGraphData extends Omit<LineChartData, 'global'> {
|
|
42
51
|
base: number;
|
|
43
52
|
}
|
|
@@ -45,7 +54,9 @@ interface PerformanceGraphData extends Omit<LineChartData, 'global'> {
|
|
|
45
54
|
const useGraphQuery = ({
|
|
46
55
|
metrics,
|
|
47
56
|
baseEndpoint,
|
|
48
|
-
timePeriod =
|
|
57
|
+
timePeriod = {
|
|
58
|
+
timePeriodType: 1
|
|
59
|
+
},
|
|
49
60
|
refreshInterval = false
|
|
50
61
|
}: UseMetricsQueryProps): UseMetricsQueryState => {
|
|
51
62
|
const metricIds = pipe(
|
|
@@ -55,16 +66,32 @@ const useGraphQuery = ({
|
|
|
55
66
|
join(',')
|
|
56
67
|
)(metrics);
|
|
57
68
|
|
|
58
|
-
const
|
|
69
|
+
const timePeriodToUse = equals(timePeriod?.timePeriodType, -1)
|
|
70
|
+
? {
|
|
71
|
+
end: timePeriod.end,
|
|
72
|
+
start: timePeriod.start
|
|
73
|
+
}
|
|
74
|
+
: timePeriod?.timePeriodType;
|
|
59
75
|
|
|
60
76
|
const {
|
|
61
77
|
data: graphData,
|
|
62
78
|
isFetching,
|
|
63
79
|
isLoading
|
|
64
80
|
} = useFetchQuery<PerformanceGraphData>({
|
|
65
|
-
getEndpoint: () =>
|
|
66
|
-
|
|
67
|
-
|
|
81
|
+
getEndpoint: () => {
|
|
82
|
+
if (isCustomTimePeriod(timePeriodToUse)) {
|
|
83
|
+
return `${baseEndpoint}?metricIds=[${metricIds}]&start=${
|
|
84
|
+
(timePeriodToUse as CustomTimePeriod).start
|
|
85
|
+
}&end=${(timePeriodToUse as CustomTimePeriod).end}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const { end, start } = getStartEndFromTimePeriod(
|
|
89
|
+
timePeriodToUse as number
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
return `${baseEndpoint}?metricIds=[${metricIds}]&start=${start}&end=${end}`;
|
|
93
|
+
},
|
|
94
|
+
getQueryKey: () => ['graph', metricIds, timePeriod],
|
|
68
95
|
queryOptions: {
|
|
69
96
|
enabled: !isEmpty(metricIds),
|
|
70
97
|
refetchInterval: refreshInterval,
|
|
@@ -83,6 +110,10 @@ const useGraphQuery = ({
|
|
|
83
110
|
}
|
|
84
111
|
: undefined;
|
|
85
112
|
|
|
113
|
+
const { end, start } = isCustomTimePeriod(timePeriodToUse)
|
|
114
|
+
? (timePeriodToUse as CustomTimePeriod)
|
|
115
|
+
: getStartEndFromTimePeriod(timePeriodToUse as number);
|
|
116
|
+
|
|
86
117
|
return {
|
|
87
118
|
end,
|
|
88
119
|
graphData: formattedGraphData,
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { always, cond, equals } from 'ramda';
|
|
2
|
+
|
|
3
|
+
interface Props {
|
|
4
|
+
globalRefreshInterval?: number;
|
|
5
|
+
refreshInterval: 'default' | 'custom' | 'manual';
|
|
6
|
+
refreshIntervalCustom?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const useRefreshInterval = ({
|
|
10
|
+
refreshInterval,
|
|
11
|
+
refreshIntervalCustom,
|
|
12
|
+
globalRefreshInterval
|
|
13
|
+
}: Props): number | false => {
|
|
14
|
+
const refreshIntervalToUse = cond([
|
|
15
|
+
[equals('default'), always(globalRefreshInterval)],
|
|
16
|
+
[equals('custom'), always(refreshIntervalCustom)],
|
|
17
|
+
[equals('manual'), always(0)]
|
|
18
|
+
])(refreshInterval);
|
|
19
|
+
|
|
20
|
+
return refreshIntervalToUse ? refreshIntervalToUse * 1000 : false;
|
|
21
|
+
};
|
|
File without changes
|