@giteeteam/apps-team-components 1.11.16-alpha.2 → 1.11.16

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.
@@ -5,7 +5,6 @@ interface UserAvatarProps {
5
5
  avatar?: {
6
6
  url?: string;
7
7
  };
8
- bosKey?: string;
9
8
  username?: string;
10
9
  name?: string;
11
10
  nickname?: string;
@@ -1,22 +1,11 @@
1
1
  import { jsx } from '@emotion/react/jsx-runtime';
2
2
  import React__default, { useMemo } from 'react';
3
3
  import { ClassNames } from '@emotion/react';
4
- import useCurrentWorkspace from '../../../lib/hooks/useCurrentWorkspace.js';
5
4
  import { getNameBadge, getBackgroundColor } from '../utils.js';
6
5
  import { avatarItemStyle, avatarStyle, defaultAvatarStyle } from './style/index.js';
7
6
 
8
7
  const UserAvatar = React__default.memo(({ user, className }) => {
9
- const { workspaceKey } = useCurrentWorkspace();
10
- const avatarUrl = useMemo(() => {
11
- var _a, _b, _c, _d;
12
- const url = (_a = user === null || user === void 0 ? void 0 : user.avatar) === null || _a === void 0 ? void 0 : _a.url;
13
- if (url)
14
- return url;
15
- 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;
16
- if (!workspaceKey || !bosKey)
17
- return undefined;
18
- return `/api/one/${workspaceKey}/rest/v1/companies/${workspaceKey}/users/logo/picture?url=${encodeURIComponent(bosKey)}`;
19
- }, [user, workspaceKey]);
8
+ const avatarUrl = useMemo(() => { var _a; return (_a = user === null || user === void 0 ? void 0 : user.avatar) === null || _a === void 0 ? void 0 : _a.url; }, [user]);
20
9
  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]);
21
10
  const userBadge = useMemo(() => getNameBadge(displayName), [displayName]);
22
11
  return (jsx(ClassNames, { children: ({ cx, css }) => {
@@ -1,10 +1,11 @@
1
1
  import { jsx, jsxs, Fragment } from '@emotion/react/jsx-runtime';
2
- import { useMemo, useState, useRef, useEffect, useCallback } from 'react';
2
+ import React__default, { useMemo, useState, useRef, useEffect, useCallback } from 'react';
3
3
  import { Overlay } from 'react-overlays';
4
4
  import { DownOutlined } from '@ant-design/icons';
5
5
  import { ClassNames } from '@emotion/react';
6
6
  import { Checkbox, Divider, Spin, Select, Col } from 'antd';
7
7
  import debug from 'debug';
8
+ import { useAtomValue } from 'jotai';
8
9
  import { isNil, isObject, noop, isPlainObject, xorWith } from 'lodash-es';
9
10
  import { emptyIconWrapper } from '../../../style/global.js';
10
11
  import useSWR from 'swr';
@@ -21,12 +22,21 @@ import { REMOTE_DATA_QUOTE_FIELD_TYPE } from '../../../lib/constants/field.js';
21
22
  import { BASE_FIELD_WIDTH, FIELD_CONTAINERS_PAGE, CURRENT_WORKSPACE, FIELD_TYPE_KEY_MAPPINGS } from '../../../lib/global.js';
22
23
  import useAntdConfig from '../../../lib/hooks/useAntdConfig.js';
23
24
  import useI18n from '../../../lib/hooks/useI18n.js';
25
+ import { dropDownOptionsState, createDropDownOptionsStoreKey } from '../../../lib/store/dropDownOptionsStore.js';
24
26
  import { API_KEY } from '../../../lib/swr/constants.js';
25
27
  import useViewClass from '../hooks/useViewClass.js';
26
28
  import { EMPTY_OPTIONS, useCommonProps } from './hook.js';
27
29
  import { dropdownSelectDisabled, onlyWorkspaceStyle, onlyWorkspaceDividerStyle, dropdownSelectStyle, optionDisplayWrapClass, dropdownSelectOptionClass, disabledClass, workspaceClass, dropdownStyle, hiddenHoverClass, displayWrapClass, cellWrapperStyle, valueOptionContentClass, valueOptionClass, valueOptionIconClass, valueOptionLabelClass, hoverIconClass } from './style.js';
28
30
 
29
31
  const loggers = debug('dropdown:BaseField');
32
+ const mergeStoreOptions = (baseOptions, storeOptions) => {
33
+ if (!(storeOptions === null || storeOptions === void 0 ? void 0 : storeOptions.length))
34
+ return baseOptions || [];
35
+ const base = baseOptions || [];
36
+ const existingValues = new Set(base.map(o => o.value));
37
+ const additional = storeOptions.filter(o => !existingValues.has(o.value));
38
+ return additional.length ? [...base, ...additional] : base;
39
+ };
30
40
  const isNilFilter = function (value) {
31
41
  var _a;
32
42
  return (_a = value === null || value === void 0 ? void 0 : value.filter) === null || _a === void 0 ? void 0 : _a.call(value, val => !isNil(val));
@@ -83,6 +93,8 @@ const Dropdown = props => {
83
93
  ? propsValue
84
94
  : options;
85
95
  }, [dataQuoteInit, options, propsValue, userData === null || userData === void 0 ? void 0 : userData.display, value]);
96
+ const dropDownOptionsMap = useAtomValue(dropDownOptionsState);
97
+ const storeOptions = dropDownOptionsMap[createDropDownOptionsStoreKey(objectId)];
86
98
  const _options = useMemo(() => ((options === null || options === void 0 ? void 0 : options.length) > 0 ? options : finallyOptions) || [], [finallyOptions, options]);
87
99
  async function fetcher() {
88
100
  return await fetchOptions('');
@@ -283,7 +295,8 @@ const Dropdown = props => {
283
295
  const showValue = useCallback(({ cx, css }) => {
284
296
  var _a, _b, _c, _d;
285
297
  let showValue = null;
286
- const _options = isCascaded ? _propsOptions : noClickEditing ? finallyOptions : options;
298
+ const _baseOptions = isCascaded ? _propsOptions : noClickEditing ? finallyOptions : options;
299
+ const _options = mergeStoreOptions(_baseOptions, storeOptions);
287
300
  const _optionsMap = {};
288
301
  if (Array.isArray(_options)) {
289
302
  _options.forEach(item => {
@@ -300,7 +313,7 @@ const Dropdown = props => {
300
313
  return null;
301
314
  showValue = valueArr.map((item, index) => {
302
315
  const content = _optionsMap[item] ? getFormattedLabel(_optionsMap[item]) : item;
303
- return index === value.length - 1 ? content : jsxs(Fragment, { children: [content, ","] });
316
+ return (jsxs(React__default.Fragment, { children: [content, index === value.length - 1 ? '' : ','] }, `${String(item)}-${index}`));
304
317
  });
305
318
  }
306
319
  }
@@ -316,7 +329,7 @@ const Dropdown = props => {
316
329
  }
317
330
  }
318
331
  return showValue;
319
- }, [isCascaded, _propsOptions, noClickEditing, finallyOptions, options, isMultiple, value, screenMode]);
332
+ }, [isCascaded, _propsOptions, noClickEditing, finallyOptions, options, isMultiple, value, screenMode, storeOptions]);
320
333
  const valueOptions = useMemo(() => {
321
334
  if ((Array.isArray(options) && (options === null || options === void 0 ? void 0 : options.length) >= 1 && value && Array.isArray(value)) ||
322
335
  (noClickEditing && Array.isArray(_options) && _options.length > 0)) {
@@ -565,10 +578,11 @@ const Dropdown = props => {
565
578
  selectValue,
566
579
  t,
567
580
  ]);
581
+ const mergedValueOptions = useMemo(() => mergeStoreOptions(valueOptions, storeOptions), [valueOptions, storeOptions]);
568
582
  return (jsx(ClassNames, { children: ({ cx, css }) => {
569
583
  const cxShowValue = showValue({ cx, css });
570
584
  return (jsx(Col, { style: style, ref: containerRef, className: cx(css(dropdownStyle(antPrefix)), 'field-value', viewClassNames, { [hiddenHoverClass]: hiddenHover }, { [displayWrapClass]: valueDisplayWrap }, { [css(dropdownSelectStyle(antPrefix))]: disabledLineThrough || displayValueHidden }), onClick: handleClick, children: jsxs("div", { css: css(cellWrapperStyle), children: [(readonly || (!editMode && !editing)) &&
571
- (cxShowValue ? (!valueDisplayWrap ? (isView && isMultiple ? (jsx(Expand, { readonly: readonly, editing: editing, expandType: EXPAND_TYPE_ENUM.TAG, children: valueOptions.map(item => (jsx("span", { className: "field-common-view-tag", children: jsx(BaseOverflowTooltip, { title: item.label, children: item.label }) }, item.value))) })) : (jsx(OverflowTooltip, { title: cxShowValue, children: cxShowValue }))) : (jsx("div", { className: cx(valueOptionContentClass), children: valueOptions.map(ele => {
585
+ (cxShowValue ? (!valueDisplayWrap ? (isView && isMultiple ? (jsx(Expand, { readonly: readonly, editing: editing, expandType: EXPAND_TYPE_ENUM.TAG, children: mergedValueOptions.map(item => (jsx("span", { className: "field-common-view-tag", children: jsx(BaseOverflowTooltip, { title: item.label, children: item.label }) }, item.value))) })) : (jsx(OverflowTooltip, { title: cxShowValue, children: cxShowValue }))) : (jsx("div", { className: cx(valueOptionContentClass), children: mergedValueOptions.map(ele => {
572
586
  return (jsxs("div", { className: cx(valueOptionClass), title: ele.label, children: [jsx(ItemIcon, { className: cx(valueOptionIconClass), icon: ele.icon }), jsx("span", { className: cx(valueOptionLabelClass), children: ele.label })] }, ele.value));
573
587
  }) }))) : (jsx(EmptyField, { readonly: readonly }))), !readonly && (editMode || editing) && containerRef && (jsx(Overlay, { show: true, rootClose: true, container: containerRef, target: containerRef, onHide: noop, children: () => overlayRender })), jsx(DownOutlined, { className: cx(hoverIconClass) })] }) }));
574
588
  } }));
package/dist/index.d.ts CHANGED
@@ -48,3 +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';
package/dist/index.js CHANGED
@@ -48,3 +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';
@@ -0,0 +1,12 @@
1
+ interface CustomField {
2
+ key: string;
3
+ name: string;
4
+ objectId: string;
5
+ fieldType: Record<string, any>;
6
+ }
7
+ interface DataSourceItem {
8
+ values?: Record<string, any>;
9
+ [key: string]: any;
10
+ }
11
+ export declare const useFetchDropdownOptionsStore: (dataSource?: DataSourceItem[], customFields?: CustomField[], workspaceId?: string) => void;
12
+ export {};
@@ -0,0 +1,109 @@
1
+ import { useRef, useMemo, useEffect } from 'react';
2
+ import { useSetAtom } from 'jotai';
3
+ import useFetch from '../fetch.js';
4
+ import { FIELD_TYPE_KEY_MAPPINGS } from '../global.js';
5
+ import { dropDownOptionsState, createDropDownOptionsStoreKey } from '../store/dropDownOptionsStore.js';
6
+
7
+ const mergeDropDownOptions = (currentOptions, newOptions) => {
8
+ const seen = new Map();
9
+ for (const option of currentOptions) {
10
+ if (option)
11
+ seen.set(option.value, option);
12
+ }
13
+ for (const option of newOptions) {
14
+ if (option && !seen.has(option.value)) {
15
+ seen.set(option.value, option);
16
+ }
17
+ }
18
+ return Array.from(seen.values());
19
+ };
20
+ const getRequestCacheKey = (storeKey, workspaceId) => {
21
+ return `${workspaceId || 'default'}:${storeKey}`;
22
+ };
23
+ const useFetchDropdownOptionsStore = (dataSource, customFields, workspaceId) => {
24
+ const fetch = useFetch();
25
+ const setDropDownOptionsMap = useSetAtom(dropDownOptionsState);
26
+ const fetchedValuesRef = useRef({});
27
+ const pendingRequestRef = useRef({});
28
+ const prevWorkspaceIdRef = useRef(workspaceId);
29
+ const dropdownFields = useMemo(() => {
30
+ if (!(customFields === null || customFields === void 0 ? void 0 : customFields.length))
31
+ return [];
32
+ return customFields.filter(field => { var _a; return ((_a = field.fieldType) === null || _a === void 0 ? void 0 : _a.key) === FIELD_TYPE_KEY_MAPPINGS.Dropdown; });
33
+ }, [customFields]);
34
+ useEffect(() => {
35
+ if (prevWorkspaceIdRef.current !== workspaceId) {
36
+ fetchedValuesRef.current = {};
37
+ pendingRequestRef.current = {};
38
+ prevWorkspaceIdRef.current = workspaceId;
39
+ }
40
+ if (!dropdownFields.length || !(dataSource === null || dataSource === void 0 ? void 0 : dataSource.length))
41
+ return;
42
+ let cancelled = false;
43
+ const fetchFieldOptions = async (field) => {
44
+ var _a;
45
+ const storeKey = createDropDownOptionsStoreKey(field.objectId);
46
+ if (!storeKey)
47
+ return;
48
+ const requestCacheKey = getRequestCacheKey(storeKey, workspaceId);
49
+ const values = new Set();
50
+ for (const item of dataSource) {
51
+ const fieldValues = (_a = item.values) === null || _a === void 0 ? void 0 : _a[field.key];
52
+ if (Array.isArray(fieldValues)) {
53
+ fieldValues.forEach(v => {
54
+ if (v != null)
55
+ values.add(String(v));
56
+ });
57
+ }
58
+ }
59
+ if (!values.size)
60
+ return;
61
+ const fetchedValues = fetchedValuesRef.current[requestCacheKey] || new Set();
62
+ fetchedValuesRef.current[requestCacheKey] = fetchedValues;
63
+ const missingValues = Array.from(values).filter(v => !fetchedValues.has(v));
64
+ if (!missingValues.length)
65
+ return;
66
+ const requestSignature = JSON.stringify(missingValues.slice().sort());
67
+ if (pendingRequestRef.current[requestCacheKey] === requestSignature) {
68
+ return;
69
+ }
70
+ pendingRequestRef.current[requestCacheKey] = requestSignature;
71
+ try {
72
+ const { data } = await fetch.get(`/dropdown/data/${field.objectId}`, {
73
+ params: { propsValue: JSON.stringify(missingValues), workspaceId },
74
+ });
75
+ const options = (data === null || data === void 0 ? void 0 : data.data) || [];
76
+ if (cancelled)
77
+ return;
78
+ missingValues.forEach(v => fetchedValues.add(v));
79
+ if (!options.length)
80
+ return;
81
+ setDropDownOptionsMap(prev => {
82
+ const currentOptions = prev[storeKey] || [];
83
+ const mergedOptions = mergeDropDownOptions(currentOptions, options);
84
+ if (mergedOptions.length === currentOptions.length) {
85
+ return prev;
86
+ }
87
+ return {
88
+ ...prev,
89
+ [storeKey]: mergedOptions,
90
+ };
91
+ });
92
+ }
93
+ catch (e) {
94
+ console.error('fetchDropdownData_error', e);
95
+ }
96
+ finally {
97
+ if (pendingRequestRef.current[requestCacheKey] === requestSignature) {
98
+ delete pendingRequestRef.current[requestCacheKey];
99
+ }
100
+ }
101
+ };
102
+ Promise.allSettled(dropdownFields.map(field => fetchFieldOptions(field)));
103
+ return () => {
104
+ cancelled = true;
105
+ };
106
+ }, [dropdownFields, dataSource, fetch, setDropDownOptionsMap, workspaceId]);
107
+ };
108
+
109
+ export { useFetchDropdownOptionsStore };
@@ -0,0 +1,18 @@
1
+ export interface DropDownOptionItem {
2
+ label: React.ReactNode;
3
+ value: string | number;
4
+ disabled?: boolean;
5
+ enable?: boolean;
6
+ icon?: string;
7
+ archived?: boolean;
8
+ name?: string;
9
+ key?: string;
10
+ itemType?: any;
11
+ values?: {
12
+ [propName: string]: any;
13
+ };
14
+ }
15
+ export declare const dropDownOptionsState: import("jotai").PrimitiveAtom<Record<string, DropDownOptionItem[]>> & {
16
+ init: Record<string, DropDownOptionItem[]>;
17
+ };
18
+ export declare const createDropDownOptionsStoreKey: (fieldId?: string) => string;
@@ -0,0 +1,8 @@
1
+ import { atom } from 'jotai';
2
+
3
+ const dropDownOptionsState = atom({});
4
+ const createDropDownOptionsStoreKey = (fieldId) => {
5
+ return fieldId || '';
6
+ };
7
+
8
+ export { createDropDownOptionsStoreKey, dropDownOptionsState };
@@ -13,6 +13,5 @@ export type UserValueOption = {
13
13
  deleted: boolean;
14
14
  enabled: boolean;
15
15
  email?: string;
16
- bosKey?: string | null;
17
16
  };
18
17
  export declare const userDataFormat: (user: UserValue) => UserValueOption;
@@ -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, _b;
25
+ var _a;
26
26
  return ({
27
27
  label: generateUserDisplayName(user),
28
28
  value: (_a = user.objectId) !== null && _a !== void 0 ? _a : user.value,
@@ -31,7 +31,6 @@ 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,
35
34
  });
36
35
  };
37
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giteeteam/apps-team-components",
3
- "version": "1.11.16-alpha.2",
3
+ "version": "1.11.16",
4
4
  "description": "Gitee team components",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",