@centreon/ui 25.5.6 → 25.5.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centreon/ui",
3
- "version": "25.5.6",
3
+ "version": "25.5.8",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -7,6 +7,8 @@ import {
7
7
  import { Typography, useTheme } from '@mui/material';
8
8
 
9
9
  import dayjs from 'dayjs';
10
+ import timezonePlugin from 'dayjs/plugin/timezone';
11
+ import utc from 'dayjs/plugin/utc';
10
12
 
11
13
  import { userAtom } from '@centreon/ui-context';
12
14
  import { Axis } from '@visx/visx';
@@ -22,6 +24,8 @@ import type { TimelineProps } from './models';
22
24
  import { useStyles } from './timeline.styles';
23
25
  import { useTimeline } from './useTimeline';
24
26
 
27
+ dayjs.extend(utc);
28
+ dayjs.extend(timezonePlugin);
25
29
  interface Props extends TimelineProps {
26
30
  width: number;
27
31
  height: number;
@@ -1,14 +1,31 @@
1
+ import type { ParentSizeProps } from '@visx/responsive/lib/components/ParentSize';
1
2
  import { ParentSize } from '../..';
2
3
 
3
4
  import ResponsiveTimeline from './ResponsiveTimeline';
4
5
  import type { TimelineProps } from './models';
5
6
 
6
- const Timeline = (props: TimelineProps): JSX.Element => (
7
- <ParentSize>
7
+ interface Props extends ParentSizeProps, TimelineProps {}
8
+
9
+ const Timeline = ({
10
+ data,
11
+ startDate,
12
+ endDate,
13
+ TooltipContent,
14
+ tooltipClassName,
15
+ ...rest
16
+ }: Props): JSX.Element => (
17
+ <ParentSize {...rest}>
8
18
  {({ width, height }) => (
9
- <ResponsiveTimeline {...props} height={height} width={width} />
19
+ <ResponsiveTimeline
20
+ data={data}
21
+ startDate={startDate}
22
+ endDate={endDate}
23
+ TooltipContent={TooltipContent}
24
+ tooltipClassName={tooltipClassName}
25
+ height={height}
26
+ width={width}
27
+ />
10
28
  )}
11
29
  </ParentSize>
12
30
  );
13
-
14
31
  export default Timeline;
@@ -1,3 +1,4 @@
1
+ export type { ParentSizeProps } from '@visx/responsive/lib/components/ParentSize';
1
2
  export { default as LineChart } from './Chart';
2
3
  export { default as ThresholdLines } from './Chart/BasicComponents/Lines/Threshold';
3
4
  export { default as useLineChartData } from './Chart/useChartData';
@@ -10,8 +10,6 @@ import { Typography } from '@mui/material';
10
10
  import { LocalizationProvider } from '@mui/x-date-pickers';
11
11
  import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
12
12
 
13
- import { userAtom } from '@centreon/ui-context';
14
-
15
13
  import DateTimePickerInput from '../../DateTimePickerInput';
16
14
  import { isInvalidDate } from '../../helpers';
17
15
  import {
@@ -20,6 +18,7 @@ import {
20
18
  } from '../../models';
21
19
  import { errorTimePeriodAtom } from '../../timePeriodsAtoms';
22
20
 
21
+ import { useLocale } from '../../../utils';
23
22
  import ErrorText from './ErrorText';
24
23
  import {
25
24
  PickersStartEndDateDirection,
@@ -100,7 +99,7 @@ const PickersStartEndDate = ({
100
99
  }: PickersStartEndDateProps): JSX.Element => {
101
100
  const { classes } = useStyles();
102
101
 
103
- const { locale } = useAtomValue(userAtom);
102
+ const locale = useLocale();
104
103
  const error = useAtomValue(errorTimePeriodAtom);
105
104
  const isError = error || isInvalidDate({ endDate, startDate });
106
105
 
@@ -13,6 +13,7 @@ import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
13
13
 
14
14
  import { userAtom } from '@centreon/ui-context';
15
15
 
16
+ import { useLocale } from '../utils';
16
17
  import { CustomTimePeriodProperty } from './models';
17
18
 
18
19
  interface ChangeDateProps {
@@ -50,6 +51,7 @@ const DateTimePickerInput = ({
50
51
  '@media (min-width: 1024px) or (pointer: fine)';
51
52
 
52
53
  const user = useAtomValue(userAtom);
54
+ const localeToUse = useLocale();
53
55
 
54
56
  const isUTC = equals(timezone ?? user.timezone, 'UTC');
55
57
 
@@ -72,7 +74,7 @@ const DateTimePickerInput = ({
72
74
 
73
75
  return (
74
76
  <LocalizationProvider
75
- adapterLocale={(locale ?? user.locale).substring(0, 2)}
77
+ adapterLocale={(locale ?? localeToUse).substring(0, 2)}
76
78
  dateAdapter={AdapterDayjs}
77
79
  dateLibInstance={dayjs}
78
80
  >
@@ -187,7 +187,6 @@ const useGraphQuery = ({
187
187
  });
188
188
  };
189
189
 
190
-
191
190
  const formatLegend = ({
192
191
  host = null,
193
192
  service = null,
@@ -28,3 +28,4 @@ export * from '../Graph/Chart/InteractiveComponents/TimeShiftZones/useTimeShiftZ
28
28
  export * from '../TimePeriods/helpers';
29
29
  export { lastDayPeriod, type Parameters } from '../TimePeriods/models';
30
30
  export * from './useLocaleTimezoneDate/useLocaleTimezoneDate';
31
+ export * from './useLocale';
@@ -0,0 +1,9 @@
1
+ import { browserLocaleAtom, userAtom } from '@centreon/ui-context';
2
+ import { useAtomValue } from 'jotai';
3
+
4
+ export const useLocale = () => {
5
+ const user = useAtomValue(userAtom);
6
+ const browserLocale = useAtomValue(browserLocaleAtom);
7
+
8
+ return user.locale || browserLocale;
9
+ };
@@ -0,0 +1,38 @@
1
+ import { browserLocaleAtom, userAtom } from '@centreon/ui-context';
2
+ import { Provider, createStore } from 'jotai';
3
+ import { useLocale } from '.';
4
+
5
+ const TestComponent = () => {
6
+ const locale = useLocale();
7
+
8
+ return <p>{locale}</p>;
9
+ };
10
+
11
+ const initialize = ({ userLocale, browserLocale }) => {
12
+ const store = createStore();
13
+
14
+ store.set(userAtom, { locale: userLocale });
15
+ store.set(browserLocaleAtom, browserLocale);
16
+
17
+ cy.mount({
18
+ Component: (
19
+ <Provider store={store}>
20
+ <TestComponent />
21
+ </Provider>
22
+ )
23
+ });
24
+ };
25
+
26
+ describe('useLocale', () => {
27
+ it('displays the user locale when the corresponding atom is set', () => {
28
+ initialize({ userLocale: 'fi', browserLocale: 'en' });
29
+
30
+ cy.contains('fi').should('be.visible');
31
+ });
32
+
33
+ it('displays the browser locale when the user locale is not set', () => {
34
+ initialize({ browserLocale: 'de', userLocale: null });
35
+
36
+ cy.contains('de').should('be.visible');
37
+ });
38
+ });
@@ -5,6 +5,7 @@ import { useAtomValue } from 'jotai';
5
5
 
6
6
  import { userAtom } from '@centreon/ui-context';
7
7
 
8
+ import { useLocale } from '../useLocale';
8
9
  import shortLocales from './sortLocales';
9
10
 
10
11
  interface FormatParameters {
@@ -28,10 +29,11 @@ const timeFormat = 'LT';
28
29
  const dateTimeFormat = `${dateFormat} ${timeFormat}`;
29
30
 
30
31
  const useLocaleDateTimeFormat = (): LocaleDateTimeFormat => {
31
- const { locale, timezone } = useAtomValue(userAtom);
32
+ const locale = useLocale();
33
+ const { timezone } = useAtomValue(userAtom);
32
34
 
33
35
  const format = ({ date, formatString }: FormatParameters): string => {
34
- const normalizedLocale = locale.substring(0, 2);
36
+ const normalizedLocale = locale?.substring(0, 2);
35
37
 
36
38
  const timezoneDate = dayjs(
37
39
  new Date(date).toLocaleString('en', { timeZone: timezone })
@@ -1,11 +1,10 @@
1
1
  import { useCallback } from 'react';
2
2
 
3
- import { useAtomValue } from 'jotai';
4
3
  import pluralize from 'pluralize';
5
4
  import { equals, includes } from 'ramda';
6
5
  import { useTranslation } from 'react-i18next';
7
6
 
8
- import { userAtom } from '@centreon/ui-context';
7
+ import { useLocale } from './useLocale';
9
8
 
10
9
  interface TProps {
11
10
  count: number;
@@ -16,7 +15,7 @@ export const usePluralizedTranslation = (): {
16
15
  pluralizedT: (props: TProps) => string;
17
16
  } => {
18
17
  const translation = useTranslation();
19
- const { locale } = useAtomValue(userAtom);
18
+ const locale = useLocale();
20
19
 
21
20
  const isNotPartitiveLocale = includes('fr', locale);
22
21