@giteeteam/apps-team-components 1.11.16 → 1.11.18-alpha.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/dist/components/common/user-field/UserAvatar.d.ts +1 -0
- package/dist/components/common/user-field/UserAvatar.js +26 -3
- 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/dist/lib/useUser.d.ts +1 -0
- package/dist/lib/useUser.js +2 -1
- package/package.json +1 -1
|
@@ -1,15 +1,38 @@
|
|
|
1
1
|
import { jsx } from '@emotion/react/jsx-runtime';
|
|
2
|
-
import React__default, { useMemo } from 'react';
|
|
2
|
+
import React__default, { useState, useMemo, useEffect } from 'react';
|
|
3
3
|
import { ClassNames } from '@emotion/react';
|
|
4
|
+
import useCurrentWorkspace from '../../../lib/hooks/useCurrentWorkspace.js';
|
|
4
5
|
import { getNameBadge, getBackgroundColor } from '../utils.js';
|
|
5
6
|
import { avatarItemStyle, avatarStyle, defaultAvatarStyle } from './style/index.js';
|
|
6
7
|
|
|
8
|
+
const imgInAvatarStyle = `
|
|
9
|
+
display: block;
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: 100%;
|
|
12
|
+
object-fit: contain;
|
|
13
|
+
border-radius: 50%;
|
|
14
|
+
`;
|
|
7
15
|
const UserAvatar = React__default.memo(({ user, className }) => {
|
|
8
|
-
const
|
|
16
|
+
const { workspaceKey } = useCurrentWorkspace();
|
|
17
|
+
const [imageLoadFailed, setImageLoadFailed] = useState(false);
|
|
18
|
+
const avatarUrl = useMemo(() => {
|
|
19
|
+
var _a, _b, _c, _d;
|
|
20
|
+
const url = (_a = user === null || user === void 0 ? void 0 : user.avatar) === null || _a === void 0 ? void 0 : _a.url;
|
|
21
|
+
if (url)
|
|
22
|
+
return url;
|
|
23
|
+
const bosKey = (_d = (_c = (_b = user === null || user === void 0 ? void 0 : user.bosKey) === null || _b === void 0 ? void 0 : _b.trim) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : user === null || user === void 0 ? void 0 : user.bosKey;
|
|
24
|
+
if (!workspaceKey || !bosKey)
|
|
25
|
+
return undefined;
|
|
26
|
+
return `/api/one/${workspaceKey}/rest/v1/companies/${workspaceKey}/users/logo/picture?url=${encodeURIComponent(bosKey)}`;
|
|
27
|
+
}, [user, workspaceKey]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
setImageLoadFailed(false);
|
|
30
|
+
}, [avatarUrl]);
|
|
9
31
|
const displayName = useMemo(() => (user === null || user === void 0 ? void 0 : user.name) || (user === null || user === void 0 ? void 0 : user.nickname) || (user === null || user === void 0 ? void 0 : user.username), [user]);
|
|
10
32
|
const userBadge = useMemo(() => getNameBadge(displayName), [displayName]);
|
|
33
|
+
const showImage = Boolean(avatarUrl) && !imageLoadFailed;
|
|
11
34
|
return (jsx(ClassNames, { children: ({ cx, css }) => {
|
|
12
|
-
return
|
|
35
|
+
return showImage ? (jsx("span", { className: cx('avatar-item', css(avatarItemStyle), css(avatarStyle), css(className)), style: { overflow: 'hidden' }, children: jsx("img", { src: avatarUrl, alt: "", decoding: "async", className: cx(css(imgInAvatarStyle)), onError: () => setImageLoadFailed(true) }) })) : (jsx("span", { className: cx('avatar-item', css(avatarItemStyle), css(defaultAvatarStyle), css(className)), style: getBackgroundColor(userBadge), children: userBadge }));
|
|
13
36
|
} }));
|
|
14
37
|
});
|
|
15
38
|
UserAvatar.displayName = 'UserAvatar';
|
|
@@ -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 };
|
package/dist/lib/useUser.d.ts
CHANGED
package/dist/lib/useUser.js
CHANGED
|
@@ -22,7 +22,7 @@ const generateUserDisplayName = (user, onlyNickname = false) => {
|
|
|
22
22
|
return (user === null || user === void 0 ? void 0 : user.nickname) ? `${user === null || user === void 0 ? void 0 : user.nickname}${displaySuffix}` : user === null || user === void 0 ? void 0 : user.username;
|
|
23
23
|
};
|
|
24
24
|
const userDataFormat = (user) => {
|
|
25
|
-
var _a;
|
|
25
|
+
var _a, _b;
|
|
26
26
|
return ({
|
|
27
27
|
label: generateUserDisplayName(user),
|
|
28
28
|
value: (_a = user.objectId) !== null && _a !== void 0 ? _a : user.value,
|
|
@@ -31,6 +31,7 @@ const userDataFormat = (user) => {
|
|
|
31
31
|
deleted: user.deleted,
|
|
32
32
|
enabled: user.enabled,
|
|
33
33
|
email: user.email,
|
|
34
|
+
bosKey: (_b = user.bosKey) !== null && _b !== void 0 ? _b : null,
|
|
34
35
|
});
|
|
35
36
|
};
|
|
36
37
|
|