@centreon/ui 23.10.18-MON-17793-create-graph-component-centreon-ui.8 → 23.10.18-MON-17793-create-graph-component-centreon-ui.10

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.18-MON-17793-create-graph-component-centreon-ui.8",
3
+ "version": "23.10.18-MON-17793-create-graph-component-centreon-ui.10",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
@@ -26,12 +26,19 @@ import useAnchorPoint from './IntercatifsComponents/AnchorPoint/useAnchorPoint';
26
26
  import GraphTooltip from './IntercatifsComponents/Tooltip';
27
27
  import useGraphTooltip from './IntercatifsComponents/Tooltip/useGraphTooltip';
28
28
  import Legend from './Legend';
29
- import { Data, GlobalAreaLines, GraphInterval, GraphProps } from './models';
29
+ import {
30
+ Data,
31
+ GlobalAreaLines,
32
+ GraphInterval,
33
+ GraphProps,
34
+ LegendModel
35
+ } from './models';
30
36
  import { getLeftScale, getRightScale, getXScale } from './timeSeries';
31
37
 
32
38
  interface Props extends GraphProps {
33
39
  graphData: Data;
34
40
  graphInterval: GraphInterval;
41
+ legend?: LegendModel;
35
42
  loading: boolean;
36
43
  shapeLines?: GlobalAreaLines;
37
44
  }
@@ -48,7 +55,8 @@ const Graph = ({
48
55
  graphInterval,
49
56
  timeShiftZones,
50
57
  annotationEvent,
51
- tooltip
58
+ tooltip,
59
+ legend
52
60
  }: Props): JSX.Element => {
53
61
  const graphSvgRef = useRef<SVGSVGElement | null>(null);
54
62
 
@@ -261,7 +269,12 @@ const Graph = ({
261
269
  </Group.Group>
262
270
  </svg>
263
271
  <GraphTooltip {...tooltip} {...graphTooltipData} />
264
- <Legend base={baseAxis} lines={newLines} timeSeries={timeSeries} />
272
+ <Legend
273
+ base={baseAxis}
274
+ lines={newLines}
275
+ renderExtraComponent={legend?.renderExtraComponent}
276
+ timeSeries={timeSeries}
277
+ />
265
278
  </div>
266
279
  </ClickAwayListener>
267
280
  </>
@@ -1,3 +1,5 @@
1
+ import { ReactNode } from 'react';
2
+
1
3
  import { slice } from 'ramda';
2
4
 
3
5
  import { Box, alpha, useTheme } from '@mui/material';
@@ -20,6 +22,7 @@ interface Props {
20
22
  base: number;
21
23
  limitLegendRows?: boolean;
22
24
  lines: Array<Line>;
25
+ renderExtraComponent?: ReactNode;
23
26
  timeSeries: Array<TimeValue>;
24
27
  toggable?: boolean;
25
28
  }
@@ -29,7 +32,8 @@ const Legend = ({
29
32
  timeSeries,
30
33
  base,
31
34
  toggable = true,
32
- limitLegendRows = true
35
+ limitLegendRows = true,
36
+ renderExtraComponent
33
37
  }: Props): JSX.Element => {
34
38
  const { classes, cx } = useStyles({ limitLegendRows });
35
39
  const theme = useTheme();
@@ -127,6 +131,7 @@ const Legend = ({
127
131
  );
128
132
  })}
129
133
  </div>
134
+ {renderExtraComponent}
130
135
  </div>
131
136
  );
132
137
  };
@@ -9,7 +9,7 @@ import timezonePlugin from 'dayjs/plugin/timezone';
9
9
  import utcPlugin from 'dayjs/plugin/utc';
10
10
 
11
11
  import Graph from './Graph';
12
- import { GlobalAreaLines, GraphData, GraphProps } from './models';
12
+ import { GlobalAreaLines, GraphData, GraphProps, LegendModel } from './models';
13
13
  import useGraphData from './useGraphData';
14
14
 
15
15
  dayjs.extend(localizedFormat);
@@ -19,6 +19,7 @@ dayjs.extend(timezonePlugin);
19
19
  interface Props extends Partial<GraphProps> {
20
20
  data: GraphData;
21
21
  end: string;
22
+ legend: LegendModel;
22
23
  loading: boolean;
23
24
  shapeLines?: GlobalAreaLines;
24
25
  start: string;
@@ -37,7 +38,8 @@ const WrapperGraph = ({
37
38
  loading,
38
39
  timeShiftZones,
39
40
  tooltip,
40
- annotationEvent
41
+ annotationEvent,
42
+ legend
41
43
  }: Props): JSX.Element | null => {
42
44
  const { adjustedData } = useGraphData({ data, end, start });
43
45
 
@@ -59,6 +61,7 @@ const WrapperGraph = ({
59
61
  graphData={{ ...adjustedData }}
60
62
  graphInterval={{ end, start }}
61
63
  height={height ?? responsiveHeight}
64
+ legend={legend}
62
65
  loading={loading}
63
66
  shapeLines={shapeLines}
64
67
  timeShiftZones={timeShiftZones}
@@ -110,3 +110,6 @@ export interface GlobalAreaLines {
110
110
  areaStackedLines?: Area;
111
111
  areaThresholdLines?: ThresholdArea;
112
112
  }
113
+ export interface LegendModel {
114
+ renderExtraComponent?: ReactNode;
115
+ }
@@ -1,4 +1,5 @@
1
1
  import { useAtomValue } from 'jotai';
2
+ import { useTranslation } from 'react-i18next';
2
3
 
3
4
  import AccessTimeIcon from '@mui/icons-material/AccessTime';
4
5
  import { Button, Typography } from '@mui/material';
@@ -6,6 +7,11 @@ import { Button, Typography } from '@mui/material';
6
7
  import { dateTimeFormat, useLocaleDateTimeFormat } from '@centreon/ui';
7
8
 
8
9
  import { customTimePeriodAtom } from '../timePeriodsAtoms';
10
+ import {
11
+ labelCompactTimePeriod,
12
+ labelFrom,
13
+ labelTo
14
+ } from '../translatedLabels';
9
15
 
10
16
  import useStyles from './CompactCustomTimePeriod.styles';
11
17
 
@@ -19,6 +25,7 @@ const CompactCustomTimePeriod = ({
19
25
  disabled = false
20
26
  }: Props): JSX.Element => {
21
27
  const { classes } = useStyles();
28
+ const { t } = useTranslation();
22
29
 
23
30
  const { format } = useLocaleDateTimeFormat();
24
31
 
@@ -27,10 +34,10 @@ const CompactCustomTimePeriod = ({
27
34
  return (
28
35
  <div>
29
36
  <Button
30
- aria-label="CompactTimePeriod"
37
+ aria-label={t(labelCompactTimePeriod) as string}
31
38
  className={classes.button}
32
39
  color="primary"
33
- data-testid="Compact time period"
40
+ data-testid={labelCompactTimePeriod}
34
41
  disabled={disabled}
35
42
  variant="outlined"
36
43
  onClick={onClick}
@@ -44,7 +51,7 @@ const CompactCustomTimePeriod = ({
44
51
  component="div"
45
52
  variant="caption"
46
53
  >
47
- From:
54
+ {t(labelFrom)}:
48
55
  </Typography>
49
56
 
50
57
  <Typography
@@ -64,7 +71,7 @@ const CompactCustomTimePeriod = ({
64
71
  component="div"
65
72
  variant="caption"
66
73
  >
67
- To:
74
+ {t(labelTo)}:
68
75
  </Typography>
69
76
 
70
77
  <Typography
@@ -1,6 +1,7 @@
1
1
  import { useAtomValue, useSetAtom } from 'jotai';
2
2
  import { T, always, cond, equals, lte, map, pick } from 'ramda';
3
3
  import { makeStyles } from 'tss-react/mui';
4
+ import { useTranslation } from 'react-i18next';
4
5
 
5
6
  import { Button, ButtonGroup, Tooltip, useTheme } from '@mui/material';
6
7
 
@@ -35,7 +36,7 @@ const SelectedTimePeriod = ({
35
36
  }: Props): JSX.Element => {
36
37
  const { classes } = useStyles();
37
38
  const theme = useTheme();
38
-
39
+ const { t } = useTranslation();
39
40
  const selectedTimePeriodData = useAtomValue(selectedTimePeriodAtom);
40
41
 
41
42
  const changeSelectedTimePeriod = useSetAtom(
@@ -52,6 +53,12 @@ const SelectedTimePeriod = ({
52
53
  currentTimePeriods
53
54
  );
54
55
 
56
+ const translatedTimePeriodOptions = timePeriodOptions.map((timePeriod) => ({
57
+ ...timePeriod,
58
+ largeName: t(timePeriod.largeName),
59
+ name: t(timePeriod.name)
60
+ }));
61
+
55
62
  return (
56
63
  <ButtonGroup
57
64
  className={classes.buttonGroup}
@@ -86,7 +93,7 @@ const SelectedTimePeriod = ({
86
93
  </Button>
87
94
  </Tooltip>
88
95
  ),
89
- timePeriodOptions
96
+ translatedTimePeriodOptions
90
97
  )}
91
98
  </ButtonGroup>
92
99
  );
@@ -1,5 +1,14 @@
1
1
  import dayjs from 'dayjs';
2
2
 
3
+ import {
4
+ labelLastDay,
5
+ label1Day,
6
+ label7Days,
7
+ label31Days,
8
+ labelLast7Days,
9
+ labelLast31Days
10
+ } from './translatedLabels';
11
+
3
12
  export const dateFormat = 'L';
4
13
  export const timeFormat = 'LT';
5
14
  export const dateTimeFormat = `${dateFormat} ${timeFormat}`;
@@ -18,13 +27,6 @@ export interface TimePeriod {
18
27
  timelineEventsLimit: number;
19
28
  }
20
29
 
21
- export const label1Day = '1 day';
22
- export const label7Days = '7 days';
23
- export const label31Days = '31 days';
24
- export const labelLastDay = 'Last day';
25
- export const labelLast7Days = 'Last 7 days';
26
- export const labelLast31Days = 'Last 31 days';
27
-
28
30
  export const lastDayPeriod: TimePeriod = {
29
31
  dateTimeFormat: timeFormat,
30
32
  getStart: (): Date => dayjs(Date.now()).subtract(24, 'hour').toDate(),
@@ -0,0 +1,9 @@
1
+ export const label1Day = '1 day';
2
+ export const label7Days = '7 days';
3
+ export const label31Days = '31 days';
4
+ export const labelLastDay = 'Last day';
5
+ export const labelLast7Days = 'Last 7 days';
6
+ export const labelLast31Days = 'Last 31 days';
7
+ export const labelFrom = 'From';
8
+ export const labelTo = 'To';
9
+ export const labelCompactTimePeriod = 'Compact time period';