@centreon/ui 23.10.17 → 23.10.18-MON-17793-create-graph-component-centreon-ui.0
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 +2 -1
- package/src/Graph/Axes/UnitLabel.tsx +20 -0
- package/src/Graph/Axes/index.tsx +99 -0
- package/src/Graph/Axes/models.ts +26 -0
- package/src/Graph/Axes/useAxisY.ts +100 -0
- package/src/Graph/Graph.tsx +231 -0
- package/src/Graph/Grids/index.tsx +20 -0
- package/src/Graph/Header/index.tsx +34 -0
- package/src/Graph/InteractionWithGraph/AnchorPoint/RegularAnchorPoint.tsx +88 -0
- package/src/Graph/InteractionWithGraph/AnchorPoint/StackedAnchorPoint.tsx +97 -0
- package/src/Graph/InteractionWithGraph/AnchorPoint/index.tsx +56 -0
- package/src/Graph/InteractionWithGraph/AnchorPoint/models.ts +25 -0
- package/src/Graph/InteractionWithGraph/AnchorPoint/useAnchorPoint.ts +109 -0
- package/src/Graph/InteractionWithGraph/Bar.tsx +21 -0
- package/src/Graph/InteractionWithGraph/ZoomPreview/index.tsx +38 -0
- package/src/Graph/InteractionWithGraph/ZoomPreview/models.ts +17 -0
- package/src/Graph/InteractionWithGraph/ZoomPreview/useZoomPreview.ts +101 -0
- package/src/Graph/InteractionWithGraph/ZoomPreview/zoomPreviewAtoms.ts +5 -0
- package/src/Graph/InteractionWithGraph/index.tsx +93 -0
- package/src/Graph/InteractionWithGraph/interactionWithGraphAtoms.ts +7 -0
- package/src/Graph/InteractionWithGraph/mouseTimeValueAtoms.ts +49 -0
- package/src/Graph/Lines/RegularLines/index.tsx +99 -0
- package/src/Graph/Lines/RegularLines/useRegularLines.ts +15 -0
- package/src/Graph/Lines/StackedLines/index.tsx +74 -0
- package/src/Graph/Lines/StackedLines/useStackedLines.ts +39 -0
- package/src/Graph/Lines/index.tsx +153 -0
- package/src/Graph/Lines/models.ts +32 -0
- package/src/Graph/LoadingProgress.tsx +46 -0
- package/src/Graph/common/index.ts +33 -0
- package/src/Graph/data.json +1338 -0
- package/src/Graph/helpers/doc.ts +323 -0
- package/src/Graph/helpers/index.ts +15 -0
- package/src/Graph/index.stories.tsx +30 -0
- package/src/Graph/index.tsx +66 -0
- package/src/Graph/models.ts +68 -0
- package/src/Graph/timeSeries/index.test.ts +484 -0
- package/src/Graph/timeSeries/index.ts +512 -0
- package/src/Graph/timeSeries/models.ts +119 -0
- package/src/Graph/useGraphData.ts +117 -0
- package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.styles.ts +57 -0
- package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.tsx +78 -0
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/ErrorText.tsx +14 -0
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +169 -0
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/index.tsx +76 -0
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +61 -0
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/usePickersStartEndDate.ts +91 -0
- package/src/TimePeriods/CustomTimePeriod/index.tsx +63 -0
- package/src/TimePeriods/DateTimePickerInput.tsx +99 -0
- package/src/TimePeriods/SelectedTimePeriod.tsx +99 -0
- package/src/TimePeriods/TimePeriods.cypress.spec.tsx +497 -0
- package/src/TimePeriods/helpers/index.ts +25 -0
- package/src/TimePeriods/index.stories.tsx +74 -0
- package/src/TimePeriods/index.tsx +77 -0
- package/src/TimePeriods/models.ts +103 -0
- package/src/TimePeriods/timePeriods.styles.ts +20 -0
- package/src/TimePeriods/timePeriodsAtoms.ts +113 -0
- package/src/TimePeriods/useDateTimePickerAdapter.ts +329 -0
- package/src/TimePeriods/useSortTimePeriods.ts +24 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { MouseEvent, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useAtomValue, useSetAtom } from 'jotai';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
changeCustomTimePeriodDerivedAtom,
|
|
7
|
+
customTimePeriodAtom
|
|
8
|
+
} from '../timePeriodsAtoms';
|
|
9
|
+
|
|
10
|
+
import CompactCustomTimePeriod from './CompactCustomTimePeriod';
|
|
11
|
+
import PopoverCustomTimePeriod from './PopoverCustomTimePeriod';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
width: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const CustomTimePeriod = ({ width, disabled = false }: Props): JSX.Element => {
|
|
19
|
+
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement>();
|
|
20
|
+
|
|
21
|
+
const customTimePeriod = useAtomValue(customTimePeriodAtom);
|
|
22
|
+
const changeCustomTimePeriod = useSetAtom(changeCustomTimePeriodDerivedAtom);
|
|
23
|
+
|
|
24
|
+
const acceptDate = ({ property, date }): void =>
|
|
25
|
+
changeCustomTimePeriod({ date, property });
|
|
26
|
+
|
|
27
|
+
const onClickCompactCustomTimePeriod = (
|
|
28
|
+
event: MouseEvent<HTMLButtonElement>
|
|
29
|
+
): void => {
|
|
30
|
+
setAnchorEl(event.currentTarget);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const closePopover = (): void => {
|
|
34
|
+
setAnchorEl(undefined);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<>
|
|
39
|
+
<CompactCustomTimePeriod
|
|
40
|
+
disabled={disabled}
|
|
41
|
+
width={width}
|
|
42
|
+
onClick={onClickCompactCustomTimePeriod}
|
|
43
|
+
/>
|
|
44
|
+
<PopoverCustomTimePeriod
|
|
45
|
+
pickersData={{
|
|
46
|
+
acceptDate,
|
|
47
|
+
customTimePeriod,
|
|
48
|
+
isDisabledEndPicker: disabled,
|
|
49
|
+
isDisabledStartPicker: disabled,
|
|
50
|
+
rangeEndDate: { min: customTimePeriod.start },
|
|
51
|
+
rangeStartDate: { max: customTimePeriod.end }
|
|
52
|
+
}}
|
|
53
|
+
popoverData={{
|
|
54
|
+
anchorEl,
|
|
55
|
+
onClose: closePopover,
|
|
56
|
+
open: Boolean(anchorEl)
|
|
57
|
+
}}
|
|
58
|
+
/>
|
|
59
|
+
</>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default CustomTimePeriod;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
|
|
5
|
+
import { TextFieldProps } from '@mui/material';
|
|
6
|
+
import { DesktopDateTimePicker } from '@mui/x-date-pickers';
|
|
7
|
+
|
|
8
|
+
import { TextField } from '@centreon/ui';
|
|
9
|
+
|
|
10
|
+
import { DateTimePickerInputModel } from './models';
|
|
11
|
+
import useDateTimePickerAdapter from './useDateTimePickerAdapter';
|
|
12
|
+
|
|
13
|
+
const renderDateTimePickerTextField =
|
|
14
|
+
(blur: () => void) =>
|
|
15
|
+
({ inputRef, inputProps, InputProps }: TextFieldProps): JSX.Element => {
|
|
16
|
+
return (
|
|
17
|
+
<TextField
|
|
18
|
+
// eslint-disable-next-line react/no-unstable-nested-components
|
|
19
|
+
EndAdornment={(): JSX.Element => <div>{InputProps?.endAdornment}</div>}
|
|
20
|
+
dataTestId="calendar"
|
|
21
|
+
inputProps={{
|
|
22
|
+
...inputProps,
|
|
23
|
+
ref: inputRef,
|
|
24
|
+
style: { padding: 8 }
|
|
25
|
+
}}
|
|
26
|
+
onBlur={blur}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const DateTimePickerInput = ({
|
|
32
|
+
date,
|
|
33
|
+
maxDate,
|
|
34
|
+
minDate,
|
|
35
|
+
property,
|
|
36
|
+
changeDate,
|
|
37
|
+
setDate,
|
|
38
|
+
onClosePicker,
|
|
39
|
+
disabled = false
|
|
40
|
+
}: DateTimePickerInputModel): JSX.Element => {
|
|
41
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
42
|
+
|
|
43
|
+
const { getDestinationAndConfiguredTimezoneOffset, formatKeyboardValue } =
|
|
44
|
+
useDateTimePickerAdapter();
|
|
45
|
+
|
|
46
|
+
const changeTime = (
|
|
47
|
+
newValue: dayjs.Dayjs | null,
|
|
48
|
+
keyBoardValue: string | undefined
|
|
49
|
+
): void => {
|
|
50
|
+
if (isOpen) {
|
|
51
|
+
changeDate({ date: dayjs(newValue).toDate(), property });
|
|
52
|
+
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const value = dayjs(formatKeyboardValue(keyBoardValue))
|
|
56
|
+
.add(
|
|
57
|
+
dayjs.duration({ hours: getDestinationAndConfiguredTimezoneOffset() })
|
|
58
|
+
)
|
|
59
|
+
.toDate();
|
|
60
|
+
|
|
61
|
+
setDate(value);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const blur = (): void => {
|
|
65
|
+
changeDate({ date, property });
|
|
66
|
+
};
|
|
67
|
+
const close = (): void => {
|
|
68
|
+
setIsOpen(false);
|
|
69
|
+
onClosePicker?.(true);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const open = (): void => {
|
|
73
|
+
setIsOpen(true);
|
|
74
|
+
onClosePicker?.(false);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<DesktopDateTimePicker<dayjs.Dayjs>
|
|
79
|
+
hideTabs
|
|
80
|
+
PopperProps={{
|
|
81
|
+
open: isOpen
|
|
82
|
+
}}
|
|
83
|
+
dayOfWeekFormatter={(day: string): string =>
|
|
84
|
+
day.substring(0, 2).toUpperCase()
|
|
85
|
+
}
|
|
86
|
+
disabled={disabled}
|
|
87
|
+
maxDate={maxDate && dayjs(maxDate)}
|
|
88
|
+
minDate={minDate && dayjs(minDate)}
|
|
89
|
+
open={isOpen}
|
|
90
|
+
renderInput={renderDateTimePickerTextField(blur)}
|
|
91
|
+
value={date as dayjs.Dayjs}
|
|
92
|
+
onChange={changeTime}
|
|
93
|
+
onClose={close}
|
|
94
|
+
onOpen={open}
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export default DateTimePickerInput;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useAtomValue, useSetAtom } from 'jotai';
|
|
2
|
+
import { T, always, cond, equals, lte, map, pick } from 'ramda';
|
|
3
|
+
import { makeStyles } from 'tss-react/mui';
|
|
4
|
+
|
|
5
|
+
import { Button, ButtonGroup, Tooltip, useTheme } from '@mui/material';
|
|
6
|
+
|
|
7
|
+
import { TimePeriod, timePeriods } from './models';
|
|
8
|
+
import {
|
|
9
|
+
changeSelectedTimePeriodDerivedAtom,
|
|
10
|
+
selectedTimePeriodAtom
|
|
11
|
+
} from './timePeriodsAtoms';
|
|
12
|
+
import useSortTimePeriods from './useSortTimePeriods';
|
|
13
|
+
|
|
14
|
+
const useStyles = makeStyles()((theme) => ({
|
|
15
|
+
button: {
|
|
16
|
+
fontSize: theme.typography.body2.fontSize,
|
|
17
|
+
pointerEvents: 'all'
|
|
18
|
+
},
|
|
19
|
+
buttonGroup: {
|
|
20
|
+
alignSelf: 'center',
|
|
21
|
+
height: '100%'
|
|
22
|
+
}
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
interface Props {
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
extraTimePeriods?: Array<TimePeriod>;
|
|
28
|
+
width: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const SelectedTimePeriod = ({
|
|
32
|
+
width,
|
|
33
|
+
disabled = false,
|
|
34
|
+
extraTimePeriods = []
|
|
35
|
+
}: Props): JSX.Element => {
|
|
36
|
+
const { classes } = useStyles();
|
|
37
|
+
const theme = useTheme();
|
|
38
|
+
|
|
39
|
+
const selectedTimePeriodData = useAtomValue(selectedTimePeriodAtom);
|
|
40
|
+
|
|
41
|
+
const changeSelectedTimePeriod = useSetAtom(
|
|
42
|
+
changeSelectedTimePeriodDerivedAtom
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const currentTimePeriods = useSortTimePeriods([
|
|
46
|
+
...timePeriods,
|
|
47
|
+
...extraTimePeriods
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
const timePeriodOptions = map(
|
|
51
|
+
pick(['id', 'name', 'largeName']),
|
|
52
|
+
currentTimePeriods
|
|
53
|
+
);
|
|
54
|
+
|
|
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>
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export default SelectedTimePeriod;
|