@centreon/ui 24.10.22 → 24.10.24

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": "24.10.22",
3
+ "version": "24.10.24",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -24,8 +24,8 @@
24
24
  "url": "git+https://github.com/centreon/centreon.git"
25
25
  },
26
26
  "keywords": [
27
- "centreon",
28
- "react"
27
+ "react",
28
+ "centreon"
29
29
  ],
30
30
  "author": {
31
31
  "name": "centreon@centreon.com"
@@ -191,7 +191,7 @@ describe('Bar chart', () => {
191
191
  cy.contains('Centreon-Server: Round-Trip Maximum Time').should(
192
192
  'be.visible'
193
193
  );
194
- cy.contains('7.47 KB').should('be.visible');
194
+ cy.contains('7.47 KiB').should('be.visible');
195
195
 
196
196
  cy.makeSnapshot();
197
197
  });
@@ -61,7 +61,7 @@ const ResponsiveBarChart = ({
61
61
 
62
62
  const { classes, cx } = useTooltipStyles();
63
63
 
64
- const [linesGraph, setLinesGraph] = useState<Array<Line>>(lines);
64
+ const [linesGraph, setLinesGraph] = useState<Array<Line>>(lines || []);
65
65
  const graphSvgRef = useRef<SVGSVGElement | null>(null);
66
66
 
67
67
  const [tooltipData, setTooltipData] = useAtom(tooltipDataAtom);
@@ -74,7 +74,7 @@ const ResponsiveBarChart = ({
74
74
  );
75
75
 
76
76
  const [firstUnit, secondUnit] = getUnits(displayedLines);
77
- const allUnits = getUnits(lines);
77
+ const allUnits = getUnits(lines || []);
78
78
 
79
79
  const { maxLeftAxisCharacters, maxRightAxisCharacters } =
80
80
  useComputeYAxisMaxCharacters({
@@ -147,12 +147,12 @@ const ResponsiveBarChart = ({
147
147
  ]
148
148
  );
149
149
 
150
- const leftScale = yScalesPerUnit[firstUnit];
151
- const rightScale = yScalesPerUnit[secondUnit];
150
+ const leftScale = yScalesPerUnit[firstUnit ?? allUnits[0]];
151
+ const rightScale = yScalesPerUnit[secondUnit ?? allUnits[1]];
152
152
 
153
153
  useEffect(
154
154
  () => {
155
- setLinesGraph(lines);
155
+ setLinesGraph(lines || []);
156
156
  },
157
157
  useDeepCompare([lines])
158
158
  );
@@ -676,7 +676,7 @@ describe('Lines and bars', () => {
676
676
  cy.findByLabelText('B').click();
677
677
 
678
678
  cy.findAllByTestId('unit-selector').eq(0).should('have.value', 'B');
679
- cy.contains('8.79 KB').should('be.visible');
679
+ cy.contains('8.79 KiB').should('be.visible');
680
680
 
681
681
  cy.findAllByTestId('unit-selector').eq(1).parent().click();
682
682
  cy.findByLabelText('%').click();
@@ -194,8 +194,11 @@ const Chart = ({
194
194
  ]
195
195
  );
196
196
 
197
- const leftScale = yScalesPerUnit[axis?.axisYLeft?.unit ?? firstUnit];
198
- const rightScale = yScalesPerUnit[axis?.axisYRight?.unit ?? secondUnit];
197
+ const fallbackLeftUnit = axis?.axisYLeft?.unit ?? firstUnit ?? allUnits[0];
198
+ const fallbackRightUnit = axis?.axisYRight?.unit ?? secondUnit ?? allUnits[1];
199
+
200
+ const leftScale = yScalesPerUnit[fallbackLeftUnit];
201
+ const rightScale = yScalesPerUnit[fallbackRightUnit];
199
202
 
200
203
  const linesDisplayedAsLine = useMemo(
201
204
  () =>
@@ -31,6 +31,15 @@ interface Props {
31
31
  }
32
32
 
33
33
  const getBoolean = (value) => Boolean(Number(value));
34
+ const defaultDsData = {
35
+ ds_color_line: '#000000',
36
+ ds_filled: false,
37
+ ds_invert: false,
38
+ ds_legend: '',
39
+ ds_order: '0',
40
+ ds_stack: '0',
41
+ ds_transparency: 80
42
+ };
34
43
 
35
44
  const useGraphData = ({ data, end, start }: Props): GraphDataResult => {
36
45
  const adjustedDataRef = useRef<Data>();
@@ -44,9 +53,21 @@ const useGraphData = ({ data, end, start }: Props): GraphDataResult => {
44
53
  return undefined;
45
54
  }
46
55
 
56
+ const metricsWithValidDsData = (data?.metrics || []).map((metric) => ({
57
+ ...metric,
58
+ ds_data: {
59
+ ...defaultDsData,
60
+ ...(metric?.ds_data || {}),
61
+ ds_color_area:
62
+ metric?.ds_data?.ds_color_area ??
63
+ metric?.ds_data?.ds_color_line ??
64
+ defaultDsData.ds_color_line
65
+ }
66
+ }));
67
+
47
68
  const metricsGroupedByColor = groupBy(
48
- (metric) => metric.ds_data.ds_color_line
49
- )(data?.metrics || []);
69
+ (metric) => metric.ds_data?.ds_color_line || '#000000'
70
+ )(metricsWithValidDsData);
50
71
 
51
72
  const newMetrics = Object.entries(metricsGroupedByColor).map(
52
73
  ([color, value]) => {
@@ -59,7 +59,7 @@ const Axes = ({
59
59
  const formatAxisTick = (tick): string =>
60
60
  format({ date: new Date(tick), formatString: tickFormat });
61
61
 
62
- const displayAxisRight = !isNil(secondUnit);
62
+ const displayAxisRight = !isNil(secondUnit) && !isNil(rightScale);
63
63
 
64
64
  const AxisBottom = isHorizontal ? Axis.AxisBottom : Axis.AxisLeft;
65
65
  const AxisLeft = isHorizontal ? Axis.AxisLeft : Axis.AxisTop;
@@ -49,6 +49,11 @@ const ChartSvgWrapper = ({
49
49
  hasSecondUnit
50
50
  }: Props): JSX.Element => {
51
51
  const isHorizontal = equals(orientation, 'horizontal');
52
+ const hasValidLeftScale = Boolean(leftScale);
53
+ const hasValidXScale = Boolean(xScale);
54
+ const canRenderAxes = hasValidLeftScale && hasValidXScale;
55
+ const canRenderGridRows = Boolean(isHorizontal ? leftScale : xScale);
56
+ const canRenderGridColumns = Boolean(isHorizontal ? xScale : leftScale);
52
57
 
53
58
  return (
54
59
  <svg
@@ -64,7 +69,7 @@ const ChartSvgWrapper = ({
64
69
  }
65
70
  top={margin.top}
66
71
  >
67
- {showGridLines && (
72
+ {showGridLines && (canRenderGridRows || canRenderGridColumns) && (
68
73
  <Grids
69
74
  gridLinesType={gridLinesType}
70
75
  height={graphHeight - margin.top}
@@ -73,21 +78,23 @@ const ChartSvgWrapper = ({
73
78
  xScale={isHorizontal ? xScale : leftScale}
74
79
  />
75
80
  )}
76
- <Axes
77
- allUnits={allUnits}
78
- data={{
79
- baseAxis: base,
80
- lines: displayedLines,
81
- timeSeries,
82
- ...axis
83
- }}
84
- height={graphHeight}
85
- leftScale={leftScale}
86
- orientation={orientation}
87
- rightScale={rightScale}
88
- width={graphWidth}
89
- xScale={xScale}
90
- />
81
+ {canRenderAxes && (
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
+ />
97
+ )}
91
98
  {children}
92
99
  </Group.Group>
93
100
  </svg>
@@ -8,9 +8,9 @@ import { ChartAxis } from '../../Chart/models';
8
8
 
9
9
  interface Props extends Pick<ChartAxis, 'gridLinesType'> {
10
10
  height: number;
11
- leftScale: ScaleLinear<number, number>;
11
+ leftScale?: ScaleLinear<number, number>;
12
12
  width: number;
13
- xScale: ScaleLinear<number, number>;
13
+ xScale?: ScaleLinear<number, number>;
14
14
  }
15
15
 
16
16
  const Grids = ({
@@ -31,10 +31,10 @@ const Grids = ({
31
31
 
32
32
  return (
33
33
  <g>
34
- {displayRows && (
34
+ {displayRows && leftScale && (
35
35
  <Grid.GridRows height={height} scale={leftScale} width={width} />
36
36
  )}
37
- {displayColumns && (
37
+ {displayColumns && xScale && (
38
38
  <Grid.GridColumns height={height} scale={xScale} width={width} />
39
39
  )}
40
40
  </g>
@@ -362,10 +362,10 @@ describe('timeSeries', () => {
362
362
  describe(formatMetricValue, () => {
363
363
  const cases: Array<TestCase> = [
364
364
  [218857269, '', 1000, '218.86m'],
365
- [218857269, '', 1024, '208.72 M'],
365
+ [218857269, '', 1024, '208.72 Mi'],
366
366
  [0.12232323445, '', 1000, '0.12'],
367
- [1024, 'B', 1000, '1 KB'],
368
- [1024, 'B', 1024, '1 KB'],
367
+ [1024, 'B', 1000, '1 KiB'],
368
+ [1024, 'B', 1024, '1 KiB'],
369
369
  [null, 'B', 1024, null]
370
370
  ];
371
371
 
@@ -553,7 +553,7 @@ describe('Format value with unit', () => {
553
553
  return '324.23m';
554
554
  }
555
555
 
556
- return `309.21 M${unit}`;
556
+ return `309.21 Mi${unit}`;
557
557
  };
558
558
 
559
559
  const humanReadableTestCases = units.map((unit) => {
@@ -53,6 +53,17 @@ interface TimeTickWithMetrics {
53
53
  timeTick: string;
54
54
  }
55
55
 
56
+ const defaultDsData = {
57
+ ds_color_line: '#000000',
58
+ ds_filled: false,
59
+ ds_invert: false,
60
+ ds_legend: '',
61
+ ds_order: '0',
62
+ ds_stack: '0',
63
+ ds_stack_key: null,
64
+ ds_transparency: 80
65
+ };
66
+
56
67
  const toTimeTickWithMetrics = ({
57
68
  metrics,
58
69
  times
@@ -119,29 +130,41 @@ const toLine = ({
119
130
  maximum_value,
120
131
  metric_id,
121
132
  displayAs
122
- }: Metric): Line => ({
123
- areaColor: ds_data.ds_color_area,
124
- average_value,
125
- color: ds_data.ds_color_line,
126
- display: true,
127
- displayAs,
128
- filled: ds_data.ds_filled,
129
- highlight: undefined,
130
- invert: ds_data.ds_invert,
131
- legend: ds_data.ds_legend,
132
- lineColor: ds_data.ds_color_line,
133
- maximum_value,
134
- metric,
135
- metric_id,
136
- minimum_value,
137
- name: legend,
138
- stackOrder:
139
- equals(ds_data.ds_stack, '1') || equals(ds_data.ds_stack, true)
140
- ? Number.parseInt(ds_data.ds_order || '0', 10)
141
- : null,
142
- transparency: ds_data.ds_transparency,
143
- unit
144
- });
133
+ }: Metric): Line => {
134
+ const safeDsData = {
135
+ ...defaultDsData,
136
+ ...(ds_data || {}),
137
+ ds_color_area:
138
+ ds_data?.ds_color_area ??
139
+ ds_data?.ds_color_line ??
140
+ defaultDsData.ds_color_line
141
+ };
142
+
143
+ return {
144
+ areaColor: safeDsData.ds_color_area,
145
+ average_value,
146
+ color: safeDsData.ds_color_line,
147
+ display: true,
148
+ displayAs,
149
+ filled: safeDsData.ds_filled,
150
+ highlight: undefined,
151
+ invert: safeDsData.ds_invert,
152
+ legend: safeDsData.ds_legend,
153
+ lineColor: safeDsData.ds_color_line,
154
+ maximum_value,
155
+ metric,
156
+ metric_id,
157
+ minimum_value,
158
+ name: legend,
159
+ stackKey: safeDsData.ds_stack_key || null,
160
+ stackOrder:
161
+ equals(safeDsData.ds_stack, '1') || equals(safeDsData.ds_stack, true)
162
+ ? Number.parseInt(safeDsData.ds_order || '0', 10)
163
+ : null,
164
+ transparency: safeDsData.ds_transparency,
165
+ unit
166
+ };
167
+ };
145
168
 
146
169
  const getLineData = (graphData: LineChartData): Array<Line> =>
147
170
  map(toLine, graphData.metrics);
@@ -607,7 +630,7 @@ const formatMetricValue = ({
607
630
 
608
631
  const formattedMetricValue = numeral(Math.abs(value))
609
632
  .format(`0.[00]${formatSuffix}`)
610
- .replace(/iB/g, unit);
633
+ .replace(/B/, unit);
611
634
 
612
635
  if (lt(value, 0)) {
613
636
  return `-${formattedMetricValue}`;
@@ -9,7 +9,8 @@ interface DsData {
9
9
  ds_invert: string | null;
10
10
  ds_legend: string | null;
11
11
  ds_order: string | null;
12
- ds_stack: string | null;
12
+ ds_stack: string | boolean | null;
13
+ ds_stack_key?: string | null;
13
14
  ds_transparency: number;
14
15
  }
15
16
 
@@ -56,6 +57,7 @@ export interface Line {
56
57
  minimum_value: number | null;
57
58
  name: string;
58
59
  stackOrder: number | null;
60
+ stackKey: string | null;
59
61
  transparency: number;
60
62
  unit: string;
61
63
  }