@giteeteam/apps-team-components 1.2.2 → 1.3.0-alpha.2
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/README.md +21 -28
- package/dist/components/common/EmptyField.d.ts +0 -1
- package/dist/components/common/EmptyField.js +7 -5
- package/dist/components/common/PriceTag.js +26 -23
- package/dist/components/common/expand-component/index.d.ts +22 -0
- package/dist/components/common/expand-component/index.js +67 -0
- package/dist/components/common/expand-component/style.d.ts +2 -0
- package/dist/components/common/expand-component/style.js +10 -0
- package/dist/components/common/item-icon/ItemIcon.d.ts +7 -0
- package/dist/components/common/item-icon/ItemIcon.js +8 -0
- package/dist/components/common/overflow-tooltip/BaseOverflowTooltip.d.ts +0 -1
- package/dist/components/common/overflow-tooltip/BaseOverflowTooltip.js +9 -6
- package/dist/components/common/overflow-tooltip/OverflowTooltip.d.ts +19 -0
- package/dist/components/common/overflow-tooltip/OverflowTooltip.js +57 -0
- package/dist/components/common/overflow-tooltip/SimpleOverflowToolTip.js +8 -5
- package/dist/components/common/overflow-tooltip/style/index.js +16 -14
- package/dist/components/common/style/global.js +4 -2
- package/dist/components/common/style/mixin.d.ts +2 -0
- package/dist/components/common/style/mixin.js +20 -0
- package/dist/components/common/user-field/UserAvatar.js +8 -6
- package/dist/components/common/user-field/style/index.js +23 -21
- package/dist/components/common/utils.d.ts +6 -0
- package/dist/components/common/utils.js +63 -5
- package/dist/components/default-empty-icon/config.d.ts +2 -0
- package/dist/components/default-empty-icon/config.js +24 -0
- package/dist/components/default-empty-icon/index.d.ts +5 -0
- package/dist/components/default-empty-icon/index.js +24 -0
- package/dist/components/default-empty-icon/style.d.ts +11 -0
- package/dist/components/default-empty-icon/style.js +67 -0
- package/dist/components/default-empty-icon/types.d.ts +29 -0
- package/dist/components/default-empty-icon/types.js +8 -0
- package/dist/components/field-behavior/fields/type.js +5 -2
- package/dist/components/fields/actors/BaseField.js +5 -2
- package/dist/components/fields/actors/ReadView.d.ts +0 -1
- package/dist/components/fields/actors/ReadView.js +8 -6
- package/dist/components/fields/ancestor/ReadView.js +8 -6
- package/dist/components/fields/ancestor/utils.js +4 -12
- package/dist/components/fields/assignee/ReadView.d.ts +0 -1
- package/dist/components/fields/assignee/ReadView.js +13 -11
- package/dist/components/fields/base-component/types.d.ts +1 -0
- package/dist/components/fields/base-component/utils.d.ts +2 -0
- package/dist/components/fields/base-component/utils.js +11 -0
- package/dist/components/fields/bind-workspace/ReadView.d.ts +0 -1
- package/dist/components/fields/bind-workspace/ReadView.js +11 -9
- package/dist/components/fields/bind-workspace/hooks.js +10 -7
- package/dist/components/fields/bind-workspace/style/index.js +5 -3
- package/dist/components/fields/cascade/ReadView.js +8 -6
- package/dist/components/fields/cascade/utils.js +4 -3
- package/dist/components/fields/checkbox/ReadView.d.ts +0 -1
- package/dist/components/fields/checkbox/ReadView.js +7 -5
- package/dist/components/fields/created-at/ReadView.js +10 -8
- package/dist/components/fields/created-by/ReadView.d.ts +0 -1
- package/dist/components/fields/created-by/ReadView.js +11 -9
- package/dist/components/fields/data-quote/ReadView.js +12 -10
- package/dist/components/fields/data-quote/utils.js +5 -3
- package/dist/components/fields/date/ReadView.d.ts +0 -1
- package/dist/components/fields/date/ReadView.js +8 -6
- package/dist/components/fields/dropdown/BaseField.d.ts +24 -2
- package/dist/components/fields/dropdown/BaseField.js +565 -2
- package/dist/components/fields/dropdown/Cell.d.ts +3 -0
- package/dist/components/fields/dropdown/Cell.js +8 -0
- package/dist/components/fields/dropdown/ReadView.d.ts +0 -1
- package/dist/components/fields/dropdown/ReadView.js +10 -8
- package/dist/components/fields/dropdown/data.d.ts +9 -0
- package/dist/components/fields/dropdown/data.js +29 -0
- package/dist/components/fields/dropdown/hook.d.ts +102 -0
- package/dist/components/fields/dropdown/hook.js +155 -0
- package/dist/components/fields/dropdown/style.d.ts +16 -0
- package/dist/components/fields/dropdown/style.js +93 -0
- package/dist/components/fields/file/ReadView.d.ts +0 -1
- package/dist/components/fields/file/ReadView.js +7 -5
- package/dist/components/fields/formula/ReadView.d.ts +0 -1
- package/dist/components/fields/formula/ReadView.js +7 -5
- package/dist/components/fields/hooks/useViewClass.d.ts +11 -0
- package/dist/components/fields/hooks/useViewClass.js +20 -0
- package/dist/components/fields/hyper-link/ReadView.d.ts +0 -1
- package/dist/components/fields/hyper-link/ReadView.js +8 -6
- package/dist/components/fields/hyper-link/style/index.js +18 -15
- package/dist/components/fields/item-group/ReadView.d.ts +0 -1
- package/dist/components/fields/item-group/ReadView.js +6 -4
- package/dist/components/fields/item-type/ItemTypeIcon.d.ts +9 -0
- package/dist/components/fields/item-type/ItemTypeIcon.js +31 -0
- package/dist/components/fields/item-type/ReadView.d.ts +0 -1
- package/dist/components/fields/item-type/ReadView.js +7 -5
- package/dist/components/fields/item-type/style/index.d.ts +1 -0
- package/dist/components/fields/item-type/style/index.js +8 -0
- package/dist/components/fields/key/ReadView.d.ts +0 -1
- package/dist/components/fields/key/ReadView.js +7 -5
- package/dist/components/fields/long-text/ReadView.d.ts +0 -1
- package/dist/components/fields/long-text/ReadView.js +8 -6
- package/dist/components/fields/long-text/style/index.js +7 -5
- package/dist/components/fields/number/BaseField.js +5 -2
- package/dist/components/fields/number/ReadView.d.ts +0 -1
- package/dist/components/fields/number/ReadView.js +8 -6
- package/dist/components/fields/priority/ReadView.js +12 -10
- package/dist/components/fields/priority/style/index.js +54 -51
- package/dist/components/fields/radio/ReadView.d.ts +0 -1
- package/dist/components/fields/radio/ReadView.js +8 -6
- package/dist/components/fields/repo-files/ReadView.js +8 -6
- package/dist/components/fields/repo-files/utils.js +5 -3
- package/dist/components/fields/reporter/ReadView.d.ts +0 -1
- package/dist/components/fields/reporter/ReadView.js +11 -9
- package/dist/components/fields/script/BaseField.js +4 -1
- package/dist/components/fields/script/ReadView.d.ts +0 -1
- package/dist/components/fields/script/ReadView.js +10 -8
- package/dist/components/fields/sprint/ReadView.js +7 -5
- package/dist/components/fields/status/Cell.js +8 -6
- package/dist/components/fields/status/Field.d.ts +0 -1
- package/dist/components/fields/status/ReadView.js +10 -8
- package/dist/components/fields/status/SelectFlowHandler.js +15 -12
- package/dist/components/fields/status/SelectTransition.js +13 -10
- package/dist/components/fields/status/Transition.js +18 -15
- package/dist/components/fields/status/TransitionButton.js +17 -14
- package/dist/components/fields/status/TransitionPanel.js +14 -11
- package/dist/components/fields/status/View.js +11 -8
- package/dist/components/fields/status/style/index.js +302 -325
- package/dist/components/fields/story-point/ReadView.d.ts +0 -1
- package/dist/components/fields/story-point/ReadView.js +6 -4
- package/dist/components/fields/tag/ReadView.js +10 -8
- package/dist/components/fields/tag/style/index.js +7 -5
- package/dist/components/fields/team/ReadView.js +10 -8
- package/dist/components/fields/team/style/index.js +5 -3
- package/dist/components/fields/text/BaseField.d.ts +0 -1
- package/dist/components/fields/text/ReadView.js +8 -6
- package/dist/components/fields/tree/ReadView.js +10 -8
- package/dist/components/fields/tree/utils.js +5 -3
- package/dist/components/fields/updated-at/ReadView.js +10 -8
- package/dist/components/fields/updated-by/ReadView.d.ts +0 -1
- package/dist/components/fields/updated-by/ReadView.js +11 -9
- package/dist/components/fields/user/ReadView.d.ts +0 -1
- package/dist/components/fields/user/ReadView.js +11 -9
- package/dist/components/fields/user/style/index.js +12 -9
- package/dist/components/fields/user-group/BaseField.d.ts +0 -1
- package/dist/components/fields/user-group/ReadView.js +12 -14
- package/dist/components/fields/version/ReadView.js +8 -6
- package/dist/components/fields/workspace/ReadView.d.ts +0 -1
- package/dist/components/fields/workspace/ReadView.js +10 -8
- package/dist/components/filters/filter-search/utils.d.ts +4 -0
- package/dist/components/filters/filter-search/utils.js +28 -0
- package/dist/components/item/hooks.js +5 -2
- package/dist/components/table-components/EditTableCell.d.ts +1 -0
- package/dist/components/table-components/EditTableCell.js +8 -4
- package/dist/components/table-components/index.js +14 -11
- package/dist/components/table-components/style/index.js +7 -5
- package/dist/components/table-components/utils.js +50 -45
- package/dist/icons/SyncIconFont.d.ts +6 -0
- package/dist/icons/SyncIconFont.js +17 -0
- package/dist/icons/createFromIconFontClass.d.ts +4 -0
- package/dist/icons/createFromIconFontClass.js +35 -0
- package/dist/icons/empty-icon/data-empty.png +0 -0
- package/dist/icons/empty-icon/forbidden.png +0 -0
- package/dist/icons/empty-icon/index.d.ts +8 -0
- package/dist/icons/empty-icon/large-item@2x.png +0 -0
- package/dist/icons/empty-icon/large-item@2x.png.js +3 -0
- package/dist/icons/empty-icon/large-workspace@2x.png +0 -0
- package/dist/icons/empty-icon/large-workspace@2x.png.js +3 -0
- package/dist/icons/empty-icon/load-error.png +0 -0
- package/dist/icons/empty-icon/not-found.png +0 -0
- package/dist/icons/empty-icon/small-default@2x.png +0 -0
- package/dist/icons/empty-icon/small-default@2x.png.js +3 -0
- package/dist/icons/empty-icon/workspace-empty.svg +127 -0
- package/dist/icons/index.d.ts +58 -1
- package/dist/icons/index.js +315 -19
- package/dist/icons/style/index.d.ts +2 -0
- package/dist/icons/style/index.js +25 -0
- package/dist/icons/svg/ArrowBack.svg.js +3 -0
- package/dist/icons/svg/Done.svg.js +3 -0
- package/dist/icons/svg/DottedCircle.svg.js +3 -0
- package/dist/icons/svg/HollowCircle.svg.js +3 -0
- package/dist/icons/svg/Search.svg.js +3 -0
- package/dist/icons/svg/Workflow.svg.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +47 -46
- package/dist/lib/app/utils.d.ts +2 -0
- package/dist/lib/app/utils.js +18 -0
- package/dist/lib/array.js +5 -44
- package/dist/lib/config.d.ts +14 -0
- package/dist/lib/config.js +47 -0
- package/dist/lib/constants/code.d.ts +4 -0
- package/dist/lib/constants/code.js +6 -0
- package/dist/lib/constants/field.d.ts +1 -0
- package/dist/lib/constants/field.js +5 -0
- package/dist/lib/contexts/antdConfig.js +10 -7
- package/dist/lib/contexts/currentUser.js +7 -4
- package/dist/lib/contexts/currentWorkspace.js +7 -4
- package/dist/lib/contexts/datetimeFormat.js +7 -4
- package/dist/lib/contexts/index.js +16 -13
- package/dist/lib/contexts/itemConfig.js +7 -4
- package/dist/lib/contexts/teamConfig.d.ts +3 -0
- package/dist/lib/contexts/teamConfig.js +25 -7
- package/dist/lib/contexts/tenant.js +7 -4
- package/dist/lib/contexts/workflowConfig.js +7 -4
- package/dist/lib/dataType.js +4 -5
- package/dist/lib/date.js +11 -52
- package/dist/lib/dayjs.js +2 -1
- package/dist/lib/error/index.d.ts +2 -0
- package/dist/lib/error/log.d.ts +10 -0
- package/dist/lib/error/log.js +28 -0
- package/dist/lib/error/utils.d.ts +14 -0
- package/dist/lib/error/utils.js +38 -0
- package/dist/lib/error/withServerError.d.ts +1 -0
- package/dist/lib/error/withServerError.js +3 -0
- package/dist/lib/fetch.d.ts +45 -0
- package/dist/lib/fetch.js +270 -0
- package/dist/lib/global.d.ts +18 -0
- package/dist/lib/global.js +28 -8
- package/dist/lib/hooks/useAntdConfig.js +4 -2
- package/dist/lib/hooks/useCurrentUser.js +4 -2
- package/dist/lib/hooks/useCurrentWorkspace.js +4 -2
- package/dist/lib/hooks/useDataQuoteStore.js +8 -5
- package/dist/lib/hooks/useDateTimeFormatType.js +4 -2
- package/dist/lib/hooks/useI18n.d.ts +1 -1
- package/dist/lib/hooks/useI18n.js +4 -2
- package/dist/lib/hooks/useItemConfig.js +4 -2
- package/dist/lib/hooks/useTeamConfig.js +4 -2
- package/dist/lib/hooks/useTenant.js +4 -2
- package/dist/lib/hooks/useWorkflowConfig.js +4 -2
- package/dist/lib/i18n.d.ts +1 -0
- package/dist/lib/i18n.js +6 -2
- package/dist/lib/icons/utils.d.ts +23 -0
- package/dist/lib/icons/utils.js +60 -0
- package/dist/lib/isInOne.js +2 -1
- package/dist/lib/number.js +3 -1
- package/dist/lib/path.d.ts +5 -0
- package/dist/lib/path.js +50 -0
- package/dist/lib/regExp.js +3 -1
- package/dist/lib/router.d.ts +23 -0
- package/dist/lib/router.js +23 -0
- package/dist/lib/storage.d.ts +10 -0
- package/dist/lib/storage.js +27 -0
- package/dist/lib/store/dataQuoteStore.js +5 -2
- package/dist/lib/swr/constants.js +4 -2
- package/dist/lib/swr/hooks.js +6 -3
- package/dist/lib/swr/throttleWithCache.d.ts +17 -0
- package/dist/lib/swr/throttleWithCache.js +110 -0
- package/dist/lib/throttleFetch.d.ts +2 -0
- package/dist/lib/throttleFetch.js +68 -0
- package/dist/lib/useConfig.d.ts +8 -0
- package/dist/lib/useConfig.js +31 -0
- package/dist/lib/useUser.js +9 -6
- package/dist/lib/users.js +5 -2
- package/dist/lib/workflow.js +21 -20
- package/dist/locales/index.d.ts +45 -0
- package/dist/locales/index.js +50 -3
- package/dist/public/icons/BulbIcon.svg +1 -0
- package/dist/public/icons/Cloud.svg +1 -0
- package/dist/public/icons/ConsultIcon.svg +1 -0
- package/dist/public/icons/Demo.svg +1 -0
- package/dist/public/icons/ErrorTemplate.svg +1 -0
- package/dist/public/icons/Fail.svg +1 -0
- package/dist/public/icons/Flag.svg +1 -0
- package/dist/public/icons/GiteeIcon.svg +1 -0
- package/dist/public/icons/IntelligenceGradient.svg +1 -0
- package/dist/public/icons/Issue_Approval.svg +1 -0
- package/dist/public/icons/Issue_Bug.svg +1 -0
- package/dist/public/icons/Issue_Demand.svg +1 -0
- package/dist/public/icons/Issue_Doc.svg +1 -0
- package/dist/public/icons/Issue_Idea.svg +1 -0
- package/dist/public/icons/Issue_List.svg +1 -0
- package/dist/public/icons/Issue_Plan.svg +1 -0
- package/dist/public/icons/Issue_Product.svg +1 -0
- package/dist/public/icons/Issue_Risk.svg +1 -0
- package/dist/public/icons/Issue_Story.svg +1 -0
- package/dist/public/icons/Issue_Subtask.svg +1 -0
- package/dist/public/icons/Issue_Task.svg +1 -0
- package/dist/public/icons/Issue_Test.svg +1 -0
- package/dist/public/icons/Issue_TestExcution.svg +1 -0
- package/dist/public/icons/Issue_TestPlan.svg +1 -0
- package/dist/public/icons/Issue_Time.svg +1 -0
- package/dist/public/icons/Issue_develop.svg +1 -0
- package/dist/public/icons/KanbanCover.svg +7 -0
- package/dist/public/icons/ListCover.svg +118 -0
- package/dist/public/icons/ManHour.svg +1 -0
- package/dist/public/icons/MobileIcon.svg +1 -0
- package/dist/public/icons/NoItemType.svg +10 -0
- package/dist/public/icons/ProductIcon.svg +1 -0
- package/dist/public/icons/RedFlagIcon.svg +1 -0
- package/dist/public/icons/Safe.svg +1 -0
- package/dist/public/icons/StarIcon.svg +61 -0
- package/dist/public/icons/StructureCover.svg +1 -0
- package/dist/public/icons/Success.svg +1 -0
- package/dist/public/icons/TeamIcon.svg +1 -0
- package/dist/public/icons/WebIcon.svg +1 -0
- package/dist/public/icons/iconfont.svg +467 -0
- package/dist/public/icons/iconfont.ttf +0 -0
- package/dist/public/icons/iconfont.woff +0 -0
- package/dist/public/icons/iconfont.woff2 +0 -0
- package/dist/public/icons/iconfont_multiple_color.js +1 -0
- package/dist/public/icons/iconfont_single_color.css +912 -0
- package/dist/public/icons/iconfont_single_color.js +1 -0
- package/dist/public/icons/loginBg.svg +1 -0
- package/dist/public/mockServiceWorker.js +284 -0
- package/dist/style/common.d.ts +1 -0
- package/dist/style/common.js +19 -23
- package/dist/style/global.d.ts +1 -0
- package/dist/style/global.js +10 -0
- package/package.json +111 -69
- package/dist/components/fields/base-component/types.js +0 -1
- package/dist/components/fields/hooks/useParamsAdapter.js +0 -1
- package/dist/components/fields/radio/BaseField.js +0 -1
- package/dist/components/fields/status/Field.js +0 -1
- package/dist/components/fields/tag/BaseField.js +0 -1
- package/dist/components/fields/text/BaseField.js +0 -1
- package/dist/components/fields/tree/BaseField.js +0 -1
- package/dist/components/fields/tree/types.js +0 -1
- package/dist/components/fields/types.js +0 -1
- package/dist/components/fields/user-group/ActionCell.js +0 -1
- package/dist/components/fields/user-group/BaseField.js +0 -1
- package/dist/icons/svg/ArrowBack.svg +0 -1
- package/dist/icons/svg/Done.svg +0 -1
- package/dist/icons/svg/DottedCircle.svg +0 -7
- package/dist/icons/svg/HollowCircle.svg +0 -6
- package/dist/icons/svg/Search.svg +0 -1
- package/dist/icons/svg/Workflow.svg +0 -12
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { jsx
|
|
1
|
+
import { jsx, Fragment } from '@emotion/react/jsx-runtime';
|
|
2
2
|
import { memo, useMemo } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import EmptyField from '../../common/EmptyField';
|
|
5
|
-
import BaseOverflowTooltip from '../../common/overflow-tooltip/BaseOverflowTooltip';
|
|
3
|
+
import { getFormat, getDateType } from '../../../lib/date.js';
|
|
4
|
+
import EmptyField from '../../common/EmptyField.js';
|
|
5
|
+
import BaseOverflowTooltip from '../../common/overflow-tooltip/BaseOverflowTooltip.js';
|
|
6
|
+
|
|
6
7
|
const DateReadView = memo(props => {
|
|
7
8
|
const { readonly, value, pickerType, format } = props;
|
|
8
9
|
const showValue = useMemo(() => {
|
|
9
10
|
return getFormat(value, format || getDateType(pickerType));
|
|
10
11
|
}, [value, format, pickerType]);
|
|
11
|
-
return (
|
|
12
|
+
return (jsx(Fragment, { children: value ? (jsx(BaseOverflowTooltip, { title: showValue, maxline: 1, children: showValue })) : (jsx(EmptyField, { readonly: readonly })) }));
|
|
12
13
|
});
|
|
13
14
|
DateReadView.displayName = 'DateReadView';
|
|
14
|
-
|
|
15
|
+
|
|
16
|
+
export { DateReadView as default };
|
|
@@ -1,7 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ItemType, PointerObject } from 'lib/types/models';
|
|
3
|
+
import { BaseDropdownProps } from './hook';
|
|
2
4
|
export interface selectValue {
|
|
3
5
|
label: React.ReactNode;
|
|
4
6
|
value: string | number;
|
|
5
|
-
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
enable?: boolean;
|
|
9
|
+
icon?: string;
|
|
10
|
+
itemType?: PointerObject | ItemType;
|
|
11
|
+
archived?: boolean;
|
|
12
|
+
name?: string;
|
|
13
|
+
key?: string;
|
|
14
|
+
values?: {
|
|
15
|
+
[propName: string]: any;
|
|
16
|
+
};
|
|
6
17
|
}
|
|
18
|
+
export declare const isNilFilter: <T>(value: T[]) => T[];
|
|
7
19
|
export declare const handleValue: (value: selectValue | string | number) => string | number;
|
|
20
|
+
type GetFormattedLabelParams = {
|
|
21
|
+
label: string;
|
|
22
|
+
style?: {
|
|
23
|
+
color?: string;
|
|
24
|
+
background?: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export declare const getFormattedLabel: ({ label, style }?: GetFormattedLabelParams) => import("@emotion/react/types/jsx-namespace").EmotionJSX.Element;
|
|
28
|
+
declare const Dropdown: React.FC<BaseDropdownProps>;
|
|
29
|
+
export default Dropdown;
|
|
@@ -1,4 +1,567 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { jsxs, Fragment, jsx } from '@emotion/react/jsx-runtime';
|
|
2
|
+
import { useMemo, useState, useRef, useEffect, useCallback } from 'react';
|
|
3
|
+
import { Overlay } from 'react-overlays';
|
|
4
|
+
import { DownOutlined } from '@ant-design/icons';
|
|
5
|
+
import { ClassNames } from '@emotion/react';
|
|
6
|
+
import { Checkbox, Divider, Spin, Select, Col } from 'antd';
|
|
7
|
+
import debug from 'debug';
|
|
8
|
+
import { isObject, isPlainObject, isNil, xorWith, noop } from 'lodash-es';
|
|
9
|
+
import { emptyIconWrapper } from '../../../style/global.js';
|
|
10
|
+
import useSWR from 'swr';
|
|
11
|
+
import EmptyField from '../../common/EmptyField.js';
|
|
12
|
+
import Expand, { EXPAND_TYPE_ENUM } from '../../common/expand-component/index.js';
|
|
13
|
+
import ItemIcon from '../../common/item-icon/ItemIcon.js';
|
|
14
|
+
import BaseOverflowTooltip from '../../common/overflow-tooltip/BaseOverflowTooltip.js';
|
|
15
|
+
import OverflowTooltip from '../../common/overflow-tooltip/OverflowTooltip.js';
|
|
16
|
+
import { defaultFilterOptions, getPopupContainerFun } from '../../common/utils.js';
|
|
17
|
+
import EmptyIcon from '../../default-empty-icon/index.js';
|
|
18
|
+
import { getFieldWidthStyle } from '../base-component/utils.js';
|
|
19
|
+
import { getRealValueByIqlTo } from '../../filters/filter-search/utils.js';
|
|
20
|
+
import { REMOTE_DATA_QUOTE_FIELD_TYPE } from '../../../lib/constants/field.js';
|
|
21
|
+
import { FIELD_CONTAINERS_PAGE, CURRENT_WORKSPACE, FIELD_TYPE_KEY_MAPPINGS, BASE_FIELD_WIDTH } from '../../../lib/global.js';
|
|
22
|
+
import useAntdConfig from '../../../lib/hooks/useAntdConfig.js';
|
|
23
|
+
import useI18n from '../../../lib/hooks/useI18n.js';
|
|
24
|
+
import { API_KEY } from '../../../lib/swr/constants.js';
|
|
25
|
+
import useViewClass from '../hooks/useViewClass.js';
|
|
26
|
+
import { useCommonProps, EMPTY_OPTIONS } from './hook.js';
|
|
27
|
+
import { dropdownSelectDisabled, onlyWorkspaceStyle, onlyWorkspaceDividerStyle, dropdownSelectStyle, optionDisplayWrapClass, dropdownSelectOptionClass, disabledClass, workspaceClass, dropdownStyle, hiddenHoverClass, displayWrapClass, valueOptionContentClass, valueOptionClass, valueOptionIconClass, valueOptionLabelClass, hoverIconClass } from './style.js';
|
|
28
|
+
|
|
29
|
+
const loggers = debug('dropdown:BaseField');
|
|
30
|
+
const isNilFilter = function (value) {
|
|
31
|
+
var _a;
|
|
32
|
+
return (_a = value === null || value === void 0 ? void 0 : value.filter) === null || _a === void 0 ? void 0 : _a.call(value, val => !isNil(val));
|
|
33
|
+
};
|
|
34
|
+
const handleValue = function (value) {
|
|
3
35
|
return isObject(value) ? value === null || value === void 0 ? void 0 : value.value : value;
|
|
4
36
|
};
|
|
37
|
+
const getFormattedLabel = ({ label, style = {} } = {}) => {
|
|
38
|
+
return jsx("span", { style: { borderRadius: 2, color: style === null || style === void 0 ? void 0 : style.color, background: style === null || style === void 0 ? void 0 : style.background }, children: label });
|
|
39
|
+
};
|
|
40
|
+
const Dropdown = props => {
|
|
41
|
+
const { onSelect = noop, onBlur, onChange = noop, labelWidth = BASE_FIELD_WIDTH, labelAlign, readonly: propsReadonly = false, options: _propsOptions = EMPTY_OPTIONS, editMode = false, apply, mode, hiddenLabel, allowClear = true, useChange = false, objectId, getPopupContainer, dataQuoteInit, userData, workspace, valueDisplayWrap, optionDisplayWrap, onOptionsChange, page, disabledSwr, onlyValue, screenMode, displayValueHidden = false, disabledLineThrough = false, displayWorkspace = false, isShowOnlyWorkspace = false, fieldTypeKey, iqlKey = 'value', fetchOnFocus, isCascaded, clickFetch, iqlToNeedMore = false, ...defaultProps } = props;
|
|
42
|
+
const { t } = useI18n();
|
|
43
|
+
const { antPrefix } = useAntdConfig();
|
|
44
|
+
const { propsValue, onSearchChange: handleSearch, options, onlyWorkspace, setOnlyWorkspace: onChangeCurrent, loading, _setValue, setLoading, setOptions, propsOptions, cachedOptionsRef, needFetchDataSource, fetchOptions, fetchValues, canAsyncFetchOption, cacheSelectOptions, value, } = useCommonProps(props);
|
|
45
|
+
const isClickFetch = useMemo(() => {
|
|
46
|
+
var _a;
|
|
47
|
+
return page && page !== FIELD_CONTAINERS_PAGE.FILTER && clickFetch && ((_a = propsValue === null || propsValue === void 0 ? void 0 : propsValue[0]) === null || _a === void 0 ? void 0 : _a.label);
|
|
48
|
+
}, [clickFetch, page, propsValue]);
|
|
49
|
+
const [editing, setEditing] = useState(false);
|
|
50
|
+
const [readonly, setReadonly] = useState(false);
|
|
51
|
+
const [open, setOpen] = useState(false);
|
|
52
|
+
const valueRef = useRef([]);
|
|
53
|
+
const containerRef = useRef(null);
|
|
54
|
+
const targetRef = useRef(null);
|
|
55
|
+
const [isClicked, setClicked] = useState(false);
|
|
56
|
+
const optionLoadedRef = useRef(false);
|
|
57
|
+
const loadMoreRef = useRef(false);
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (needFetchDataSource) {
|
|
60
|
+
if (screenMode !== 'create' && screenMode) {
|
|
61
|
+
setReadonly((userData === null || userData === void 0 ? void 0 : userData.readonly) || propsReadonly);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
setReadonly(propsReadonly);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
setReadonly(propsReadonly);
|
|
69
|
+
}
|
|
70
|
+
}, [propsReadonly, userData === null || userData === void 0 ? void 0 : userData.readonly, needFetchDataSource, screenMode]);
|
|
71
|
+
const { isView, viewClassNames } = useViewClass({ screenMode, readonly, editing });
|
|
72
|
+
const shouldSWRFetch = useMemo(() => {
|
|
73
|
+
return apply === 'cell';
|
|
74
|
+
}, [apply]);
|
|
75
|
+
const hasClickFetch = useMemo(() => { var _a; return isClickFetch && !isClicked && ((propsValue === null || propsValue === void 0 ? void 0 : propsValue[0]) ? (_a = propsValue === null || propsValue === void 0 ? void 0 : propsValue[0]) === null || _a === void 0 ? void 0 : _a.label : true); }, [isClickFetch, isClicked, propsValue]);
|
|
76
|
+
const noClickEditing = useMemo(() => isClickFetch && !editing && !(options === null || options === void 0 ? void 0 : options.length), [editing, isClickFetch, options === null || options === void 0 ? void 0 : options.length]);
|
|
77
|
+
const finallyOptions = useMemo(() => {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
return typeof dataQuoteInit === 'function'
|
|
80
|
+
? dataQuoteInit(((_a = propsValue === null || propsValue === void 0 ? void 0 : propsValue[0]) === null || _a === void 0 ? void 0 : _a.label) && !(options === null || options === void 0 ? void 0 : options.length) ? propsValue : options, value, userData === null || userData === void 0 ? void 0 : userData.display)
|
|
81
|
+
: ((_b = propsValue === null || propsValue === void 0 ? void 0 : propsValue[0]) === null || _b === void 0 ? void 0 : _b.label)
|
|
82
|
+
? propsValue
|
|
83
|
+
: options;
|
|
84
|
+
}, [dataQuoteInit, options, propsValue, userData === null || userData === void 0 ? void 0 : userData.display, value]);
|
|
85
|
+
const _options = useMemo(() => ((options === null || options === void 0 ? void 0 : options.length) > 0 ? options : finallyOptions) || [], [finallyOptions, options]);
|
|
86
|
+
async function fetcher() {
|
|
87
|
+
return await fetchOptions('');
|
|
88
|
+
}
|
|
89
|
+
const { data = [], isValidating = false } = useSWR(!disabledSwr && shouldSWRFetch && canAsyncFetchOption
|
|
90
|
+
? `${API_KEY.GET_BASE_FIELD_OPTIONS}_${objectId + workspace}_${onlyWorkspace}`
|
|
91
|
+
: null, fetcher);
|
|
92
|
+
const opts = useMemo(() => data, [data]);
|
|
93
|
+
const isMultiple = useMemo(() => mode === 'multiple', [mode]);
|
|
94
|
+
const setValue = useCallback(value => {
|
|
95
|
+
valueRef.current = value;
|
|
96
|
+
_setValue(value);
|
|
97
|
+
}, [_setValue]);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
if (canAsyncFetchOption) {
|
|
100
|
+
cachedOptionsRef.current = [];
|
|
101
|
+
setOptions([]);
|
|
102
|
+
optionLoadedRef.current = false;
|
|
103
|
+
}
|
|
104
|
+
}, [canAsyncFetchOption, workspace, onlyWorkspace, props.itemId, props.expression, cachedOptionsRef, setOptions]);
|
|
105
|
+
const handleSelectFocus = useCallback(() => {
|
|
106
|
+
setTimeout(() => {
|
|
107
|
+
if (!readonly && !editMode) {
|
|
108
|
+
targetRef.current && targetRef.current.focus();
|
|
109
|
+
if (!open) {
|
|
110
|
+
setOpen(true);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}, [editMode, readonly, open]);
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (!canAsyncFetchOption && Array.isArray(propsOptions)) {
|
|
117
|
+
setOptions(propsOptions || []);
|
|
118
|
+
}
|
|
119
|
+
if (!optionLoadedRef.current && canAsyncFetchOption && !isValidating) {
|
|
120
|
+
if (!shouldSWRFetch && (!fetchOnFocus || (props === null || props === void 0 ? void 0 : props.searchComponent))) {
|
|
121
|
+
if (!(isClickFetch && !isClicked)) {
|
|
122
|
+
optionLoadedRef.current = true;
|
|
123
|
+
fetchOptions('')
|
|
124
|
+
.then(options => {
|
|
125
|
+
var _a;
|
|
126
|
+
let optionsInit = options;
|
|
127
|
+
if (REMOTE_DATA_QUOTE_FIELD_TYPE.includes(fieldTypeKey)) {
|
|
128
|
+
optionsInit = (_a = cacheSelectOptions(options)) === null || _a === void 0 ? void 0 : _a.map(opt => {
|
|
129
|
+
const newOption = options.find(ele => ele.value === opt.value);
|
|
130
|
+
return {
|
|
131
|
+
...opt,
|
|
132
|
+
values: newOption === null || newOption === void 0 ? void 0 : newOption.values,
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
setOptions(cacheSelectOptions(optionsInit));
|
|
137
|
+
setLoading(false);
|
|
138
|
+
if (noClickEditing) {
|
|
139
|
+
setEditing(true);
|
|
140
|
+
handleSelectFocus();
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
.finally(() => {
|
|
144
|
+
setLoading(false);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
cacheSelectOptions(finallyOptions);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
setOptions(cacheSelectOptions(opts));
|
|
153
|
+
optionLoadedRef.current = true;
|
|
154
|
+
setLoading(false);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}, [
|
|
158
|
+
cacheSelectOptions,
|
|
159
|
+
fetchOptions,
|
|
160
|
+
fetchValues,
|
|
161
|
+
canAsyncFetchOption,
|
|
162
|
+
propsOptions,
|
|
163
|
+
options,
|
|
164
|
+
opts,
|
|
165
|
+
shouldSWRFetch,
|
|
166
|
+
isValidating,
|
|
167
|
+
hasClickFetch,
|
|
168
|
+
handleSelectFocus,
|
|
169
|
+
finallyOptions,
|
|
170
|
+
noClickEditing,
|
|
171
|
+
isClickFetch,
|
|
172
|
+
isClicked,
|
|
173
|
+
fetchOnFocus,
|
|
174
|
+
props === null || props === void 0 ? void 0 : props.searchComponent,
|
|
175
|
+
fieldTypeKey,
|
|
176
|
+
setOptions,
|
|
177
|
+
setLoading,
|
|
178
|
+
]);
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
var _a;
|
|
181
|
+
loggers('loadMoreRef', loadMoreRef.current);
|
|
182
|
+
if (canAsyncFetchOption &&
|
|
183
|
+
Array.isArray(value) &&
|
|
184
|
+
optionLoadedRef.current === true &&
|
|
185
|
+
loadMoreRef.current === false &&
|
|
186
|
+
(!value.some(item => item === null || item === void 0 ? void 0 : item.iqlTo) || iqlToNeedMore)) {
|
|
187
|
+
let isNotExistedKeys = [];
|
|
188
|
+
const v = value[0];
|
|
189
|
+
if (isPlainObject(v)) {
|
|
190
|
+
isNotExistedKeys = value
|
|
191
|
+
.filter(val => val && (val === null || val === void 0 ? void 0 : val.value) !== CURRENT_WORKSPACE && cachedOptionsRef.current.every(opt => opt.value !== val.value))
|
|
192
|
+
.map(val => val === null || val === void 0 ? void 0 : val.value)
|
|
193
|
+
.filter(data => data !== undefined);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
isNotExistedKeys = value.filter(val => val && cachedOptionsRef.current.every(opt => opt.value !== val));
|
|
197
|
+
}
|
|
198
|
+
if (isNotExistedKeys.length) {
|
|
199
|
+
setLoading(true);
|
|
200
|
+
loadMoreRef.current = true;
|
|
201
|
+
fetchValues(isNotExistedKeys === null || isNotExistedKeys === void 0 ? void 0 : isNotExistedKeys.filter(Boolean), fieldTypeKey).then(appendOptions => {
|
|
202
|
+
const options = cacheSelectOptions(typeof dataQuoteInit === 'function'
|
|
203
|
+
? dataQuoteInit(appendOptions, value, userData === null || userData === void 0 ? void 0 : userData.display)
|
|
204
|
+
: appendOptions);
|
|
205
|
+
setOptions(options);
|
|
206
|
+
setLoading(false);
|
|
207
|
+
const res = valueRef.current.filter(val => {
|
|
208
|
+
const value = typeof val === 'object' ? val.value : val;
|
|
209
|
+
const index = options === null || options === void 0 ? void 0 : options.findIndex((o) => {
|
|
210
|
+
return o.value === value;
|
|
211
|
+
});
|
|
212
|
+
if (index !== -1 || value === 'NULL' || value === CURRENT_WORKSPACE) {
|
|
213
|
+
return val;
|
|
214
|
+
}
|
|
215
|
+
else if (displayValueHidden && value !== 'NULL') {
|
|
216
|
+
setOptions(cacheSelectOptions([{ value, label: t('global.haveDelete'), disabled: true }]));
|
|
217
|
+
return val;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
setValue(res || []);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (!loadMoreRef.current && value.some(item => item === null || item === void 0 ? void 0 : item.iqlTo)) {
|
|
225
|
+
loggers('canAsyncFetchOption', canAsyncFetchOption);
|
|
226
|
+
const isSet = canAsyncFetchOption ? optionLoadedRef.current : value.some(item => item === null || item === void 0 ? void 0 : item.iqlTo) && (options === null || options === void 0 ? void 0 : options.length);
|
|
227
|
+
loggers('isSet', isSet);
|
|
228
|
+
if (isSet) {
|
|
229
|
+
const _value = (_a = getRealValueByIqlTo(value, options, iqlKey)) === null || _a === void 0 ? void 0 : _a.map(item => {
|
|
230
|
+
if ((item === null || item === void 0 ? void 0 : item.value) === CURRENT_WORKSPACE) {
|
|
231
|
+
return {
|
|
232
|
+
label: `${t('pages.fields.workspace.default.currentWorkspace')}(currentWorkspace)`,
|
|
233
|
+
value: CURRENT_WORKSPACE,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
return item;
|
|
237
|
+
});
|
|
238
|
+
loggers('_value', _value);
|
|
239
|
+
loadMoreRef.current = true;
|
|
240
|
+
setTimeout(() => {
|
|
241
|
+
setValue(_value);
|
|
242
|
+
}, 0);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}, [
|
|
246
|
+
t,
|
|
247
|
+
value,
|
|
248
|
+
fetchValues,
|
|
249
|
+
cacheSelectOptions,
|
|
250
|
+
canAsyncFetchOption,
|
|
251
|
+
opts,
|
|
252
|
+
userData === null || userData === void 0 ? void 0 : userData.display,
|
|
253
|
+
dataQuoteInit,
|
|
254
|
+
displayValueHidden,
|
|
255
|
+
options,
|
|
256
|
+
iqlKey,
|
|
257
|
+
setValue,
|
|
258
|
+
fieldTypeKey,
|
|
259
|
+
iqlToNeedMore,
|
|
260
|
+
cachedOptionsRef,
|
|
261
|
+
setLoading,
|
|
262
|
+
setOptions,
|
|
263
|
+
]);
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
onOptionsChange && onOptionsChange(options);
|
|
266
|
+
}, [onOptionsChange, options]);
|
|
267
|
+
const handleFetchOptions = useCallback(() => {
|
|
268
|
+
optionLoadedRef.current = true;
|
|
269
|
+
setLoading(true);
|
|
270
|
+
fetchOptions('').then(options => {
|
|
271
|
+
setOptions(cacheSelectOptions(options));
|
|
272
|
+
setLoading(false);
|
|
273
|
+
});
|
|
274
|
+
}, [cacheSelectOptions, fetchOptions, setLoading, setOptions]);
|
|
275
|
+
useEffect(() => {
|
|
276
|
+
loadMoreRef.current = false;
|
|
277
|
+
const _propsValue = isClickFetch && Array.isArray(propsValue)
|
|
278
|
+
? propsValue === null || propsValue === void 0 ? void 0 : propsValue.map(item => (item === null || item === void 0 ? void 0 : item.value) || (item === null || item === void 0 ? void 0 : item.objectId) || item)
|
|
279
|
+
: propsValue;
|
|
280
|
+
setValue(Array.isArray(_propsValue) ? _propsValue : []);
|
|
281
|
+
}, [isClickFetch, propsValue, setValue]);
|
|
282
|
+
const showValue = useCallback(({ cx, css }) => {
|
|
283
|
+
var _a, _b, _c, _d;
|
|
284
|
+
let showValue = null;
|
|
285
|
+
const _options = isCascaded ? _propsOptions : noClickEditing ? finallyOptions : options;
|
|
286
|
+
const _optionsMap = {};
|
|
287
|
+
if (Array.isArray(_options)) {
|
|
288
|
+
_options.forEach(item => {
|
|
289
|
+
_optionsMap[item.label] = item;
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
if (isMultiple) {
|
|
293
|
+
if ((Array.isArray(_options) && _options.length >= 1 && value && Array.isArray(value) && value.length) ||
|
|
294
|
+
(noClickEditing && Array.isArray(finallyOptions) && finallyOptions.length > 0)) {
|
|
295
|
+
const valueArr = value
|
|
296
|
+
.map(item => { var _a; return (item === null || item === void 0 ? void 0 : item.label) || ((_a = _options.find(opt => opt.value === handleValue(item))) === null || _a === void 0 ? void 0 : _a.label); })
|
|
297
|
+
.filter(Boolean);
|
|
298
|
+
if (!(valueArr === null || valueArr === void 0 ? void 0 : valueArr.length))
|
|
299
|
+
return null;
|
|
300
|
+
showValue = valueArr.map((item, index) => {
|
|
301
|
+
const content = _optionsMap[item] ? getFormattedLabel(_optionsMap[item]) : item;
|
|
302
|
+
return index === value.length - 1 ? content : jsxs(Fragment, { children: [content, ","] });
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
if ((Array.isArray(_options) && _options.length >= 1 && value && Array.isArray(value) && value.length) ||
|
|
308
|
+
(noClickEditing && Array.isArray(finallyOptions) && finallyOptions.length > 0)) {
|
|
309
|
+
const val = value === null || value === void 0 ? void 0 : value[0];
|
|
310
|
+
const opt = _options.filter(item => item.value === handleValue(val));
|
|
311
|
+
const label = ((_a = opt[0]) === null || _a === void 0 ? void 0 : _a.label) || handleValue(val);
|
|
312
|
+
if (opt.length >= 1) {
|
|
313
|
+
showValue = (jsx("span", { className: cx({ [css(dropdownSelectDisabled)]: ((_b = opt[0]) === null || _b === void 0 ? void 0 : _b.disabled) || !opt.length }), children: ((_c = opt[0]) === null || _c === void 0 ? void 0 : _c.icon) ? (jsx(ItemIcon, { icon: (_d = opt[0]) === null || _d === void 0 ? void 0 : _d.icon, label: label })) : !screenMode && _optionsMap[label] ? (getFormattedLabel(_optionsMap[label])) : (label) }));
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return showValue;
|
|
318
|
+
}, [isCascaded, _propsOptions, noClickEditing, finallyOptions, options, isMultiple, value, screenMode]);
|
|
319
|
+
const valueOptions = useMemo(() => {
|
|
320
|
+
if ((Array.isArray(options) && (options === null || options === void 0 ? void 0 : options.length) >= 1 && value && Array.isArray(value)) ||
|
|
321
|
+
(noClickEditing && Array.isArray(_options) && _options.length > 0)) {
|
|
322
|
+
return value
|
|
323
|
+
.map(val => {
|
|
324
|
+
return _options === null || _options === void 0 ? void 0 : _options.find(opt => (opt === null || opt === void 0 ? void 0 : opt.value) === handleValue(val));
|
|
325
|
+
})
|
|
326
|
+
.filter(Boolean);
|
|
327
|
+
}
|
|
328
|
+
return [];
|
|
329
|
+
}, [options, value, noClickEditing, _options]);
|
|
330
|
+
const selectValue = useMemo(() => {
|
|
331
|
+
if (value === undefined) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
if (isMultiple) {
|
|
335
|
+
if (Array.isArray(value)) {
|
|
336
|
+
return isNilFilter(value.map(handleValue));
|
|
337
|
+
}
|
|
338
|
+
return isNil(value) ? [] : [value];
|
|
339
|
+
}
|
|
340
|
+
if (Array.isArray(value)) {
|
|
341
|
+
if ((value.length && (optionLoadedRef.current || !canAsyncFetchOption)) ||
|
|
342
|
+
(Array.isArray(_options) && _options.length > 0)) {
|
|
343
|
+
const v = value[0];
|
|
344
|
+
if (isPlainObject(v)) {
|
|
345
|
+
if (_options.some(option => option.value === v.value)) {
|
|
346
|
+
return onlyValue ? v.value : (v === null || v === void 0 ? void 0 : v.value) || v;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
if (_options.some(option => option.value === v))
|
|
351
|
+
return (v === null || v === void 0 ? void 0 : v.value) || v;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return undefined;
|
|
355
|
+
}
|
|
356
|
+
}, [value, canAsyncFetchOption, _options, onlyValue, isMultiple]);
|
|
357
|
+
const handleClick = useCallback(() => {
|
|
358
|
+
if (!hasClickFetch) {
|
|
359
|
+
setEditing(true);
|
|
360
|
+
handleSelectFocus();
|
|
361
|
+
}
|
|
362
|
+
if (shouldSWRFetch && disabledSwr) {
|
|
363
|
+
handleFetchOptions();
|
|
364
|
+
}
|
|
365
|
+
hasClickFetch && setClicked(true);
|
|
366
|
+
}, [hasClickFetch, shouldSWRFetch, disabledSwr, handleSelectFocus, handleFetchOptions]);
|
|
367
|
+
const handleSelect = useCallback((val, option) => {
|
|
368
|
+
if (isMultiple) {
|
|
369
|
+
onSelect && onSelect([val], option);
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
onSelect && onSelect([val], option);
|
|
373
|
+
}
|
|
374
|
+
}, [onSelect, isMultiple]);
|
|
375
|
+
const handleChange = useCallback((val, option) => {
|
|
376
|
+
var _a;
|
|
377
|
+
setTimeout(() => {
|
|
378
|
+
var _a;
|
|
379
|
+
(_a = targetRef === null || targetRef === void 0 ? void 0 : targetRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
380
|
+
});
|
|
381
|
+
const value = isMultiple ? val : val ? [val] : [];
|
|
382
|
+
setValue(value);
|
|
383
|
+
if (propsValue === undefined && !value.length) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (useChange) {
|
|
387
|
+
if (isMultiple) {
|
|
388
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(value, option === null || option === void 0 ? void 0 : option.map(item => {
|
|
389
|
+
var _a;
|
|
390
|
+
return ({
|
|
391
|
+
...item,
|
|
392
|
+
label: (_a = options === null || options === void 0 ? void 0 : options.find(ops => ops.value === item.value)) === null || _a === void 0 ? void 0 : _a.label,
|
|
393
|
+
});
|
|
394
|
+
}));
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
const targetValue = Array.isArray(value) ? value[0] : value;
|
|
398
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(value, {
|
|
399
|
+
...option,
|
|
400
|
+
label: (_a = options === null || options === void 0 ? void 0 : options.find(ops => ops.value === targetValue)) === null || _a === void 0 ? void 0 : _a.label,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}, [propsValue, setValue, useChange, onChange, options, isMultiple]);
|
|
405
|
+
const handleClear = useCallback(() => {
|
|
406
|
+
setValue([]);
|
|
407
|
+
onChange && onChange([], options);
|
|
408
|
+
}, [onChange, options, setValue]);
|
|
409
|
+
const handleFocus = useCallback(() => {
|
|
410
|
+
if (fetchOnFocus) {
|
|
411
|
+
optionLoadedRef.current = true;
|
|
412
|
+
fetchOptions('').then(options => {
|
|
413
|
+
setOptions(cacheSelectOptions(options));
|
|
414
|
+
setLoading(false);
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
else if (!(options === null || options === void 0 ? void 0 : options.length) && !canAsyncFetchOption) {
|
|
418
|
+
setValue([]);
|
|
419
|
+
}
|
|
420
|
+
}, [
|
|
421
|
+
fetchOnFocus,
|
|
422
|
+
options === null || options === void 0 ? void 0 : options.length,
|
|
423
|
+
canAsyncFetchOption,
|
|
424
|
+
fetchOptions,
|
|
425
|
+
setOptions,
|
|
426
|
+
cacheSelectOptions,
|
|
427
|
+
setLoading,
|
|
428
|
+
setValue,
|
|
429
|
+
]);
|
|
430
|
+
const handleBlur = useCallback(e => {
|
|
431
|
+
var _a;
|
|
432
|
+
if (open) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
if (!editMode) {
|
|
436
|
+
setEditing(false);
|
|
437
|
+
}
|
|
438
|
+
if (canAsyncFetchOption) {
|
|
439
|
+
setOptions(cachedOptionsRef.current);
|
|
440
|
+
}
|
|
441
|
+
if (propsValue === undefined && !value.length) {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
if (!useChange) {
|
|
445
|
+
if (isClickFetch && ((_a = propsValue === null || propsValue === void 0 ? void 0 : propsValue[0]) === null || _a === void 0 ? void 0 : _a.label)) {
|
|
446
|
+
const needChange = value.length !== propsValue.length ||
|
|
447
|
+
xorWith(propsValue, value, (oldV, newV) => isPlainObject(oldV) ? oldV.value === newV : newV.value === oldV).length > 0;
|
|
448
|
+
needChange && (onChange === null || onChange === void 0 ? void 0 : onChange(value, options));
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(value, options);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
|
|
455
|
+
}, [
|
|
456
|
+
open,
|
|
457
|
+
editMode,
|
|
458
|
+
canAsyncFetchOption,
|
|
459
|
+
propsValue,
|
|
460
|
+
value,
|
|
461
|
+
useChange,
|
|
462
|
+
onBlur,
|
|
463
|
+
setOptions,
|
|
464
|
+
cachedOptionsRef,
|
|
465
|
+
isClickFetch,
|
|
466
|
+
onChange,
|
|
467
|
+
options,
|
|
468
|
+
]);
|
|
469
|
+
useEffect(() => {
|
|
470
|
+
if (mode !== 'multiple' && (propsValue === null || propsValue === void 0 ? void 0 : propsValue.length)) {
|
|
471
|
+
if (apply === 'cell') {
|
|
472
|
+
if (propsValue[0].archived === 'true') {
|
|
473
|
+
setReadonly(true);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
const valueFirst = propsValue[0];
|
|
478
|
+
const result = options === null || options === void 0 ? void 0 : options.find(opt => opt.value === (isObject(valueFirst) ? valueFirst.value : valueFirst));
|
|
479
|
+
if (result === null || result === void 0 ? void 0 : result.archived) {
|
|
480
|
+
setReadonly(true);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}, [options, propsValue, mode, apply]);
|
|
485
|
+
const filterOptionProp = useMemo(() => (canAsyncFetchOption ? false : defaultFilterOptions), [canAsyncFetchOption]);
|
|
486
|
+
useEffect(() => {
|
|
487
|
+
if (open) {
|
|
488
|
+
handleClick();
|
|
489
|
+
}
|
|
490
|
+
}, [onlyWorkspace]);
|
|
491
|
+
const onDropdownVisibleChange = useCallback(open => {
|
|
492
|
+
setOpen(open);
|
|
493
|
+
if (!isMultiple && !open) {
|
|
494
|
+
setTimeout(() => {
|
|
495
|
+
var _a;
|
|
496
|
+
(_a = targetRef === null || targetRef === void 0 ? void 0 : targetRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
}, [isMultiple]);
|
|
500
|
+
const dropdownRender = useCallback(({ cx, css }) => {
|
|
501
|
+
return menu => {
|
|
502
|
+
if (!isShowOnlyWorkspace)
|
|
503
|
+
return menu;
|
|
504
|
+
const message = t('pages.fields.default.onlyWorkspace', {
|
|
505
|
+
name: props.onlyWorkspaceTip || t(`pages.fields.fieldName.${fieldTypeKey}`),
|
|
506
|
+
});
|
|
507
|
+
return (jsxs(Fragment, { children: [jsx("div", { className: cx(css(onlyWorkspaceStyle)), children: jsx(Checkbox, { checked: onlyWorkspace, onChange: onChangeCurrent, onClick: e => {
|
|
508
|
+
e.stopPropagation();
|
|
509
|
+
}, children: jsx(BaseOverflowTooltip, { title: message, children: message }) }) }), jsx(Divider, { className: cx(css(onlyWorkspaceDividerStyle)) }), menu] }));
|
|
510
|
+
};
|
|
511
|
+
}, [fieldTypeKey, isShowOnlyWorkspace, onChangeCurrent, onlyWorkspace, props.onlyWorkspaceTip, t]);
|
|
512
|
+
const notFoundContentMemo = useMemo(() => {
|
|
513
|
+
return loading && canAsyncFetchOption ? (jsx(Spin, { size: "small" })) : (jsx(ClassNames, { children: ({ css, cx }) => (jsx("div", { className: cx(css(emptyIconWrapper)), children: jsx(EmptyIcon, { noMargin: true }) })) }));
|
|
514
|
+
}, [canAsyncFetchOption, loading]);
|
|
515
|
+
const style = getFieldWidthStyle(labelWidth, labelAlign, hiddenLabel, apply);
|
|
516
|
+
const hiddenHover = readonly || editMode || editing || apply === 'cell' || isView;
|
|
517
|
+
const overlayRender = useMemo(() => {
|
|
518
|
+
return (jsx(ClassNames, { children: ({ cx, css }) => {
|
|
519
|
+
const cxDropdownRender = dropdownRender({ cx, css });
|
|
520
|
+
return (jsx("div", { className: 'field-value-overlay', children: jsx(Select, { getPopupContainer: triggerNode => getPopupContainerFun(getPopupContainer, triggerNode, apply, page), filterOption: filterOptionProp, ...defaultProps, className: cx('field-value-overlay-component', disabledLineThrough || displayValueHidden ? css(dropdownSelectStyle(antPrefix)) : '', {
|
|
521
|
+
[optionDisplayWrapClass]: optionDisplayWrap,
|
|
522
|
+
}), mode: mode, ref: targetRef, value: selectValue, showSearch: true, maxTagCount: optionDisplayWrap || isView ? null : 'responsive', onSelect: handleSelect, onClear: handleClear, onBlur: handleBlur, open: open, onDropdownVisibleChange: onDropdownVisibleChange, onFocus: handleFocus, onChange: handleChange, allowClear: allowClear, onSearch: handleSearch, defaultOpen: !editMode, listItemHeight: 32, listHeight: 200, optionLabelProp: fieldTypeKey === FIELD_TYPE_KEY_MAPPINGS.Version ? 'label' : 'children', notFoundContent: notFoundContentMemo, dropdownRender: cxDropdownRender, children: _options.map(item => {
|
|
523
|
+
var _a, _b, _c;
|
|
524
|
+
return (jsxs(Select.Option, { value: item.value, label: item.label, disabled: item.disabled, values: item.values, children: [jsx("span", { className: cx({ [dropdownSelectOptionClass]: disabledLineThrough || displayValueHidden }, { [disabledClass]: item === null || item === void 0 ? void 0 : item.disabled }), children: jsxs(BaseOverflowTooltip, { title: (_a = item === null || item === void 0 ? void 0 : item.label) === null || _a === void 0 ? void 0 : _a.toString(), className: "custom-overflow", children: [jsx(ItemIcon, { icon: item.icon, label: item.label }), fieldTypeKey === FIELD_TYPE_KEY_MAPPINGS.Version && item.archived && (jsxs("span", { children: ["(", t('workspaceArchived.archived'), ")"] }))] }) }), displayWorkspace ? (jsx("div", { className: cx(workspaceClass), children: jsx(BaseOverflowTooltip, { title: (_b = item === null || item === void 0 ? void 0 : item.workspace) === null || _b === void 0 ? void 0 : _b.name, children: (_c = item === null || item === void 0 ? void 0 : item.workspace) === null || _c === void 0 ? void 0 : _c.name }) })) : null] }, item.value));
|
|
525
|
+
}) }) }));
|
|
526
|
+
} }));
|
|
527
|
+
}, [
|
|
528
|
+
_options,
|
|
529
|
+
allowClear,
|
|
530
|
+
antPrefix,
|
|
531
|
+
apply,
|
|
532
|
+
defaultProps,
|
|
533
|
+
disabledLineThrough,
|
|
534
|
+
displayValueHidden,
|
|
535
|
+
displayWorkspace,
|
|
536
|
+
dropdownRender,
|
|
537
|
+
editMode,
|
|
538
|
+
fieldTypeKey,
|
|
539
|
+
filterOptionProp,
|
|
540
|
+
getPopupContainer,
|
|
541
|
+
handleBlur,
|
|
542
|
+
handleChange,
|
|
543
|
+
handleClear,
|
|
544
|
+
handleFocus,
|
|
545
|
+
handleSearch,
|
|
546
|
+
handleSelect,
|
|
547
|
+
isView,
|
|
548
|
+
mode,
|
|
549
|
+
notFoundContentMemo,
|
|
550
|
+
onDropdownVisibleChange,
|
|
551
|
+
open,
|
|
552
|
+
optionDisplayWrap,
|
|
553
|
+
page,
|
|
554
|
+
selectValue,
|
|
555
|
+
t,
|
|
556
|
+
]);
|
|
557
|
+
return (jsx(ClassNames, { children: ({ cx, css }) => {
|
|
558
|
+
const cxShowValue = showValue({ cx, css });
|
|
559
|
+
return (jsxs(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: [(readonly || (!editMode && !editing)) &&
|
|
560
|
+
(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 => {
|
|
561
|
+
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));
|
|
562
|
+
}) }))) : (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) })] }));
|
|
563
|
+
} }));
|
|
564
|
+
};
|
|
565
|
+
Dropdown.displayName = 'DropdownBaseField';
|
|
566
|
+
|
|
567
|
+
export { Dropdown as default, getFormattedLabel, handleValue, isNilFilter };
|