@centreon/ui 23.10.18-MON-17793-create-graph-component-centreon-ui.1 → 23.10.18-MON-17793-create-graph-component-centreon-ui.3

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.1",
3
+ "version": "23.10.18-MON-17793-create-graph-component-centreon-ui.3",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
@@ -46,7 +46,7 @@ export const defaultLastMonth = new Date(
46
46
  ).toISOString();
47
47
 
48
48
  export const zoomPreviewDate = '2023-04-22';
49
- export const lastDayForwardDate = '2023-05-23T';
49
+ export const lastDayForwardDate = '2023-05-23T21';
50
50
 
51
51
  export const getCustomText = (text: string): string =>
52
52
  `<span style="color:#1EA7FD;fontSize:12px">(${text})</span>`;
@@ -3,43 +3,33 @@ import { makeStyles } from 'tss-react/mui';
3
3
  const useStyles = makeStyles()((theme) => ({
4
4
  button: {
5
5
  height: '100%',
6
- minWidth: 120,
7
6
  padding: theme.spacing(0, 0.5)
8
7
  },
9
8
  buttonContent: {
10
9
  alignItems: 'center',
11
10
  columnGap: theme.spacing(1),
12
- display: 'grid',
13
- gridTemplateColumns: 'min-content auto'
11
+ display: 'flex'
14
12
  },
15
- compactFromTo: {
13
+ containerDates: {
16
14
  display: 'flex',
17
- flexDirection: 'column',
18
- padding: theme.spacing(0.5, 0, 0.5, 0)
15
+ gap: theme.spacing(0.5),
16
+ [theme.breakpoints.down('sm')]: {
17
+ columnGap: theme.spacing(0.5),
18
+ flexDirection: 'column'
19
+ }
19
20
  },
20
21
  date: {
21
- display: 'flex'
22
- },
23
- dateLabel: {
24
- display: 'flex',
25
- flex: 1,
26
- paddingRight: 4
22
+ minWidth: theme.spacing(12.5),
23
+ textAlign: 'start'
27
24
  },
28
25
  error: {
29
26
  textAlign: 'center'
30
27
  },
31
- fromTo: {
32
- alignItems: 'center',
33
- columnGap: theme.spacing(0.5),
34
- display: 'grid',
35
- gridTemplateColumns: 'repeat(2, auto)'
36
- },
37
- minimalPickers: {
38
- alignItems: 'center',
39
- columnGap: theme.spacing(1),
40
- display: 'grid',
41
- gridTemplateColumns: 'min-content auto'
28
+ label: {
29
+ minWidth: theme.spacing(3),
30
+ textAlign: 'start'
42
31
  },
32
+
43
33
  picker: {
44
34
  display: 'flex',
45
35
  flexDirection: 'column',
@@ -49,8 +39,12 @@ const useStyles = makeStyles()((theme) => ({
49
39
  },
50
40
  timeContainer: {
51
41
  alignItems: 'center',
42
+ columnGap: theme.spacing(1),
52
43
  display: 'flex',
53
- flexDirection: 'row'
44
+ flexDirection: 'row',
45
+ [theme.breakpoints.down('sm')]: {
46
+ alignItems: 'flex-start'
47
+ }
54
48
  }
55
49
  }));
56
50
 
@@ -1,8 +1,7 @@
1
1
  import { useAtomValue } from 'jotai';
2
- import { lt } from 'ramda';
3
2
 
4
3
  import AccessTimeIcon from '@mui/icons-material/AccessTime';
5
- import { Button, Typography, useTheme } from '@mui/material';
4
+ import { Button, Typography } from '@mui/material';
6
5
 
7
6
  import { dateTimeFormat, useLocaleDateTimeFormat } from '@centreon/ui';
8
7
 
@@ -13,55 +12,66 @@ import useStyles from './CompactCustomTimePeriod.styles';
13
12
  interface Props {
14
13
  disabled?: boolean;
15
14
  onClick: (event) => void;
16
- width: number;
17
15
  }
18
16
 
19
17
  const CompactCustomTimePeriod = ({
20
- width,
21
18
  onClick,
22
19
  disabled = false
23
20
  }: Props): JSX.Element => {
24
- const theme = useTheme();
25
21
  const { classes } = useStyles();
26
22
 
27
23
  const { format } = useLocaleDateTimeFormat();
28
24
 
29
25
  const customTimePeriod = useAtomValue(customTimePeriodAtom);
30
26
 
31
- const isCompact = lt(width, theme.breakpoints.values.sm);
32
-
33
27
  return (
34
- <Button
35
- aria-label="Compact time period"
36
- className={classes.button}
37
- color="primary"
38
- data-testid="Compact time period"
39
- disabled={disabled}
40
- variant="outlined"
41
- onClick={onClick}
42
- >
43
- <div className={classes.buttonContent}>
44
- <AccessTimeIcon />
45
- <div className={isCompact ? classes.compactFromTo : classes.fromTo}>
46
- <div className={classes.timeContainer}>
47
- <div className={classes.dateLabel}>
48
- <Typography variant="caption">From:</Typography>
49
- </div>
50
- <div className={classes.date}>
51
- <Typography variant="caption">
28
+ <div>
29
+ <Button
30
+ aria-label="CompactTimePeriod"
31
+ className={classes.button}
32
+ color="primary"
33
+ data-testid="Compact time period"
34
+ disabled={disabled}
35
+ variant="outlined"
36
+ onClick={onClick}
37
+ >
38
+ <div className={classes.buttonContent}>
39
+ <AccessTimeIcon />
40
+ <div className={classes.containerDates}>
41
+ <div className={classes.timeContainer}>
42
+ <Typography
43
+ className={classes.label}
44
+ component="div"
45
+ variant="caption"
46
+ >
47
+ From:
48
+ </Typography>
49
+
50
+ <Typography
51
+ className={classes.date}
52
+ component="div"
53
+ variant="caption"
54
+ >
52
55
  {format({
53
56
  date: customTimePeriod.start,
54
57
  formatString: dateTimeFormat
55
58
  })}
56
59
  </Typography>
57
60
  </div>
58
- </div>
59
- <div className={classes.timeContainer}>
60
- <div className={classes.dateLabel}>
61
- <Typography variant="caption">To:</Typography>
62
- </div>
63
- <div className={classes.date}>
64
- <Typography variant="caption">
61
+ <div className={classes.timeContainer}>
62
+ <Typography
63
+ className={classes.label}
64
+ component="div"
65
+ variant="caption"
66
+ >
67
+ To:
68
+ </Typography>
69
+
70
+ <Typography
71
+ className={classes.date}
72
+ component="div"
73
+ variant="caption"
74
+ >
65
75
  {format({
66
76
  date: customTimePeriod.end,
67
77
  formatString: dateTimeFormat
@@ -70,8 +80,8 @@ const CompactCustomTimePeriod = ({
70
80
  </div>
71
81
  </div>
72
82
  </div>
73
- </div>
74
- </Button>
83
+ </Button>
84
+ </div>
75
85
  );
76
86
  };
77
87
 
@@ -58,10 +58,8 @@ const PickerDateWithLabel = ({
58
58
  maxDate,
59
59
  minDate,
60
60
  property,
61
- onClosePicker,
62
61
  disabled,
63
62
  date,
64
- setDate,
65
63
  direction = PickersStartEndDateDirection.column
66
64
  }: PropsPickersDateWithLabel): JSX.Element => {
67
65
  const { classes, cx } = useStyles();
@@ -77,8 +75,6 @@ const PickerDateWithLabel = ({
77
75
  maxDate={maxDate}
78
76
  minDate={minDate}
79
77
  property={property}
80
- setDate={setDate}
81
- onClosePicker={onClosePicker}
82
78
  />
83
79
  </div>
84
80
  );
@@ -110,9 +106,6 @@ const PickersStartEndDate = ({
110
106
  const { locale } = useAtomValue(userAtom);
111
107
  const error = useAtomValue(errorTimePeriodAtom);
112
108
 
113
- const { start, setStart } = startDate;
114
- const { end, setEnd } = endDate;
115
-
116
109
  const maxStart = rangeStartDate?.max;
117
110
  const minStart = rangeStartDate?.min;
118
111
  const maxEnd = rangeEndDate?.max;
@@ -135,25 +128,23 @@ const PickersStartEndDate = ({
135
128
  <div className={styleContainer}>
136
129
  <PickerDateWithLabel
137
130
  changeDate={changeDate}
138
- date={start}
131
+ date={startDate}
139
132
  direction={direction}
140
133
  disabled={disabled?.isDisabledStartPicker}
141
134
  label="From"
142
135
  maxDate={maxStart}
143
136
  minDate={minStart}
144
137
  property={CustomTimePeriodProperty.start}
145
- setDate={setStart}
146
138
  />
147
139
  <PickerDateWithLabel
148
140
  changeDate={changeDate}
149
- date={end}
141
+ date={endDate}
150
142
  direction={direction}
151
143
  disabled={disabled?.isDisabledEndPicker}
152
144
  label="To"
153
145
  maxDate={maxEnd}
154
146
  minDate={minEnd}
155
147
  property={CustomTimePeriodProperty.end}
156
- setDate={setEnd}
157
148
  />
158
149
  </div>
159
150
 
@@ -1,27 +1,18 @@
1
- import { Dispatch, SetStateAction, useEffect, useState } from 'react';
1
+ import { useEffect, useState } from 'react';
2
2
 
3
3
  import dayjs from 'dayjs';
4
- import { and, cond, equals, isNil } from 'ramda';
5
4
  import { useSetAtom } from 'jotai';
5
+ import { and, cond, equals, isNil } from 'ramda';
6
6
 
7
- import { errorTimePeriodAtom } from '../../timePeriodsAtoms';
8
7
  import { CustomTimePeriod, CustomTimePeriodProperty } from '../../models';
8
+ import { errorTimePeriodAtom } from '../../timePeriodsAtoms';
9
9
 
10
10
  import { AcceptDateProps } from './models';
11
11
 
12
- interface StartDate {
13
- setStart: Dispatch<SetStateAction<Date | null>>;
14
- start: Date | null;
15
- }
16
- interface EndDate {
17
- end: Date | null;
18
- setEnd: Dispatch<SetStateAction<Date | null>>;
19
- }
20
-
21
12
  export interface PickersStartEndDateModel {
22
13
  changeDate: (props: AcceptDateProps) => void;
23
- endDate: EndDate;
24
- startDate: StartDate;
14
+ endDate: Date | null;
15
+ startDate: Date | null;
25
16
  }
26
17
  interface Props {
27
18
  acceptDate: (props: AcceptDateProps) => void;
@@ -83,8 +74,8 @@ const usePickersStartEndDate = ({
83
74
 
84
75
  return {
85
76
  changeDate,
86
- endDate: { end, setEnd },
87
- startDate: { setStart, start }
77
+ endDate: end,
78
+ startDate: start
88
79
  };
89
80
  };
90
81
 
@@ -2,6 +2,8 @@ import { MouseEvent, useState } from 'react';
2
2
 
3
3
  import { useAtomValue, useSetAtom } from 'jotai';
4
4
 
5
+ import { useDebounce } from '@centreon/ui';
6
+
5
7
  import {
6
8
  changeCustomTimePeriodDerivedAtom,
7
9
  customTimePeriodAtom
@@ -12,17 +14,19 @@ import PopoverCustomTimePeriod from './PopoverCustomTimePeriod';
12
14
 
13
15
  interface Props {
14
16
  disabled?: boolean;
15
- width: number;
16
17
  }
17
18
 
18
- const CustomTimePeriod = ({ width, disabled = false }: Props): JSX.Element => {
19
+ const CustomTimePeriod = ({ disabled = false }: Props): JSX.Element => {
19
20
  const [anchorEl, setAnchorEl] = useState<HTMLButtonElement>();
20
21
 
21
22
  const customTimePeriod = useAtomValue(customTimePeriodAtom);
22
23
  const changeCustomTimePeriod = useSetAtom(changeCustomTimePeriodDerivedAtom);
23
24
 
24
- const acceptDate = ({ property, date }): void =>
25
- changeCustomTimePeriod({ date, property });
25
+ const debouncedChangeDate = useDebounce({
26
+ functionToDebounce: ({ property, date }): void =>
27
+ changeCustomTimePeriod({ date, property }),
28
+ wait: 500
29
+ });
26
30
 
27
31
  const onClickCompactCustomTimePeriod = (
28
32
  event: MouseEvent<HTMLButtonElement>
@@ -38,12 +42,11 @@ const CustomTimePeriod = ({ width, disabled = false }: Props): JSX.Element => {
38
42
  <>
39
43
  <CompactCustomTimePeriod
40
44
  disabled={disabled}
41
- width={width}
42
45
  onClick={onClickCompactCustomTimePeriod}
43
46
  />
44
47
  <PopoverCustomTimePeriod
45
48
  pickersData={{
46
- acceptDate,
49
+ acceptDate: debouncedChangeDate,
47
50
  customTimePeriod,
48
51
  isDisabledEndPicker: disabled,
49
52
  isDisabledStartPicker: disabled,
@@ -8,11 +8,11 @@ import { CustomTimePeriodProperty } from './models';
8
8
 
9
9
  interface Props {
10
10
  changeDate: (props) => void;
11
- date: Date | dayjs.Dayjs | null;
11
+ date: Date | null;
12
12
  desktopMediaQuery?: string;
13
13
  disabled?: boolean;
14
- maxDate?: Date | dayjs.Dayjs;
15
- minDate?: Date | dayjs.Dayjs;
14
+ maxDate?: Date;
15
+ minDate?: Date;
16
16
  property: CustomTimePeriodProperty;
17
17
  }
18
18
 
@@ -0,0 +1,65 @@
1
+ import dayjs from 'dayjs';
2
+ import 'dayjs/locale/fr';
3
+ import localizedFormatPlugin from 'dayjs/plugin/localizedFormat';
4
+ import timezonePlugin from 'dayjs/plugin/timezone';
5
+ import utcPlugin from 'dayjs/plugin/utc';
6
+ import { Provider, createStore } from 'jotai';
7
+
8
+ import { Switch } from '@mui/material';
9
+
10
+ import { userAtom } from '@centreon/ui-context';
11
+
12
+ import { retrievedUser } from './mockedData';
13
+
14
+ import AwesomeTimePeriod from '.';
15
+
16
+ dayjs.extend(timezonePlugin);
17
+ dayjs.extend(utcPlugin);
18
+ dayjs.extend(localizedFormatPlugin);
19
+
20
+ const data = [
21
+ {
22
+ locale: 'fr_FR',
23
+ resolution: { height: 720, width: 500 },
24
+ timezone: 'Europe/Paris'
25
+ },
26
+ {
27
+ locale: 'fr_FR',
28
+ resolution: { height: 720, width: 200 },
29
+ timezone: 'Europe/Paris'
30
+ },
31
+ {
32
+ locale: 'fr_FR',
33
+ resolution: { height: 720, width: 1024 },
34
+ timezone: 'Europe/Paris'
35
+ }
36
+ ];
37
+
38
+ data.forEach((item) =>
39
+ describe('Time period', () => {
40
+ const { height, width } = item.resolution;
41
+ beforeEach(() => {
42
+ cy.viewport(width, height);
43
+
44
+ const store = createStore();
45
+
46
+ store.set(userAtom, {
47
+ ...retrievedUser,
48
+ locale: 'fr_FR',
49
+ timezone: 'Europe/Paris'
50
+ });
51
+
52
+ cy.mount({
53
+ Component: (
54
+ <Provider store={store}>
55
+ <AwesomeTimePeriod renderExternalComponent={<Switch />} />
56
+ </Provider>
57
+ )
58
+ });
59
+ });
60
+
61
+ it(`displays correctly the dates design when screen resolution is ${width}px`, () => {
62
+ cy.matchImageSnapshot(`${width}px`);
63
+ });
64
+ })
65
+ );
@@ -53,46 +53,42 @@ const SelectedTimePeriod = ({
53
53
  );
54
54
 
55
55
  return (
56
- <div>
57
- <ButtonGroup
58
- className={classes.buttonGroup}
59
- color="primary"
60
- component="span"
61
- disabled={disabled}
62
- size="small"
63
- >
64
- {map(
65
- ({ id, name, largeName }) => (
66
- <Tooltip key={name} placement="top" title={largeName}>
67
- <Button
68
- className={classes.button}
69
- component="span"
70
- data-testid={id}
71
- variant={
72
- equals(selectedTimePeriodData?.id, id)
73
- ? 'contained'
74
- : 'outlined'
75
- }
76
- onClick={(): void =>
77
- changeSelectedTimePeriod({
78
- id,
79
- timePeriods: currentTimePeriods
80
- })
81
- }
82
- >
83
- {
84
- cond<number, string>([
85
- [lte(theme.breakpoints.values.md), always(largeName)],
86
- [T, always(name)]
87
- ])(width) as string
88
- }
89
- </Button>
90
- </Tooltip>
91
- ),
92
- timePeriodOptions
93
- )}
94
- </ButtonGroup>
95
- </div>
56
+ <ButtonGroup
57
+ className={classes.buttonGroup}
58
+ color="primary"
59
+ disabled={disabled}
60
+ size="small"
61
+ >
62
+ {map(
63
+ ({ id, name, largeName }) => (
64
+ <Tooltip key={name} placement="top" title={largeName}>
65
+ <Button
66
+ className={classes.button}
67
+ data-testid={id}
68
+ variant={
69
+ equals(selectedTimePeriodData?.id, id)
70
+ ? 'contained'
71
+ : 'outlined'
72
+ }
73
+ onClick={(): void =>
74
+ changeSelectedTimePeriod({
75
+ id,
76
+ timePeriods: currentTimePeriods
77
+ })
78
+ }
79
+ >
80
+ {
81
+ cond<number, string>([
82
+ [lte(theme.breakpoints.values.md), always(largeName)],
83
+ [T, always(name)]
84
+ ])(width) as string
85
+ }
86
+ </Button>
87
+ </Tooltip>
88
+ ),
89
+ timePeriodOptions
90
+ )}
91
+ </ButtonGroup>
96
92
  );
97
93
  };
98
94
 
@@ -6,15 +6,17 @@ interface StylesProps {
6
6
 
7
7
  export const useStyles = makeStyles<StylesProps>()((theme, { disabled }) => ({
8
8
  header: {
9
- alignItems: 'center',
9
+ [theme.breakpoints.down('sm')]: {
10
+ flexWrap: 'wrap',
11
+ justifyContent: 'center',
12
+ rowGap: theme.spacing(1)
13
+ },
10
14
  backgroundColor: disabled ? 'transparent' : 'undefined',
11
15
  border: disabled ? 'unset' : 'undefined',
12
16
  boxShadow: disabled ? 'unset' : 'undefined',
13
17
  columnGap: theme.spacing(2),
14
- display: 'grid',
15
- gridTemplateColumns: `repeat(4, auto)`,
18
+ display: 'flex',
16
19
  gridTemplateRows: '1fr',
17
- justifyContent: 'center',
18
- padding: theme.spacing(1, 0.5)
20
+ justifyContent: 'center'
19
21
  }
20
22
  }));
@@ -1,6 +1,8 @@
1
1
  import { Meta, StoryObj } from '@storybook/react';
2
2
  import dayjs from 'dayjs';
3
3
 
4
+ import Switch from '@mui/material/Switch';
5
+
4
6
  import { dateFormat } from './models';
5
7
 
6
8
  import AwesomeTimePeriod from '.';
@@ -18,16 +20,10 @@ const Template: Story = {
18
20
  render: (args) => <AwesomeTimePeriod {...args} />
19
21
  };
20
22
 
21
- const args = {
22
- extraTimePeriods: [
23
- {
24
- dateTimeFormat: dateFormat,
25
- getStart: (): Date => dayjs(Date.now()).subtract(29, 'day').toDate(),
26
- id: 'last_29_days',
27
- largeName: 'last 29 days',
28
- name: '29 days'
29
- }
30
- ]
23
+ const TemplateWithExternalComponent: Story = {
24
+ render: (args) => (
25
+ <AwesomeTimePeriod {...args} renderExternalComponent={<Switch />} />
26
+ )
31
27
  };
32
28
 
33
29
  const argTypes = {
@@ -66,9 +62,30 @@ const argTypes = {
66
62
  }
67
63
  }
68
64
  };
65
+ const args = {
66
+ extraTimePeriods: [
67
+ {
68
+ dateTimeFormat: dateFormat,
69
+ getStart: (): Date => dayjs(Date.now()).subtract(29, 'day').toDate(),
70
+ id: 'last_29_days',
71
+ largeName: 'last 29 days',
72
+ name: '29 days'
73
+ }
74
+ ]
75
+ };
69
76
 
70
77
  export const TimePeriod: Story = {
78
+ ...Template,
79
+ argTypes
80
+ };
81
+
82
+ export const WithExtraTimePeriods: Story = {
71
83
  ...Template,
72
84
  argTypes,
73
85
  args
74
86
  };
87
+
88
+ export const WithExternalComponent: Story = {
89
+ ...TemplateWithExternalComponent,
90
+ argTypes
91
+ };
@@ -1,16 +1,18 @@
1
- import { useEffect } from 'react';
1
+ import { ReactNode } from 'react';
2
2
 
3
3
  import { Responsive } from '@visx/visx';
4
- import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
4
+ import 'dayjs/locale/en';
5
+ import 'dayjs/locale/pt';
6
+ import 'dayjs/locale/fr';
7
+ import 'dayjs/locale/es';
5
8
  import dayjs from 'dayjs';
9
+ import duration from 'dayjs/plugin/duration';
10
+ import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
6
11
  import timezonePlugin from 'dayjs/plugin/timezone';
7
12
  import utcPlugin from 'dayjs/plugin/utc';
8
- import duration from 'dayjs/plugin/duration';
9
- import { useAtomValue, useSetAtom } from 'jotai';
10
13
 
11
14
  import { Paper } from '@mui/material';
12
15
 
13
- import { useStyles } from './timePeriods.styles';
14
16
  import CustomTimePeriod from './CustomTimePeriod';
15
17
  import SelectedTimePeriod from './SelectedTimePeriod';
16
18
  import {
@@ -18,25 +20,21 @@ import {
18
20
  EndStartInterval,
19
21
  TimePeriod
20
22
  } from './models';
21
- import {
22
- customTimePeriodAtom,
23
- getDatesDerivedAtom,
24
- selectedTimePeriodAtom,
25
- errorTimePeriodAtom,
26
- adjustTimePeriodDerivedAtom
27
- } from './timePeriodsAtoms';
23
+ import { useStyles } from './TimePeriods.styles';
24
+ import useAwesomeTimePeriod from './useAwesomeTimePeriod';
28
25
 
29
26
  dayjs.extend(isSameOrAfter);
30
27
  dayjs.extend(utcPlugin);
31
28
  dayjs.extend(timezonePlugin);
32
29
  dayjs.extend(duration);
33
30
 
34
- interface Props {
31
+ export interface Props {
35
32
  adjustTimePeriodData?: CustomTimePeriodModel;
36
33
  disabled?: boolean;
37
34
  extraTimePeriods?: Array<TimePeriod>;
38
35
  getIsError?: (value: boolean) => void;
39
36
  getStartEndParameters?: ({ start, end }: EndStartInterval) => void;
37
+ renderExternalComponent?: ReactNode;
40
38
  }
41
39
 
42
40
  const AwesomeTimePeriod = ({
@@ -44,32 +42,16 @@ const AwesomeTimePeriod = ({
44
42
  disabled = false,
45
43
  getStartEndParameters,
46
44
  getIsError,
47
- adjustTimePeriodData
45
+ adjustTimePeriodData,
46
+ renderExternalComponent
48
47
  }: Props): JSX.Element => {
49
48
  const { classes } = useStyles({ disabled });
50
49
 
51
- const selectedTimePeriod = useAtomValue(selectedTimePeriodAtom);
52
- const customTimePeriod = useAtomValue(customTimePeriodAtom);
53
- const getCurrentEndStartInterval = useAtomValue(getDatesDerivedAtom);
54
- const errorTimePeriod = useAtomValue(errorTimePeriodAtom);
55
- const adjustTimeTimePeriod = useSetAtom(adjustTimePeriodDerivedAtom);
56
-
57
- useEffect(() => {
58
- if (!adjustTimePeriodData) {
59
- return;
60
- }
61
-
62
- adjustTimeTimePeriod(adjustTimePeriodData);
63
- }, [adjustTimePeriodData?.start, adjustTimePeriodData?.end]);
64
-
65
- useEffect(() => {
66
- const [start, end] = getCurrentEndStartInterval(selectedTimePeriod);
67
- getStartEndParameters?.({ end, start });
68
- }, [customTimePeriod.start, customTimePeriod.end, selectedTimePeriod]);
69
-
70
- useEffect(() => {
71
- getIsError?.(errorTimePeriod);
72
- }, [errorTimePeriod]);
50
+ useAwesomeTimePeriod({
51
+ adjustTimePeriodData,
52
+ getIsError,
53
+ getStartEndParameters
54
+ });
73
55
 
74
56
  return (
75
57
  <div>
@@ -82,7 +64,8 @@ const AwesomeTimePeriod = ({
82
64
  extraTimePeriods={extraTimePeriods}
83
65
  width={width}
84
66
  />
85
- <CustomTimePeriod disabled={disabled} width={width} />
67
+ <CustomTimePeriod disabled={disabled} />
68
+ <div>{renderExternalComponent}</div>
86
69
  </Paper>
87
70
  );
88
71
  }}
@@ -0,0 +1,12 @@
1
+ import { ListingVariant } from '@centreon/ui-context';
2
+
3
+ export const retrievedUser = {
4
+ alias: 'Admin alias',
5
+ default_page: '/monitoring/resources',
6
+ is_export_button_enabled: true,
7
+ isExportButtonEnabled: true,
8
+ locale: 'fr_FR.UTF8',
9
+ name: 'Admin',
10
+ use_deprecated_pages: false,
11
+ user_interface_density: ListingVariant.compact
12
+ };
@@ -70,10 +70,10 @@ export interface CustomTimePeriod {
70
70
 
71
71
  export interface DateTimePickerInputModel {
72
72
  changeDate: (props) => void;
73
- date: Date | dayjs.Dayjs | null;
73
+ date: Date | null;
74
74
  disabled?: boolean;
75
- maxDate?: Date | dayjs.Dayjs;
76
- minDate?: Date | dayjs.Dayjs;
75
+ maxDate?: Date;
76
+ minDate?: Date;
77
77
  property: CustomTimePeriodProperty;
78
78
  }
79
79
 
@@ -0,0 +1,48 @@
1
+ import { useEffect } from 'react';
2
+
3
+ import { useAtomValue, useSetAtom } from 'jotai';
4
+
5
+ import {
6
+ customTimePeriodAtom,
7
+ getDatesDerivedAtom,
8
+ selectedTimePeriodAtom,
9
+ errorTimePeriodAtom,
10
+ adjustTimePeriodDerivedAtom
11
+ } from './timePeriodsAtoms';
12
+
13
+ import { Props } from '.';
14
+
15
+ const useAwesomeTimePeriod = ({
16
+ getStartEndParameters,
17
+ getIsError,
18
+ adjustTimePeriodData
19
+ }: Omit<Props, 'extraTimePeriods' | 'disabled'>): void => {
20
+ const selectedTimePeriod = useAtomValue(selectedTimePeriodAtom);
21
+ const customTimePeriod = useAtomValue(customTimePeriodAtom);
22
+ const getCurrentEndStartInterval = useAtomValue(getDatesDerivedAtom);
23
+ const errorTimePeriod = useAtomValue(errorTimePeriodAtom);
24
+ const adjustTimeTimePeriod = useSetAtom(adjustTimePeriodDerivedAtom);
25
+
26
+ useEffect(() => {
27
+ if (!adjustTimePeriodData) {
28
+ return;
29
+ }
30
+
31
+ adjustTimeTimePeriod(adjustTimePeriodData);
32
+ }, [adjustTimePeriodData?.start, adjustTimePeriodData?.end]);
33
+
34
+ useEffect(() => {
35
+ const [start, end] = getCurrentEndStartInterval(selectedTimePeriod);
36
+
37
+ getStartEndParameters?.({ end, start });
38
+ }, [customTimePeriod.start, customTimePeriod.end, selectedTimePeriod]);
39
+
40
+ useEffect(() => {
41
+ if (!errorTimePeriod) {
42
+ return;
43
+ }
44
+ getIsError?.(errorTimePeriod);
45
+ }, [errorTimePeriod]);
46
+ };
47
+
48
+ export default useAwesomeTimePeriod;