@giteeteam/apps-team-components 1.11.16 → 1.11.17
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/dist/components/fields/dropdown/BaseField.js +8 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/hooks/useFetchDropdownOptionsStore.d.ts +1 -0
- package/dist/lib/hooks/useFetchDropdownOptionsStore.js +16 -11
- package/dist/lib/store/dropDownOptionsStore.d.ts +3 -0
- package/dist/lib/store/dropDownOptionsStore.js +2 -1
- package/package.json +1 -1
|
@@ -21,6 +21,7 @@ import { getRealValueByIqlTo } from '../../filters/filter-search/utils.js';
|
|
|
21
21
|
import { REMOTE_DATA_QUOTE_FIELD_TYPE } from '../../../lib/constants/field.js';
|
|
22
22
|
import { BASE_FIELD_WIDTH, FIELD_CONTAINERS_PAGE, CURRENT_WORKSPACE, FIELD_TYPE_KEY_MAPPINGS } from '../../../lib/global.js';
|
|
23
23
|
import useAntdConfig from '../../../lib/hooks/useAntdConfig.js';
|
|
24
|
+
import { useDropdownOptionsFetching } from '../../../lib/hooks/useFetchDropdownOptionsStore.js';
|
|
24
25
|
import useI18n from '../../../lib/hooks/useI18n.js';
|
|
25
26
|
import { dropDownOptionsState, createDropDownOptionsStoreKey } from '../../../lib/store/dropDownOptionsStore.js';
|
|
26
27
|
import { API_KEY } from '../../../lib/swr/constants.js';
|
|
@@ -95,6 +96,7 @@ const Dropdown = props => {
|
|
|
95
96
|
}, [dataQuoteInit, options, propsValue, userData === null || userData === void 0 ? void 0 : userData.display, value]);
|
|
96
97
|
const dropDownOptionsMap = useAtomValue(dropDownOptionsState);
|
|
97
98
|
const storeOptions = dropDownOptionsMap[createDropDownOptionsStoreKey(objectId)];
|
|
99
|
+
const isDropdownOptionsFetching = useDropdownOptionsFetching();
|
|
98
100
|
const _options = useMemo(() => ((options === null || options === void 0 ? void 0 : options.length) > 0 ? options : finallyOptions) || [], [finallyOptions, options]);
|
|
99
101
|
async function fetcher() {
|
|
100
102
|
return await fetchOptions('');
|
|
@@ -193,6 +195,7 @@ const Dropdown = props => {
|
|
|
193
195
|
var _a;
|
|
194
196
|
loggers('loadMoreRef', loadMoreRef.current);
|
|
195
197
|
if (canAsyncFetchOption &&
|
|
198
|
+
!isDropdownOptionsFetching &&
|
|
196
199
|
Array.isArray(value) &&
|
|
197
200
|
optionLoadedRef.current === true &&
|
|
198
201
|
loadMoreRef.current === false &&
|
|
@@ -215,11 +218,12 @@ const Dropdown = props => {
|
|
|
215
218
|
const options = cacheSelectOptions(typeof dataQuoteInit === 'function'
|
|
216
219
|
? dataQuoteInit(appendOptions, value, userData === null || userData === void 0 ? void 0 : userData.display)
|
|
217
220
|
: appendOptions);
|
|
218
|
-
|
|
221
|
+
const mergedOptions = mergeStoreOptions(options, storeOptions);
|
|
222
|
+
setOptions(mergedOptions);
|
|
219
223
|
setLoading(false);
|
|
220
224
|
const res = valueRef.current.filter(val => {
|
|
221
225
|
const value = typeof val === 'object' ? val.value : val;
|
|
222
|
-
const index =
|
|
226
|
+
const index = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.findIndex((o) => {
|
|
223
227
|
return o.value === value;
|
|
224
228
|
});
|
|
225
229
|
if (index !== -1 || value === 'NULL' || value === CURRENT_WORKSPACE) {
|
|
@@ -273,6 +277,8 @@ const Dropdown = props => {
|
|
|
273
277
|
cachedOptionsRef,
|
|
274
278
|
setLoading,
|
|
275
279
|
setOptions,
|
|
280
|
+
storeOptions,
|
|
281
|
+
isDropdownOptionsFetching,
|
|
276
282
|
]);
|
|
277
283
|
useEffect(() => {
|
|
278
284
|
onOptionsChange && onOptionsChange(options);
|
package/dist/index.d.ts
CHANGED
|
@@ -48,4 +48,4 @@ export { TableCell } from './components/table-components';
|
|
|
48
48
|
export { getAllReadComponents, getStandardEditComponents, getStandardReadComponents, } from './components/table-components/utils';
|
|
49
49
|
export { LibraryProvider } from './lib/contexts';
|
|
50
50
|
export { useDataQuoteStore } from './lib/hooks/useDataQuoteStore';
|
|
51
|
-
export { useFetchDropdownOptionsStore } from './lib/hooks/useFetchDropdownOptionsStore';
|
|
51
|
+
export { useDropdownOptionsFetching, useFetchDropdownOptionsStore } from './lib/hooks/useFetchDropdownOptionsStore';
|
package/dist/index.js
CHANGED
|
@@ -48,4 +48,4 @@ export { TableCell } from './components/table-components/index.js';
|
|
|
48
48
|
export { getAllReadComponents, getStandardEditComponents, getStandardReadComponents } from './components/table-components/utils.js';
|
|
49
49
|
export { LibraryProvider } from './lib/contexts/index.js';
|
|
50
50
|
export { useDataQuoteStore } from './lib/hooks/useDataQuoteStore.js';
|
|
51
|
-
export { useFetchDropdownOptionsStore } from './lib/hooks/useFetchDropdownOptionsStore.js';
|
|
51
|
+
export { useDropdownOptionsFetching, useFetchDropdownOptionsStore } from './lib/hooks/useFetchDropdownOptionsStore.js';
|
|
@@ -8,5 +8,6 @@ interface DataSourceItem {
|
|
|
8
8
|
values?: Record<string, any>;
|
|
9
9
|
[key: string]: any;
|
|
10
10
|
}
|
|
11
|
+
export declare const useDropdownOptionsFetching: () => boolean;
|
|
11
12
|
export declare const useFetchDropdownOptionsStore: (dataSource?: DataSourceItem[], customFields?: CustomField[], workspaceId?: string) => void;
|
|
12
13
|
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useRef, useMemo, useEffect } from 'react';
|
|
2
|
-
import { useSetAtom } from 'jotai';
|
|
1
|
+
import { useRef, useCallback, useMemo, useEffect } from 'react';
|
|
2
|
+
import { useAtomValue, useSetAtom } from 'jotai';
|
|
3
3
|
import useFetch from '../fetch.js';
|
|
4
4
|
import { FIELD_TYPE_KEY_MAPPINGS } from '../global.js';
|
|
5
|
-
import { dropDownOptionsState, createDropDownOptionsStoreKey } from '../store/dropDownOptionsStore.js';
|
|
5
|
+
import { dropDownOptionsFetchingState, dropDownOptionsState, createDropDownOptionsStoreKey } from '../store/dropDownOptionsStore.js';
|
|
6
6
|
|
|
7
7
|
const mergeDropDownOptions = (currentOptions, newOptions) => {
|
|
8
8
|
const seen = new Map();
|
|
@@ -20,12 +20,21 @@ const mergeDropDownOptions = (currentOptions, newOptions) => {
|
|
|
20
20
|
const getRequestCacheKey = (storeKey, workspaceId) => {
|
|
21
21
|
return `${workspaceId || 'default'}:${storeKey}`;
|
|
22
22
|
};
|
|
23
|
+
const useDropdownOptionsFetching = () => {
|
|
24
|
+
return useAtomValue(dropDownOptionsFetchingState);
|
|
25
|
+
};
|
|
23
26
|
const useFetchDropdownOptionsStore = (dataSource, customFields, workspaceId) => {
|
|
24
27
|
const fetch = useFetch();
|
|
25
28
|
const setDropDownOptionsMap = useSetAtom(dropDownOptionsState);
|
|
29
|
+
const setFetching = useSetAtom(dropDownOptionsFetchingState);
|
|
30
|
+
const activeRequestCountRef = useRef(0);
|
|
26
31
|
const fetchedValuesRef = useRef({});
|
|
27
32
|
const pendingRequestRef = useRef({});
|
|
28
33
|
const prevWorkspaceIdRef = useRef(workspaceId);
|
|
34
|
+
const updateFetchingState = useCallback((delta) => {
|
|
35
|
+
activeRequestCountRef.current += delta;
|
|
36
|
+
setFetching(activeRequestCountRef.current > 0);
|
|
37
|
+
}, [setFetching]);
|
|
29
38
|
const dropdownFields = useMemo(() => {
|
|
30
39
|
if (!(customFields === null || customFields === void 0 ? void 0 : customFields.length))
|
|
31
40
|
return [];
|
|
@@ -39,7 +48,6 @@ const useFetchDropdownOptionsStore = (dataSource, customFields, workspaceId) =>
|
|
|
39
48
|
}
|
|
40
49
|
if (!dropdownFields.length || !(dataSource === null || dataSource === void 0 ? void 0 : dataSource.length))
|
|
41
50
|
return;
|
|
42
|
-
let cancelled = false;
|
|
43
51
|
const fetchFieldOptions = async (field) => {
|
|
44
52
|
var _a;
|
|
45
53
|
const storeKey = createDropDownOptionsStoreKey(field.objectId);
|
|
@@ -68,13 +76,12 @@ const useFetchDropdownOptionsStore = (dataSource, customFields, workspaceId) =>
|
|
|
68
76
|
return;
|
|
69
77
|
}
|
|
70
78
|
pendingRequestRef.current[requestCacheKey] = requestSignature;
|
|
79
|
+
updateFetchingState(1);
|
|
71
80
|
try {
|
|
72
81
|
const { data } = await fetch.get(`/dropdown/data/${field.objectId}`, {
|
|
73
82
|
params: { propsValue: JSON.stringify(missingValues), workspaceId },
|
|
74
83
|
});
|
|
75
84
|
const options = (data === null || data === void 0 ? void 0 : data.data) || [];
|
|
76
|
-
if (cancelled)
|
|
77
|
-
return;
|
|
78
85
|
missingValues.forEach(v => fetchedValues.add(v));
|
|
79
86
|
if (!options.length)
|
|
80
87
|
return;
|
|
@@ -94,16 +101,14 @@ const useFetchDropdownOptionsStore = (dataSource, customFields, workspaceId) =>
|
|
|
94
101
|
console.error('fetchDropdownData_error', e);
|
|
95
102
|
}
|
|
96
103
|
finally {
|
|
104
|
+
updateFetchingState(-1);
|
|
97
105
|
if (pendingRequestRef.current[requestCacheKey] === requestSignature) {
|
|
98
106
|
delete pendingRequestRef.current[requestCacheKey];
|
|
99
107
|
}
|
|
100
108
|
}
|
|
101
109
|
};
|
|
102
110
|
Promise.allSettled(dropdownFields.map(field => fetchFieldOptions(field)));
|
|
103
|
-
|
|
104
|
-
cancelled = true;
|
|
105
|
-
};
|
|
106
|
-
}, [dropdownFields, dataSource, fetch, setDropDownOptionsMap, workspaceId]);
|
|
111
|
+
}, [dropdownFields, dataSource, fetch, setDropDownOptionsMap, workspaceId, updateFetchingState]);
|
|
107
112
|
};
|
|
108
113
|
|
|
109
|
-
export { useFetchDropdownOptionsStore };
|
|
114
|
+
export { useDropdownOptionsFetching, useFetchDropdownOptionsStore };
|
|
@@ -15,4 +15,7 @@ export interface DropDownOptionItem {
|
|
|
15
15
|
export declare const dropDownOptionsState: import("jotai").PrimitiveAtom<Record<string, DropDownOptionItem[]>> & {
|
|
16
16
|
init: Record<string, DropDownOptionItem[]>;
|
|
17
17
|
};
|
|
18
|
+
export declare const dropDownOptionsFetchingState: import("jotai").PrimitiveAtom<boolean> & {
|
|
19
|
+
init: boolean;
|
|
20
|
+
};
|
|
18
21
|
export declare const createDropDownOptionsStoreKey: (fieldId?: string) => string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { atom } from 'jotai';
|
|
2
2
|
|
|
3
3
|
const dropDownOptionsState = atom({});
|
|
4
|
+
const dropDownOptionsFetchingState = atom(false);
|
|
4
5
|
const createDropDownOptionsStoreKey = (fieldId) => {
|
|
5
6
|
return fieldId || '';
|
|
6
7
|
};
|
|
7
8
|
|
|
8
|
-
export { createDropDownOptionsStoreKey, dropDownOptionsState };
|
|
9
|
+
export { createDropDownOptionsStoreKey, dropDownOptionsFetchingState, dropDownOptionsState };
|