@centreon/ui 23.10.18-MON-17793-create-graph-component-centreon-ui.1 → 23.10.18-MON-17793-create-graph-component-centreon-ui.2
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 +1 -1
- package/src/Graph/helpers/doc.ts +1 -1
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +2 -11
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/usePickersStartEndDate.ts +7 -16
- package/src/TimePeriods/CustomTimePeriod/index.tsx +8 -3
- package/src/TimePeriods/DateTimePickerInput.tsx +3 -3
- package/src/TimePeriods/index.tsx +10 -36
- package/src/TimePeriods/models.ts +3 -3
- package/src/TimePeriods/useAwesomeTimePeriod.ts +48 -0
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.
|
|
3
|
+
"version": "23.10.18-MON-17793-create-graph-component-centreon-ui.2",
|
|
4
4
|
"description": "Centreon UI Components",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
|
package/src/Graph/helpers/doc.ts
CHANGED
|
@@ -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-
|
|
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>`;
|
|
@@ -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={
|
|
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={
|
|
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 {
|
|
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:
|
|
24
|
-
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:
|
|
87
|
-
startDate:
|
|
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
|
|
@@ -21,8 +23,11 @@ const CustomTimePeriod = ({ width, disabled = false }: Props): JSX.Element => {
|
|
|
21
23
|
const customTimePeriod = useAtomValue(customTimePeriodAtom);
|
|
22
24
|
const changeCustomTimePeriod = useSetAtom(changeCustomTimePeriodDerivedAtom);
|
|
23
25
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
+
const debouncedChangeDate = useDebounce({
|
|
27
|
+
functionToDebounce: ({ property, date }): void =>
|
|
28
|
+
changeCustomTimePeriod({ date, property }),
|
|
29
|
+
wait: 500
|
|
30
|
+
});
|
|
26
31
|
|
|
27
32
|
const onClickCompactCustomTimePeriod = (
|
|
28
33
|
event: MouseEvent<HTMLButtonElement>
|
|
@@ -43,7 +48,7 @@ const CustomTimePeriod = ({ width, disabled = false }: Props): JSX.Element => {
|
|
|
43
48
|
/>
|
|
44
49
|
<PopoverCustomTimePeriod
|
|
45
50
|
pickersData={{
|
|
46
|
-
acceptDate,
|
|
51
|
+
acceptDate: debouncedChangeDate,
|
|
47
52
|
customTimePeriod,
|
|
48
53
|
isDisabledEndPicker: disabled,
|
|
49
54
|
isDisabledStartPicker: disabled,
|
|
@@ -8,11 +8,11 @@ import { CustomTimePeriodProperty } from './models';
|
|
|
8
8
|
|
|
9
9
|
interface Props {
|
|
10
10
|
changeDate: (props) => void;
|
|
11
|
-
date: Date |
|
|
11
|
+
date: Date | null;
|
|
12
12
|
desktopMediaQuery?: string;
|
|
13
13
|
disabled?: boolean;
|
|
14
|
-
maxDate?: Date
|
|
15
|
-
minDate?: Date
|
|
14
|
+
maxDate?: Date;
|
|
15
|
+
minDate?: Date;
|
|
16
16
|
property: CustomTimePeriodProperty;
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
|
|
3
1
|
import { Responsive } from '@visx/visx';
|
|
4
|
-
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
|
|
5
2
|
import dayjs from 'dayjs';
|
|
3
|
+
import duration from 'dayjs/plugin/duration';
|
|
4
|
+
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
|
|
6
5
|
import timezonePlugin from 'dayjs/plugin/timezone';
|
|
7
6
|
import utcPlugin from 'dayjs/plugin/utc';
|
|
8
|
-
import duration from 'dayjs/plugin/duration';
|
|
9
|
-
import { useAtomValue, useSetAtom } from 'jotai';
|
|
10
7
|
|
|
11
8
|
import { Paper } from '@mui/material';
|
|
12
9
|
|
|
13
|
-
import { useStyles } from './timePeriods.styles';
|
|
14
10
|
import CustomTimePeriod from './CustomTimePeriod';
|
|
15
11
|
import SelectedTimePeriod from './SelectedTimePeriod';
|
|
16
12
|
import {
|
|
@@ -18,20 +14,15 @@ import {
|
|
|
18
14
|
EndStartInterval,
|
|
19
15
|
TimePeriod
|
|
20
16
|
} from './models';
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
getDatesDerivedAtom,
|
|
24
|
-
selectedTimePeriodAtom,
|
|
25
|
-
errorTimePeriodAtom,
|
|
26
|
-
adjustTimePeriodDerivedAtom
|
|
27
|
-
} from './timePeriodsAtoms';
|
|
17
|
+
import { useStyles } from './timePeriods.styles';
|
|
18
|
+
import useAwesomeTimePeriod from './useAwesomeTimePeriod';
|
|
28
19
|
|
|
29
20
|
dayjs.extend(isSameOrAfter);
|
|
30
21
|
dayjs.extend(utcPlugin);
|
|
31
22
|
dayjs.extend(timezonePlugin);
|
|
32
23
|
dayjs.extend(duration);
|
|
33
24
|
|
|
34
|
-
interface Props {
|
|
25
|
+
export interface Props {
|
|
35
26
|
adjustTimePeriodData?: CustomTimePeriodModel;
|
|
36
27
|
disabled?: boolean;
|
|
37
28
|
extraTimePeriods?: Array<TimePeriod>;
|
|
@@ -48,28 +39,11 @@ const AwesomeTimePeriod = ({
|
|
|
48
39
|
}: Props): JSX.Element => {
|
|
49
40
|
const { classes } = useStyles({ disabled });
|
|
50
41
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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]);
|
|
42
|
+
useAwesomeTimePeriod({
|
|
43
|
+
adjustTimePeriodData,
|
|
44
|
+
getIsError,
|
|
45
|
+
getStartEndParameters
|
|
46
|
+
});
|
|
73
47
|
|
|
74
48
|
return (
|
|
75
49
|
<div>
|
|
@@ -70,10 +70,10 @@ export interface CustomTimePeriod {
|
|
|
70
70
|
|
|
71
71
|
export interface DateTimePickerInputModel {
|
|
72
72
|
changeDate: (props) => void;
|
|
73
|
-
date: Date |
|
|
73
|
+
date: Date | null;
|
|
74
74
|
disabled?: boolean;
|
|
75
|
-
maxDate?: Date
|
|
76
|
-
minDate?: Date
|
|
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;
|