@centreon/ui 23.10.18-MON-17793-create-graph-component-centreon-ui.0 → 23.10.18
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 -2
- package/src/Graph/Axes/UnitLabel.tsx +0 -20
- package/src/Graph/Axes/index.tsx +0 -99
- package/src/Graph/Axes/models.ts +0 -26
- package/src/Graph/Axes/useAxisY.ts +0 -100
- package/src/Graph/Graph.tsx +0 -231
- package/src/Graph/Grids/index.tsx +0 -20
- package/src/Graph/Header/index.tsx +0 -34
- package/src/Graph/InteractionWithGraph/AnchorPoint/RegularAnchorPoint.tsx +0 -88
- package/src/Graph/InteractionWithGraph/AnchorPoint/StackedAnchorPoint.tsx +0 -97
- package/src/Graph/InteractionWithGraph/AnchorPoint/index.tsx +0 -56
- package/src/Graph/InteractionWithGraph/AnchorPoint/models.ts +0 -25
- package/src/Graph/InteractionWithGraph/AnchorPoint/useAnchorPoint.ts +0 -109
- package/src/Graph/InteractionWithGraph/Bar.tsx +0 -21
- package/src/Graph/InteractionWithGraph/ZoomPreview/index.tsx +0 -38
- package/src/Graph/InteractionWithGraph/ZoomPreview/models.ts +0 -17
- package/src/Graph/InteractionWithGraph/ZoomPreview/useZoomPreview.ts +0 -101
- package/src/Graph/InteractionWithGraph/ZoomPreview/zoomPreviewAtoms.ts +0 -5
- package/src/Graph/InteractionWithGraph/index.tsx +0 -93
- package/src/Graph/InteractionWithGraph/interactionWithGraphAtoms.ts +0 -7
- package/src/Graph/InteractionWithGraph/mouseTimeValueAtoms.ts +0 -49
- package/src/Graph/Lines/RegularLines/index.tsx +0 -99
- package/src/Graph/Lines/RegularLines/useRegularLines.ts +0 -15
- package/src/Graph/Lines/StackedLines/index.tsx +0 -74
- package/src/Graph/Lines/StackedLines/useStackedLines.ts +0 -39
- package/src/Graph/Lines/index.tsx +0 -153
- package/src/Graph/Lines/models.ts +0 -32
- package/src/Graph/LoadingProgress.tsx +0 -46
- package/src/Graph/common/index.ts +0 -33
- package/src/Graph/data.json +0 -1338
- package/src/Graph/helpers/doc.ts +0 -323
- package/src/Graph/helpers/index.ts +0 -15
- package/src/Graph/index.stories.tsx +0 -30
- package/src/Graph/index.tsx +0 -66
- package/src/Graph/models.ts +0 -68
- package/src/Graph/timeSeries/index.test.ts +0 -484
- package/src/Graph/timeSeries/index.ts +0 -512
- package/src/Graph/timeSeries/models.ts +0 -119
- package/src/Graph/useGraphData.ts +0 -117
- package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.styles.ts +0 -57
- package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.tsx +0 -78
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/ErrorText.tsx +0 -14
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +0 -169
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/index.tsx +0 -76
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +0 -61
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/usePickersStartEndDate.ts +0 -91
- package/src/TimePeriods/CustomTimePeriod/index.tsx +0 -63
- package/src/TimePeriods/DateTimePickerInput.tsx +0 -99
- package/src/TimePeriods/SelectedTimePeriod.tsx +0 -99
- package/src/TimePeriods/TimePeriods.cypress.spec.tsx +0 -497
- package/src/TimePeriods/helpers/index.ts +0 -25
- package/src/TimePeriods/index.stories.tsx +0 -74
- package/src/TimePeriods/index.tsx +0 -77
- package/src/TimePeriods/models.ts +0 -103
- package/src/TimePeriods/timePeriods.styles.ts +0 -20
- package/src/TimePeriods/timePeriodsAtoms.ts +0 -113
- package/src/TimePeriods/useDateTimePickerAdapter.ts +0 -329
- package/src/TimePeriods/useSortTimePeriods.ts +0 -24
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useAtom } from 'jotai';
|
|
4
|
-
import { find, propEq } from 'ramda';
|
|
5
|
-
|
|
6
|
-
import { getData, useRequest } from '@centreon/ui';
|
|
7
|
-
|
|
8
|
-
import { zoomParametersAtom } from './InteractionWithGraph/ZoomPreview/zoomPreviewAtoms';
|
|
9
|
-
import { adjustGraphData } from './helpers';
|
|
10
|
-
import { Data, GraphData, GraphParameters } from './models';
|
|
11
|
-
|
|
12
|
-
interface QueryParameter {
|
|
13
|
-
endTime: string;
|
|
14
|
-
startTime: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface GraphDataResult {
|
|
18
|
-
data?: Data;
|
|
19
|
-
loading: boolean;
|
|
20
|
-
}
|
|
21
|
-
interface Props extends GraphParameters {
|
|
22
|
-
baseUrl: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const useGraphData = ({ baseUrl, start, end }: Props): GraphDataResult => {
|
|
26
|
-
const [data, setData] = useState<Data>();
|
|
27
|
-
|
|
28
|
-
const { sendRequest: sendGetGraphDataRequest, sending: loading } =
|
|
29
|
-
useRequest<GraphData>({
|
|
30
|
-
request: getData
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const [zoomParameters, setZoomParameters] = useAtom(zoomParametersAtom);
|
|
34
|
-
|
|
35
|
-
const prepareData = ({ response, queryParameters }): void => {
|
|
36
|
-
const { timeSeries } = adjustGraphData(response);
|
|
37
|
-
const baseAxis = response.global.base;
|
|
38
|
-
const { title } = response.global;
|
|
39
|
-
|
|
40
|
-
const newLineData = adjustGraphData(response).lines;
|
|
41
|
-
|
|
42
|
-
if (response?.lines) {
|
|
43
|
-
const newLines = newLineData.map((line) => ({
|
|
44
|
-
...line,
|
|
45
|
-
display:
|
|
46
|
-
find(propEq('name', line.name), response.lines)?.display ?? true
|
|
47
|
-
}));
|
|
48
|
-
|
|
49
|
-
setData({
|
|
50
|
-
baseAxis,
|
|
51
|
-
lines: newLines,
|
|
52
|
-
queryParameters,
|
|
53
|
-
timeSeries,
|
|
54
|
-
title
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
setData({
|
|
61
|
-
baseAxis,
|
|
62
|
-
lines: newLineData,
|
|
63
|
-
queryParameters,
|
|
64
|
-
timeSeries,
|
|
65
|
-
title
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const getQueryParameters = ({ startTime, endTime }: QueryParameter): string =>
|
|
70
|
-
`?start=${startTime}&end=${endTime}`;
|
|
71
|
-
|
|
72
|
-
const getParameters = (): GraphParameters => {
|
|
73
|
-
const beginning = zoomParameters ? zoomParameters.start : start;
|
|
74
|
-
const ending = zoomParameters ? zoomParameters.end : end;
|
|
75
|
-
|
|
76
|
-
return { end: ending, start: beginning };
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const queryParameters = zoomParameters
|
|
80
|
-
? getQueryParameters({
|
|
81
|
-
endTime: zoomParameters.end,
|
|
82
|
-
startTime: zoomParameters.start
|
|
83
|
-
})
|
|
84
|
-
: getQueryParameters({ endTime: end, startTime: start });
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
if (!end || !start || !baseUrl) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const endpoint = `${baseUrl}${queryParameters}`;
|
|
91
|
-
|
|
92
|
-
sendGetGraphDataRequest({
|
|
93
|
-
endpoint
|
|
94
|
-
}).then((response) => {
|
|
95
|
-
prepareData({ queryParameters: getParameters(), response });
|
|
96
|
-
});
|
|
97
|
-
}, [baseUrl, start, end]);
|
|
98
|
-
|
|
99
|
-
useEffect(() => {
|
|
100
|
-
if (!zoomParameters) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const endpoint = `${baseUrl}${queryParameters}`;
|
|
105
|
-
|
|
106
|
-
sendGetGraphDataRequest({
|
|
107
|
-
endpoint
|
|
108
|
-
}).then((response) => {
|
|
109
|
-
prepareData({ queryParameters: getParameters(), response });
|
|
110
|
-
setZoomParameters(null);
|
|
111
|
-
});
|
|
112
|
-
}, [zoomParameters]);
|
|
113
|
-
|
|
114
|
-
return { data, loading };
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export default useGraphData;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { makeStyles } from 'tss-react/mui';
|
|
2
|
-
|
|
3
|
-
const useStyles = makeStyles()((theme) => ({
|
|
4
|
-
button: {
|
|
5
|
-
height: '100%',
|
|
6
|
-
minWidth: 120,
|
|
7
|
-
padding: theme.spacing(0, 0.5)
|
|
8
|
-
},
|
|
9
|
-
buttonContent: {
|
|
10
|
-
alignItems: 'center',
|
|
11
|
-
columnGap: theme.spacing(1),
|
|
12
|
-
display: 'grid',
|
|
13
|
-
gridTemplateColumns: 'min-content auto'
|
|
14
|
-
},
|
|
15
|
-
compactFromTo: {
|
|
16
|
-
display: 'flex',
|
|
17
|
-
flexDirection: 'column',
|
|
18
|
-
padding: theme.spacing(0.5, 0, 0.5, 0)
|
|
19
|
-
},
|
|
20
|
-
date: {
|
|
21
|
-
display: 'flex'
|
|
22
|
-
},
|
|
23
|
-
dateLabel: {
|
|
24
|
-
display: 'flex',
|
|
25
|
-
flex: 1,
|
|
26
|
-
paddingRight: 4
|
|
27
|
-
},
|
|
28
|
-
error: {
|
|
29
|
-
textAlign: 'center'
|
|
30
|
-
},
|
|
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'
|
|
42
|
-
},
|
|
43
|
-
picker: {
|
|
44
|
-
display: 'flex',
|
|
45
|
-
flexDirection: 'column',
|
|
46
|
-
gap: theme.spacing(1),
|
|
47
|
-
justifyItems: 'center',
|
|
48
|
-
padding: theme.spacing(1, 2)
|
|
49
|
-
},
|
|
50
|
-
timeContainer: {
|
|
51
|
-
alignItems: 'center',
|
|
52
|
-
display: 'flex',
|
|
53
|
-
flexDirection: 'row'
|
|
54
|
-
}
|
|
55
|
-
}));
|
|
56
|
-
|
|
57
|
-
export default useStyles;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { useAtomValue } from 'jotai';
|
|
2
|
-
import { lt } from 'ramda';
|
|
3
|
-
|
|
4
|
-
import AccessTimeIcon from '@mui/icons-material/AccessTime';
|
|
5
|
-
import { Button, Typography, useTheme } from '@mui/material';
|
|
6
|
-
|
|
7
|
-
import { dateTimeFormat, useLocaleDateTimeFormat } from '@centreon/ui';
|
|
8
|
-
|
|
9
|
-
import { customTimePeriodAtom } from '../timePeriodsAtoms';
|
|
10
|
-
|
|
11
|
-
import useStyles from './CompactCustomTimePeriod.styles';
|
|
12
|
-
|
|
13
|
-
interface Props {
|
|
14
|
-
disabled?: boolean;
|
|
15
|
-
onClick: (event) => void;
|
|
16
|
-
width: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const CompactCustomTimePeriod = ({
|
|
20
|
-
width,
|
|
21
|
-
onClick,
|
|
22
|
-
disabled = false
|
|
23
|
-
}: Props): JSX.Element => {
|
|
24
|
-
const theme = useTheme();
|
|
25
|
-
const { classes } = useStyles();
|
|
26
|
-
|
|
27
|
-
const { format } = useLocaleDateTimeFormat();
|
|
28
|
-
|
|
29
|
-
const customTimePeriod = useAtomValue(customTimePeriodAtom);
|
|
30
|
-
|
|
31
|
-
const isCompact = lt(width, theme.breakpoints.values.sm);
|
|
32
|
-
|
|
33
|
-
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">
|
|
52
|
-
{format({
|
|
53
|
-
date: customTimePeriod.start,
|
|
54
|
-
formatString: dateTimeFormat
|
|
55
|
-
})}
|
|
56
|
-
</Typography>
|
|
57
|
-
</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">
|
|
65
|
-
{format({
|
|
66
|
-
date: customTimePeriod.end,
|
|
67
|
-
formatString: dateTimeFormat
|
|
68
|
-
})}
|
|
69
|
-
</Typography>
|
|
70
|
-
</div>
|
|
71
|
-
</div>
|
|
72
|
-
</div>
|
|
73
|
-
</div>
|
|
74
|
-
</Button>
|
|
75
|
-
);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export default CompactCustomTimePeriod;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { FormHelperText } from '@mui/material';
|
|
2
|
-
|
|
3
|
-
interface Props {
|
|
4
|
-
message: string;
|
|
5
|
-
style: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const ErrorText = ({ message, style }: Props): JSX.Element => (
|
|
9
|
-
<FormHelperText error className={style}>
|
|
10
|
-
{message}
|
|
11
|
-
</FormHelperText>
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
export default ErrorText;
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { useAtomValue } from 'jotai';
|
|
2
|
-
import { makeStyles } from 'tss-react/mui';
|
|
3
|
-
import { equals } from 'ramda';
|
|
4
|
-
|
|
5
|
-
import { Typography } from '@mui/material';
|
|
6
|
-
import { LocalizationProvider } from '@mui/x-date-pickers';
|
|
7
|
-
|
|
8
|
-
import { userAtom } from '@centreon/ui-context';
|
|
9
|
-
|
|
10
|
-
import DateTimePickerInput from '../../DateTimePickerInput';
|
|
11
|
-
import {
|
|
12
|
-
CustomTimePeriodProperty,
|
|
13
|
-
DateTimePickerInputModel
|
|
14
|
-
} from '../../models';
|
|
15
|
-
import useDateTimePickerAdapter from '../../useDateTimePickerAdapter';
|
|
16
|
-
import { errorTimePeriodAtom } from '../../timePeriodsAtoms';
|
|
17
|
-
|
|
18
|
-
import ErrorText from './ErrorText';
|
|
19
|
-
import { PickersData, PickersStartEndDateDirection } from './models';
|
|
20
|
-
import { PickersStartEndDateModel } from './usePickersStartEndDate';
|
|
21
|
-
|
|
22
|
-
const useStyles = makeStyles()((theme) => ({
|
|
23
|
-
error: {
|
|
24
|
-
textAlign: 'center'
|
|
25
|
-
},
|
|
26
|
-
horizontalDirection: {
|
|
27
|
-
display: 'flex',
|
|
28
|
-
flexDirection: 'row',
|
|
29
|
-
gap: theme.spacing(1),
|
|
30
|
-
justifyItems: 'center',
|
|
31
|
-
padding: 0
|
|
32
|
-
},
|
|
33
|
-
horizontalError: {
|
|
34
|
-
textAlign: 'left'
|
|
35
|
-
},
|
|
36
|
-
row: {
|
|
37
|
-
display: 'flex',
|
|
38
|
-
flexDirection: 'row',
|
|
39
|
-
gap: theme.spacing(1)
|
|
40
|
-
},
|
|
41
|
-
verticalDirection: {
|
|
42
|
-
display: 'flex',
|
|
43
|
-
flexDirection: 'column',
|
|
44
|
-
gap: theme.spacing(1),
|
|
45
|
-
justifyItems: 'center',
|
|
46
|
-
padding: theme.spacing(1, 2)
|
|
47
|
-
}
|
|
48
|
-
}));
|
|
49
|
-
|
|
50
|
-
interface PropsPickersDateWithLabel extends DateTimePickerInputModel {
|
|
51
|
-
direction?: PickersStartEndDateDirection;
|
|
52
|
-
label: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const PickerDateWithLabel = ({
|
|
56
|
-
label,
|
|
57
|
-
changeDate,
|
|
58
|
-
maxDate,
|
|
59
|
-
minDate,
|
|
60
|
-
property,
|
|
61
|
-
onClosePicker,
|
|
62
|
-
disabled,
|
|
63
|
-
date,
|
|
64
|
-
setDate,
|
|
65
|
-
direction = PickersStartEndDateDirection.column
|
|
66
|
-
}: PropsPickersDateWithLabel): JSX.Element => {
|
|
67
|
-
const { classes, cx } = useStyles();
|
|
68
|
-
const isRow = equals(direction, PickersStartEndDateDirection.row);
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
<div aria-label={label} className={cx({ [classes.row]: isRow })}>
|
|
72
|
-
<Typography component={isRow ? 'div' : 'p'}>{label}</Typography>
|
|
73
|
-
<DateTimePickerInput
|
|
74
|
-
changeDate={changeDate}
|
|
75
|
-
date={date}
|
|
76
|
-
disabled={disabled}
|
|
77
|
-
maxDate={maxDate}
|
|
78
|
-
minDate={minDate}
|
|
79
|
-
property={property}
|
|
80
|
-
setDate={setDate}
|
|
81
|
-
onClosePicker={onClosePicker}
|
|
82
|
-
/>
|
|
83
|
-
</div>
|
|
84
|
-
);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
interface DisabledPicker {
|
|
88
|
-
isDisabledEndPicker?: boolean;
|
|
89
|
-
isDisabledStartPicker?: boolean;
|
|
90
|
-
}
|
|
91
|
-
type PickersDate = Pick<PickersData, 'rangeEndDate' | 'rangeStartDate'>;
|
|
92
|
-
|
|
93
|
-
interface Props extends PickersDate, PickersStartEndDateModel {
|
|
94
|
-
direction?: PickersStartEndDateDirection;
|
|
95
|
-
disabled?: DisabledPicker;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const PickersStartEndDate = ({
|
|
99
|
-
startDate,
|
|
100
|
-
endDate,
|
|
101
|
-
disabled,
|
|
102
|
-
changeDate,
|
|
103
|
-
rangeStartDate,
|
|
104
|
-
rangeEndDate,
|
|
105
|
-
direction = PickersStartEndDateDirection.column
|
|
106
|
-
}: Props): JSX.Element => {
|
|
107
|
-
const { classes, cx } = useStyles();
|
|
108
|
-
const { Adapter } = useDateTimePickerAdapter();
|
|
109
|
-
|
|
110
|
-
const { locale } = useAtomValue(userAtom);
|
|
111
|
-
const error = useAtomValue(errorTimePeriodAtom);
|
|
112
|
-
|
|
113
|
-
const { start, setStart } = startDate;
|
|
114
|
-
const { end, setEnd } = endDate;
|
|
115
|
-
|
|
116
|
-
const maxStart = rangeStartDate?.max;
|
|
117
|
-
const minStart = rangeStartDate?.min;
|
|
118
|
-
const maxEnd = rangeEndDate?.max;
|
|
119
|
-
const minEnd = rangeEndDate?.min;
|
|
120
|
-
|
|
121
|
-
const styleContainer = equals(direction, PickersStartEndDateDirection.column)
|
|
122
|
-
? classes.verticalDirection
|
|
123
|
-
: classes.horizontalDirection;
|
|
124
|
-
|
|
125
|
-
const isHorizontalDirection = equals(
|
|
126
|
-
direction,
|
|
127
|
-
PickersStartEndDateDirection.row
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
return (
|
|
131
|
-
<LocalizationProvider dateAdapter={Adapter} locale={locale.substring(0, 2)}>
|
|
132
|
-
<div className={styleContainer}>
|
|
133
|
-
<PickerDateWithLabel
|
|
134
|
-
changeDate={changeDate}
|
|
135
|
-
date={start}
|
|
136
|
-
direction={direction}
|
|
137
|
-
disabled={disabled?.isDisabledStartPicker}
|
|
138
|
-
label="From"
|
|
139
|
-
maxDate={maxStart}
|
|
140
|
-
minDate={minStart}
|
|
141
|
-
property={CustomTimePeriodProperty.start}
|
|
142
|
-
setDate={setStart}
|
|
143
|
-
/>
|
|
144
|
-
<PickerDateWithLabel
|
|
145
|
-
changeDate={changeDate}
|
|
146
|
-
date={end}
|
|
147
|
-
direction={direction}
|
|
148
|
-
disabled={disabled?.isDisabledEndPicker}
|
|
149
|
-
label="To"
|
|
150
|
-
maxDate={maxEnd}
|
|
151
|
-
minDate={minEnd}
|
|
152
|
-
property={CustomTimePeriodProperty.end}
|
|
153
|
-
setDate={setEnd}
|
|
154
|
-
/>
|
|
155
|
-
</div>
|
|
156
|
-
|
|
157
|
-
{error && (
|
|
158
|
-
<ErrorText
|
|
159
|
-
message="The end date must be greater than the start date"
|
|
160
|
-
style={cx(classes.error, {
|
|
161
|
-
[classes.horizontalError]: isHorizontalDirection
|
|
162
|
-
})}
|
|
163
|
-
/>
|
|
164
|
-
)}
|
|
165
|
-
</LocalizationProvider>
|
|
166
|
-
);
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
export default PickersStartEndDate;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { makeStyles } from 'tss-react/mui';
|
|
2
|
-
|
|
3
|
-
import { Popover } from '@mui/material';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
PickersData,
|
|
7
|
-
PopoverData,
|
|
8
|
-
defaultAnchorOrigin,
|
|
9
|
-
defaultTransformOrigin
|
|
10
|
-
} from './models';
|
|
11
|
-
import usePickersStartEndDate from './usePickersStartEndDate';
|
|
12
|
-
import PickersStartEndDate from './PickersStartEndDate';
|
|
13
|
-
|
|
14
|
-
const useStyles = makeStyles()((theme) => ({
|
|
15
|
-
paper: {
|
|
16
|
-
'& .MuiPopover-paper': {
|
|
17
|
-
minWidth: 250,
|
|
18
|
-
padding: theme.spacing(1)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
interface Props {
|
|
24
|
-
pickersData: PickersData;
|
|
25
|
-
popoverData: PopoverData;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const PopoverCustomTimePeriod = ({
|
|
29
|
-
popoverData,
|
|
30
|
-
pickersData
|
|
31
|
-
}: Props): JSX.Element => {
|
|
32
|
-
const { classes } = useStyles();
|
|
33
|
-
|
|
34
|
-
const { open, onClose } = popoverData;
|
|
35
|
-
const { acceptDate, customTimePeriod } = pickersData;
|
|
36
|
-
|
|
37
|
-
const { startDate, endDate, changeDate } = usePickersStartEndDate({
|
|
38
|
-
acceptDate,
|
|
39
|
-
customTimePeriod
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const anchorEl = popoverData?.anchorEl;
|
|
43
|
-
const anchorPosition = popoverData?.anchorPosition;
|
|
44
|
-
const anchorOrigin = popoverData?.anchorOrigin;
|
|
45
|
-
const transformOrigin = popoverData?.transformOrigin;
|
|
46
|
-
const anchorReference = anchorPosition ? 'anchorPosition' : 'anchorEl';
|
|
47
|
-
|
|
48
|
-
const disabled = {
|
|
49
|
-
isDisabledEndPicker: pickersData?.isDisabledEndPicker,
|
|
50
|
-
isDisabledStartPicker: pickersData?.isDisabledStartPicker
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<Popover
|
|
55
|
-
anchorEl={anchorEl}
|
|
56
|
-
anchorOrigin={anchorOrigin ?? defaultAnchorOrigin}
|
|
57
|
-
anchorPosition={anchorPosition}
|
|
58
|
-
anchorReference={anchorReference}
|
|
59
|
-
className={classes.paper}
|
|
60
|
-
open={open}
|
|
61
|
-
transformOrigin={transformOrigin ?? defaultTransformOrigin}
|
|
62
|
-
onClose={onClose}
|
|
63
|
-
>
|
|
64
|
-
<PickersStartEndDate
|
|
65
|
-
changeDate={changeDate}
|
|
66
|
-
disabled={disabled}
|
|
67
|
-
endDate={endDate}
|
|
68
|
-
rangeEndDate={pickersData?.rangeEndDate}
|
|
69
|
-
rangeStartDate={pickersData?.rangeStartDate}
|
|
70
|
-
startDate={startDate}
|
|
71
|
-
/>
|
|
72
|
-
</Popover>
|
|
73
|
-
);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export default PopoverCustomTimePeriod;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { PopoverOrigin, PopoverPosition } from '@mui/material';
|
|
2
|
-
|
|
3
|
-
import { CustomTimePeriod, CustomTimePeriodProperty } from '../../models';
|
|
4
|
-
|
|
5
|
-
interface RangeDate {
|
|
6
|
-
max?: Date;
|
|
7
|
-
min?: Date;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface AcceptDateProps {
|
|
11
|
-
date: Date;
|
|
12
|
-
property: CustomTimePeriodProperty;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface PickersData {
|
|
16
|
-
acceptDate: (props: AcceptDateProps) => void;
|
|
17
|
-
customTimePeriod: CustomTimePeriod;
|
|
18
|
-
getError?: (value: boolean) => void;
|
|
19
|
-
isDisabledEndPicker?: boolean;
|
|
20
|
-
isDisabledStartPicker?: boolean;
|
|
21
|
-
onCloseEndPicker?: (isClosed: boolean) => void;
|
|
22
|
-
onCloseStartPicker?: (isClosed: boolean) => void;
|
|
23
|
-
rangeEndDate?: RangeDate;
|
|
24
|
-
rangeStartDate?: RangeDate;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface PopoverData {
|
|
28
|
-
anchorEl?: HTMLButtonElement;
|
|
29
|
-
anchorOrigin?: PopoverOrigin;
|
|
30
|
-
anchorPosition?: PopoverPosition;
|
|
31
|
-
onClose?: () => void;
|
|
32
|
-
open: boolean;
|
|
33
|
-
transformOrigin?: PopoverOrigin;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export enum OriginHorizontalEnum {
|
|
37
|
-
center = 'center',
|
|
38
|
-
left = 'left',
|
|
39
|
-
right = 'right'
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export enum OriginVerticalEnum {
|
|
43
|
-
bottom = 'bottom',
|
|
44
|
-
center = 'center',
|
|
45
|
-
top = 'top'
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const defaultAnchorOrigin = {
|
|
49
|
-
horizontal: OriginHorizontalEnum.center,
|
|
50
|
-
vertical: OriginVerticalEnum.top
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const defaultTransformOrigin = {
|
|
54
|
-
horizontal: OriginHorizontalEnum.center,
|
|
55
|
-
vertical: OriginVerticalEnum.top
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export enum PickersStartEndDateDirection {
|
|
59
|
-
column = 'column',
|
|
60
|
-
row = 'row'
|
|
61
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import dayjs from 'dayjs';
|
|
4
|
-
import { and, cond, equals, isNil } from 'ramda';
|
|
5
|
-
import { useSetAtom } from 'jotai';
|
|
6
|
-
|
|
7
|
-
import { errorTimePeriodAtom } from '../../timePeriodsAtoms';
|
|
8
|
-
import { CustomTimePeriod, CustomTimePeriodProperty } from '../../models';
|
|
9
|
-
|
|
10
|
-
import { AcceptDateProps } from './models';
|
|
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
|
-
export interface PickersStartEndDateModel {
|
|
22
|
-
changeDate: (props: AcceptDateProps) => void;
|
|
23
|
-
endDate: EndDate;
|
|
24
|
-
startDate: StartDate;
|
|
25
|
-
}
|
|
26
|
-
interface Props {
|
|
27
|
-
acceptDate: (props: AcceptDateProps) => void;
|
|
28
|
-
customTimePeriod: CustomTimePeriod;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const usePickersStartEndDate = ({
|
|
32
|
-
customTimePeriod,
|
|
33
|
-
acceptDate
|
|
34
|
-
}: Props): PickersStartEndDateModel => {
|
|
35
|
-
const [start, setStart] = useState<Date | null>(
|
|
36
|
-
!isNil(customTimePeriod) ? customTimePeriod.start : null
|
|
37
|
-
);
|
|
38
|
-
const [end, setEnd] = useState<Date | null>(
|
|
39
|
-
!isNil(customTimePeriod) ? customTimePeriod.end : null
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const setError = useSetAtom(errorTimePeriodAtom);
|
|
43
|
-
|
|
44
|
-
const isInvalidDate = ({ startDate, endDate }): boolean =>
|
|
45
|
-
dayjs(startDate).isSameOrAfter(dayjs(endDate), 'minute');
|
|
46
|
-
|
|
47
|
-
const changeDate = ({ property, date }): void => {
|
|
48
|
-
const currentDate = customTimePeriod[property];
|
|
49
|
-
cond([
|
|
50
|
-
[equals(CustomTimePeriodProperty?.start), (): void => setStart(date)],
|
|
51
|
-
[equals(CustomTimePeriodProperty?.end), (): void => setEnd(date)]
|
|
52
|
-
])(property);
|
|
53
|
-
|
|
54
|
-
if (dayjs(date).isSame(dayjs(currentDate)) || !dayjs(date).isValid()) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
acceptDate({
|
|
59
|
-
date,
|
|
60
|
-
property
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
if (
|
|
66
|
-
and(
|
|
67
|
-
dayjs(customTimePeriod.start).isSame(dayjs(start), 'minute'),
|
|
68
|
-
dayjs(customTimePeriod.end).isSame(dayjs(end), 'minute')
|
|
69
|
-
)
|
|
70
|
-
) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
setStart(customTimePeriod.start);
|
|
74
|
-
setEnd(customTimePeriod.end);
|
|
75
|
-
}, [customTimePeriod.start, customTimePeriod.end]);
|
|
76
|
-
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
if (!end || !start) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
setError(isInvalidDate({ endDate: end, startDate: start }));
|
|
82
|
-
}, [end, start]);
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
changeDate,
|
|
86
|
-
endDate: { end, setEnd },
|
|
87
|
-
startDate: { setStart, start }
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export default usePickersStartEndDate;
|