@centreon/ui 23.10.31 → 23.10.32-MON-19938-cloud-notifications-fix-search-select-boxes.0
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,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useMemo } from 'react';
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import { FormikValues, useFormikContext } from 'formik';
|
|
4
4
|
import { equals, isEmpty, path, split } from 'ramda';
|
|
@@ -11,7 +11,12 @@ import {
|
|
|
11
11
|
} from '../..';
|
|
12
12
|
import MultiConnectedAutocompleteField from '../../InputField/Select/Autocomplete/Connected/Multi';
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
AutoCompleteChangeData,
|
|
16
|
+
InputPropsWithoutGroup,
|
|
17
|
+
InputType,
|
|
18
|
+
Reason
|
|
19
|
+
} from './models';
|
|
15
20
|
|
|
16
21
|
const defaultFilterKey = 'name';
|
|
17
22
|
|
|
@@ -29,6 +34,8 @@ const ConnectedAutocomplete = ({
|
|
|
29
34
|
}: InputPropsWithoutGroup): JSX.Element => {
|
|
30
35
|
const { t } = useTranslation();
|
|
31
36
|
|
|
37
|
+
const [autocompleteChangeData, setAutocompleteChangeData] =
|
|
38
|
+
useState<AutoCompleteChangeData>();
|
|
32
39
|
const { values, touched, errors, setFieldValue, setFieldTouched } =
|
|
33
40
|
useFormikContext<FormikValues>();
|
|
34
41
|
|
|
@@ -55,7 +62,9 @@ const ConnectedAutocomplete = ({
|
|
|
55
62
|
const fieldNamePath = split('.', fieldName);
|
|
56
63
|
|
|
57
64
|
const changeAutocomplete = useCallback(
|
|
58
|
-
(_, value): void => {
|
|
65
|
+
(_, value, reason: Reason): void => {
|
|
66
|
+
setAutocompleteChangeData({ reason, value });
|
|
67
|
+
|
|
59
68
|
if (change) {
|
|
60
69
|
change({ setFieldValue, value });
|
|
61
70
|
|
|
@@ -104,6 +113,7 @@ const ConnectedAutocomplete = ({
|
|
|
104
113
|
return useMemoComponent({
|
|
105
114
|
Component: (
|
|
106
115
|
<AutocompleteField
|
|
116
|
+
autocompleteChangeData={autocompleteChangeData}
|
|
107
117
|
dataTestId={dataTestId}
|
|
108
118
|
disableClearable={false}
|
|
109
119
|
disabled={disabled}
|
|
@@ -103,3 +103,16 @@ export interface Group {
|
|
|
103
103
|
name: string;
|
|
104
104
|
order: number;
|
|
105
105
|
}
|
|
106
|
+
|
|
107
|
+
export enum Reason {
|
|
108
|
+
blur = 'blur',
|
|
109
|
+
clear = 'clear',
|
|
110
|
+
createOption = 'createOption',
|
|
111
|
+
removeOption = 'removeOption',
|
|
112
|
+
selectOption = 'selectOption'
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface AutoCompleteChangeData {
|
|
116
|
+
reason: Reason;
|
|
117
|
+
value: string;
|
|
118
|
+
}
|
|
@@ -28,8 +28,10 @@ import {
|
|
|
28
28
|
SearchParameter
|
|
29
29
|
} from '../../../../api/buildListingEndpoint/models';
|
|
30
30
|
import useFetchQuery from '../../../../api/useFetchQuery';
|
|
31
|
+
import { AutoCompleteChangeData } from '../../../../Form/Inputs/models';
|
|
31
32
|
|
|
32
33
|
export interface ConnectedAutoCompleteFieldProps<TData> {
|
|
34
|
+
autocompleteChangeData?: AutoCompleteChangeData;
|
|
33
35
|
conditionField?: keyof SelectEntry;
|
|
34
36
|
field: string;
|
|
35
37
|
getEndpoint: ({ search, page }) => string;
|
|
@@ -55,6 +57,7 @@ const ConnectedAutocompleteField = (
|
|
|
55
57
|
getRenderedOptionText = (option): string => option.name?.toString(),
|
|
56
58
|
getRequestHeaders,
|
|
57
59
|
displayOptionThumbnail,
|
|
60
|
+
autocompleteChangeData,
|
|
58
61
|
...props
|
|
59
62
|
}: ConnectedAutoCompleteFieldProps<TData> &
|
|
60
63
|
Omit<AutocompleteFieldProps, 'options'>): JSX.Element => {
|
|
@@ -274,6 +277,13 @@ const ConnectedAutocompleteField = (
|
|
|
274
277
|
);
|
|
275
278
|
}, useDeepCompare([searchConditions]));
|
|
276
279
|
|
|
280
|
+
useEffect(() => {
|
|
281
|
+
if (!autocompleteChangeData) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
setSearchParameter(undefined);
|
|
285
|
+
}, [autocompleteChangeData?.reason, autocompleteChangeData?.value]);
|
|
286
|
+
|
|
277
287
|
useEffect(() => {
|
|
278
288
|
if (!optionsOpen) {
|
|
279
289
|
return;
|