@m4l/components 9.2.52 → 9.2.54-beta.1
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/.storybook/utils/getStylesColorsByMode.d.ts +4 -4
- package/components/Chip/Chip.js +3 -1
- package/components/Chip/types.d.ts +4 -0
- package/components/DataGrid/constants.d.ts +21 -0
- package/components/DataGrid/constants.js +24 -1
- package/components/DataGrid/index.d.ts +1 -0
- package/components/DataGrid/subcomponents/Table/subcomponents/ActionsColumn.js +2 -2
- package/components/DynamicFilter/subcomponents/FieldTypes/DateTimeFilter/helpers.js +3 -2
- package/components/DynamicFilter/types.d.ts +2 -2
- package/components/ObjectLogs/subcomponents/ObjectLogsByOthers/ObjectLogsByOthers.js +1 -1
- package/components/hook-form/RHFAutocomplete/RHFAutocomplete.js +30 -19
- package/components/hook-form/RHFAutocomplete/tests/common.d.ts +37 -0
- package/components/hook-form/RHFAutocomplete/types.d.ts +3 -8
- package/components/hook-form/RHFAutocompleteAsync/RHFAutocompleteAsync.d.ts +32 -5
- package/components/hook-form/RHFAutocompleteAsync/RHFAutocompleteAsync.js +49 -84
- package/components/hook-form/RHFAutocompleteAsync/RHFAutocompleteAsyncStyles.d.ts +2 -2
- package/components/hook-form/RHFAutocompleteAsync/hooks/useFetchOptions.d.ts +5 -0
- package/components/hook-form/RHFAutocompleteAsync/hooks/useFetchOptions.js +64 -0
- package/components/hook-form/RHFAutocompleteAsync/reducer/RHFAutocompleteReducer.d.ts +14 -0
- package/components/hook-form/RHFAutocompleteAsync/reducer/RHFAutocompleteReducer.js +74 -0
- package/components/hook-form/RHFAutocompleteAsync/slots/RHFAutocompleteSlotsAsync.d.ts +1 -1
- package/components/hook-form/RHFAutocompleteAsync/tests/OnChangFilterParmsDefined.test.d.ts +1 -0
- package/components/hook-form/RHFAutocompleteAsync/tests/OnChangFilterParmsUndefined.test.d.ts +1 -0
- package/components/hook-form/RHFAutocompleteAsync/tests/RHFAutocompleteReducer.test.d.ts +1 -0
- package/components/hook-form/RHFAutocompleteAsync/tests/common.d.ts +41 -0
- package/components/hook-form/RHFAutocompleteAsync/types.d.ts +120 -4
- package/components/hook-form/RHFAutocompleteAsync/types.js +44 -0
- package/components/hook-form/RHFTextField/RHFTextField.js +3 -2
- package/components/mui_extended/Autocomplete/Autocomplete.d.ts +7 -0
- package/components/mui_extended/Autocomplete/Autocomplete.js +68 -196
- package/components/mui_extended/Autocomplete/Autocomplete.styles.js +27 -16
- package/components/mui_extended/Autocomplete/hooks/useEndAdornments.d.ts +14 -0
- package/components/mui_extended/Autocomplete/hooks/useEndAdornments.js +47 -0
- package/components/mui_extended/Autocomplete/hooks/useStartAdornments.d.ts +21 -0
- package/components/mui_extended/Autocomplete/hooks/useStartAdornments.js +31 -0
- package/components/mui_extended/Autocomplete/hooks/useValuesAndHandlers.d.ts +23 -0
- package/components/mui_extended/Autocomplete/hooks/useValuesAndHandlers.js +135 -0
- package/components/mui_extended/Autocomplete/icons.d.ts +4 -0
- package/components/mui_extended/Autocomplete/icons.js +7 -0
- package/components/mui_extended/Autocomplete/renderOptions/index.d.ts +7 -2
- package/components/mui_extended/Autocomplete/renderOptions/index.js +7 -6
- package/components/mui_extended/Autocomplete/slots/AutocompleteSlots.js +6 -7
- package/components/mui_extended/Autocomplete/types.d.ts +2 -0
- package/hooks/useDynamicFilterAndSort/useDynamicFilterAndSort.js +13 -10
- package/index.js +8 -6
- package/mockServiceWorker.js +1 -1
- package/package.json +3 -3
- package/storybook/components/extended/mui/Autocomplete/AutoComple.stories.d.ts +1 -0
- package/storybook/hook-form/RHFAutocomplete/RHFAutocomplete.stories.d.ts +8 -6
- package/storybook/hook-form/RHFAutocomplete/constants.d.ts +23 -0
- package/storybook/hook-form/RHFAutocompleteAsync/RHFAutocompleteAsync.stories.d.ts +11 -4
- package/storybook/hook-form/RHFAutocompleteAsync/constants.d.ts +10 -1
- package/storybook/hook-form/RHFAutocompleteAsync/handlers.d.ts +1 -0
- package/components/hook-form/RHFAutocomplete/oldTypes.d.ts +0 -43
- /package/components/hook-form/RHFAutocomplete/{RHFAutocomplete.test.d.ts → tests/RHFAutocomplete.test.d.ts} +0 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useRef, useEffect } from "react";
|
|
2
|
+
import { a as actionsType } from "../types.js";
|
|
3
|
+
import { useNetwork, getPropertyByString } from "@m4l/core";
|
|
4
|
+
const useFetchOptions = (props) => {
|
|
5
|
+
const {
|
|
6
|
+
state,
|
|
7
|
+
dispatch,
|
|
8
|
+
endPoint,
|
|
9
|
+
timeout,
|
|
10
|
+
isExternalUrl,
|
|
11
|
+
parms,
|
|
12
|
+
responseToCamelCase,
|
|
13
|
+
isRemote,
|
|
14
|
+
resultField = "data"
|
|
15
|
+
} = props;
|
|
16
|
+
const { networkOperation } = useNetwork();
|
|
17
|
+
const abortControllerRef = useRef(null);
|
|
18
|
+
const refFireFetchCount = useRef(state.fireFetchCount);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
dispatch({ type: actionsType.SET_PARAMS, payload: parms });
|
|
21
|
+
}, [parms]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
let cancel = false;
|
|
24
|
+
if (refFireFetchCount.current === state.fireFetchCount) {
|
|
25
|
+
return;
|
|
26
|
+
} else {
|
|
27
|
+
refFireFetchCount.current = state.fireFetchCount;
|
|
28
|
+
}
|
|
29
|
+
if (state.fireFetchCount > 0) {
|
|
30
|
+
if (abortControllerRef.current) {
|
|
31
|
+
abortControllerRef.current.abort();
|
|
32
|
+
}
|
|
33
|
+
abortControllerRef.current = new AbortController();
|
|
34
|
+
networkOperation({
|
|
35
|
+
method: "GET",
|
|
36
|
+
endPoint,
|
|
37
|
+
timeout,
|
|
38
|
+
isExternalUrl,
|
|
39
|
+
parms: { ...parms, ...state.queryParams },
|
|
40
|
+
responseToCamelCase,
|
|
41
|
+
isRemote,
|
|
42
|
+
signal: abortControllerRef.current.signal
|
|
43
|
+
}).then((response) => {
|
|
44
|
+
if (cancel) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const valueMaybeArray = getPropertyByString(response, resultField);
|
|
48
|
+
const newOptions = Array.isArray(valueMaybeArray) ? valueMaybeArray : [];
|
|
49
|
+
dispatch({ type: actionsType.FINISH_LOAD_OPTIONS, payload: { options: newOptions } });
|
|
50
|
+
}).catch(() => {
|
|
51
|
+
dispatch({ type: actionsType.FINISH_LOAD_OPTIONS, payload: {} });
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return () => {
|
|
55
|
+
cancel = true;
|
|
56
|
+
if (abortControllerRef.current) {
|
|
57
|
+
abortControllerRef.current.abort();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}, [state.fireFetchCount]);
|
|
61
|
+
};
|
|
62
|
+
export {
|
|
63
|
+
useFetchOptions as u
|
|
64
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RHFAutocompleteAsyncAction, RHFAutocompleteAsyncState, OnChangeFilterParms } from '../types';
|
|
2
|
+
type getInitialStateRHFAutocompleteAsyncProps = {
|
|
3
|
+
parms?: Record<string, any>;
|
|
4
|
+
onChangeFilterParms?: OnChangeFilterParms;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Returns the initial state for the RHFAutocompleteAsync component.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getInitialStateRHFAutocompleteAsync: <T>(props: getInitialStateRHFAutocompleteAsyncProps) => RHFAutocompleteAsyncState<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Reducer to manage state of RHFAutocompleteAsync component.
|
|
12
|
+
*/
|
|
13
|
+
export declare const RHFAutocompleteAsyncReducer: <T>(onChangeFilterParms?: OnChangeFilterParms) => (state: RHFAutocompleteAsyncState<T>, action: RHFAutocompleteAsyncAction<T>) => RHFAutocompleteAsyncState<T>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { deepEqual } from "fast-equals";
|
|
2
|
+
import { a as actionsType } from "../types.js";
|
|
3
|
+
const getInitialStateRHFAutocompleteAsync = (props) => ({
|
|
4
|
+
fireFetchCount: 0,
|
|
5
|
+
options: [],
|
|
6
|
+
parms: props.parms,
|
|
7
|
+
// allowFetch: false,
|
|
8
|
+
loading: false,
|
|
9
|
+
queryParams: props.onChangeFilterParms ? props.onChangeFilterParms("") : {},
|
|
10
|
+
isOpen: false,
|
|
11
|
+
firstOpen: true
|
|
12
|
+
// selectedOptions: [],
|
|
13
|
+
});
|
|
14
|
+
const RHFAutocompleteAsyncReducer = (onChangeFilterParms) => (state, action) => {
|
|
15
|
+
switch (action.type) {
|
|
16
|
+
case actionsType.REFRESH:
|
|
17
|
+
return {
|
|
18
|
+
...state,
|
|
19
|
+
fireFetchCount: state.fireFetchCount + 1
|
|
20
|
+
//Lanzr una nueva petición
|
|
21
|
+
};
|
|
22
|
+
case actionsType.SET_PARAMS:
|
|
23
|
+
if (deepEqual(state.parms, action.payload)) {
|
|
24
|
+
return state;
|
|
25
|
+
}
|
|
26
|
+
if (onChangeFilterParms) {
|
|
27
|
+
state.queryParams = onChangeFilterParms("");
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
parms: action.payload,
|
|
32
|
+
fireFetchCount: 0,
|
|
33
|
+
firstOpen: true
|
|
34
|
+
};
|
|
35
|
+
case actionsType.SET_QUERY_PARAMS:
|
|
36
|
+
if (deepEqual(state.queryParams, action.payload)) {
|
|
37
|
+
return state;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
...state,
|
|
41
|
+
queryParams: action.payload,
|
|
42
|
+
fireFetchCount: state.fireFetchCount + 1
|
|
43
|
+
};
|
|
44
|
+
case actionsType.FINISH_LOAD_OPTIONS:
|
|
45
|
+
const finalOptions = action.payload?.options || state.options;
|
|
46
|
+
const firstOpen = action.payload?.options ? state.firstOpen : true;
|
|
47
|
+
return {
|
|
48
|
+
...state,
|
|
49
|
+
options: finalOptions,
|
|
50
|
+
loading: false,
|
|
51
|
+
firstOpen
|
|
52
|
+
};
|
|
53
|
+
case actionsType.OPEN:
|
|
54
|
+
return {
|
|
55
|
+
...state,
|
|
56
|
+
isOpen: true,
|
|
57
|
+
fireFetchCount: state.firstOpen ? state.fireFetchCount + 1 : state.fireFetchCount,
|
|
58
|
+
firstOpen: false,
|
|
59
|
+
loading: state.firstOpen ? true : state.loading
|
|
60
|
+
// allowFetch: true,
|
|
61
|
+
};
|
|
62
|
+
case actionsType.CLOSE:
|
|
63
|
+
return {
|
|
64
|
+
...state,
|
|
65
|
+
isOpen: false
|
|
66
|
+
};
|
|
67
|
+
default:
|
|
68
|
+
return state;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
export {
|
|
72
|
+
RHFAutocompleteAsyncReducer as R,
|
|
73
|
+
getInitialStateRHFAutocompleteAsync as g
|
|
74
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const RHFAutocompleteAsyncRootStyled: import('@emotion/styled').StyledComponent<Pick<import('../../RHFAutocomplete/types').RHFAutocompleteProps<unknown,
|
|
1
|
+
export declare const RHFAutocompleteAsyncRootStyled: import('@emotion/styled').StyledComponent<Pick<import('../../RHFAutocomplete/types').RHFAutocompleteProps<unknown, undefined, undefined, undefined>, keyof import('../../RHFAutocomplete/types').RHFAutocompleteProps<unknown, undefined, undefined, undefined>> & import('@mui/system').MUIStyledCommonProps<import('@mui/material').Theme> & Record<string, unknown>, {}, {}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RHFAutocompleteAsyncProps } from '../types';
|
|
2
|
+
import { renderMaterialUI } from '../../../../test';
|
|
3
|
+
import { FieldValues } from 'react-hook-form';
|
|
4
|
+
export declare const FIELD_NAME = "rhf-autocomplete-async";
|
|
5
|
+
export declare const FIELD_NAME_PRESELECTED = "rhf-autocomplete-async-preselected";
|
|
6
|
+
export declare const FIELD_NAME_PRESELECTED_NOT_IN_OPTIONS = "rhf-autocomplete-async-preselected-not-in-options";
|
|
7
|
+
export declare const FIELD_NAME_PRESELECTED_MULTIPLE = "rhf-autocomplete-async-preselected-multiple";
|
|
8
|
+
export declare const FIELD_NAME_PRESELECTED_MULTIPLE_NOT_IN_OPTIONS = "rhf-autocomplete-async-preselected-multiple-not-in-options";
|
|
9
|
+
export interface OptionsTests {
|
|
10
|
+
id: number;
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const mockItems: OptionsTests[];
|
|
14
|
+
export declare const mockItemPreselected: OptionsTests;
|
|
15
|
+
export declare const mockItemPreselectedMultiple: OptionsTests[];
|
|
16
|
+
export declare const mockItemPreselectedNotInOptions: OptionsTests;
|
|
17
|
+
export declare const mockItemPreselectedMultipleNotInOptions: OptionsTests[];
|
|
18
|
+
export declare const INITIAL_FORM_VALUES: FieldValues;
|
|
19
|
+
export declare const DEFAULT_PROPS: RHFAutocompleteAsyncProps<OptionsTests>;
|
|
20
|
+
/**
|
|
21
|
+
* Custom filter function
|
|
22
|
+
*/
|
|
23
|
+
export declare const onChangeFilterParms: (newValue: string) => {
|
|
24
|
+
f: ({
|
|
25
|
+
n: string;
|
|
26
|
+
o: string;
|
|
27
|
+
o1: boolean;
|
|
28
|
+
} | {
|
|
29
|
+
n: string;
|
|
30
|
+
o: string;
|
|
31
|
+
o1: string;
|
|
32
|
+
})[];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Renderiza el componente con el contexto de EnvironmentProvider y RHFormProvider.
|
|
36
|
+
*/
|
|
37
|
+
export declare const renderWithContexts: (ui: React.ReactElement, initialValuesFormContext?: FieldValues, validationSchema?: any) => ReturnType<typeof renderMaterialUI>;
|
|
38
|
+
/**
|
|
39
|
+
* Renders the RHFAutocompleteAsync component with the provided props.
|
|
40
|
+
*/
|
|
41
|
+
export declare const renderRHFAutocompleteAsync: (fieldName: string, overrideProps?: Partial<RHFAutocompleteAsyncProps<OptionsTests>>) => ReturnType<typeof renderMaterialUI>;
|
|
@@ -1,17 +1,46 @@
|
|
|
1
|
-
import { OverridesStyleRules } from '@mui/material/styles/overrides';
|
|
2
1
|
import { RHFAutocompleteProps } from '../RHFAutocomplete/types';
|
|
3
2
|
import { RFHAUTOCOMPLETEASYNC_KEY_COMPONENT } from './constants';
|
|
4
3
|
import { RHFAutocompleteAsyncSlots } from './slots';
|
|
5
4
|
import { Theme } from '@mui/material';
|
|
6
|
-
|
|
5
|
+
import { M4LOverridesStyleRules } from '../../../@types/augmentations';
|
|
6
|
+
export type OnChangeFilterParms = (newValue: string) => Record<string, any>;
|
|
7
|
+
export interface RHFAutocompleteAsyncProps<T extends any = unknown> extends Omit<RHFAutocompleteProps<T>, 'options' | 'onOpen' | 'onClose' | 'open' | 'multiple'> {
|
|
8
|
+
/**
|
|
9
|
+
* URL to fetch data from
|
|
10
|
+
*/
|
|
7
11
|
endPoint: string;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the response should be converted to camel case
|
|
14
|
+
*/
|
|
8
15
|
responseToCamelCase?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Timeout for the fetch request
|
|
18
|
+
*/
|
|
9
19
|
timeout?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Parameters to send with the fetch request
|
|
22
|
+
*/
|
|
10
23
|
parms?: Record<string, any>;
|
|
24
|
+
/**
|
|
25
|
+
* Whether the URL is external
|
|
26
|
+
*/
|
|
11
27
|
isExternalUrl?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Field in the response object that contains the data, normalmente data.
|
|
30
|
+
*/
|
|
12
31
|
resultField?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Whether the data is fetched remotely
|
|
34
|
+
*/
|
|
13
35
|
isRemote?: boolean;
|
|
14
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Callback for when the filter parameters change, or initial state.
|
|
38
|
+
*/
|
|
39
|
+
onChangeFilterParms?: OnChangeFilterParms;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the autocomplete is multiple
|
|
42
|
+
*/
|
|
43
|
+
multiple?: boolean;
|
|
15
44
|
}
|
|
16
45
|
/**
|
|
17
46
|
* Defines the types of Slots available for the Autocomplete.
|
|
@@ -20,4 +49,91 @@ export type RHFAutocompleteAsyncSlotsType = keyof typeof RHFAutocompleteAsyncSlo
|
|
|
20
49
|
/**
|
|
21
50
|
* Styles applicable to the Autocomplete using themes and custom slots.
|
|
22
51
|
*/
|
|
23
|
-
export type
|
|
52
|
+
export type RHFAutocompleteAsyncStyles = M4LOverridesStyleRules<RHFAutocompleteAsyncSlotsType, typeof RFHAUTOCOMPLETEASYNC_KEY_COMPONENT, Theme>;
|
|
53
|
+
/**
|
|
54
|
+
* Name of actions for reducer in RHFAutocompleteAsync component.
|
|
55
|
+
*/
|
|
56
|
+
export declare const actionsType: {
|
|
57
|
+
/**
|
|
58
|
+
* Refresh the options of the autocomplete, esta opcion es manual, por lo tanto debe forzar
|
|
59
|
+
* la recarga de las options.
|
|
60
|
+
*/
|
|
61
|
+
readonly REFRESH: "REFRESH";
|
|
62
|
+
/**
|
|
63
|
+
* Set the params to request the options. When the parms change, the options are requested again, and queryParams are rebuilt.
|
|
64
|
+
*/
|
|
65
|
+
readonly SET_PARAMS: "SET_PARAMS";
|
|
66
|
+
/**
|
|
67
|
+
* Set the query params to request the options with the new filter
|
|
68
|
+
* selected from the option listed in the autocomplete.
|
|
69
|
+
*/
|
|
70
|
+
readonly SET_QUERY_PARAMS: "SET_QUERY_PARAMS";
|
|
71
|
+
/**
|
|
72
|
+
* Indicate if the popover options are open.
|
|
73
|
+
*/
|
|
74
|
+
readonly OPEN: "OPEN";
|
|
75
|
+
/**
|
|
76
|
+
* Indicate if the popover options are close.
|
|
77
|
+
*/
|
|
78
|
+
readonly CLOSE: "CLOSE";
|
|
79
|
+
/**
|
|
80
|
+
* Reset the state options, allowFetchingOptionsAutocomplete (false)
|
|
81
|
+
* and loading (true) to initial state before fetching options
|
|
82
|
+
* to wait the response from the server.
|
|
83
|
+
*/
|
|
84
|
+
readonly START_FETCHING_OPTIONS: "START_FETCHING_OPTIONS";
|
|
85
|
+
/**
|
|
86
|
+
* Set new options to list in autocomplete.
|
|
87
|
+
* For example, when the user is typing,
|
|
88
|
+
* the options are filtered from the server and the new options are set to the list.
|
|
89
|
+
*/
|
|
90
|
+
readonly FINISH_LOAD_OPTIONS: "FINISH_LOAD_OPTIONS";
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Action type for RHFAutocompleteAsync component.
|
|
94
|
+
*/
|
|
95
|
+
export type RHFAutocompleteAsyncAction<T> = {
|
|
96
|
+
type: typeof actionsType.REFRESH;
|
|
97
|
+
} | {
|
|
98
|
+
type: typeof actionsType.SET_QUERY_PARAMS;
|
|
99
|
+
payload: Record<string, any>;
|
|
100
|
+
} | {
|
|
101
|
+
type: typeof actionsType.FINISH_LOAD_OPTIONS;
|
|
102
|
+
payload: {
|
|
103
|
+
options?: Array<T>;
|
|
104
|
+
};
|
|
105
|
+
} | {
|
|
106
|
+
type: typeof actionsType.OPEN;
|
|
107
|
+
} | {
|
|
108
|
+
type: typeof actionsType.CLOSE;
|
|
109
|
+
} | {
|
|
110
|
+
type: typeof actionsType.SET_PARAMS;
|
|
111
|
+
payload: Record<string, any> | undefined;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* State type for RHFAutocompleteAsync component.
|
|
115
|
+
*/
|
|
116
|
+
export type RHFAutocompleteAsyncState<T> = {
|
|
117
|
+
options: Array<T>;
|
|
118
|
+
loading: boolean;
|
|
119
|
+
parms?: Record<string, any>;
|
|
120
|
+
queryParams: Record<string, any>;
|
|
121
|
+
isOpen: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Indica si es la primera apertura el componente
|
|
124
|
+
*/
|
|
125
|
+
firstOpen: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Number of times the fetching is fired.
|
|
128
|
+
* the fetching count is incremented, useFetchOptions Effect is fired.
|
|
129
|
+
* When the fetching count is equal to 0, the fetching is not allowed.
|
|
130
|
+
*/
|
|
131
|
+
fireFetchCount: number;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Params for useFetchOptions hook.
|
|
135
|
+
*/
|
|
136
|
+
export interface UseFetchOptionsProps<T> extends Pick<RHFAutocompleteAsyncProps<T>, 'endPoint' | 'timeout' | 'isExternalUrl' | 'parms' | 'responseToCamelCase' | 'isRemote' | 'resultField'> {
|
|
137
|
+
state: RHFAutocompleteAsyncState<T>;
|
|
138
|
+
dispatch: (value: RHFAutocompleteAsyncAction<T>) => void;
|
|
139
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const actionsType = {
|
|
2
|
+
/**
|
|
3
|
+
* Refresh the options of the autocomplete, esta opcion es manual, por lo tanto debe forzar
|
|
4
|
+
* la recarga de las options.
|
|
5
|
+
*/
|
|
6
|
+
REFRESH: "REFRESH",
|
|
7
|
+
/**
|
|
8
|
+
* Set the params to request the options. When the parms change, the options are requested again, and queryParams are rebuilt.
|
|
9
|
+
*/
|
|
10
|
+
SET_PARAMS: "SET_PARAMS",
|
|
11
|
+
/**
|
|
12
|
+
* Set the query params to request the options with the new filter
|
|
13
|
+
* selected from the option listed in the autocomplete.
|
|
14
|
+
*/
|
|
15
|
+
SET_QUERY_PARAMS: "SET_QUERY_PARAMS",
|
|
16
|
+
/**
|
|
17
|
+
* Indicate if the popover options are open.
|
|
18
|
+
*/
|
|
19
|
+
OPEN: "OPEN",
|
|
20
|
+
/**
|
|
21
|
+
* Indicate if the popover options are close.
|
|
22
|
+
*/
|
|
23
|
+
CLOSE: "CLOSE",
|
|
24
|
+
/**
|
|
25
|
+
* Reset the state options, allowFetchingOptionsAutocomplete (false)
|
|
26
|
+
* and loading (true) to initial state before fetching options
|
|
27
|
+
* to wait the response from the server.
|
|
28
|
+
*/
|
|
29
|
+
START_FETCHING_OPTIONS: "START_FETCHING_OPTIONS",
|
|
30
|
+
/**
|
|
31
|
+
* Set new options to list in autocomplete.
|
|
32
|
+
* For example, when the user is typing,
|
|
33
|
+
* the options are filtered from the server and the new options are set to the list.
|
|
34
|
+
*/
|
|
35
|
+
FINISH_LOAD_OPTIONS: "FINISH_LOAD_OPTIONS"
|
|
36
|
+
// /**
|
|
37
|
+
// * Set the selected options to the autocomplete because
|
|
38
|
+
// * are necessary merge with the options obtains from the server
|
|
39
|
+
// */
|
|
40
|
+
// SET_SELECTED_OPTIONS_TO_AUTOCOMPLETE: 'SET_SELECTED_OPTIONS_TO_AUTOCOMPLETE',
|
|
41
|
+
};
|
|
42
|
+
export {
|
|
43
|
+
actionsType as a
|
|
44
|
+
};
|
|
@@ -27,9 +27,11 @@ const RHFTextField = forwardRef((props, ref) => {
|
|
|
27
27
|
mandatoryMessage,
|
|
28
28
|
helperText = true,
|
|
29
29
|
className,
|
|
30
|
+
htmlFor,
|
|
30
31
|
...other
|
|
31
32
|
} = props;
|
|
32
|
-
const
|
|
33
|
+
const id = useId();
|
|
34
|
+
const htmlForId = htmlFor ?? id;
|
|
33
35
|
const ariaLabelledById = `field-label-${htmlForId}`;
|
|
34
36
|
const {
|
|
35
37
|
control
|
|
@@ -87,7 +89,6 @@ const RHFTextField = forwardRef((props, ref) => {
|
|
|
87
89
|
value: type === "number" ? isNaN(parseFloat(value)) ? "" : value : value || "",
|
|
88
90
|
inputProps: {
|
|
89
91
|
name,
|
|
90
|
-
ss: 1,
|
|
91
92
|
id: htmlForId,
|
|
92
93
|
"aria-labelledby": ariaLabelledById,
|
|
93
94
|
...getPropDataTestId(RHF_TEXT_FIELD_KEY_COMPONENT, RHFTextFieldSlots.textField)
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import { AutocompleteProps } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Autocomplete refactorizado con slots M4L.
|
|
4
|
+
* Tener en cuenta que cuando es multiple y se abre el dropdown, y el value no está dentro de lasl opciones.
|
|
5
|
+
* MUI va a genera el siguiente warning (Y es normal que suceda, no es necesario darle solución):
|
|
6
|
+
* MUI: The value provided to Autocomplete is invalid.
|
|
7
|
+
* None of the options match with `{"y":y,"x":"xxx"}`. etc.
|
|
8
|
+
*/
|
|
2
9
|
export declare const Autocomplete: import('react').ForwardRefExoticComponent<AutocompleteProps<unknown, boolean | undefined> & import('react').RefAttributes<HTMLInputElement | HTMLTextAreaElement>>;
|