@centreon/ui 23.10.111 → 23.10.113
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 +14 -12
- package/src/Button/Save/StartIcon.tsx +3 -3
- package/src/Dashboard/Item.tsx +1 -1
- package/src/FileDropZone/index.tsx +3 -1
- package/src/Form/Inputs/CheckboxGroup.tsx +1 -4
- package/src/Form/Inputs/index.tsx +1 -1
- package/src/Graph/Gauge/Gauge.stories.tsx +15 -1
- package/src/Graph/LineChart/BasicComponents/Lines/Threshold/index.tsx +5 -4
- package/src/Graph/LineChart/BasicComponents/useFilterLines.ts +1 -1
- package/src/Graph/LineChart/InteractiveComponents/Annotations/Annotation/index.tsx +2 -3
- package/src/Graph/LineChart/InteractiveComponents/Annotations/EventAnnotations.tsx +1 -1
- package/src/Graph/LineChart/Legend/useLegend.ts +5 -5
- package/src/Graph/LineChart/helpers/doc.ts +16 -13
- package/src/Graph/LineChart/helpers/index.ts +1 -1
- package/src/Graph/LineChart/index.stories.tsx +1 -2
- package/src/Graph/Text/Text.stories.tsx +60 -4
- package/src/Graph/common/timeSeries/index.ts +3 -3
- package/src/InputField/Select/Autocomplete/Connected/index.tsx +10 -7
- package/src/InputField/Select/Autocomplete/Draggable/SortableList.tsx +1 -1
- package/src/InputField/Select/Autocomplete/Draggable/SortableListContent.tsx +1 -1
- package/src/InputField/Select/Autocomplete/Draggable/index.tsx +1 -1
- package/src/InputField/Select/IconPopover/index.tsx +2 -2
- package/src/InputField/Select/index.tsx +1 -1
- package/src/Listing/Header/ListingHeader.tsx +1 -1
- package/src/Listing/index.tsx +1 -1
- package/src/RichTextEditor/RichTextEditor.tsx +11 -1
- package/src/SortableItems/index.tsx +2 -7
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +8 -3
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +0 -2
- package/src/TimePeriods/DateTimePickerInput.tsx +45 -17
- package/src/TimePeriods/TimePeriods.cypress.spec.tsx +9 -33
- package/src/TimePeriods/helpers/index.ts +1 -1
- package/src/api/QueryProvider.tsx +1 -1
- package/src/api/TestQueryProvider.tsx +1 -1
- package/src/api/useFetchQuery/index.ts +28 -24
- package/src/api/useMutationQuery/index.ts +39 -17
- package/src/components/Form/AccessRights/useAccessRightsForm.utils.ts +1 -1
- package/src/components/Form/Dashboard/DashboardForm.tsx +15 -12
- package/src/components/ItemComposition/ItemComposition.tsx +4 -2
- package/src/index.ts +1 -0
- package/src/queryParameters/url/index.ts +5 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/{useLicenseExpirationWarning.cypress.spec.tsx → useLicenseExpirationWarning.test.tsx} +48 -37
- package/src/utils/useLicenseExpirationWarning.ts +18 -18
- package/src/utils/useDateTimePickerAdapter.ts +0 -309
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import dayjs, { Dayjs } from 'dayjs';
|
|
4
|
+
import { useAtomValue } from 'jotai';
|
|
5
|
+
import { equals } from 'ramda';
|
|
4
6
|
|
|
5
|
-
import {
|
|
7
|
+
import { DateTimePicker, LocalizationProvider } from '@mui/x-date-pickers';
|
|
8
|
+
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
|
|
9
|
+
|
|
10
|
+
import { userAtom } from '@centreon/ui-context';
|
|
6
11
|
|
|
7
12
|
import { CustomTimePeriodProperty } from './models';
|
|
8
13
|
|
|
14
|
+
interface ChangeDateProps {
|
|
15
|
+
date: Date;
|
|
16
|
+
property: CustomTimePeriodProperty | string;
|
|
17
|
+
}
|
|
18
|
+
|
|
9
19
|
interface Props {
|
|
10
|
-
changeDate: (props) => void;
|
|
20
|
+
changeDate: (props: ChangeDateProps) => void;
|
|
11
21
|
date: Date | null;
|
|
12
22
|
desktopMediaQuery?: string;
|
|
13
23
|
disabled?: boolean;
|
|
14
24
|
maxDate?: Date;
|
|
15
25
|
minDate?: Date;
|
|
16
|
-
property: CustomTimePeriodProperty;
|
|
26
|
+
property: CustomTimePeriodProperty | string;
|
|
17
27
|
}
|
|
18
28
|
|
|
19
29
|
const DateTimePickerInput = ({
|
|
@@ -25,24 +35,42 @@ const DateTimePickerInput = ({
|
|
|
25
35
|
disabled = false,
|
|
26
36
|
desktopMediaQuery
|
|
27
37
|
}: Props): JSX.Element => {
|
|
28
|
-
const
|
|
38
|
+
const desktopPickerMediaQuery =
|
|
39
|
+
'@media (min-width: 1024px) or (pointer: fine)';
|
|
40
|
+
|
|
41
|
+
const { timezone, locale } = useAtomValue(userAtom);
|
|
42
|
+
|
|
43
|
+
const isUTC = equals(timezone, 'UTC');
|
|
29
44
|
|
|
30
45
|
const changeTime = (newValue: dayjs.Dayjs | null): void => {
|
|
31
46
|
changeDate({ date: dayjs(newValue).toDate(), property });
|
|
32
47
|
};
|
|
33
48
|
|
|
49
|
+
const formatDate = useCallback(
|
|
50
|
+
(currentDate: Date | null): Dayjs => {
|
|
51
|
+
return isUTC ? dayjs.utc(currentDate) : dayjs.tz(currentDate, timezone);
|
|
52
|
+
},
|
|
53
|
+
[isUTC, timezone]
|
|
54
|
+
);
|
|
55
|
+
|
|
34
56
|
return (
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
<LocalizationProvider
|
|
58
|
+
adapterLocale={locale.substring(0, 2)}
|
|
59
|
+
dateAdapter={AdapterDayjs}
|
|
60
|
+
dateLibInstance={dayjs}
|
|
61
|
+
>
|
|
62
|
+
<DateTimePicker<dayjs.Dayjs>
|
|
63
|
+
dayOfWeekFormatter={(dayOfWeek) =>
|
|
64
|
+
dayOfWeek.substring(0, 2).toLocaleUpperCase()
|
|
65
|
+
}
|
|
66
|
+
desktopModeMediaQuery={desktopMediaQuery ?? desktopPickerMediaQuery}
|
|
67
|
+
disabled={disabled}
|
|
68
|
+
maxDate={maxDate && formatDate(maxDate)}
|
|
69
|
+
minDate={minDate && formatDate(minDate)}
|
|
70
|
+
value={formatDate(date)}
|
|
71
|
+
onChange={changeTime}
|
|
72
|
+
/>
|
|
73
|
+
</LocalizationProvider>
|
|
46
74
|
);
|
|
47
75
|
};
|
|
48
76
|
|
|
@@ -3,15 +3,10 @@ import localizedFormatPlugin from 'dayjs/plugin/localizedFormat';
|
|
|
3
3
|
import timezonePlugin from 'dayjs/plugin/timezone';
|
|
4
4
|
import utcPlugin from 'dayjs/plugin/utc';
|
|
5
5
|
import { Provider, createStore } from 'jotai';
|
|
6
|
-
import { equals
|
|
6
|
+
import { equals } from 'ramda';
|
|
7
7
|
import { renderHook } from '@testing-library/react';
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
useLocaleDateTimeFormat,
|
|
13
|
-
useDateTimePickerAdapter
|
|
14
|
-
} from '@centreon/ui';
|
|
9
|
+
import { useLocaleDateTimeFormat } from '@centreon/ui';
|
|
15
10
|
import { ListingVariant, userAtom } from '@centreon/ui-context';
|
|
16
11
|
|
|
17
12
|
import { CustomTimePeriodProperty } from './models';
|
|
@@ -297,10 +292,6 @@ testData.forEach((item) =>
|
|
|
297
292
|
beforeEach(() => {
|
|
298
293
|
cy.viewport('macbook-13');
|
|
299
294
|
|
|
300
|
-
const { result } = renderHook(() => useDateTimePickerAdapter());
|
|
301
|
-
|
|
302
|
-
const { Adapter } = result.current;
|
|
303
|
-
|
|
304
295
|
const store = createStore();
|
|
305
296
|
store.set(userAtom, {
|
|
306
297
|
...retrievedUser,
|
|
@@ -311,31 +302,16 @@ testData.forEach((item) =>
|
|
|
311
302
|
cy.mount({
|
|
312
303
|
Component: (
|
|
313
304
|
<Provider store={store}>
|
|
314
|
-
<
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
property={CustomTimePeriodProperty.start}
|
|
320
|
-
/>
|
|
321
|
-
</LocalizationProvider>
|
|
305
|
+
<DateTimePickerInput
|
|
306
|
+
changeDate={cy.stub()}
|
|
307
|
+
date={new Date(item.initialDate)}
|
|
308
|
+
property={CustomTimePeriodProperty.start}
|
|
309
|
+
/>
|
|
322
310
|
</Provider>
|
|
323
311
|
)
|
|
324
312
|
});
|
|
325
313
|
});
|
|
326
314
|
|
|
327
|
-
it('checks input calendar value contains correct date', () => {
|
|
328
|
-
const { result } = renderHook(() => useLocaleDateTimeFormat());
|
|
329
|
-
const { format } = result.current;
|
|
330
|
-
|
|
331
|
-
const dateInput = format({
|
|
332
|
-
date: dayjs(item.initialDate).tz(item.timezone),
|
|
333
|
-
formatString: 'L hh:mm A'
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
cy.get('input').should('have.value', dateInput);
|
|
337
|
-
});
|
|
338
|
-
|
|
339
315
|
it(`displays the correct number of days for the current month when the ${item.button} button is clicked`, () => {
|
|
340
316
|
cy.get('button').click();
|
|
341
317
|
item.data.forEach((element) => {
|
|
@@ -389,7 +365,7 @@ testData.forEach((item) =>
|
|
|
389
365
|
|
|
390
366
|
cy.get('[role="rowgroup"]').children().as('listWeeks');
|
|
391
367
|
|
|
392
|
-
cy.get('@listWeeks').should('have.length',
|
|
368
|
+
cy.get('@listWeeks').should('have.length', numberWeeks);
|
|
393
369
|
cy.get('@listWeeks').eq(0).as('firstWeek');
|
|
394
370
|
cy.get('@firstWeek').children().as('listDaysInFirstWeek');
|
|
395
371
|
|
|
@@ -416,7 +392,7 @@ testData.forEach((item) =>
|
|
|
416
392
|
|
|
417
393
|
cy.get('[role="rowgroup"]').children().as('listWeeks');
|
|
418
394
|
|
|
419
|
-
cy.get('@listWeeks').should('have.length',
|
|
395
|
+
cy.get('@listWeeks').should('have.length', numberWeeks);
|
|
420
396
|
|
|
421
397
|
cy.get('@listWeeks')
|
|
422
398
|
.eq(numberWeeks - 1)
|
|
@@ -25,7 +25,9 @@ export interface UseFetchQueryProps<T> {
|
|
|
25
25
|
getQueryKey: () => QueryKey;
|
|
26
26
|
httpCodesBypassErrorSnackbar?: Array<number>;
|
|
27
27
|
isPaginated?: boolean;
|
|
28
|
-
queryOptions?:
|
|
28
|
+
queryOptions?: {
|
|
29
|
+
suspense?: boolean;
|
|
30
|
+
} & Omit<
|
|
29
31
|
UseQueryOptions<T | ResponseError, Error, T | ResponseError, QueryKey>,
|
|
30
32
|
'queryKey' | 'queryFn'
|
|
31
33
|
>;
|
|
@@ -33,11 +35,12 @@ export interface UseFetchQueryProps<T> {
|
|
|
33
35
|
|
|
34
36
|
export type UseFetchQueryState<T> = {
|
|
35
37
|
data?: T;
|
|
38
|
+
error: Omit<ResponseError, 'isError'> | null;
|
|
36
39
|
fetchQuery: () => Promise<T | ResponseError>;
|
|
37
40
|
prefetchNextPage: ({ page, getPrefetchQueryKey }) => void;
|
|
38
41
|
prefetchPreviousPage: ({ page, getPrefetchQueryKey }) => void;
|
|
39
42
|
prefetchQuery: ({ endpointParams, queryKey }) => void;
|
|
40
|
-
} & Omit<QueryObserverBaseResult, 'data'>;
|
|
43
|
+
} & Omit<QueryObserverBaseResult, 'data' | 'error'>;
|
|
41
44
|
|
|
42
45
|
export interface PrefetchEndpointParams {
|
|
43
46
|
page: number;
|
|
@@ -58,9 +61,8 @@ const useFetchQuery = <T extends object>({
|
|
|
58
61
|
}: UseFetchQueryProps<T>): UseFetchQueryState<T> => {
|
|
59
62
|
const { showErrorMessage } = useSnackbar();
|
|
60
63
|
|
|
61
|
-
const queryData = useQuery<T | ResponseError, Error>(
|
|
62
|
-
|
|
63
|
-
({ signal }): Promise<T | ResponseError> =>
|
|
64
|
+
const queryData = useQuery<T | ResponseError, Error>({
|
|
65
|
+
queryFn: ({ signal }): Promise<T | ResponseError> =>
|
|
64
66
|
customFetch<T>({
|
|
65
67
|
catchError,
|
|
66
68
|
decoder,
|
|
@@ -69,10 +71,9 @@ const useFetchQuery = <T extends object>({
|
|
|
69
71
|
headers: new Headers(fetchHeaders),
|
|
70
72
|
signal
|
|
71
73
|
}),
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
);
|
|
74
|
+
queryKey: getQueryKey(),
|
|
75
|
+
...queryOptions
|
|
76
|
+
});
|
|
76
77
|
|
|
77
78
|
const queryClient = useQueryClient();
|
|
78
79
|
|
|
@@ -92,9 +93,8 @@ const useFetchQuery = <T extends object>({
|
|
|
92
93
|
};
|
|
93
94
|
|
|
94
95
|
const prefetchQuery = ({ endpointParams, queryKey }): void => {
|
|
95
|
-
queryClient.prefetchQuery(
|
|
96
|
-
|
|
97
|
-
({ signal }): Promise<T | ResponseError> =>
|
|
96
|
+
queryClient.prefetchQuery({
|
|
97
|
+
queryFn: ({ signal }): Promise<T | ResponseError> =>
|
|
98
98
|
customFetch<T>({
|
|
99
99
|
catchError,
|
|
100
100
|
decoder,
|
|
@@ -102,8 +102,9 @@ const useFetchQuery = <T extends object>({
|
|
|
102
102
|
endpoint: getEndpoint(endpointParams),
|
|
103
103
|
headers: new Headers(fetchHeaders),
|
|
104
104
|
signal
|
|
105
|
-
})
|
|
106
|
-
|
|
105
|
+
}),
|
|
106
|
+
queryKey
|
|
107
|
+
});
|
|
107
108
|
};
|
|
108
109
|
|
|
109
110
|
const prefetchNextPage = ({ page, getPrefetchQueryKey }): void => {
|
|
@@ -133,9 +134,8 @@ const useFetchQuery = <T extends object>({
|
|
|
133
134
|
};
|
|
134
135
|
|
|
135
136
|
const fetchQuery = (): Promise<T | ResponseError> => {
|
|
136
|
-
return queryClient.fetchQuery(
|
|
137
|
-
|
|
138
|
-
({ signal }): Promise<T | ResponseError> =>
|
|
137
|
+
return queryClient.fetchQuery({
|
|
138
|
+
queryFn: ({ signal }): Promise<T | ResponseError> =>
|
|
139
139
|
customFetch<T>({
|
|
140
140
|
catchError,
|
|
141
141
|
decoder,
|
|
@@ -143,8 +143,9 @@ const useFetchQuery = <T extends object>({
|
|
|
143
143
|
endpoint: getEndpoint(),
|
|
144
144
|
headers: new Headers(fetchHeaders),
|
|
145
145
|
signal
|
|
146
|
-
})
|
|
147
|
-
|
|
146
|
+
}),
|
|
147
|
+
queryKey: getQueryKey()
|
|
148
|
+
});
|
|
148
149
|
};
|
|
149
150
|
|
|
150
151
|
const data = useMemo(
|
|
@@ -157,16 +158,19 @@ const useFetchQuery = <T extends object>({
|
|
|
157
158
|
|
|
158
159
|
useEffect(() => {
|
|
159
160
|
return (): void => {
|
|
160
|
-
queryClient.cancelQueries(getQueryKey());
|
|
161
|
+
queryClient.cancelQueries({ queryKey: getQueryKey() });
|
|
161
162
|
};
|
|
162
163
|
}, []);
|
|
163
164
|
|
|
164
|
-
useEffect(
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
useEffect(
|
|
166
|
+
() => {
|
|
167
|
+
manageError();
|
|
168
|
+
},
|
|
169
|
+
useDeepCompare([queryData.data])
|
|
170
|
+
);
|
|
167
171
|
|
|
168
172
|
return {
|
|
169
|
-
...omit(['data'], queryData),
|
|
173
|
+
...omit(['data', 'error'], queryData),
|
|
170
174
|
data,
|
|
171
175
|
error: errorData?.isError ? omit(['isError'], errorData) : null,
|
|
172
176
|
fetchQuery,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from '@tanstack/react-query';
|
|
9
9
|
import { JsonDecoder } from 'ts.data.json';
|
|
10
10
|
import anylogger from 'anylogger';
|
|
11
|
-
import { includes } from 'ramda';
|
|
11
|
+
import { includes, omit } from 'ramda';
|
|
12
12
|
|
|
13
13
|
import { CatchErrorProps, customFetch, ResponseError } from '../customFetch';
|
|
14
14
|
import useSnackbar from '../../Snackbar/useSnackbar';
|
|
@@ -30,14 +30,33 @@ export type UseMutationQueryProps<T, TMeta> = {
|
|
|
30
30
|
getEndpoint: (_meta: TMeta) => string;
|
|
31
31
|
httpCodesBypassErrorSnackbar?: Array<number>;
|
|
32
32
|
method: Method;
|
|
33
|
-
|
|
33
|
+
onError?: (
|
|
34
|
+
error: ResponseError,
|
|
35
|
+
variables: T & { _meta: TMeta },
|
|
36
|
+
context: unknown
|
|
37
|
+
) => unknown;
|
|
38
|
+
onMutate?: (variables: T & { _meta: TMeta }) => Promise<unknown> | unknown;
|
|
39
|
+
onSuccess?: (
|
|
40
|
+
data: ResponseError | T,
|
|
41
|
+
variables: T & {
|
|
42
|
+
_meta: TMeta;
|
|
43
|
+
},
|
|
44
|
+
context: unknown
|
|
45
|
+
) => unknown;
|
|
46
|
+
} & Omit<
|
|
47
|
+
UseMutationOptions<T & { _meta?: TMeta }>,
|
|
48
|
+
'mutationFn' | 'onError' | 'onMutate' | 'onSuccess'
|
|
49
|
+
>;
|
|
34
50
|
|
|
35
51
|
const log = anylogger('API Request');
|
|
36
52
|
|
|
37
|
-
export type UseMutationQueryState<T> =
|
|
53
|
+
export type UseMutationQueryState<T> = Omit<
|
|
54
|
+
UseMutationResult<T | ResponseError>,
|
|
55
|
+
'isError'
|
|
56
|
+
> & {
|
|
38
57
|
isError: boolean;
|
|
39
58
|
isMutating: boolean;
|
|
40
|
-
}
|
|
59
|
+
};
|
|
41
60
|
|
|
42
61
|
const useMutationQuery = <T extends object, TMeta>({
|
|
43
62
|
getEndpoint,
|
|
@@ -57,8 +76,10 @@ const useMutationQuery = <T extends object, TMeta>({
|
|
|
57
76
|
T | ResponseError,
|
|
58
77
|
ResponseError,
|
|
59
78
|
T & { _meta: TMeta }
|
|
60
|
-
>(
|
|
61
|
-
|
|
79
|
+
>({
|
|
80
|
+
mutationFn: (
|
|
81
|
+
_payload: T & { _meta: TMeta }
|
|
82
|
+
): Promise<T | ResponseError> => {
|
|
62
83
|
const { _meta, ...payload } = _payload || {};
|
|
63
84
|
|
|
64
85
|
return customFetch<T>({
|
|
@@ -75,12 +96,10 @@ const useMutationQuery = <T extends object, TMeta>({
|
|
|
75
96
|
payload
|
|
76
97
|
});
|
|
77
98
|
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
);
|
|
99
|
+
onError,
|
|
100
|
+
onMutate,
|
|
101
|
+
onSuccess
|
|
102
|
+
});
|
|
84
103
|
|
|
85
104
|
const manageError = (): void => {
|
|
86
105
|
const data = queryData.data as ResponseError | undefined;
|
|
@@ -97,14 +116,17 @@ const useMutationQuery = <T extends object, TMeta>({
|
|
|
97
116
|
}
|
|
98
117
|
};
|
|
99
118
|
|
|
100
|
-
useEffect(
|
|
101
|
-
|
|
102
|
-
|
|
119
|
+
useEffect(
|
|
120
|
+
() => {
|
|
121
|
+
manageError();
|
|
122
|
+
},
|
|
123
|
+
useDeepCompare([queryData.data])
|
|
124
|
+
);
|
|
103
125
|
|
|
104
126
|
return {
|
|
105
|
-
...queryData,
|
|
127
|
+
...omit(['isError'], queryData),
|
|
106
128
|
isError: (queryData.data as ResponseError | undefined)?.isError || false,
|
|
107
|
-
isMutating: queryData.
|
|
129
|
+
isMutating: queryData.isPending
|
|
108
130
|
};
|
|
109
131
|
};
|
|
110
132
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ReactElement, useCallback, useMemo } from 'react';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { string, number, object } from 'yup';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { equals } from 'ramda';
|
|
5
6
|
|
|
6
7
|
import { InputType } from '../../../Form/Inputs/models';
|
|
7
8
|
import { Form, FormProps } from '../../../Form';
|
|
@@ -84,8 +85,8 @@ const DashboardForm = ({
|
|
|
84
85
|
}
|
|
85
86
|
],
|
|
86
87
|
submit: (values, bag) => onSubmit?.(values, bag),
|
|
87
|
-
validationSchema:
|
|
88
|
-
description:
|
|
88
|
+
validationSchema: object({
|
|
89
|
+
description: string()
|
|
89
90
|
.label(labels?.entity?.description || '')
|
|
90
91
|
.max(
|
|
91
92
|
180,
|
|
@@ -93,17 +94,19 @@ const DashboardForm = ({
|
|
|
93
94
|
`${p.label} ${t(labelMustBeMost)} ${p.max} ${t(labelCharacters)}`
|
|
94
95
|
)
|
|
95
96
|
.nullable(),
|
|
96
|
-
globalRefreshInterval:
|
|
97
|
-
interval:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
globalRefreshInterval: object({
|
|
98
|
+
interval: number().when('type', ([type], schema) => {
|
|
99
|
+
if (equals(type, 'manual')) {
|
|
100
|
+
schema
|
|
101
|
+
.min(1, ({ min }) => t(labelMustBeAtLeast, { min }))
|
|
102
|
+
.required(t(labelRequired) as string);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return schema.nullable();
|
|
103
106
|
}),
|
|
104
|
-
type:
|
|
107
|
+
type: string()
|
|
105
108
|
}),
|
|
106
|
-
name:
|
|
109
|
+
name: string()
|
|
107
110
|
.label(labels?.entity?.name)
|
|
108
111
|
.min(3, ({ min, label }) => t(labelMustBeAtLeast, { label, min }))
|
|
109
112
|
.max(50, ({ max, label }) => t(labelMustBeMost, { label, max }))
|
|
@@ -7,6 +7,7 @@ import { Button } from '..';
|
|
|
7
7
|
import { useItemCompositionStyles } from './ItemComposition.styles';
|
|
8
8
|
|
|
9
9
|
type Props = {
|
|
10
|
+
IconAdd?;
|
|
10
11
|
addButtonHidden?: boolean;
|
|
11
12
|
addbuttonDisabled?: boolean;
|
|
12
13
|
children: Array<ReactElement>;
|
|
@@ -19,7 +20,8 @@ export const ItemComposition = ({
|
|
|
19
20
|
children,
|
|
20
21
|
labelAdd,
|
|
21
22
|
addbuttonDisabled,
|
|
22
|
-
addButtonHidden
|
|
23
|
+
addButtonHidden,
|
|
24
|
+
IconAdd
|
|
23
25
|
}: Props): JSX.Element => {
|
|
24
26
|
const { classes } = useItemCompositionStyles();
|
|
25
27
|
|
|
@@ -31,7 +33,7 @@ export const ItemComposition = ({
|
|
|
31
33
|
aria-label={labelAdd}
|
|
32
34
|
data-testid={labelAdd}
|
|
33
35
|
disabled={addbuttonDisabled}
|
|
34
|
-
icon={<AddIcon />}
|
|
36
|
+
icon={IconAdd || <AddIcon />}
|
|
35
37
|
iconVariant="start"
|
|
36
38
|
size="small"
|
|
37
39
|
variant="ghost"
|
package/src/index.ts
CHANGED
|
@@ -161,4 +161,5 @@ export * from './Graph/common/timeSeries';
|
|
|
161
161
|
|
|
162
162
|
export { default as TimePeriods } from './TimePeriods';
|
|
163
163
|
export { default as SimpleCustomTimePeriod } from './TimePeriods/CustomTimePeriod/SimpleCustomTimePeriod';
|
|
164
|
+
export { default as DateTimePickerInput } from './TimePeriods/DateTimePickerInput';
|
|
164
165
|
export * from './ParentSize';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fromPairs } from 'ramda';
|
|
1
|
+
import { fromPairs, startsWith } from 'ramda';
|
|
2
2
|
|
|
3
3
|
import { QueryParameter } from '../models';
|
|
4
4
|
|
|
@@ -25,6 +25,10 @@ const getUrlQueryParameters = <
|
|
|
25
25
|
|
|
26
26
|
const entries = [...urlParams.entries()].map<[string, string]>(
|
|
27
27
|
([key, value]) => {
|
|
28
|
+
if (startsWith('/', value)) {
|
|
29
|
+
return [key, value];
|
|
30
|
+
}
|
|
31
|
+
|
|
28
32
|
return [key, JSON.parse(value)];
|
|
29
33
|
}
|
|
30
34
|
);
|
package/src/utils/index.ts
CHANGED
|
@@ -3,7 +3,6 @@ export * from './getNormalizedId';
|
|
|
3
3
|
export * from './statuses';
|
|
4
4
|
export * from './typedMemo';
|
|
5
5
|
export * from './useCopyToClipboard';
|
|
6
|
-
export * from './useDateTimePickerAdapter';
|
|
7
6
|
export * from './useDebounce';
|
|
8
7
|
export * from './useDeepCallback';
|
|
9
8
|
export * from './useDeepMemo';
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
|
+
import { renderHook } from '@testing-library/react';
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getFetchCall,
|
|
6
|
+
mockResponse,
|
|
7
|
+
resetMocks,
|
|
8
|
+
waitFor
|
|
9
|
+
} from '../../test/testRenderer';
|
|
10
|
+
import TestQueryProvider from '../api/TestQueryProvider';
|
|
4
11
|
|
|
5
12
|
import { labelLicenseWarning } from './translatedLabel';
|
|
6
13
|
|
|
@@ -79,59 +86,63 @@ const getMockedResponse = (expirationDate): object => ({
|
|
|
79
86
|
});
|
|
80
87
|
|
|
81
88
|
const mockRequest = ({ expirationDate }: { expirationDate }): void => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
path: '**internal.php?object=centreon_module&action=list',
|
|
86
|
-
response: getMockedResponse(expirationDate)
|
|
89
|
+
resetMocks();
|
|
90
|
+
mockResponse({
|
|
91
|
+
data: getMockedResponse(expirationDate)
|
|
87
92
|
});
|
|
88
93
|
};
|
|
89
94
|
|
|
90
|
-
const
|
|
91
|
-
useLicenseExpirationWarning({
|
|
92
|
-
module: 'centreon-autodiscovery-server'
|
|
93
|
-
});
|
|
95
|
+
const showMessage = jest.fn();
|
|
94
96
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
<SnackbarProvider>
|
|
102
|
-
<TestComponent />
|
|
103
|
-
</SnackbarProvider>
|
|
104
|
-
</TestQueryProvider>
|
|
105
|
-
);
|
|
106
|
-
};
|
|
97
|
+
jest.mock('../Snackbar/useSnackbar', () => ({
|
|
98
|
+
__esModule: true,
|
|
99
|
+
default: jest
|
|
100
|
+
.fn()
|
|
101
|
+
.mockImplementation(() => ({ showWarningMessage: showMessage }))
|
|
102
|
+
}));
|
|
107
103
|
|
|
108
104
|
const initialize = (): void => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
renderHook(
|
|
106
|
+
() =>
|
|
107
|
+
useLicenseExpirationWarning({
|
|
108
|
+
module: 'centreon-autodiscovery-server'
|
|
109
|
+
}),
|
|
110
|
+
{
|
|
111
|
+
wrapper: TestQueryProvider
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
114
|
};
|
|
115
115
|
|
|
116
116
|
const currentDate = dayjs();
|
|
117
117
|
|
|
118
118
|
describe('License', () => {
|
|
119
|
-
beforeEach(initialize);
|
|
120
|
-
|
|
121
119
|
it('does not display any warning message when the license expires in more than 15 days from the current date', () => {
|
|
122
120
|
mockRequest({ expirationDate: currentDate.add(20, 'day') });
|
|
121
|
+
initialize();
|
|
123
122
|
|
|
124
|
-
|
|
123
|
+
waitFor(() => {
|
|
124
|
+
expect(getFetchCall(0)).toEqual(
|
|
125
|
+
'internal.php?object=centreon_module&action=list'
|
|
126
|
+
);
|
|
127
|
+
});
|
|
125
128
|
|
|
126
|
-
|
|
127
|
-
labelLicenseWarning('centreon-autodiscovery-server', 20)
|
|
128
|
-
).should('not.exist');
|
|
129
|
+
expect(showMessage).not.toHaveBeenCalled();
|
|
129
130
|
});
|
|
131
|
+
|
|
130
132
|
it('displays a warning message when the license expires within 15 days', () => {
|
|
131
133
|
mockRequest({ expirationDate: currentDate.add(10.5, 'day') });
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
initialize();
|
|
135
|
+
|
|
136
|
+
waitFor(() => {
|
|
137
|
+
expect(getFetchCall(0)).toEqual(
|
|
138
|
+
'internal.php?object=centreon_module&action=list'
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
waitFor(() => {
|
|
143
|
+
expect(showMessage).toHaveBeenCalledWith(
|
|
144
|
+
labelLicenseWarning('centreon-autodiscovery-server', 10)
|
|
145
|
+
);
|
|
146
|
+
});
|
|
136
147
|
});
|
|
137
148
|
});
|