@centreon/ui 23.10.18-MON-fix-chromatic-parameters.0 → 23.10.19
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/Button/Icon/index.tsx +1 -1
- package/src/Button/Save/index.tsx +1 -1
- package/src/FileDropZone/index.tsx +1 -1
- package/src/Form/FormButtons.tsx +1 -2
- package/src/Form/Inputs/Autocomplete.tsx +1 -1
- package/src/Form/Inputs/Radio.tsx +1 -1
- package/src/Form/Inputs/Switch.tsx +1 -1
- package/src/InputField/Select/Autocomplete/Connected/index.tsx +5 -3
- package/src/InputField/Select/Autocomplete/index.tsx +1 -1
- package/src/InputField/Select/index.tsx +1 -1
- package/src/InputField/Text/index.tsx +1 -1
- package/src/Listing/ActionBar/index.tsx +1 -1
- package/src/Listing/index.tsx +1 -2
- package/src/ListingPage/index.tsx +1 -1
- package/src/Panel/Memoized.tsx +1 -1
- package/src/Panel/Section/index.tsx +1 -1
- package/src/SortableItems/SortableItem.tsx +1 -1
- package/src/index.ts +2 -18
- package/src/utils/getNormalizedId.ts +1 -3
- package/src/utils/index.ts +15 -0
- package/src/utils/useCopyToClipboard.ts +2 -3
- package/src/utils/useDateTimePickerAdapter.ts +309 -0
- package/src/utils/useDebounce.ts +1 -3
- package/src/utils/useDeepCallback.ts +1 -3
- package/src/utils/useDeepMemo.ts +1 -3
- package/src/utils/useIntersectionObserver.ts +1 -3
- package/src/utils/useKeyObserver.tsx +1 -3
- package/src/utils/useLocaleDateTimeFormat/index.test.tsx +1 -1
- package/src/utils/useLocaleDateTimeFormat/index.ts +1 -2
- package/src/utils/useLocaleDateTimeFormat/localeFallback.test.tsx +1 -1
- package/src/utils/useMemoComponent.ts +1 -3
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import { makeStyles } from 'tss-react/mui';
|
|
|
4
4
|
import { Theme, Tooltip } from '@mui/material';
|
|
5
5
|
import { LoadingButton } from '@mui/lab';
|
|
6
6
|
|
|
7
|
-
import getNormalizedId from '../../utils
|
|
7
|
+
import { getNormalizedId } from '../../utils';
|
|
8
8
|
|
|
9
9
|
import StartIcon from './StartIcon';
|
|
10
10
|
import Content from './Content';
|
|
@@ -17,7 +17,7 @@ import { alpha, Box, FormHelperText, Typography } from '@mui/material';
|
|
|
17
17
|
|
|
18
18
|
import { userAtom } from '@centreon/ui-context';
|
|
19
19
|
|
|
20
|
-
import useMemoComponent from '../utils
|
|
20
|
+
import { useMemoComponent } from '../utils';
|
|
21
21
|
|
|
22
22
|
import { labelDropOr, labelSelectAFile } from './translatedLabels';
|
|
23
23
|
import useDropzone, { UseDropzoneState } from './useDropzone';
|
package/src/Form/FormButtons.tsx
CHANGED
|
@@ -8,8 +8,7 @@ import { makeStyles } from 'tss-react/mui';
|
|
|
8
8
|
import { Button } from '@mui/material';
|
|
9
9
|
|
|
10
10
|
import SaveButton from '../Button/Save';
|
|
11
|
-
import useMemoComponent from '../utils
|
|
12
|
-
import getNormalizedId from '../utils/getNormalizedId';
|
|
11
|
+
import { useMemoComponent, getNormalizedId } from '../utils';
|
|
13
12
|
|
|
14
13
|
import {
|
|
15
14
|
labelReset,
|
|
@@ -9,7 +9,7 @@ import { FormHelperText, Stack } from '@mui/material';
|
|
|
9
9
|
import SingleAutocompleteField from '../../InputField/Select/Autocomplete';
|
|
10
10
|
import { labelPressEnterToAccept } from '../translatedLabels';
|
|
11
11
|
import MultiAutocompleteField from '../../InputField/Select/Autocomplete/Multi';
|
|
12
|
-
import useMemoComponent from '../../utils
|
|
12
|
+
import { useMemoComponent } from '../../utils';
|
|
13
13
|
import { SelectEntry } from '../../InputField/Select';
|
|
14
14
|
|
|
15
15
|
import { InputPropsWithoutGroup, InputType } from './models';
|
|
@@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
6
6
|
|
|
7
7
|
import { FormControlLabel, Switch as MUISwitch } from '@mui/material';
|
|
8
8
|
|
|
9
|
-
import getNormalizedId from '../../utils/getNormalizedId';
|
|
9
|
+
import { getNormalizedId } from '../../utils/getNormalizedId';
|
|
10
10
|
import { useMemoComponent } from '../..';
|
|
11
11
|
|
|
12
12
|
import { InputPropsWithoutGroup } from './models';
|
|
@@ -16,16 +16,18 @@ import {
|
|
|
16
16
|
import { CircularProgress, useTheme } from '@mui/material';
|
|
17
17
|
|
|
18
18
|
import { Props as AutocompleteFieldProps } from '..';
|
|
19
|
-
import
|
|
19
|
+
import {
|
|
20
|
+
useDebounce,
|
|
21
|
+
useIntersectionObserver,
|
|
22
|
+
useDeepCompare
|
|
23
|
+
} from '../../../../utils';
|
|
20
24
|
import { ListingModel, SelectEntry } from '../../../..';
|
|
21
25
|
import Option from '../../Option';
|
|
22
26
|
import {
|
|
23
27
|
ConditionsSearchParameter,
|
|
24
28
|
SearchParameter
|
|
25
29
|
} from '../../../../api/buildListingEndpoint/models';
|
|
26
|
-
import useDebounce from '../../../../utils/useDebounce';
|
|
27
30
|
import useFetchQuery from '../../../../api/useFetchQuery';
|
|
28
|
-
import { useDeepCompare } from '../../../../utils/useMemoComponent';
|
|
29
31
|
|
|
30
32
|
export interface ConnectedAutoCompleteFieldProps<TData> {
|
|
31
33
|
conditionField?: keyof SelectEntry;
|
|
@@ -20,7 +20,7 @@ import Option from '../Option';
|
|
|
20
20
|
import TextField from '../../Text';
|
|
21
21
|
import { SelectEntry } from '..';
|
|
22
22
|
import { searchLabel } from '../../translatedLabels';
|
|
23
|
-
import getNormalizedId from '../../../utils
|
|
23
|
+
import { getNormalizedId } from '../../../utils';
|
|
24
24
|
|
|
25
25
|
export type Props = {
|
|
26
26
|
autoFocus?: boolean;
|
|
@@ -11,7 +11,7 @@ import { userAtom, ListingVariant } from '@centreon/ui-context';
|
|
|
11
11
|
|
|
12
12
|
import { ListingProps } from '../..';
|
|
13
13
|
import { labelOf, labelRowsPerPage } from '../translatedLabels';
|
|
14
|
-
import useMemoComponent from '../../utils
|
|
14
|
+
import { useMemoComponent } from '../../utils';
|
|
15
15
|
import IconButton from '../../Button/Icon/index';
|
|
16
16
|
|
|
17
17
|
import StyledPagination from './Pagination';
|
package/src/Listing/index.tsx
CHANGED
|
@@ -31,8 +31,7 @@ import { Box, LinearProgress, Table, TableBody } from '@mui/material';
|
|
|
31
31
|
|
|
32
32
|
import { ListingVariant } from '@centreon/ui-context';
|
|
33
33
|
|
|
34
|
-
import useKeyObserver from '../utils
|
|
35
|
-
import useMemoComponent from '../utils/useMemoComponent';
|
|
34
|
+
import { useKeyObserver, useMemoComponent } from '../utils';
|
|
36
35
|
|
|
37
36
|
import ListingActionBar from './ActionBar';
|
|
38
37
|
import Cell from './Cell';
|
|
@@ -4,7 +4,7 @@ import { makeStyles } from 'tss-react/mui';
|
|
|
4
4
|
|
|
5
5
|
import { Box } from '@mui/material';
|
|
6
6
|
|
|
7
|
-
import useMemoComponent from '../utils
|
|
7
|
+
import { useMemoComponent } from '../utils';
|
|
8
8
|
import WithPanel from '../Panel/WithPanel';
|
|
9
9
|
|
|
10
10
|
import FilterSkeleton from './FilterSkeleton';
|
package/src/Panel/Memoized.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import ForwardIcon from '@mui/icons-material/ArrowForwardIos';
|
|
|
6
6
|
|
|
7
7
|
import Panel from '..';
|
|
8
8
|
import ContentWithCircularLoading from '../../ContentWithCircularProgress';
|
|
9
|
-
import useMemoComponent from '../../utils
|
|
9
|
+
import { useMemoComponent } from '../../utils';
|
|
10
10
|
|
|
11
11
|
import ExpandableSection from './ExpandableSection';
|
|
12
12
|
|
package/src/index.ts
CHANGED
|
@@ -82,15 +82,6 @@ export type {
|
|
|
82
82
|
} from './api/buildListingEndpoint/models';
|
|
83
83
|
export { default as buildListingDecoder } from './api/buildListingDecoder';
|
|
84
84
|
|
|
85
|
-
export {
|
|
86
|
-
default as useLocaleDateTimeFormat,
|
|
87
|
-
dateTimeFormat,
|
|
88
|
-
dateFormat,
|
|
89
|
-
timeFormat
|
|
90
|
-
} from './utils/useLocaleDateTimeFormat';
|
|
91
|
-
|
|
92
|
-
export { default as useDebounce } from './utils/useDebounce';
|
|
93
|
-
export { default as useIntersectionObserver } from './utils/useIntersectionObserver';
|
|
94
85
|
export { default as ContentWithCircularLoading } from './ContentWithCircularProgress';
|
|
95
86
|
export {
|
|
96
87
|
setUrlQueryParameters,
|
|
@@ -102,12 +93,6 @@ export type {
|
|
|
102
93
|
ListsSearchParameter
|
|
103
94
|
} from './api/buildListingEndpoint/models';
|
|
104
95
|
|
|
105
|
-
export {
|
|
106
|
-
default as useMemoComponent,
|
|
107
|
-
useDeepCompare
|
|
108
|
-
} from './utils/useMemoComponent';
|
|
109
|
-
export { default as useCopyToClipboard } from './utils/useCopyToClipboard';
|
|
110
|
-
|
|
111
96
|
export { default as MenuSkeleton } from './MenuSkeleton';
|
|
112
97
|
export { default as PopoverMenu } from './PopoverMenu';
|
|
113
98
|
|
|
@@ -143,8 +128,6 @@ export {
|
|
|
143
128
|
} from './FileDropZone';
|
|
144
129
|
export type { CustomDropZoneContentProps } from './FileDropZone';
|
|
145
130
|
export { default as TestQueryProvider } from './api/TestQueryProvider';
|
|
146
|
-
export * from './utils/useThemeMode';
|
|
147
|
-
export * from './utils/typedMemo';
|
|
148
131
|
export * from './FallbackPage/FallbackPage';
|
|
149
132
|
export * from './Logo/CentreonLogo';
|
|
150
133
|
export * from './TopCounterElements';
|
|
@@ -152,6 +135,7 @@ export { default as Image, ImageVariant } from './Image/Image';
|
|
|
152
135
|
export { default as WallpaperPage } from './WallpaperPage';
|
|
153
136
|
export { RichTextEditor } from './RichTextEditor';
|
|
154
137
|
export { default as ActionsList } from './ActionsList';
|
|
155
|
-
export { getStatusColors, SeverityCode } from './utils/statuses';
|
|
156
138
|
|
|
157
139
|
export type { ResponseError, CatchErrorProps } from './api/customFetch';
|
|
140
|
+
|
|
141
|
+
export * from './utils';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './useLocaleDateTimeFormat';
|
|
2
|
+
export * from './getNormalizedId';
|
|
3
|
+
export * from './statuses';
|
|
4
|
+
export * from './typedMemo';
|
|
5
|
+
export * from './useCopyToClipboard';
|
|
6
|
+
export * from './useDateTimePickerAdapter';
|
|
7
|
+
export * from './useDebounce';
|
|
8
|
+
export * from './useDeepCallback';
|
|
9
|
+
export * from './useDeepMemo';
|
|
10
|
+
export * from './useIntersectionObserver';
|
|
11
|
+
export * from './useKeyObserver';
|
|
12
|
+
export * from './useLoadImage';
|
|
13
|
+
export * from './useMemoComponent';
|
|
14
|
+
export * from './useThemeMode';
|
|
15
|
+
export * from './useViewportIntersection';
|
|
@@ -10,7 +10,8 @@ interface Props {
|
|
|
10
10
|
errorMessage: string;
|
|
11
11
|
successMessage: string;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
export const useCopyToClipboard = ({
|
|
14
15
|
successMessage,
|
|
15
16
|
errorMessage
|
|
16
17
|
}: Props): Result => {
|
|
@@ -53,5 +54,3 @@ const useCopyToClipboard = ({
|
|
|
53
54
|
|
|
54
55
|
return { copy };
|
|
55
56
|
};
|
|
56
|
-
|
|
57
|
-
export default useCopyToClipboard;
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/* eslint-disable class-methods-use-this */
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
import dayjs from 'dayjs';
|
|
5
|
+
import { useAtomValue } from 'jotai';
|
|
6
|
+
import { equals, isNil, not } from 'ramda';
|
|
7
|
+
|
|
8
|
+
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
|
|
9
|
+
|
|
10
|
+
import { useLocaleDateTimeFormat } from '@centreon/ui';
|
|
11
|
+
import { userAtom } from '@centreon/ui-context';
|
|
12
|
+
|
|
13
|
+
interface GetDestinationAndConfiguredTimezoneOffsetProps {
|
|
14
|
+
endTimezone?: string;
|
|
15
|
+
startTimezone?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface UseDateTimePickerAdapterProps {
|
|
19
|
+
Adapter;
|
|
20
|
+
desktopPickerMediaQuery: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
enum DSTState {
|
|
24
|
+
SUMMER,
|
|
25
|
+
WINTER,
|
|
26
|
+
NODST
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ToTimezonedDateProps {
|
|
30
|
+
date: Date;
|
|
31
|
+
timeZone?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface GetDSTStateProps {
|
|
35
|
+
date: dayjs.Dayjs;
|
|
36
|
+
timezoneToUse?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const useDateTimePickerAdapter = (): UseDateTimePickerAdapterProps => {
|
|
40
|
+
const { timezone, locale } = useAtomValue(userAtom);
|
|
41
|
+
const { format } = useLocaleDateTimeFormat();
|
|
42
|
+
|
|
43
|
+
const desktopPickerMediaQuery =
|
|
44
|
+
'@media (pointer: fine) or (min-width: 1024px)';
|
|
45
|
+
|
|
46
|
+
const toTimezonedDate = ({
|
|
47
|
+
date,
|
|
48
|
+
timeZone = undefined
|
|
49
|
+
}: ToTimezonedDateProps): Date => {
|
|
50
|
+
if (isNil(timeZone)) {
|
|
51
|
+
return new Date(date.toLocaleString('en-US'));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return new Date(date.toLocaleString('en-US', { timeZone }));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const getDestinationAndConfiguredTimezoneOffset = ({
|
|
58
|
+
startTimezone = undefined,
|
|
59
|
+
endTimezone = timezone
|
|
60
|
+
}: GetDestinationAndConfiguredTimezoneOffsetProps): number => {
|
|
61
|
+
const now = new Date();
|
|
62
|
+
const currentTimezoneDate = toTimezonedDate({
|
|
63
|
+
date: now,
|
|
64
|
+
timeZone: startTimezone
|
|
65
|
+
});
|
|
66
|
+
const destinationTimezoneDate = toTimezonedDate({
|
|
67
|
+
date: now,
|
|
68
|
+
timeZone: endTimezone
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return Math.floor(
|
|
72
|
+
(currentTimezoneDate.getTime() - destinationTimezoneDate.getTime()) /
|
|
73
|
+
60 /
|
|
74
|
+
60 /
|
|
75
|
+
1000
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const getDSTState = useCallback(
|
|
80
|
+
({ date, timezoneToUse }: GetDSTStateProps): DSTState => {
|
|
81
|
+
const hasNoTimezone = isNil(timezoneToUse);
|
|
82
|
+
const currentYear = toTimezonedDate({
|
|
83
|
+
date: new Date(),
|
|
84
|
+
timeZone: timezoneToUse
|
|
85
|
+
}).getFullYear();
|
|
86
|
+
|
|
87
|
+
const january = hasNoTimezone
|
|
88
|
+
? dayjs(new Date(currentYear, 0, 1)).utcOffset()
|
|
89
|
+
: dayjs(new Date(currentYear, 0, 1)).tz(timezoneToUse).utcOffset();
|
|
90
|
+
const july = hasNoTimezone
|
|
91
|
+
? dayjs(new Date(currentYear, 6, 1)).utcOffset()
|
|
92
|
+
: dayjs(new Date(currentYear, 6, 1)).tz(timezoneToUse).utcOffset();
|
|
93
|
+
|
|
94
|
+
if (equals(january, july)) {
|
|
95
|
+
return DSTState.NODST;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return july === date.tz().utcOffset() ? DSTState.SUMMER : DSTState.WINTER;
|
|
99
|
+
},
|
|
100
|
+
[timezone]
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const getDSTStateForCurrentTimezone = useCallback(
|
|
104
|
+
(date: dayjs.Dayjs): DSTState => {
|
|
105
|
+
return getDSTState({ date });
|
|
106
|
+
},
|
|
107
|
+
[]
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
interface Chunk {
|
|
111
|
+
array: Array<unknown>;
|
|
112
|
+
size: number;
|
|
113
|
+
}
|
|
114
|
+
class Adapter extends AdapterDayjs {
|
|
115
|
+
public formatByString = (value, formatKey: string): string => {
|
|
116
|
+
return format({
|
|
117
|
+
date: value.tz(timezone).toDate(),
|
|
118
|
+
formatString: formatKey
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
public format = (date: dayjs.Dayjs, formatKey: string): string => {
|
|
123
|
+
return this.formatByString(
|
|
124
|
+
date.tz(timezone, true),
|
|
125
|
+
this.formats[formatKey]
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
public startOfWeek = (date: dayjs.Dayjs): dayjs.Dayjs => {
|
|
130
|
+
if (date.tz(timezone).isUTC()) {
|
|
131
|
+
return date.tz(timezone).startOf('week').utc();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return date.tz(timezone).startOf('week');
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
public setMinutes = (date: dayjs.Dayjs, count: number): dayjs.Dayjs => {
|
|
138
|
+
return date.minute(count);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
public setHours = (date: dayjs.Dayjs, count: number): dayjs.Dayjs => {
|
|
142
|
+
return date.hour(count);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
public isSameDay = (date: dayjs.Dayjs, comparing: dayjs.Dayjs): boolean => {
|
|
146
|
+
const isSameYearAndMonth = this.isSameYear(date, comparing)
|
|
147
|
+
? this.isSameMonth(date, comparing)
|
|
148
|
+
: false;
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
isSameYearAndMonth &&
|
|
152
|
+
date.tz(timezone).isSame(comparing.tz(timezone), 'day')
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
public startOfDay = (date: dayjs.Dayjs): dayjs.Dayjs => {
|
|
157
|
+
return date.tz(timezone).startOf('day') as dayjs.Dayjs;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
public endOfDay = (date: dayjs.Dayjs): dayjs.Dayjs => {
|
|
161
|
+
return date.tz(timezone).endOf('day') as dayjs.Dayjs;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
public startOfMonth = (date: dayjs.Dayjs): dayjs.Dayjs => {
|
|
165
|
+
if (date.tz(timezone).isUTC()) {
|
|
166
|
+
return date.tz(timezone).utc();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return date.tz(timezone);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
public endOfMonth = (date: dayjs.Dayjs): dayjs.Dayjs => {
|
|
173
|
+
return date.tz(timezone).endOf('month') as dayjs.Dayjs;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
public isSameMonth = (
|
|
177
|
+
date: dayjs.Dayjs,
|
|
178
|
+
comparing: dayjs.Dayjs
|
|
179
|
+
): boolean => {
|
|
180
|
+
return date.tz(timezone).isSame(comparing.tz(timezone), 'month');
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
public getMonth = (date: dayjs.Dayjs): number => {
|
|
184
|
+
return date.tz(timezone).month();
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
public isAfter = (date: dayjs.Dayjs, value: dayjs.Dayjs): boolean => {
|
|
188
|
+
return date.isAfter(value.endOf('month'));
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
public isBefore = (date: dayjs.Dayjs, value: dayjs.Dayjs): boolean => {
|
|
192
|
+
return date.isBefore(value.startOf('month'));
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
public getDaysInMonth = (date: dayjs.Dayjs): number => {
|
|
196
|
+
return date.tz(timezone).daysInMonth();
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
public getWeekdays = (): Array<string> => {
|
|
200
|
+
const start = dayjs().locale(locale).tz(timezone).startOf('week');
|
|
201
|
+
|
|
202
|
+
return [0, 1, 2, 3, 4, 5, 6].map((diff) =>
|
|
203
|
+
this.formatByString(start.add(diff, 'day'), 'dd')
|
|
204
|
+
);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
public getChunkFromArray = ({ array, size }: Chunk): Array<unknown> => {
|
|
208
|
+
if (!array.length) {
|
|
209
|
+
return [];
|
|
210
|
+
}
|
|
211
|
+
const head = array.slice(0, size);
|
|
212
|
+
const tail = array.slice(size);
|
|
213
|
+
|
|
214
|
+
return [head, ...this.getChunkFromArray({ array: tail, size })];
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
public getWeekArray = (date: dayjs.Dayjs): Array<Array<dayjs.Dayjs>> => {
|
|
218
|
+
const isMorning = equals(dayjs().tz(timezone).format('a'), 'am');
|
|
219
|
+
const startOfWeek = date.tz(timezone).startOf('month').startOf('week');
|
|
220
|
+
const endOfWeek = date.tz(timezone).endOf('month').endOf('week');
|
|
221
|
+
const start = startOfWeek.startOf('day');
|
|
222
|
+
const end = endOfWeek.endOf('day');
|
|
223
|
+
const customStart = isMorning
|
|
224
|
+
? startOfWeek.startOf('day')
|
|
225
|
+
: startOfWeek.startOf('day');
|
|
226
|
+
const customEnd = isMorning
|
|
227
|
+
? endOfWeek.startOf('day')
|
|
228
|
+
: endOfWeek.startOf('day');
|
|
229
|
+
const currentStart = start.isUTC()
|
|
230
|
+
? start.tz(timezone, true)
|
|
231
|
+
: customStart;
|
|
232
|
+
const currentEnd = end.isUTC() ? end.tz(timezone, true) : customEnd;
|
|
233
|
+
const numberOfDaysInCurrentMonth = currentEnd.diff(
|
|
234
|
+
currentStart,
|
|
235
|
+
'd',
|
|
236
|
+
true
|
|
237
|
+
);
|
|
238
|
+
const daysOfMonthWithTimezone = [
|
|
239
|
+
...Array(Math.round(numberOfDaysInCurrentMonth)).keys()
|
|
240
|
+
].reduce(
|
|
241
|
+
(acc, _, currentIndex) => {
|
|
242
|
+
if (acc[currentIndex].isUTC()) {
|
|
243
|
+
const newCurrent = acc[currentIndex]
|
|
244
|
+
.utc()
|
|
245
|
+
.add(1, 'day')
|
|
246
|
+
.tz(timezone, true);
|
|
247
|
+
|
|
248
|
+
return [...acc, newCurrent];
|
|
249
|
+
}
|
|
250
|
+
const newCurrent = acc[currentIndex].add(1, 'day');
|
|
251
|
+
|
|
252
|
+
return [...acc, newCurrent];
|
|
253
|
+
},
|
|
254
|
+
[currentStart]
|
|
255
|
+
);
|
|
256
|
+
const weeksArray = this.getChunkFromArray({
|
|
257
|
+
array: daysOfMonthWithTimezone,
|
|
258
|
+
size: 7
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
return weeksArray as Array<Array<dayjs.Dayjs>>;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
public mergeDateAndTime = (
|
|
265
|
+
date: dayjs.Dayjs,
|
|
266
|
+
time: dayjs.Dayjs
|
|
267
|
+
): dayjs.Dayjs => {
|
|
268
|
+
const dateWithTimezone = date.tz(timezone).startOf('day');
|
|
269
|
+
const timeWithTimezone = time.tz(timezone);
|
|
270
|
+
const dateDSTState = getDSTState({
|
|
271
|
+
date: dateWithTimezone,
|
|
272
|
+
timezoneToUse: timezone
|
|
273
|
+
});
|
|
274
|
+
const dateDSTStateWithCurrentTimezone =
|
|
275
|
+
getDSTStateForCurrentTimezone(date);
|
|
276
|
+
|
|
277
|
+
if (equals(dateDSTStateWithCurrentTimezone, DSTState.WINTER)) {
|
|
278
|
+
return dateWithTimezone
|
|
279
|
+
.add(
|
|
280
|
+
timeWithTimezone.hour() -
|
|
281
|
+
getDestinationAndConfiguredTimezoneOffset({
|
|
282
|
+
endTimezone: 'UTC',
|
|
283
|
+
startTimezone: dayjs.tz.guess()
|
|
284
|
+
}),
|
|
285
|
+
'hour'
|
|
286
|
+
)
|
|
287
|
+
.add(timeWithTimezone.minute(), 'minute')
|
|
288
|
+
.add(timeWithTimezone.second(), 'second');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (not(equals(dateDSTState, DSTState.SUMMER))) {
|
|
292
|
+
return dateWithTimezone
|
|
293
|
+
.add(timeWithTimezone.hour(), 'hour')
|
|
294
|
+
.add(timeWithTimezone.minute(), 'minute')
|
|
295
|
+
.add(timeWithTimezone.second(), 'second');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return dateWithTimezone
|
|
299
|
+
.hour(timeWithTimezone.hour())
|
|
300
|
+
.minute(timeWithTimezone.minute())
|
|
301
|
+
.second(timeWithTimezone.second());
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return {
|
|
306
|
+
Adapter,
|
|
307
|
+
desktopPickerMediaQuery
|
|
308
|
+
};
|
|
309
|
+
};
|
package/src/utils/useDebounce.ts
CHANGED
|
@@ -6,7 +6,7 @@ interface Props {
|
|
|
6
6
|
wait: number;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const useDebounce = ({
|
|
9
|
+
export const useDebounce = ({
|
|
10
10
|
functionToDebounce,
|
|
11
11
|
wait,
|
|
12
12
|
memoProps = []
|
|
@@ -23,5 +23,3 @@ const useDebounce = ({
|
|
|
23
23
|
}, wait);
|
|
24
24
|
}, memoProps);
|
|
25
25
|
};
|
|
26
|
-
|
|
27
|
-
export default useDebounce;
|
|
@@ -7,11 +7,9 @@ interface UseDeepCallback<TParameters, TReturn, TMemoProps> {
|
|
|
7
7
|
deps: Array<TMemoProps>;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
const useDeepCallback = <TParameters, TReturn, TMemoProps>({
|
|
10
|
+
export const useDeepCallback = <TParameters, TReturn, TMemoProps>({
|
|
11
11
|
deps,
|
|
12
12
|
callback
|
|
13
13
|
}: UseDeepCallback<TParameters, TReturn, TMemoProps>): ((
|
|
14
14
|
props: TParameters
|
|
15
15
|
) => TReturn) => useCallback((props) => callback(props), useDeepCompare(deps));
|
|
16
|
-
|
|
17
|
-
export default useDeepCallback;
|
package/src/utils/useDeepMemo.ts
CHANGED
|
@@ -7,10 +7,8 @@ interface UseDeepMemo<TVariable, TMemoProps> {
|
|
|
7
7
|
variable: TVariable;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
const useDeepMemo = <TVariable, TMemoProps>({
|
|
10
|
+
export const useDeepMemo = <TVariable, TMemoProps>({
|
|
11
11
|
deps,
|
|
12
12
|
variable
|
|
13
13
|
}: UseDeepMemo<TVariable, TMemoProps>): TVariable =>
|
|
14
14
|
useMemo(() => variable, useDeepCompare(deps));
|
|
15
|
-
|
|
16
|
-
export default useDeepMemo;
|
|
@@ -7,7 +7,7 @@ interface HookParam {
|
|
|
7
7
|
page: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
const useIntersectionObserver = ({
|
|
10
|
+
export const useIntersectionObserver = ({
|
|
11
11
|
maxPage,
|
|
12
12
|
page,
|
|
13
13
|
loading,
|
|
@@ -41,5 +41,3 @@ const useIntersectionObserver = ({
|
|
|
41
41
|
|
|
42
42
|
return lastElementRef;
|
|
43
43
|
};
|
|
44
|
-
|
|
45
|
-
export default useIntersectionObserver;
|
|
@@ -4,7 +4,7 @@ interface UseKeyObserverProps {
|
|
|
4
4
|
isShiftKeyDown: boolean;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
const useKeyObserver = (): UseKeyObserverProps => {
|
|
7
|
+
export const useKeyObserver = (): UseKeyObserverProps => {
|
|
8
8
|
const [isShiftKeyDown, setIsShiftKeyDown] = useState<boolean>(false);
|
|
9
9
|
|
|
10
10
|
const pressShift = (): void => setIsShiftKeyDown(true);
|
|
@@ -34,5 +34,3 @@ const useKeyObserver = (): UseKeyObserverProps => {
|
|
|
34
34
|
isShiftKeyDown
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
|
-
|
|
38
|
-
export default useKeyObserver;
|
|
@@ -10,7 +10,7 @@ import { Provider, useSetAtom } from 'jotai';
|
|
|
10
10
|
|
|
11
11
|
import { userAtom, ThemeMode } from '@centreon/ui-context';
|
|
12
12
|
|
|
13
|
-
import useLocaleDateTimeFormat from '.';
|
|
13
|
+
import { useLocaleDateTimeFormat } from '.';
|
|
14
14
|
|
|
15
15
|
dayjs.extend(timezonePlugin);
|
|
16
16
|
dayjs.extend(utcPlugin);
|
|
@@ -10,7 +10,7 @@ import { render, RenderResult } from '@testing-library/react';
|
|
|
10
10
|
|
|
11
11
|
import { userAtom, ThemeMode } from '@centreon/ui-context';
|
|
12
12
|
|
|
13
|
-
import useLocaleDateTimeFormat from '.';
|
|
13
|
+
import { useLocaleDateTimeFormat } from '.';
|
|
14
14
|
|
|
15
15
|
dayjs.extend(timezonePlugin);
|
|
16
16
|
dayjs.extend(utcPlugin);
|
|
@@ -19,10 +19,8 @@ interface MemoComponent {
|
|
|
19
19
|
memoProps: Array<unknown>;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const useMemoComponent = ({
|
|
22
|
+
export const useMemoComponent = ({
|
|
23
23
|
Component,
|
|
24
24
|
memoProps
|
|
25
25
|
}: MemoComponent): JSX.Element =>
|
|
26
26
|
useMemo(() => Component, useDeepCompare(memoProps));
|
|
27
|
-
|
|
28
|
-
export default useMemoComponent;
|