@centreon/ui 23.10.18-MON-17793-create-graph-component-centreon-ui.2 → 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 +1 -1
- package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.styles.ts +18 -24
- package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.tsx +44 -34
- package/src/TimePeriods/CustomTimePeriod/index.tsx +1 -3
- package/src/TimePeriods/ResolutionTimePeriod.cypress.spec.tsx +65 -0
- package/src/TimePeriods/SelectedTimePeriod.tsx +36 -40
- package/src/TimePeriods/{timePeriods.styles.ts → TimePeriods.styles.ts} +7 -5
- package/src/TimePeriods/index.stories.tsx +27 -10
- package/src/TimePeriods/index.tsx +12 -3
- package/src/TimePeriods/mockedData.ts +12 -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.3",
|
|
4
4
|
"description": "Centreon UI Components",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
|
|
@@ -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: '
|
|
13
|
-
gridTemplateColumns: 'min-content auto'
|
|
11
|
+
display: 'flex'
|
|
14
12
|
},
|
|
15
|
-
|
|
13
|
+
containerDates: {
|
|
16
14
|
display: 'flex',
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
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
|
-
<
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
<div className={classes.
|
|
47
|
-
<div className={classes.
|
|
48
|
-
<Typography
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
</
|
|
74
|
-
</
|
|
83
|
+
</Button>
|
|
84
|
+
</div>
|
|
75
85
|
);
|
|
76
86
|
};
|
|
77
87
|
|
|
@@ -14,10 +14,9 @@ import PopoverCustomTimePeriod from './PopoverCustomTimePeriod';
|
|
|
14
14
|
|
|
15
15
|
interface Props {
|
|
16
16
|
disabled?: boolean;
|
|
17
|
-
width: number;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
const CustomTimePeriod = ({
|
|
19
|
+
const CustomTimePeriod = ({ disabled = false }: Props): JSX.Element => {
|
|
21
20
|
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement>();
|
|
22
21
|
|
|
23
22
|
const customTimePeriod = useAtomValue(customTimePeriodAtom);
|
|
@@ -43,7 +42,6 @@ const CustomTimePeriod = ({ width, disabled = false }: Props): JSX.Element => {
|
|
|
43
42
|
<>
|
|
44
43
|
<CompactCustomTimePeriod
|
|
45
44
|
disabled={disabled}
|
|
46
|
-
width={width}
|
|
47
45
|
onClick={onClickCompactCustomTimePeriod}
|
|
48
46
|
/>
|
|
49
47
|
<PopoverCustomTimePeriod
|
|
@@ -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
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
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: '
|
|
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
|
|
22
|
-
|
|
23
|
-
{
|
|
24
|
-
|
|
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,4 +1,10 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
1
3
|
import { Responsive } from '@visx/visx';
|
|
4
|
+
import 'dayjs/locale/en';
|
|
5
|
+
import 'dayjs/locale/pt';
|
|
6
|
+
import 'dayjs/locale/fr';
|
|
7
|
+
import 'dayjs/locale/es';
|
|
2
8
|
import dayjs from 'dayjs';
|
|
3
9
|
import duration from 'dayjs/plugin/duration';
|
|
4
10
|
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
|
|
@@ -14,7 +20,7 @@ import {
|
|
|
14
20
|
EndStartInterval,
|
|
15
21
|
TimePeriod
|
|
16
22
|
} from './models';
|
|
17
|
-
import { useStyles } from './
|
|
23
|
+
import { useStyles } from './TimePeriods.styles';
|
|
18
24
|
import useAwesomeTimePeriod from './useAwesomeTimePeriod';
|
|
19
25
|
|
|
20
26
|
dayjs.extend(isSameOrAfter);
|
|
@@ -28,6 +34,7 @@ export interface Props {
|
|
|
28
34
|
extraTimePeriods?: Array<TimePeriod>;
|
|
29
35
|
getIsError?: (value: boolean) => void;
|
|
30
36
|
getStartEndParameters?: ({ start, end }: EndStartInterval) => void;
|
|
37
|
+
renderExternalComponent?: ReactNode;
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
const AwesomeTimePeriod = ({
|
|
@@ -35,7 +42,8 @@ const AwesomeTimePeriod = ({
|
|
|
35
42
|
disabled = false,
|
|
36
43
|
getStartEndParameters,
|
|
37
44
|
getIsError,
|
|
38
|
-
adjustTimePeriodData
|
|
45
|
+
adjustTimePeriodData,
|
|
46
|
+
renderExternalComponent
|
|
39
47
|
}: Props): JSX.Element => {
|
|
40
48
|
const { classes } = useStyles({ disabled });
|
|
41
49
|
|
|
@@ -56,7 +64,8 @@ const AwesomeTimePeriod = ({
|
|
|
56
64
|
extraTimePeriods={extraTimePeriods}
|
|
57
65
|
width={width}
|
|
58
66
|
/>
|
|
59
|
-
<CustomTimePeriod disabled={disabled}
|
|
67
|
+
<CustomTimePeriod disabled={disabled} />
|
|
68
|
+
<div>{renderExternalComponent}</div>
|
|
60
69
|
</Paper>
|
|
61
70
|
);
|
|
62
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
|
+
};
|