@centreon/ui 23.10.68 → 23.10.70

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": "23.10.68",
3
+ "version": "23.10.70",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
@@ -45,7 +45,7 @@ const Layout = <T extends Layout>({
45
45
 
46
46
  return useMemoComponent({
47
47
  Component: (
48
- <ResponsiveHeight>
48
+ <ResponsiveHeight margin={40}>
49
49
  <Responsive.ParentSize>
50
50
  {({ width, height }): JSX.Element => (
51
51
  <div className={classes.container}>
@@ -2,7 +2,7 @@ import { useMemo, useRef } from 'react';
2
2
 
3
3
  import { Group, Tooltip } from '@visx/visx';
4
4
  import { scaleLinear } from '@visx/scale';
5
- import { flatten, head, pluck } from 'ramda';
5
+ import { equals, flatten, head, pluck } from 'ramda';
6
6
  import { Bar } from '@visx/shape';
7
7
  import { useSpring, animated } from '@react-spring/web';
8
8
 
@@ -18,7 +18,7 @@ import { margins } from '../common/margins';
18
18
 
19
19
  import { SingleBarProps } from './models';
20
20
  import Thresholds, { groupMargin } from './Thresholds';
21
- import { barHeight, margin } from './ThresholdLine';
21
+ import { barHeights } from './ThresholdLine';
22
22
 
23
23
  interface Props extends SingleBarProps {
24
24
  height: number;
@@ -36,7 +36,9 @@ const ResponsiveSingleBar = ({
36
36
  width,
37
37
  height,
38
38
  displayAsRaw,
39
- baseColor
39
+ baseColor,
40
+ size = 'medium',
41
+ showLabels = true
40
42
  }: Props): JSX.Element => {
41
43
  const theme = useTheme();
42
44
 
@@ -55,9 +57,6 @@ const ResponsiveSingleBar = ({
55
57
  head(metric.data) as number
56
58
  );
57
59
 
58
- const innerHeight = height;
59
- const centerY = innerHeight / 4;
60
-
61
60
  const {
62
61
  showTooltip,
63
62
  hideTooltip,
@@ -79,13 +78,24 @@ const ResponsiveSingleBar = ({
79
78
  [latestMetricData, thresholds, theme]
80
79
  );
81
80
 
82
- const text = (
81
+ const isSmall = equals(size, 'small');
82
+
83
+ const textStyle = isSmall
84
+ ? {
85
+ ...theme.typography.h6
86
+ }
87
+ : theme.typography.h3;
88
+
89
+ const text = showLabels && (
83
90
  <text
84
91
  dominantBaseline="middle"
85
- style={{ fill: barColor, ...theme.typography.h3 }}
92
+ style={{
93
+ fill: barColor,
94
+ ...textStyle
95
+ }}
86
96
  textAnchor="middle"
87
97
  x="50%"
88
- y={25}
98
+ y={isSmall ? 10 : 25}
89
99
  >
90
100
  {formatMetricValueWithUnit({
91
101
  base: 1000,
@@ -119,31 +129,32 @@ const ResponsiveSingleBar = ({
119
129
  return (
120
130
  <Box sx={{ position: 'relative' }}>
121
131
  <svg height={height} ref={svgRef} width={width}>
122
- <Group.Group top={centerY - margins.bottom}>
132
+ <Group.Group>
123
133
  {text}
124
134
  <animated.rect
125
135
  data-testid={`${latestMetricData}-bar-${barColor}`}
126
136
  fill={barColor}
127
- height={barHeight}
137
+ height={barHeights[size]}
128
138
  rx={4}
129
139
  style={springStyle}
130
140
  x={0}
131
- y={groupMargin + margin}
141
+ y={groupMargin + (isSmall ? 0 : 2 * margins.top)}
132
142
  />
133
143
  <Bar
134
144
  fill="transparent"
135
- height={barHeight}
145
+ height={barHeights[size]}
136
146
  rx={4}
137
147
  ry={4}
138
148
  stroke={alpha(theme.palette.text.primary, 0.3)}
139
149
  width={maxBarWidth}
140
150
  x={0}
141
- y={groupMargin + margin}
151
+ y={groupMargin + (isSmall ? 0 : 2 * margins.top)}
142
152
  />
143
153
  {thresholds.enabled && (
144
154
  <Thresholds
145
155
  hideTooltip={hideTooltip}
146
156
  showTooltip={showTooltip}
157
+ size={size}
147
158
  thresholds={thresholds}
148
159
  xScale={xScale}
149
160
  />
@@ -157,7 +168,8 @@ const ResponsiveSingleBar = ({
157
168
  ...baseStyles,
158
169
  backgroundColor: theme.palette.background.paper,
159
170
  color: theme.palette.text.primary,
160
- transform: 'translate(-50%, -20px)'
171
+ transform: `translate(-50%, ${isSmall ? -60 : -20}px)`,
172
+ zIndex: theme.zIndex.tooltip
161
173
  }}
162
174
  top={tooltipTop}
163
175
  >
@@ -161,8 +161,44 @@ export const RawValue: Story = {
161
161
  args: {
162
162
  data: dataLastWeek,
163
163
  displayAsRaw: true,
164
- thresholdTooltipLabels: ['Warning', 'Critical'],
165
- thresholds: [0.5, 1.5]
164
+ thresholds: {
165
+ critical: [
166
+ {
167
+ label: 'Critical',
168
+ value: 0.6
169
+ }
170
+ ],
171
+ enabled: false,
172
+ warning: [
173
+ {
174
+ label: 'Warning',
175
+ value: 0.5
176
+ }
177
+ ]
178
+ }
179
+ },
180
+ render: Template
181
+ };
182
+
183
+ export const Small: Story = {
184
+ args: {
185
+ data: dataLastWeek,
186
+ size: 'small',
187
+ thresholds: {
188
+ critical: [
189
+ {
190
+ label: 'Critical',
191
+ value: 0.6
192
+ }
193
+ ],
194
+ enabled: true,
195
+ warning: [
196
+ {
197
+ label: 'Warning',
198
+ value: 0.5
199
+ }
200
+ ]
201
+ }
166
202
  },
167
203
  render: Template
168
204
  };
@@ -2,18 +2,26 @@ import { equals } from 'ramda';
2
2
 
3
3
  import { useTheme } from '@mui/material';
4
4
 
5
+ import { margins } from '../common/margins';
6
+
5
7
  import { groupMargin } from './Thresholds';
6
8
 
7
- export const barHeight = 72;
9
+ export const barHeights = {
10
+ medium: 72,
11
+ small: 22
12
+ };
8
13
  export const margin = 40;
9
14
 
10
- const lineMargin = 10;
11
- const thresholdLineHeight = barHeight + 2 * lineMargin;
15
+ const lineMargins = {
16
+ medium: 10,
17
+ small: 5
18
+ };
12
19
 
13
20
  interface Props {
14
21
  hideTooltip: () => void;
15
22
  label: string;
16
23
  showTooltip: (args) => void;
24
+ size: 'small' | 'medium';
17
25
  thresholdType: string;
18
26
  value: number;
19
27
  xScale: (value: number) => number;
@@ -25,13 +33,20 @@ export const ThresholdLine = ({
25
33
  xScale,
26
34
  thresholdType,
27
35
  showTooltip,
28
- hideTooltip
36
+ hideTooltip,
37
+ size
29
38
  }: Props): JSX.Element => {
30
39
  const theme = useTheme();
31
40
 
32
41
  const scaledValue = xScale(value) || 0;
33
42
 
34
- const bottom = barHeight + margin * 2;
43
+ const lineMargin = lineMargins[size];
44
+
45
+ const thresholdLineHeight = barHeights[size] + 2 * lineMargin;
46
+
47
+ const isSmall = equals(size, 'small');
48
+
49
+ const bottom = barHeights[size] + margin * 2;
35
50
 
36
51
  const onMouseEnter = (left) => (): void =>
37
52
  showTooltip({
@@ -49,12 +64,20 @@ export const ThresholdLine = ({
49
64
  <line
50
65
  data-testid={`${thresholdType}-line-${value}`}
51
66
  stroke={lineColor}
52
- strokeDasharray={4}
67
+ strokeDasharray="6, 6"
53
68
  strokeWidth={2}
54
69
  x1={scaledValue}
55
70
  x2={scaledValue}
56
- y1={groupMargin + 3 * lineMargin}
57
- y2={thresholdLineHeight + groupMargin + 3 * lineMargin}
71
+ y1={
72
+ isSmall
73
+ ? groupMargin - lineMargin
74
+ : groupMargin + lineMargin + margins.top
75
+ }
76
+ y2={
77
+ isSmall
78
+ ? thresholdLineHeight + groupMargin - lineMargin
79
+ : thresholdLineHeight + groupMargin + lineMargin + margins.top
80
+ }
58
81
  />
59
82
  <line
60
83
  data-testid={`${thresholdType}-line-${value}-tooltip`}
@@ -62,8 +85,16 @@ export const ThresholdLine = ({
62
85
  strokeWidth={5}
63
86
  x1={scaledValue}
64
87
  x2={scaledValue}
65
- y1={groupMargin + 3 * lineMargin}
66
- y2={thresholdLineHeight + groupMargin + 3 * lineMargin}
88
+ y1={
89
+ isSmall
90
+ ? groupMargin - lineMargin
91
+ : groupMargin + lineMargin + margins.top
92
+ }
93
+ y2={
94
+ isSmall
95
+ ? thresholdLineHeight + groupMargin - lineMargin
96
+ : thresholdLineHeight + groupMargin + lineMargin + margins.top
97
+ }
67
98
  onMouseEnter={onMouseEnter(scaledValue)}
68
99
  onMouseLeave={hideTooltip}
69
100
  />
@@ -7,6 +7,7 @@ export const groupMargin = 25;
7
7
  interface Props {
8
8
  hideTooltip: () => void;
9
9
  showTooltip: (args) => void;
10
+ size: 'small' | 'medium';
10
11
  thresholds: Thresholds;
11
12
  xScale: (value: number) => number;
12
13
  }
@@ -15,7 +16,8 @@ const Thresholds = ({
15
16
  xScale,
16
17
  thresholds,
17
18
  showTooltip,
18
- hideTooltip
19
+ hideTooltip,
20
+ size
19
21
  }: Props): JSX.Element => (
20
22
  <>
21
23
  {thresholds.warning.map(({ value, label }) => (
@@ -24,6 +26,7 @@ const Thresholds = ({
24
26
  key={`warning-${value.toString()}`}
25
27
  label={label}
26
28
  showTooltip={showTooltip}
29
+ size={size}
27
30
  thresholdType="warning"
28
31
  value={value}
29
32
  xScale={xScale}
@@ -35,6 +38,7 @@ const Thresholds = ({
35
38
  key={`critical-${value.toString()}`}
36
39
  label={label}
37
40
  showTooltip={showTooltip}
41
+ size={size}
38
42
  thresholdType="critical"
39
43
  value={value}
40
44
  xScale={xScale}
@@ -4,5 +4,7 @@ export interface SingleBarProps {
4
4
  baseColor?: string;
5
5
  data?: LineChartData;
6
6
  displayAsRaw?: boolean;
7
+ showLabels?: boolean;
8
+ size?: 'medium' | 'small';
7
9
  thresholds: Thresholds;
8
10
  }
@@ -16,8 +16,8 @@ export interface Metric {
16
16
  crit: number | null;
17
17
  critical_high_threshold: number | null;
18
18
  critical_low_threshold: number | null;
19
- data: Array<number>;
20
- ds_data: DsData;
19
+ data: Array<number | null>;
20
+ ds_data?: DsData;
21
21
  legend: string;
22
22
  maximum_value: number | null;
23
23
  metric: string;