@centreon/ui 24.8.4 → 24.8.6
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/Dashboard/Dashboard.styles.ts +2 -1
- package/src/TimePeriods/DateTimePickerInput.tsx +15 -5
- package/src/utils/index.ts +1 -0
- package/src/utils/useLocaleTimezoneDate/LocaleTimezoneDate.cypress.spec.tsx +98 -0
- package/src/utils/useLocaleTimezoneDate/useLocaleTimezoneDate.ts +41 -0
package/package.json
CHANGED
|
@@ -104,7 +104,8 @@ export const useDashboardItemStyles = makeStyles<{ hasHeader: boolean }>()(
|
|
|
104
104
|
},
|
|
105
105
|
widgetPadding: {
|
|
106
106
|
overflowX: 'auto',
|
|
107
|
-
padding: theme.spacing(0.5, 1.5, 1.5)
|
|
107
|
+
padding: theme.spacing(0.5, 1.5, 1.5),
|
|
108
|
+
position: 'relative'
|
|
108
109
|
}
|
|
109
110
|
})
|
|
110
111
|
);
|
|
@@ -25,10 +25,12 @@ interface Props {
|
|
|
25
25
|
date: Date | null;
|
|
26
26
|
desktopMediaQuery?: string;
|
|
27
27
|
disabled?: boolean;
|
|
28
|
+
locale?: string;
|
|
28
29
|
maxDate?: Date;
|
|
29
30
|
minDate?: Date;
|
|
30
31
|
minDateTime?: Date;
|
|
31
32
|
property: CustomTimePeriodProperty | string;
|
|
33
|
+
timezone?: string;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
const DateTimePickerInput = ({
|
|
@@ -40,14 +42,16 @@ const DateTimePickerInput = ({
|
|
|
40
42
|
changeDate,
|
|
41
43
|
disabled = false,
|
|
42
44
|
desktopMediaQuery,
|
|
45
|
+
locale,
|
|
46
|
+
timezone,
|
|
43
47
|
...rest
|
|
44
48
|
}: Props & DateTimePickerProps<dayjs.Dayjs>): JSX.Element => {
|
|
45
49
|
const desktopPickerMediaQuery =
|
|
46
50
|
'@media (min-width: 1024px) or (pointer: fine)';
|
|
47
51
|
|
|
48
|
-
const
|
|
52
|
+
const user = useAtomValue(userAtom);
|
|
49
53
|
|
|
50
|
-
const isUTC = equals(timezone, 'UTC');
|
|
54
|
+
const isUTC = equals(timezone ?? user.timezone, 'UTC');
|
|
51
55
|
|
|
52
56
|
const changeTime = (newValue: dayjs.Dayjs | null): void => {
|
|
53
57
|
changeDate({ date: dayjs(newValue).toDate(), property });
|
|
@@ -55,14 +59,20 @@ const DateTimePickerInput = ({
|
|
|
55
59
|
|
|
56
60
|
const formatDate = useCallback(
|
|
57
61
|
(currentDate: Date | null): Dayjs => {
|
|
58
|
-
|
|
62
|
+
if (timezone) {
|
|
63
|
+
return dayjs(currentDate).tz(timezone);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return isUTC
|
|
67
|
+
? dayjs.utc(currentDate)
|
|
68
|
+
: dayjs.tz(currentDate, user.timezone);
|
|
59
69
|
},
|
|
60
|
-
[isUTC, timezone]
|
|
70
|
+
[isUTC, timezone, user.timezone]
|
|
61
71
|
);
|
|
62
72
|
|
|
63
73
|
return (
|
|
64
74
|
<LocalizationProvider
|
|
65
|
-
adapterLocale={locale.substring(0, 2)}
|
|
75
|
+
adapterLocale={(locale ?? user.locale).substring(0, 2)}
|
|
66
76
|
dateAdapter={AdapterDayjs}
|
|
67
77
|
dateLibInstance={dayjs}
|
|
68
78
|
>
|
package/src/utils/index.ts
CHANGED
|
@@ -26,3 +26,4 @@ export * from './resourcesStatusURL';
|
|
|
26
26
|
export * from '../Graph/Chart/helpers';
|
|
27
27
|
export * from '../Graph/Chart/InteractiveComponents/TimeShiftZones/useTimeShiftZones';
|
|
28
28
|
export * from '../TimePeriods/helpers';
|
|
29
|
+
export * from './useLocaleTimezoneDate/useLocaleTimezoneDate';
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
2
|
+
import utc from 'dayjs/plugin/utc';
|
|
3
|
+
import timezonePlugin from 'dayjs/plugin/timezone';
|
|
4
|
+
import dayjs from 'dayjs';
|
|
5
|
+
|
|
6
|
+
import 'dayjs/locale/de';
|
|
7
|
+
import 'dayjs/locale/fr';
|
|
8
|
+
import 'dayjs/locale/en';
|
|
9
|
+
import 'dayjs/locale/es';
|
|
10
|
+
import 'dayjs/locale/pt';
|
|
11
|
+
import { Props, useLocaleTimezoneDate } from './useLocaleTimezoneDate';
|
|
12
|
+
|
|
13
|
+
dayjs.extend(localizedFormat);
|
|
14
|
+
dayjs.extend(utc);
|
|
15
|
+
dayjs.extend(timezonePlugin);
|
|
16
|
+
|
|
17
|
+
const date = dayjs(1602252661000);
|
|
18
|
+
|
|
19
|
+
const Test = ({
|
|
20
|
+
locale,
|
|
21
|
+
timezone,
|
|
22
|
+
format
|
|
23
|
+
}: Omit<Props, 'date'>): JSX.Element => {
|
|
24
|
+
const { formatDate } = useLocaleTimezoneDate();
|
|
25
|
+
|
|
26
|
+
return <p>{formatDate({ date, format, locale, timezone })}</p>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const initialize = ({ timezone, locale, format }): void => {
|
|
30
|
+
cy.mount({
|
|
31
|
+
Component: <Test format={format} locale={locale} timezone={timezone} />
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const locales = [undefined, 'en-GB', 'fr-FR', 'de-DE'];
|
|
36
|
+
const timezones = [
|
|
37
|
+
'Europe/Paris',
|
|
38
|
+
'Europe/London',
|
|
39
|
+
'UTC',
|
|
40
|
+
'Africa/Casablanca',
|
|
41
|
+
'America/New_York'
|
|
42
|
+
];
|
|
43
|
+
const formats = ['L LT', 'LLLL'];
|
|
44
|
+
|
|
45
|
+
const resultsEN = [
|
|
46
|
+
'10/09/2020 4:11 PM',
|
|
47
|
+
'Friday, October 9, 2020 4:11 PM',
|
|
48
|
+
'10/09/2020 3:11 PM',
|
|
49
|
+
'Friday, October 9, 2020 3:11 PM',
|
|
50
|
+
'10/09/2020 2:11 PM',
|
|
51
|
+
'Friday, October 9, 2020 2:11 PM',
|
|
52
|
+
'10/09/2020 3:11 PM',
|
|
53
|
+
'Friday, October 9, 2020 3:11 PM',
|
|
54
|
+
'10/09/2020 10:11 AM',
|
|
55
|
+
'Friday, October 9, 2020 10:11 AM'
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const resultsFR = [
|
|
59
|
+
'09/10/2020 16:11',
|
|
60
|
+
'vendredi 9 octobre 2020 16:11',
|
|
61
|
+
'09/10/2020 15:11',
|
|
62
|
+
'vendredi 9 octobre 2020 15:11',
|
|
63
|
+
'09/10/2020 14:11',
|
|
64
|
+
'vendredi 9 octobre 2020 14:11',
|
|
65
|
+
'09/10/2020 15:11',
|
|
66
|
+
'vendredi 9 octobre 2020 15:11',
|
|
67
|
+
'09/10/2020 10:11',
|
|
68
|
+
'vendredi 9 octobre 2020 10:11'
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
const resultsDE = [
|
|
72
|
+
'09.10.2020 16:11',
|
|
73
|
+
'Freitag, 9. Oktober 2020 16:11',
|
|
74
|
+
'09.10.2020 15:11',
|
|
75
|
+
'Freitag, 9. Oktober 2020 15:11',
|
|
76
|
+
'09.10.2020 14:11',
|
|
77
|
+
'Freitag, 9. Oktober 2020 14:11',
|
|
78
|
+
'09.10.2020 15:11',
|
|
79
|
+
'Freitag, 9. Oktober 2020 15:11',
|
|
80
|
+
'09.10.2020 10:11',
|
|
81
|
+
'Freitag, 9. Oktober 2020 10:11'
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
const results = [...resultsEN, ...resultsEN, ...resultsFR, ...resultsDE];
|
|
85
|
+
let index = 0;
|
|
86
|
+
|
|
87
|
+
locales.forEach((locale) => {
|
|
88
|
+
timezones.forEach((timezone) => {
|
|
89
|
+
formats.forEach((format) => {
|
|
90
|
+
it(`displays the date with the locale ${locale}, the timezone ${timezone} and the format ${format}`, () => {
|
|
91
|
+
initialize({ format, locale, timezone });
|
|
92
|
+
|
|
93
|
+
cy.contains(results[index]).should('be.visible');
|
|
94
|
+
index += 1;
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Dayjs } from 'dayjs';
|
|
4
|
+
import { isNil } from 'ramda';
|
|
5
|
+
|
|
6
|
+
export interface Props {
|
|
7
|
+
date: Dayjs;
|
|
8
|
+
format?: string;
|
|
9
|
+
locale?: string;
|
|
10
|
+
timezone?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface UseLocaleTimeZoneDate {
|
|
14
|
+
formatDate: (props: Props) => string;
|
|
15
|
+
toLocaleTimezoneDate: (props: Omit<Props, 'format'>) => Dayjs;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const useLocaleTimezoneDate = (): UseLocaleTimeZoneDate => {
|
|
19
|
+
const toLocaleTimezoneDate = useCallback(
|
|
20
|
+
({ date, locale = 'en', timezone }: Omit<Props, 'format'>): Dayjs => {
|
|
21
|
+
if (isNil(timezone)) {
|
|
22
|
+
return date.locale(locale);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return date.locale(locale).tz(timezone);
|
|
26
|
+
},
|
|
27
|
+
[]
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const formatDate = useCallback(
|
|
31
|
+
({ date, locale = 'en', timezone, format = 'L LT' }: Props): string => {
|
|
32
|
+
return toLocaleTimezoneDate({ date, locale, timezone }).format(format);
|
|
33
|
+
},
|
|
34
|
+
[]
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
formatDate,
|
|
39
|
+
toLocaleTimezoneDate
|
|
40
|
+
};
|
|
41
|
+
};
|