@centreon/ui 23.10.62 → 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.
@@ -1,20 +1,13 @@
1
- import { useTheme } from '@mui/material';
1
+ import { Thresholds } from '../common/models';
2
2
 
3
- export const margin = 40;
4
-
5
- export const barHeight = 50;
3
+ import { ThresholdLine } from './ThresholdLine';
6
4
 
7
5
  export const groupMargin = 25;
8
6
 
9
- const lineMargin = 10;
10
-
11
- const thresholdLineHeight = 60 + 2 * lineMargin;
12
-
13
7
  interface Props {
14
8
  hideTooltip: () => void;
15
9
  showTooltip: (args) => void;
16
- thresholdTooltipLabels: Array<string>;
17
- thresholds: Array<number>;
10
+ thresholds: Thresholds;
18
11
  xScale: (value: number) => number;
19
12
  }
20
13
 
@@ -22,79 +15,32 @@ const Thresholds = ({
22
15
  xScale,
23
16
  thresholds,
24
17
  showTooltip,
25
- hideTooltip,
26
- thresholdTooltipLabels
27
- }: Props): JSX.Element => {
28
- const theme = useTheme();
29
-
30
- const warningValue = thresholds[0];
31
- const criticalValue = thresholds[1];
32
- const warningTooltipLabel = thresholdTooltipLabels[0];
33
- const criticalTooltipLabel = thresholdTooltipLabels[1];
34
-
35
- const bottom = barHeight + margin * 2;
36
-
37
- const onMouseEnter =
38
- ({ label, left }) =>
39
- (): void =>
40
- showTooltip({
41
- tooltipData: label,
42
- tooltipLeft: left,
43
- tooltipTop: bottom
44
- });
45
-
46
- return (
47
- <>
48
- <line
49
- data-testid="warning-line"
50
- stroke={theme.palette.warning.main}
51
- strokeDasharray={4}
52
- strokeWidth={2}
53
- x1={xScale(warningValue)}
54
- x2={xScale(warningValue)}
55
- y1={groupMargin + 3 * lineMargin}
56
- y2={thresholdLineHeight + groupMargin + 3 * lineMargin}
57
- />
58
- <line
59
- data-testid="critical-line"
60
- stroke={theme.palette.error.main}
61
- strokeDasharray={4}
62
- strokeWidth={2}
63
- x1={xScale(criticalValue)}
64
- x2={xScale(criticalValue)}
65
- y1={groupMargin + 3 * lineMargin}
66
- y2={thresholdLineHeight + groupMargin + 3 * lineMargin}
67
- />
68
- <line
69
- data-testid="warning-line-tooltip"
70
- stroke="transparent"
71
- strokeWidth={5}
72
- x1={xScale(warningValue)}
73
- x2={xScale(warningValue)}
74
- y1={groupMargin + 3 * lineMargin}
75
- y2={thresholdLineHeight + groupMargin + 3 * lineMargin}
76
- onMouseEnter={onMouseEnter({
77
- label: warningTooltipLabel,
78
- left: xScale(warningValue)
79
- })}
80
- onMouseLeave={hideTooltip}
18
+ hideTooltip
19
+ }: Props): JSX.Element => (
20
+ <>
21
+ {thresholds.warning.map(({ value, label }) => (
22
+ <ThresholdLine
23
+ hideTooltip={hideTooltip}
24
+ key={`warning-${value.toString()}`}
25
+ label={label}
26
+ showTooltip={showTooltip}
27
+ thresholdType="warning"
28
+ value={value}
29
+ xScale={xScale}
81
30
  />
82
- <line
83
- data-testid="critical-line-tooltip"
84
- stroke="transparent"
85
- strokeWidth={5}
86
- x1={xScale(criticalValue)}
87
- x2={xScale(criticalValue)}
88
- y1={groupMargin + 3 * lineMargin}
89
- y2={thresholdLineHeight + groupMargin + 3 * lineMargin}
90
- onMouseEnter={onMouseEnter({
91
- label: criticalTooltipLabel,
92
- left: xScale(criticalValue)
93
- })}
94
- onMouseLeave={hideTooltip}
31
+ ))}
32
+ {thresholds.critical.map(({ value, label }) => (
33
+ <ThresholdLine
34
+ hideTooltip={hideTooltip}
35
+ key={`critical-${value.toString()}`}
36
+ label={label}
37
+ showTooltip={showTooltip}
38
+ thresholdType="critical"
39
+ value={value}
40
+ xScale={xScale}
95
41
  />
96
- </>
97
- );
98
- };
42
+ ))}
43
+ </>
44
+ );
99
45
 
100
46
  export default Thresholds;
@@ -1,8 +1,6 @@
1
- import { LineChartData } from '../common/models';
1
+ import { LineChartData, Thresholds } from '../common/models';
2
2
 
3
3
  export interface SingleBarProps {
4
4
  data?: LineChartData;
5
- disabledThresholds?: boolean;
6
- thresholdTooltipLabels: Array<string>;
7
- thresholds: Array<number>;
5
+ thresholds: Thresholds;
8
6
  }
@@ -2,7 +2,7 @@ import { isNil } from 'ramda';
2
2
 
3
3
  import { Typography, useTheme } from '@mui/material';
4
4
 
5
- import { LineChartData } from '../common/models';
5
+ import { LineChartData, Thresholds } from '../common/models';
6
6
  import {
7
7
  formatMetricValue,
8
8
  getMetricWithLatestData
@@ -13,19 +13,17 @@ import { useTextStyles } from './Text.styles';
13
13
 
14
14
  interface Props {
15
15
  data?: LineChartData;
16
- disabledThresholds?: boolean;
17
16
  labels: {
18
17
  critical: string;
19
18
  warning: string;
20
19
  };
21
- thresholds: Array<number>;
20
+ thresholds: Thresholds;
22
21
  }
23
22
 
24
23
  export const Text = ({
25
24
  thresholds,
26
25
  data,
27
- labels,
28
- disabledThresholds
26
+ labels
29
27
  }: Props): JSX.Element | null => {
30
28
  const theme = useTheme();
31
29
  const { classes } = useTextStyles();
@@ -44,6 +42,20 @@ export const Text = ({
44
42
  thresholds
45
43
  });
46
44
 
45
+ const warningThresholdLabels = thresholds.warning.map(({ value }) =>
46
+ formatMetricValue({
47
+ unit: metricUnit,
48
+ value
49
+ })
50
+ );
51
+
52
+ const criticalThresholdLabels = thresholds.critical.map(({ value }) =>
53
+ formatMetricValue({
54
+ unit: metricUnit,
55
+ value
56
+ })
57
+ );
58
+
47
59
  return (
48
60
  <div className={classes.graphText}>
49
61
  <Typography sx={{ color }} variant="h3">
@@ -53,25 +65,17 @@ export const Text = ({
53
65
  })}{' '}
54
66
  {metricUnit}
55
67
  </Typography>
56
- {!disabledThresholds && (
68
+ {thresholds.enabled && (
57
69
  <div className={classes.thresholds}>
58
70
  <Typography sx={{ color: 'warning.main' }} variant="h5">
59
71
  {labels.warning}
60
72
  {': '}
61
- {formatMetricValue({
62
- unit: metricUnit,
63
- value: thresholds[0]
64
- })}{' '}
65
- {metricUnit}
73
+ {warningThresholdLabels.join(' - ')} {metricUnit}
66
74
  </Typography>
67
75
  <Typography sx={{ color: 'error.main' }} variant="h5">
68
76
  {labels.critical}
69
77
  {': '}
70
- {formatMetricValue({
71
- unit: metricUnit,
72
- value: thresholds[1]
73
- })}{' '}
74
- {metricUnit}
78
+ {criticalThresholdLabels.join(' - ')} {metricUnit}
75
79
  </Typography>
76
80
  </div>
77
81
  )}
@@ -5,3 +5,15 @@ export interface LineChartData {
5
5
  metrics: Array<Metric>;
6
6
  times: Array<string>;
7
7
  }
8
+
9
+ export interface Thresholds {
10
+ critical: Array<{
11
+ label: string;
12
+ value: number;
13
+ }>;
14
+ enabled: boolean;
15
+ warning: Array<{
16
+ label: string;
17
+ value: number;
18
+ }>;
19
+ }
@@ -1,20 +1,73 @@
1
- import { T, always, cond, gt, head } from 'ramda';
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: Array<number>;
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
- cond([
17
- [gt(head(thresholds) as number), always(theme.palette.success.main)],
18
- [gt(thresholds[1]), always(theme.palette.warning.main)],
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
+ };
File without changes