@centreon/ui 24.5.11 → 24.5.13

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.5.11",
3
+ "version": "24.5.13",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -9,7 +9,7 @@ import { alpha, useTheme } from '@mui/material';
9
9
  import { GraphInterval, Interval } from '../../models';
10
10
 
11
11
  import { TimeShiftDirection } from './models';
12
- import useTimeShiftZones from './useTimeShiftZones';
12
+ import { useTimeShiftZones } from './useTimeShiftZones';
13
13
 
14
14
  export const timeShiftZoneWidth = 50;
15
15
 
@@ -11,7 +11,10 @@ interface Props {
11
11
  graphInterval: GraphInterval;
12
12
  }
13
13
 
14
- const useTimeShiftZones = ({ graphInterval, direction }: Props): Interval => {
14
+ export const useTimeShiftZones = ({
15
+ graphInterval,
16
+ direction
17
+ }: Props): Interval => {
15
18
  const shiftRatio = 2;
16
19
 
17
20
  const [start, setStart] = useState<Date>();
@@ -68,5 +71,3 @@ const useTimeShiftZones = ({ graphInterval, direction }: Props): Interval => {
68
71
 
69
72
  return { end, start } as Interval;
70
73
  };
71
-
72
- export default useTimeShiftZones;
@@ -2,7 +2,7 @@ import { makeStyles } from 'tss-react/mui';
2
2
 
3
3
  const useStyles = makeStyles()((theme) => ({
4
4
  button: {
5
- height: '100%',
5
+ maxHeight: theme.spacing(4.5),
6
6
  padding: theme.spacing(0, 0.5)
7
7
  },
8
8
  buttonContent: {
@@ -11,11 +11,11 @@ const useStyles = makeStyles()((theme) => ({
11
11
  display: 'flex'
12
12
  },
13
13
  containerDates: {
14
- display: 'flex',
15
- [theme.breakpoints.down('sm')]: {
16
- flexDirection: 'column',
17
- gap: theme.spacing(0.5)
18
- }
14
+ display: 'flex'
15
+ },
16
+ containerDatesCondensed: {
17
+ flexDirection: 'column',
18
+ gap: theme.spacing(0.5)
19
19
  },
20
20
  date: {
21
21
  minWidth: theme.spacing(12),
@@ -40,10 +40,10 @@ const useStyles = makeStyles()((theme) => ({
40
40
  alignItems: 'center',
41
41
  columnGap: theme.spacing(0.5),
42
42
  display: 'flex',
43
- flexDirection: 'row',
44
- [theme.breakpoints.down('sm')]: {
45
- alignItems: 'flex-start'
46
- }
43
+ flexDirection: 'row'
44
+ },
45
+ timeContainerCondensed: {
46
+ alignItems: 'flex-start'
47
47
  }
48
48
  }));
49
49
 
@@ -17,14 +17,16 @@ import useStyles from './CompactCustomTimePeriod.styles';
17
17
 
18
18
  interface Props {
19
19
  disabled?: boolean;
20
+ isCondensed?: boolean;
20
21
  onClick: (event) => void;
21
22
  }
22
23
 
23
24
  const CompactCustomTimePeriod = ({
24
25
  onClick,
25
- disabled = false
26
+ disabled = false,
27
+ isCondensed = false
26
28
  }: Props): JSX.Element => {
27
- const { classes } = useStyles();
29
+ const { classes, cx } = useStyles();
28
30
  const { t } = useTranslation();
29
31
 
30
32
  const { format } = useLocaleDateTimeFormat();
@@ -32,63 +34,73 @@ const CompactCustomTimePeriod = ({
32
34
  const customTimePeriod = useAtomValue(customTimePeriodAtom);
33
35
 
34
36
  return (
35
- <div>
36
- <Button
37
- aria-label={t(labelCompactTimePeriod) as string}
38
- className={classes.button}
39
- color="primary"
40
- data-testid={labelCompactTimePeriod}
41
- disabled={disabled}
42
- variant="outlined"
43
- onClick={onClick}
44
- >
45
- <div className={classes.buttonContent}>
46
- <AccessTimeIcon />
47
- <div className={classes.containerDates}>
48
- <div className={classes.timeContainer}>
49
- <Typography
50
- className={classes.label}
51
- component="div"
52
- variant="caption"
53
- >
54
- {t(labelFrom)}:
55
- </Typography>
37
+ <Button
38
+ aria-label={t(labelCompactTimePeriod) as string}
39
+ className={classes.button}
40
+ color="primary"
41
+ data-testid={labelCompactTimePeriod}
42
+ disabled={disabled}
43
+ variant="outlined"
44
+ onClick={onClick}
45
+ >
46
+ <div className={classes.buttonContent}>
47
+ <AccessTimeIcon />
48
+ <div
49
+ className={cx(classes.containerDates, {
50
+ [classes.containerDatesCondensed]: isCondensed
51
+ })}
52
+ >
53
+ <div
54
+ className={cx(classes.timeContainer, {
55
+ [classes.timeContainerCondensed]: isCondensed
56
+ })}
57
+ >
58
+ <Typography
59
+ className={classes.label}
60
+ component="div"
61
+ variant="caption"
62
+ >
63
+ {t(labelFrom)}:
64
+ </Typography>
56
65
 
57
- <Typography
58
- className={classes.date}
59
- component="div"
60
- variant="caption"
61
- >
62
- {format({
63
- date: customTimePeriod.start,
64
- formatString: dateTimeFormat
65
- })}
66
- </Typography>
67
- </div>
68
- <div className={classes.timeContainer}>
69
- <Typography
70
- className={classes.label}
71
- component="div"
72
- variant="caption"
73
- >
74
- {t(labelTo)}:
75
- </Typography>
66
+ <Typography
67
+ className={classes.date}
68
+ component="div"
69
+ variant="caption"
70
+ >
71
+ {format({
72
+ date: customTimePeriod.start,
73
+ formatString: dateTimeFormat
74
+ })}
75
+ </Typography>
76
+ </div>
77
+ <div
78
+ className={cx(classes.timeContainer, {
79
+ [classes.timeContainerCondensed]: isCondensed
80
+ })}
81
+ >
82
+ <Typography
83
+ className={classes.label}
84
+ component="div"
85
+ variant="caption"
86
+ >
87
+ {t(labelTo)}:
88
+ </Typography>
76
89
 
77
- <Typography
78
- className={classes.date}
79
- component="div"
80
- variant="caption"
81
- >
82
- {format({
83
- date: customTimePeriod.end,
84
- formatString: dateTimeFormat
85
- })}
86
- </Typography>
87
- </div>
90
+ <Typography
91
+ className={classes.date}
92
+ component="div"
93
+ variant="caption"
94
+ >
95
+ {format({
96
+ date: customTimePeriod.end,
97
+ formatString: dateTimeFormat
98
+ })}
99
+ </Typography>
88
100
  </div>
89
101
  </div>
90
- </Button>
91
- </div>
102
+ </div>
103
+ </Button>
92
104
  );
93
105
  };
94
106
 
@@ -14,9 +14,13 @@ import PopoverCustomTimePeriod from './PopoverCustomTimePeriod';
14
14
 
15
15
  interface Props {
16
16
  disabled?: boolean;
17
+ isCondensed?: boolean;
17
18
  }
18
19
 
19
- const CustomTimePeriod = ({ disabled = false }: Props): JSX.Element => {
20
+ const CustomTimePeriod = ({
21
+ disabled = false,
22
+ isCondensed = false
23
+ }: Props): JSX.Element => {
20
24
  const [anchorEl, setAnchorEl] = useState<HTMLButtonElement>();
21
25
 
22
26
  const customTimePeriod = useAtomValue(customTimePeriodAtom);
@@ -42,6 +46,7 @@ const CustomTimePeriod = ({ disabled = false }: Props): JSX.Element => {
42
46
  <>
43
47
  <CompactCustomTimePeriod
44
48
  disabled={disabled}
49
+ isCondensed={isCondensed}
45
50
  onClick={onClickCompactCustomTimePeriod}
46
51
  />
47
52
  <PopoverCustomTimePeriod
@@ -5,12 +5,13 @@ interface StylesProps {
5
5
  }
6
6
 
7
7
  export const useStyles = makeStyles<StylesProps>()((theme, { disabled }) => ({
8
+ condensed: {
9
+ flexWrap: 'wrap',
10
+ justifyContent: 'center',
11
+ rowGap: theme.spacing(1)
12
+ },
8
13
  header: {
9
- [theme.breakpoints.down('sm')]: {
10
- flexWrap: 'wrap',
11
- justifyContent: 'center',
12
- rowGap: theme.spacing(1)
13
- },
14
+ alignItems: 'center',
14
15
  backgroundColor: disabled ? 'transparent' : 'undefined',
15
16
  border: disabled ? 'unset' : 'undefined',
16
17
  boxShadow: disabled ? 'unset' : 'undefined',
@@ -0,0 +1,59 @@
1
+ import dayjs from 'dayjs';
2
+ import 'dayjs/locale/en';
3
+ import 'dayjs/locale/es';
4
+ import 'dayjs/locale/fr';
5
+ import 'dayjs/locale/pt';
6
+ import duration from 'dayjs/plugin/duration';
7
+ import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
8
+ import timezonePlugin from 'dayjs/plugin/timezone';
9
+ import utcPlugin from 'dayjs/plugin/utc';
10
+ import { lt } from 'ramda';
11
+
12
+ import { Paper, Theme, useMediaQuery } from '@mui/material';
13
+
14
+ import CustomTimePeriod from './CustomTimePeriod';
15
+ import SelectedTimePeriod from './SelectedTimePeriod';
16
+ import { useStyles } from './TimePeriods.styles';
17
+ import useTimePeriod from './useTimePeriod';
18
+ import { WrapperTimePeriodProps } from './models';
19
+
20
+ dayjs.extend(isSameOrAfter);
21
+ dayjs.extend(utcPlugin);
22
+ dayjs.extend(timezonePlugin);
23
+ dayjs.extend(duration);
24
+
25
+ const TimePeriods = ({
26
+ extraTimePeriods,
27
+ disabled = false,
28
+ getParameters,
29
+ getIsError,
30
+ adjustTimePeriodData,
31
+ renderExternalComponent,
32
+ width
33
+ }: WrapperTimePeriodProps & { width: number }): JSX.Element => {
34
+ const { classes, cx } = useStyles({ disabled });
35
+
36
+ useTimePeriod({
37
+ adjustTimePeriodData,
38
+ getIsError,
39
+ getParameters
40
+ });
41
+
42
+ const isCondensed =
43
+ useMediaQuery((theme: Theme) => theme.breakpoints.down('sm')) ||
44
+ lt(width, 600);
45
+
46
+ return (
47
+ <Paper className={cx(classes.header, { [classes.condensed]: isCondensed })}>
48
+ <SelectedTimePeriod
49
+ disabled={disabled}
50
+ extraTimePeriods={extraTimePeriods}
51
+ width={width}
52
+ />
53
+ <CustomTimePeriod disabled={disabled} isCondensed={isCondensed} />
54
+ <div>{renderExternalComponent}</div>
55
+ </Paper>
56
+ );
57
+ };
58
+
59
+ export default TimePeriods;
@@ -1,5 +1,3 @@
1
- import { ReactNode } from 'react';
2
-
3
1
  import dayjs from 'dayjs';
4
2
  import 'dayjs/locale/en';
5
3
  import 'dayjs/locale/es';
@@ -10,70 +8,22 @@ import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
10
8
  import timezonePlugin from 'dayjs/plugin/timezone';
11
9
  import utcPlugin from 'dayjs/plugin/utc';
12
10
 
13
- import { Paper } from '@mui/material';
14
-
15
11
  import { ParentSize } from '..';
16
12
 
17
- import CustomTimePeriod from './CustomTimePeriod';
18
- import SelectedTimePeriod from './SelectedTimePeriod';
19
- import { useStyles } from './TimePeriods.styles';
20
- import {
21
- CustomTimePeriod as CustomTimePeriodModel,
22
- EndStartInterval,
23
- TimePeriod as TimePeriodModel
24
- } from './models';
25
- import useTimePeriod from './useTimePeriod';
13
+ import { WrapperTimePeriodProps } from './models';
14
+ import TimePeriods from './TimePeriods';
26
15
 
27
16
  dayjs.extend(isSameOrAfter);
28
17
  dayjs.extend(utcPlugin);
29
18
  dayjs.extend(timezonePlugin);
30
19
  dayjs.extend(duration);
31
- interface Parameters extends EndStartInterval {
32
- timelineEventsLimit: number;
33
- }
34
- export interface Props {
35
- adjustTimePeriodData?: Omit<CustomTimePeriodModel, 'timelineEventsLimit'>;
36
- disabled?: boolean;
37
- extraTimePeriods?: Array<Omit<TimePeriodModel, 'timelineEventsLimit'>>;
38
- getIsError?: (value: boolean) => void;
39
- getParameters?: ({ start, end, timelineEventsLimit }: Parameters) => void;
40
- renderExternalComponent?: ReactNode;
41
- }
42
-
43
- const TimePeriod = ({
44
- extraTimePeriods,
45
- disabled = false,
46
- getParameters,
47
- getIsError,
48
- adjustTimePeriodData,
49
- renderExternalComponent
50
- }: Props): JSX.Element => {
51
- const { classes } = useStyles({ disabled });
52
20
 
53
- useTimePeriod({
54
- adjustTimePeriodData,
55
- getIsError,
56
- getParameters
57
- });
21
+ const WrapperTimePeriods = (props: WrapperTimePeriodProps): JSX.Element => (
22
+ <ParentSize>
23
+ {({ width }): JSX.Element => {
24
+ return <TimePeriods width={width} {...props} />;
25
+ }}
26
+ </ParentSize>
27
+ );
58
28
 
59
- return (
60
- <div>
61
- <ParentSize>
62
- {({ width }): JSX.Element => {
63
- return (
64
- <Paper className={classes.header} style={{ width }}>
65
- <SelectedTimePeriod
66
- disabled={disabled}
67
- extraTimePeriods={extraTimePeriods}
68
- width={width}
69
- />
70
- <CustomTimePeriod disabled={disabled} />
71
- <div>{renderExternalComponent}</div>
72
- </Paper>
73
- );
74
- }}
75
- </ParentSize>
76
- </div>
77
- );
78
- };
79
- export default TimePeriod;
29
+ export default WrapperTimePeriods;
@@ -1,3 +1,5 @@
1
+ import { ReactNode } from 'react';
2
+
1
3
  import dayjs from 'dayjs';
2
4
 
3
5
  import {
@@ -95,3 +97,16 @@ export interface EndStartInterval {
95
97
  end: string;
96
98
  start: string;
97
99
  }
100
+
101
+ interface Parameters extends EndStartInterval {
102
+ timelineEventsLimit: number;
103
+ }
104
+
105
+ export interface WrapperTimePeriodProps {
106
+ adjustTimePeriodData?: Omit<CustomTimePeriod, 'timelineEventsLimit'>;
107
+ disabled?: boolean;
108
+ extraTimePeriods?: Array<Omit<TimePeriod, 'timelineEventsLimit'>>;
109
+ getIsError?: (value: boolean) => void;
110
+ getParameters?: ({ start, end, timelineEventsLimit }: Parameters) => void;
111
+ renderExternalComponent?: ReactNode;
112
+ }
@@ -9,14 +9,13 @@ import {
9
9
  errorTimePeriodAtom,
10
10
  adjustTimePeriodDerivedAtom
11
11
  } from './timePeriodsAtoms';
12
-
13
- import { Props } from '.';
12
+ import { WrapperTimePeriodProps } from './models';
14
13
 
15
14
  const useTimePeriod = ({
16
15
  getParameters,
17
16
  getIsError,
18
17
  adjustTimePeriodData
19
- }: Omit<Props, 'extraTimePeriods' | 'disabled'>): void => {
18
+ }: Omit<WrapperTimePeriodProps, 'extraTimePeriods' | 'disabled'>): void => {
20
19
  const selectedTimePeriod = useAtomValue(selectedTimePeriodAtom);
21
20
  const customTimePeriod = useAtomValue(customTimePeriodAtom);
22
21
  const getCurrentEndStartInterval = useAtomValue(getDatesDerivedAtom);
@@ -23,3 +23,5 @@ export * from './usePluralizedTranslation';
23
23
  export * from './useResizeObserver';
24
24
  export * from './useFullscreen';
25
25
  export * from './resourcesStatusURL';
26
+ export * from '../Graph/LineChart/helpers';
27
+ export * from '../Graph/LineChart/InteractiveComponents/TimeShiftZones/useTimeShiftZones';