@antscorp/antsomi-ui 1.3.5-beta.698 → 1.3.5-beta.699
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/es/components/molecules/MatchAnySelect/MatchesAnySelect.d.ts +2 -2
- package/es/components/molecules/MatchAnySelect/MatchesAnySelect.js +41 -25
- package/es/components/molecules/MatchAnySelect/constants.js +0 -20
- package/es/components/molecules/MatchAnySelect/types.d.ts +10 -6
- package/es/components/molecules/MatchAnySelect/utils.d.ts +2 -0
- package/es/components/molecules/MatchAnySelect/utils.js +34 -0
- package/es/components/organism/DataTable/hooks/useAddFilterButton.d.ts +1 -1
- package/package.json +3 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { MatchesAnyProps, MatchesAnySelectProps } from './types';
|
|
3
|
-
export declare function MatchesAny<TItem =
|
|
4
|
-
export declare function MatchesAnySelect<TItem =
|
|
3
|
+
export declare function MatchesAny<TItem = any>(props: MatchesAnyProps<TItem>): React.JSX.Element;
|
|
4
|
+
export declare function MatchesAnySelect<TItem = any>(props: MatchesAnySelectProps<TItem>): React.JSX.Element;
|
|
@@ -13,26 +13,29 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
/* eslint-disable react/destructuring-assignment */
|
|
14
14
|
// Libraries
|
|
15
15
|
import { ConfigProvider } from 'antd';
|
|
16
|
-
import
|
|
16
|
+
import clsx from 'clsx';
|
|
17
|
+
import { isEmpty, uniqBy } from 'lodash';
|
|
17
18
|
import React, { useEffect, useState } from 'react';
|
|
19
|
+
import deepmerge from 'deepmerge';
|
|
18
20
|
// Components
|
|
21
|
+
import { Button, Flex, Icon, Input, Popover, Spin, Tooltip, Typography, } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
19
22
|
import { EmptyData, PopoverSelect, Select } from '@antscorp/antsomi-ui/es/components/molecules';
|
|
20
|
-
import { Button, Flex, Icon, Input, Popover, Spin, Typography, Tooltip, } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
21
23
|
import { ExtendValuePopup } from './components/ExtendValuePopup';
|
|
22
24
|
// Styled
|
|
23
|
-
import {
|
|
25
|
+
import { ActionButton, ExtraValueLabel, GroupSelectButton, MatchesAnyWrapper, StyledTree, TextButton, } from './styled';
|
|
24
26
|
// Locales
|
|
25
27
|
import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
|
|
26
28
|
import { translations } from '@antscorp/antsomi-ui/es/locales/translations';
|
|
27
29
|
// Constants
|
|
28
|
-
import { MATCHES_ANY_THEME } from './constants';
|
|
29
30
|
import { globalToken } from '@antscorp/antsomi-ui/es/constants';
|
|
31
|
+
import { MATCHES_ANY_THEME } from './constants';
|
|
30
32
|
// Hooks
|
|
31
33
|
import { useDeepCompareEffect, useDeepCompareMemo, useIntersectionObserver, } from '@antscorp/antsomi-ui/es/hooks';
|
|
32
34
|
// Utils
|
|
33
35
|
import { flatTree, recursiveSearchItems } from '@antscorp/antsomi-ui/es/utils';
|
|
36
|
+
import { getSelectedTreeData } from './utils';
|
|
37
|
+
// Icons
|
|
34
38
|
import { DataIcon, WarningIcon } from '../../icons';
|
|
35
|
-
import clsx from 'clsx';
|
|
36
39
|
const initialState = {
|
|
37
40
|
isOpenPopover: false,
|
|
38
41
|
};
|
|
@@ -45,7 +48,7 @@ const { t } = i18nInstance;
|
|
|
45
48
|
const { Text } = Typography;
|
|
46
49
|
export function MatchesAny(props) {
|
|
47
50
|
// Props
|
|
48
|
-
const { objectName, loading = false, showExtendValue = true, items, groupSelectProps, renderExtraValues, customItemRenders, listEmptyProps, selectedListEmptyProps, onApply = () => { }, onCancel = () => { }, onLoadMore = () => { }, onChangeSearch } = props, restOfProps = __rest(props, ["objectName", "loading", "showExtendValue", "items", "groupSelectProps", "renderExtraValues", "customItemRenders", "listEmptyProps", "selectedListEmptyProps", "onApply", "onCancel", "onLoadMore", "onChangeSearch"]);
|
|
51
|
+
const { objectName, loading = false, showExtendValue = true, items, groupSelectProps, renderExtraValues, customItemRenders, listEmptyProps, selectedListEmptyProps, selectedTreeData: selectedTreeDataProp, onSelectedTreeDataChange = () => { }, onApply = () => { }, onCancel = () => { }, onLoadMore = () => { }, onChangeSearch } = props, restOfProps = __rest(props, ["objectName", "loading", "showExtendValue", "items", "groupSelectProps", "renderExtraValues", "customItemRenders", "listEmptyProps", "selectedListEmptyProps", "selectedTreeData", "onSelectedTreeDataChange", "onApply", "onCancel", "onLoadMore", "onChangeSearch"]);
|
|
49
52
|
// State
|
|
50
53
|
const [state, setState] = useState(matchesAnyInitialState);
|
|
51
54
|
// Variables
|
|
@@ -75,6 +78,13 @@ export function MatchesAny(props) {
|
|
|
75
78
|
setState(prev => (Object.assign(Object.assign({}, prev), { isShowLoadMoreEl: true })));
|
|
76
79
|
}, 500);
|
|
77
80
|
}, []);
|
|
81
|
+
useDeepCompareEffect(() => {
|
|
82
|
+
const selectedTreeData = getSelectedTreeData(items || [], selectedItems || [], selectedTreeDataProp || []);
|
|
83
|
+
if (!isEmpty(selectedTreeData)) {
|
|
84
|
+
onSelectedTreeDataChange(selectedTreeData);
|
|
85
|
+
}
|
|
86
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
87
|
+
}, [items, selectedItems]);
|
|
78
88
|
// Handlers
|
|
79
89
|
/**
|
|
80
90
|
* Adds an item and, if applicable, its leaf descendants to the list of selected items.
|
|
@@ -87,15 +97,15 @@ export function MatchesAny(props) {
|
|
|
87
97
|
* This item can have children.
|
|
88
98
|
*/
|
|
89
99
|
const onSelectItem = (item) => {
|
|
100
|
+
let newSelectedItems = [...(selectedItems || [])];
|
|
90
101
|
if (item.children) {
|
|
91
102
|
const flattenChild = flatTree(item.children, 'children');
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return;
|
|
103
|
+
newSelectedItems = newSelectedItems.concat(flattenChild.filter(item => !item.children));
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
newSelectedItems = newSelectedItems.concat(item);
|
|
97
107
|
}
|
|
98
|
-
setState(prev => (Object.assign(Object.assign({}, prev), { selectedItems:
|
|
108
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { selectedItems: newSelectedItems })));
|
|
99
109
|
};
|
|
100
110
|
/**
|
|
101
111
|
* Removes an item and its descendants from the list of selected items.
|
|
@@ -125,6 +135,10 @@ export function MatchesAny(props) {
|
|
|
125
135
|
const onRemoveAll = () => {
|
|
126
136
|
setState(prev => (Object.assign(Object.assign({}, prev), { selectedItems: [] })));
|
|
127
137
|
};
|
|
138
|
+
const onClickApply = () => {
|
|
139
|
+
const selectedTreeData = getSelectedTreeData(items || [], selectedItems || [], selectedTreeDataProp || []);
|
|
140
|
+
onApply(selectedItems || [], selectedTreeData);
|
|
141
|
+
};
|
|
128
142
|
const renderItemError = (item) => {
|
|
129
143
|
if (customItemRenders === null || customItemRenders === void 0 ? void 0 : customItemRenders.error) {
|
|
130
144
|
return customItemRenders === null || customItemRenders === void 0 ? void 0 : customItemRenders.error(item);
|
|
@@ -200,17 +214,13 @@ export function MatchesAny(props) {
|
|
|
200
214
|
treeData = treeData.filter(item => { var _a; return (_a = groupSelectProps.selected) === null || _a === void 0 ? void 0 : _a.includes(item.key); });
|
|
201
215
|
}
|
|
202
216
|
return { treeData, matchedParents };
|
|
217
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
203
218
|
}, [items, searchValue, selectedItems, groupSelectProps, onChangeSearch]);
|
|
204
219
|
// const selectedTreeData = useDeepCompareMemo(() => [], [items, selectedItems]);
|
|
205
220
|
const selectedTreeData = useDeepCompareMemo(() => {
|
|
206
221
|
var _a;
|
|
207
222
|
const notExtendValueSelectedItems = (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.filter(item => !item.isExtendValue)) || [];
|
|
208
223
|
const extendValueSelectedItems = (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.filter(item => item.isExtendValue)) || [];
|
|
209
|
-
// const lazyLoadSelectedItems =
|
|
210
|
-
// notExtendValueSelectedItems?.filter(
|
|
211
|
-
// selectedItem =>
|
|
212
|
-
// !flatTree(items || [], 'children').some(item => item.key === selectedItem.key),
|
|
213
|
-
// ) || [];
|
|
214
224
|
const serializeTreeData = (list) => {
|
|
215
225
|
var _a;
|
|
216
226
|
return ((_a = list
|
|
@@ -230,8 +240,14 @@ export function MatchesAny(props) {
|
|
|
230
240
|
children: serializeTreeData(item.children),
|
|
231
241
|
})), (!!item.error && { className: 'error-node' }))))) || [];
|
|
232
242
|
};
|
|
233
|
-
|
|
234
|
-
|
|
243
|
+
const mergeItems = deepmerge(selectedTreeDataProp || [], items || [], {
|
|
244
|
+
arrayMerge(target, source) {
|
|
245
|
+
return uniqBy([...target, ...source], 'key');
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
return serializeTreeData(mergeItems).concat(((_a = [...extendValueSelectedItems]) === null || _a === void 0 ? void 0 : _a.map(item => (Object.assign(Object.assign({}, item), { title: renderItemNodeTitle({ item, mode: 'select', onRemoveItem }) })))) || []);
|
|
249
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
250
|
+
}, [items, selectedItems, selectedTreeDataProp]);
|
|
235
251
|
const isDisableRemoveAll = useDeepCompareMemo(() => !(selectedTreeData === null || selectedTreeData === void 0 ? void 0 : selectedTreeData.length), [selectedTreeData]);
|
|
236
252
|
const isDisableSelectAll = useDeepCompareMemo(() => {
|
|
237
253
|
const flattenTreeData = flatTree(treeData, 'children');
|
|
@@ -281,7 +297,7 @@ export function MatchesAny(props) {
|
|
|
281
297
|
React.createElement(Flex, { className: "matches-any__header", justify: "space-between" },
|
|
282
298
|
React.createElement(Text, { strong: true }, `${t(translations.global.selected)} (${(selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.length) || 0})`),
|
|
283
299
|
React.createElement(TextButton, { disabled: isDisableRemoveAll, onClick: onRemoveAll }, t(translations.global.removeAll).toString())),
|
|
284
|
-
React.createElement("div", { className: "matches-any__body" }, !(selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.length) ? (React.createElement(EmptyData, Object.assign({ icon: selectedListEmptyIcon, description: selectedListEmptyDescription }, restSelectedListEmptyProps))) : (React.createElement(StyledTree, {
|
|
300
|
+
React.createElement("div", { className: "matches-any__body" }, !(selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.length) ? (React.createElement(EmptyData, Object.assign({ icon: selectedListEmptyIcon, description: selectedListEmptyDescription }, restSelectedListEmptyProps))) : (React.createElement(StyledTree, { defaultExpandedKeys: selectedTreeData === null || selectedTreeData === void 0 ? void 0 : selectedTreeData.map(item => item.key), selectable: false, treeData: selectedTreeData, height: 420, switcherIcon: props => (React.createElement(Icon, { type: "icon-ants-caret-down", style: {
|
|
285
301
|
transform: props.expanded ? 'rotate(0)' : 'rotate(-90deg)',
|
|
286
302
|
transition: 'transform 0.3s ease',
|
|
287
303
|
}, color: globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw8 })) })))));
|
|
@@ -307,14 +323,14 @@ export function MatchesAny(props) {
|
|
|
307
323
|
renderSelectedList()),
|
|
308
324
|
React.createElement(Flex, { className: "matches-any__footer", align: "center", justify: "space-between" },
|
|
309
325
|
React.createElement(Flex, { align: "center", gap: 10 },
|
|
310
|
-
React.createElement(Button, { type: "primary", onClick:
|
|
326
|
+
React.createElement(Button, { type: "primary", onClick: onClickApply }, t(translations.apply.title).toString()),
|
|
311
327
|
React.createElement(Button, { onClick: () => onCancel() }, t(translations.cancel.title).toString())),
|
|
312
328
|
showExtendValue && (React.createElement(ExtendValuePopup, { getPopupContainer: trigger => trigger.parentElement || document.body, onApply: onApplyExtendValue },
|
|
313
329
|
React.createElement(Button, { icon: React.createElement(Icon, { type: "icon-ants-empty-flag" }) }, t(translations.extendValue.title).toString())))))));
|
|
314
330
|
}
|
|
315
331
|
export function MatchesAnySelect(props) {
|
|
316
332
|
var _a, _b, _c;
|
|
317
|
-
const { placeholder = 'Select an item', dropdownStyle, objectName, selectedItems, items, loading, popupClassName, groupSelectProps, renderExtraValues, customItemRenders, popoverProps, listEmptyProps, selectedListEmptyProps, onChangeSearch, onChange = () => { }, onLoadMore } = props, restProps = __rest(props, ["placeholder", "dropdownStyle", "objectName", "selectedItems", "items", "loading", "popupClassName", "groupSelectProps", "renderExtraValues", "customItemRenders", "popoverProps", "listEmptyProps", "selectedListEmptyProps", "onChangeSearch", "onChange", "onLoadMore"]);
|
|
333
|
+
const { placeholder = 'Select an item', dropdownStyle, objectName, selectedItems, items, loading, popupClassName, groupSelectProps, renderExtraValues, customItemRenders, popoverProps, listEmptyProps, selectedListEmptyProps, selectedTreeData, onChangeSearch, onChange = () => { }, onSelectedTreeDataChange, onLoadMore } = props, restProps = __rest(props, ["placeholder", "dropdownStyle", "objectName", "selectedItems", "items", "loading", "popupClassName", "groupSelectProps", "renderExtraValues", "customItemRenders", "popoverProps", "listEmptyProps", "selectedListEmptyProps", "selectedTreeData", "onChangeSearch", "onChange", "onSelectedTreeDataChange", "onLoadMore"]);
|
|
318
334
|
// State
|
|
319
335
|
const [state, setState] = useState(initialState);
|
|
320
336
|
// Variables
|
|
@@ -323,11 +339,11 @@ export function MatchesAnySelect(props) {
|
|
|
323
339
|
? `${(_a = selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.map(item => item.title)) === null || _a === void 0 ? void 0 : _a[0]}${((_b = selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.slice(1)) === null || _b === void 0 ? void 0 : _b.length) ? `, and +${(_c = selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.slice(1)) === null || _c === void 0 ? void 0 : _c.length} more` : ''}` || []
|
|
324
340
|
: undefined;
|
|
325
341
|
// Handlers
|
|
326
|
-
const onApplyMatchesAny = (selectedItems) => {
|
|
327
|
-
onChange(selectedItems);
|
|
342
|
+
const onApplyMatchesAny = (selectedItems, selectedTreeData) => {
|
|
343
|
+
onChange(selectedItems, selectedTreeData);
|
|
328
344
|
setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false })));
|
|
329
345
|
};
|
|
330
|
-
return (React.createElement(Popover, Object.assign({ open: isOpenPopover, arrow: false, placement: "bottomLeft", content: React.createElement(MatchesAny, { className: popupClassName, items: items, selectedItems: selectedItems, loading: loading, objectName: objectName, groupSelectProps: groupSelectProps, renderExtraValues: renderExtraValues, customItemRenders: customItemRenders, listEmptyProps: listEmptyProps, selectedListEmptyProps: selectedListEmptyProps, onChangeSearch: onChangeSearch, onApply: onApplyMatchesAny, onCancel: () => setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false }))), onLoadMore: onLoadMore }), align: {
|
|
346
|
+
return (React.createElement(Popover, Object.assign({ open: isOpenPopover, arrow: false, placement: "bottomLeft", content: React.createElement(MatchesAny, { className: popupClassName, items: items, selectedItems: selectedItems, loading: loading, objectName: objectName, groupSelectProps: groupSelectProps, renderExtraValues: renderExtraValues, customItemRenders: customItemRenders, listEmptyProps: listEmptyProps, selectedListEmptyProps: selectedListEmptyProps, selectedTreeData: selectedTreeData, onChangeSearch: onChangeSearch, onApply: onApplyMatchesAny, onCancel: () => setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false }))), onLoadMore: onLoadMore, onSelectedTreeDataChange: onSelectedTreeDataChange }), align: {
|
|
331
347
|
overflow: {
|
|
332
348
|
shiftY: 0,
|
|
333
349
|
shiftX: 0,
|
|
@@ -6,26 +6,6 @@ export const SAMPLE_DATA = [
|
|
|
6
6
|
{
|
|
7
7
|
key: '12179',
|
|
8
8
|
title: 'Untitled Project#2024-06-27 09:40:18',
|
|
9
|
-
children: [
|
|
10
|
-
{
|
|
11
|
-
key: '3j2i',
|
|
12
|
-
title: 'dsjfioasdjf',
|
|
13
|
-
children: [
|
|
14
|
-
{
|
|
15
|
-
key: '3j2323i323',
|
|
16
|
-
title: 'fewfwe',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
key: '3j2323i',
|
|
20
|
-
title: 'me owi',
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
key: '3j2i-1',
|
|
26
|
-
title: 'dsjfioasdjf',
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
9
|
},
|
|
30
10
|
{
|
|
31
11
|
key: '11923',
|
|
@@ -3,7 +3,7 @@ import { ReactNode } from 'react';
|
|
|
3
3
|
import type { EmptyDataProps, SelectProps } from '@antscorp/antsomi-ui/es/components/molecules';
|
|
4
4
|
import type { FlexProps, PopoverProps } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
5
5
|
import { PopoverSelectProps } from '../SearchPopover/types';
|
|
6
|
-
export type MatchesAnyItem<TItem =
|
|
6
|
+
export type MatchesAnyItem<TItem = any> = TreeDataNode & {
|
|
7
7
|
/** Addition title of the item. */
|
|
8
8
|
subTitle?: string;
|
|
9
9
|
/** Indicates whether the item is extended */
|
|
@@ -17,7 +17,7 @@ export type GroupSelectProps = PopoverSelectProps & {
|
|
|
17
17
|
/** Name of the group select to be displayed */
|
|
18
18
|
name?: string;
|
|
19
19
|
};
|
|
20
|
-
export type RenderExtraValue<TItem =
|
|
20
|
+
export type RenderExtraValue<TItem = any> = {
|
|
21
21
|
key: keyof MatchesAnyItem<TItem>;
|
|
22
22
|
label: string;
|
|
23
23
|
render?: (item: MatchesAnyItem<TItem>) => ReactNode | ReactNode;
|
|
@@ -27,7 +27,7 @@ export type CustomItemRenders<TItem> = {
|
|
|
27
27
|
subTitle?: (item: MatchesAnyItem<TItem>) => ReactNode;
|
|
28
28
|
error?: (item: MatchesAnyItem<TItem>) => ReactNode;
|
|
29
29
|
};
|
|
30
|
-
export interface MatchesAnySelectProps<TItem =
|
|
30
|
+
export interface MatchesAnySelectProps<TItem = any> extends Omit<SelectProps, 'onChange'> {
|
|
31
31
|
/** The name of object to be displayed in Popover */
|
|
32
32
|
objectName?: string;
|
|
33
33
|
/** Indicates whether show the extend value button */
|
|
@@ -36,6 +36,8 @@ export interface MatchesAnySelectProps<TItem = Record<string, any>> extends Sele
|
|
|
36
36
|
items?: MatchesAnyItem<TItem>[];
|
|
37
37
|
/** An array of selected items. */
|
|
38
38
|
selectedItems?: MatchesAnyItem<TItem>[];
|
|
39
|
+
/** Selected Tree Data serve for case items not load complete for showing fully displayed selected items */
|
|
40
|
+
selectedTreeData?: MatchesAnyItem<TItem>[];
|
|
39
41
|
/** The properties of the group select */
|
|
40
42
|
groupSelectProps?: GroupSelectProps;
|
|
41
43
|
/** An array of render extra values */
|
|
@@ -48,20 +50,22 @@ export interface MatchesAnySelectProps<TItem = Record<string, any>> extends Sele
|
|
|
48
50
|
listEmptyProps?: EmptyDataProps;
|
|
49
51
|
/** Empty UI for selected list items */
|
|
50
52
|
selectedListEmptyProps?: EmptyDataProps;
|
|
53
|
+
/** Callback function when selectedTreeData change */
|
|
54
|
+
onSelectedTreeDataChange?: (selectedTreeData: MatchesAnyItem<TItem>[]) => void;
|
|
51
55
|
/** Callback function that is called when the selected items change. */
|
|
52
|
-
onChange?: (selectedItems: MatchesAnyItem<TItem>[]) => void;
|
|
56
|
+
onChange?: (selectedItems: MatchesAnyItem<TItem>[], selectedTreeData?: MatchesAnyItem<TItem>[]) => void;
|
|
53
57
|
/** Callback function that is called when the search value changes */
|
|
54
58
|
onChangeSearch?: (searchValue: string) => void;
|
|
55
59
|
/** Callback function that is called when the user scroll */
|
|
56
60
|
onLoadMore?: () => void;
|
|
57
61
|
}
|
|
58
|
-
export interface MatchesAnyProps<TItem =
|
|
62
|
+
export interface MatchesAnyProps<TItem = any> extends Omit<FlexProps, 'children'>, Pick<MatchesAnySelectProps<TItem>, 'objectName' | 'loading' | 'showExtendValue' | 'items' | 'selectedItems' | 'onLoadMore' | 'groupSelectProps' | 'onChangeSearch' | 'renderExtraValues' | 'customItemRenders' | 'listEmptyProps' | 'selectedListEmptyProps' | 'selectedTreeData' | 'onSelectedTreeDataChange'> {
|
|
59
63
|
/**
|
|
60
64
|
* Callback function that is called when the apply action is triggered.
|
|
61
65
|
*
|
|
62
66
|
* @param selectedItems - The array of selected items.
|
|
63
67
|
*/
|
|
64
|
-
onApply?: (selectedItems: MatchesAnyItem<TItem>[]) => void;
|
|
68
|
+
onApply?: (selectedItems: MatchesAnyItem<TItem>[], selectedTreeData?: MatchesAnyItem<TItem>[]) => void;
|
|
65
69
|
/** Callback function that is called when the cancel action is triggered. */
|
|
66
70
|
onCancel?: () => void;
|
|
67
71
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Types
|
|
2
|
+
import deepmerge from 'deepmerge';
|
|
3
|
+
// Utils
|
|
4
|
+
import { flatTree } from '@antscorp/antsomi-ui/es/utils';
|
|
5
|
+
import { uniqBy } from 'lodash';
|
|
6
|
+
export const getSelectedTreeData = (items, selectedItems, selectedTreeData = []) => {
|
|
7
|
+
const notExtendValueSelectedItems = (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.filter(item => !item.isExtendValue)) || [];
|
|
8
|
+
const extendValueSelectedItems = (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.filter(item => item.isExtendValue)) || [];
|
|
9
|
+
const serializeTreeData = (list) => {
|
|
10
|
+
var _a;
|
|
11
|
+
return ((_a = list
|
|
12
|
+
.filter(item => {
|
|
13
|
+
/**
|
|
14
|
+
* Checks if the given item or any of its descendants are selected.
|
|
15
|
+
*
|
|
16
|
+
* If the item has children, it flattens the children tree structure and checks if any node is selected.
|
|
17
|
+
* If the item does not have children, it directly checks if the item is in the selected items list.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
const isSelected = item.children
|
|
21
|
+
? flatTree(item.children, 'children').some(item => notExtendValueSelectedItems === null || notExtendValueSelectedItems === void 0 ? void 0 : notExtendValueSelectedItems.some(selectedItem => selectedItem.key === item.key))
|
|
22
|
+
: notExtendValueSelectedItems === null || notExtendValueSelectedItems === void 0 ? void 0 : notExtendValueSelectedItems.some(selectedItem => selectedItem.key === item.key);
|
|
23
|
+
return isSelected;
|
|
24
|
+
})) === null || _a === void 0 ? void 0 : _a.map(item => (Object.assign(Object.assign({}, item), (item.children && {
|
|
25
|
+
children: serializeTreeData(item.children),
|
|
26
|
+
}))))) || [];
|
|
27
|
+
};
|
|
28
|
+
const mergeItems = deepmerge(selectedTreeData || [], items || [], {
|
|
29
|
+
arrayMerge(target, source) {
|
|
30
|
+
return uniqBy([...target, ...source], 'key');
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return serializeTreeData(mergeItems).concat(extendValueSelectedItems);
|
|
34
|
+
};
|
|
@@ -13,7 +13,7 @@ type OnApplyFilterMetricConditionValue = {
|
|
|
13
13
|
export declare const useAddFilterCondition: () => {
|
|
14
14
|
filters: import("../types").FilterItem[] | undefined;
|
|
15
15
|
matchesAny: {
|
|
16
|
-
list?:
|
|
16
|
+
list?: any[] | undefined;
|
|
17
17
|
isLoading?: boolean | undefined;
|
|
18
18
|
} | undefined;
|
|
19
19
|
setState: import("react").Dispatch<import("react").SetStateAction<TState>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antscorp/antsomi-ui",
|
|
3
|
-
"version": "1.3.5-beta.
|
|
3
|
+
"version": "1.3.5-beta.699",
|
|
4
4
|
"description": "An enterprise-class UI design language and React UI library.",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"dist/*",
|
|
@@ -94,6 +94,7 @@
|
|
|
94
94
|
"currency-formatter": "1.5.9",
|
|
95
95
|
"d3-interpolate": "^3.0.1",
|
|
96
96
|
"dayjs": "^1.11.10",
|
|
97
|
+
"deepmerge": "^4.3.1",
|
|
97
98
|
"fabric": "^5.3.0",
|
|
98
99
|
"font-awesome": "4.7.0",
|
|
99
100
|
"highlight.js": "^11.8.0",
|
|
@@ -236,6 +237,7 @@
|
|
|
236
237
|
"tsconfig-paths-webpack-plugin": "^4.0.1",
|
|
237
238
|
"type-fest": "^4.10.2",
|
|
238
239
|
"tsx": "^4.16.2",
|
|
240
|
+
"type-fest": "^4.10.2",
|
|
239
241
|
"typescript": "^5.4.3",
|
|
240
242
|
"vite": "^5.3.4",
|
|
241
243
|
"vite-plugin-commonjs": "^0.10.1",
|