@antscorp/antsomi-ui 1.3.5-beta.457 → 1.3.5-beta.458
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.js +45 -26
- package/es/components/molecules/MatchAnySelect/index.d.ts +3 -1
- package/es/components/molecules/MatchAnySelect/index.js +2 -1
- package/es/components/molecules/MatchAnySelect/types.d.ts +21 -0
- package/es/test.js +3 -1
- package/es/tests/MatchesAnySelect.d.ts +2 -0
- package/es/tests/MatchesAnySelect.js +10 -0
- package/es/tests/index.d.ts +1 -0
- package/es/tests/index.js +1 -0
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@ import { uniqBy } from 'lodash';
|
|
|
16
16
|
import React, { useMemo, useState } from 'react';
|
|
17
17
|
// Components
|
|
18
18
|
import { EmptyData, Select } from '@antscorp/antsomi-ui/es/components/molecules';
|
|
19
|
-
import { Button, Flex, Icon, Input, Scrollbars, Spin, Typography, } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
19
|
+
import { Button, Flex, Icon, Input, Popover, Scrollbars, Spin, Typography, Tooltip, } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
20
20
|
import { ExtendValuePopup } from './components/ExtendValuePopup';
|
|
21
21
|
// Styled
|
|
22
22
|
import { MatchesAnyWrapper, ActionButton, StyledTree, TextButton } from './styled';
|
|
@@ -24,13 +24,15 @@ import { MatchesAnyWrapper, ActionButton, StyledTree, TextButton } from './style
|
|
|
24
24
|
import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
|
|
25
25
|
import { translations } from '@antscorp/antsomi-ui/es/locales/translations';
|
|
26
26
|
// Constants
|
|
27
|
-
import { MATCHES_ANY_THEME
|
|
27
|
+
import { MATCHES_ANY_THEME } from './constants';
|
|
28
28
|
import { globalToken } from '@antscorp/antsomi-ui/es/constants';
|
|
29
29
|
// Hooks
|
|
30
|
-
import { useDeepCompareMemo } from '@antscorp/antsomi-ui/es/hooks';
|
|
30
|
+
import { useDeepCompareEffect, useDeepCompareMemo } from '@antscorp/antsomi-ui/es/hooks';
|
|
31
31
|
// Utils
|
|
32
32
|
import { flatTree, recursiveSearchItems } from '@antscorp/antsomi-ui/es/utils';
|
|
33
|
-
const initialState = {
|
|
33
|
+
const initialState = {
|
|
34
|
+
isOpenPopover: false,
|
|
35
|
+
};
|
|
34
36
|
const matchesAnyInitialState = {
|
|
35
37
|
searchValue: '',
|
|
36
38
|
selectedItems: [],
|
|
@@ -39,11 +41,18 @@ const { t } = i18nInstance;
|
|
|
39
41
|
const { Text } = Typography;
|
|
40
42
|
export const MatchesAny = props => {
|
|
41
43
|
// Props
|
|
42
|
-
const { objectName, isLoading = false, showExtendValue = true } = props, restOfProps = __rest(props, ["objectName", "isLoading", "showExtendValue"]);
|
|
44
|
+
const { objectName, isLoading = false, showExtendValue = true, items, onApply = () => { }, onCancel = () => { } } = props, restOfProps = __rest(props, ["objectName", "isLoading", "showExtendValue", "items", "onApply", "onCancel"]);
|
|
43
45
|
// State
|
|
44
46
|
const [state, setState] = useState(matchesAnyInitialState);
|
|
45
47
|
// Variables
|
|
46
48
|
const { searchValue, selectedItems } = state;
|
|
49
|
+
// Effects
|
|
50
|
+
/**
|
|
51
|
+
* Updates the `selectedItems` state when the `selectedItems` prop changes.
|
|
52
|
+
*/
|
|
53
|
+
useDeepCompareEffect(() => {
|
|
54
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { selectedItems: props.selectedItems })));
|
|
55
|
+
}, [props.selectedItems]);
|
|
47
56
|
// Handlers
|
|
48
57
|
/**
|
|
49
58
|
* Adds an item and, if applicable, its leaf descendants to the list of selected items.
|
|
@@ -87,7 +96,7 @@ export const MatchesAny = props => {
|
|
|
87
96
|
});
|
|
88
97
|
};
|
|
89
98
|
const onSelectAll = () => {
|
|
90
|
-
const flattenTreeData = flatTree(
|
|
99
|
+
const flattenTreeData = flatTree(items, 'children').filter(item => !item.children &&
|
|
91
100
|
!(selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.some(selectedItem => selectedItem.key === item.key || selectedItem.title === item.title)));
|
|
92
101
|
setState(prev => (Object.assign(Object.assign({}, prev), { selectedItems: uniqBy([...(prev.selectedItems || []), ...flattenTreeData], 'key') })));
|
|
93
102
|
};
|
|
@@ -115,7 +124,7 @@ export const MatchesAny = props => {
|
|
|
115
124
|
// Memos
|
|
116
125
|
const { treeData, matchedParents } = useMemo(() => {
|
|
117
126
|
const { results, matchedParents } = recursiveSearchItems({
|
|
118
|
-
list:
|
|
127
|
+
list: items || [],
|
|
119
128
|
searchKeys: ['title', 'key'],
|
|
120
129
|
searchValue,
|
|
121
130
|
childrenKey: 'children',
|
|
@@ -141,7 +150,7 @@ export const MatchesAny = props => {
|
|
|
141
150
|
});
|
|
142
151
|
const treeData = serializeTreeData(results);
|
|
143
152
|
return { treeData, matchedParents };
|
|
144
|
-
}, [searchValue, selectedItems]);
|
|
153
|
+
}, [items, searchValue, selectedItems]);
|
|
145
154
|
const selectedTreeData = useMemo(() => {
|
|
146
155
|
const notExtendValueSelectedItems = selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.filter(item => !item.isExtendValue);
|
|
147
156
|
const extendValueSelectedItems = selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.filter(item => item.isExtendValue);
|
|
@@ -164,8 +173,8 @@ export const MatchesAny = props => {
|
|
|
164
173
|
children: serializeTreeData(item.children),
|
|
165
174
|
}))))) || [];
|
|
166
175
|
};
|
|
167
|
-
return serializeTreeData(
|
|
168
|
-
}, [selectedItems]);
|
|
176
|
+
return serializeTreeData(items || []).concat((extendValueSelectedItems === null || extendValueSelectedItems === void 0 ? void 0 : extendValueSelectedItems.map(item => (Object.assign(Object.assign({}, item), { title: renderItemNodeTitle({ item, onRemoveItem }) })))) || []);
|
|
177
|
+
}, [items, selectedItems]);
|
|
169
178
|
const isDisableRemoveAll = useDeepCompareMemo(() => !(selectedTreeData === null || selectedTreeData === void 0 ? void 0 : selectedTreeData.length), [selectedTreeData]);
|
|
170
179
|
const isDisableSelectAll = useDeepCompareMemo(() => {
|
|
171
180
|
const flattenTreeData = flatTree(treeData, 'children');
|
|
@@ -180,14 +189,13 @@ export const MatchesAny = props => {
|
|
|
180
189
|
React.createElement(Input.CustomSearch, { placeholder: `${(_a = t(translations.global.search)) === null || _a === void 0 ? void 0 : _a.toString()}...`, onAfterChange: searchValue => setState(prev => (Object.assign(Object.assign({}, prev), { searchValue }))) }))),
|
|
181
190
|
React.createElement("div", { className: "matches-any__body" },
|
|
182
191
|
React.createElement(Flex, { align: "center", justify: "space-between" },
|
|
183
|
-
React.createElement(Text, { strong: true }, `${objectName} (${flatTree(
|
|
192
|
+
React.createElement(Text, { strong: true }, `${objectName} (${flatTree(items, 'children').filter(item => !item.children).length})`),
|
|
184
193
|
React.createElement(TextButton, { disabled: isDisableSelectAll, onClick: onSelectAll }, t(translations.global.selectAll).toString())),
|
|
185
194
|
React.createElement(Spin, { spinning: isLoading },
|
|
186
|
-
React.createElement(Scrollbars, { style: { height: '100%' } },
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}, color: globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw8 })) }))))));
|
|
195
|
+
React.createElement(Scrollbars, { style: { height: '100%' } }, (treeData === null || treeData === void 0 ? void 0 : treeData.length) ? (React.createElement(StyledTree, { key: searchValue, defaultExpandedKeys: matchedParents.map(item => item.key), selectable: false, treeData: treeData, switcherIcon: props => (React.createElement(Icon, { type: "icon-ants-caret-down", style: {
|
|
196
|
+
transform: props.expanded ? 'rotate(0)' : 'rotate(-90deg)',
|
|
197
|
+
transition: 'transform 0.3s ease',
|
|
198
|
+
}, color: globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw8 })) })) : (React.createElement(EmptyData, { showIcon: false, title: t(translations.noData).toString() })))))));
|
|
191
199
|
};
|
|
192
200
|
const renderSelectedList = () => (React.createElement("div", { className: "matches-any__section" },
|
|
193
201
|
React.createElement(Flex, { className: "matches-any__header", justify: "space-between" },
|
|
@@ -195,7 +203,7 @@ export const MatchesAny = props => {
|
|
|
195
203
|
React.createElement(TextButton, { disabled: isDisableRemoveAll, onClick: onRemoveAll }, t(translations.global.removeAll).toString())),
|
|
196
204
|
React.createElement("div", { className: "matches-any__body" },
|
|
197
205
|
React.createElement(Spin, { spinning: isLoading },
|
|
198
|
-
React.createElement(Scrollbars, { style: { height: '100%' } }, !(selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.length) ? (React.createElement(EmptyData, { icon: "icon-ants-
|
|
206
|
+
React.createElement(Scrollbars, { style: { height: '100%' } }, !(selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.length) ? (React.createElement(EmptyData, { icon: "icon-ants-database", description: t(translations.global.selectItemsFromList).toString() })) : (React.createElement(StyledTree, { selectable: false, treeData: selectedTreeData, switcherIcon: props => (React.createElement(Icon, { type: "icon-ants-caret-down", style: {
|
|
199
207
|
transform: props.expanded ? 'rotate(0)' : 'rotate(-90deg)',
|
|
200
208
|
transition: 'transform 0.3s ease',
|
|
201
209
|
}, color: globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw8 })) })))))));
|
|
@@ -221,17 +229,28 @@ export const MatchesAny = props => {
|
|
|
221
229
|
renderSelectedList()),
|
|
222
230
|
React.createElement(Flex, { className: "matches-any__footer", align: "center", justify: "space-between" },
|
|
223
231
|
React.createElement(Flex, { align: "center", gap: 10 },
|
|
224
|
-
React.createElement(Button, { type: "primary" }, t(translations.apply.title).toString()),
|
|
225
|
-
React.createElement(Button,
|
|
232
|
+
React.createElement(Button, { type: "primary", onClick: () => onApply(selectedItems || []) }, t(translations.apply.title).toString()),
|
|
233
|
+
React.createElement(Button, { onClick: () => onCancel() }, t(translations.cancel.title).toString())),
|
|
226
234
|
showExtendValue && (React.createElement(ExtendValuePopup, { onApply: onApplyExtendValue },
|
|
227
|
-
React.createElement(Button, { icon: React.createElement(Icon, { type: "icon-ants-empty-flag" }) },
|
|
235
|
+
React.createElement(Button, { icon: React.createElement(Icon, { type: "icon-ants-empty-flag" }) }, t(translations.extendValue.title).toString())))))));
|
|
228
236
|
};
|
|
229
237
|
export const MatchesAnySelect = props => {
|
|
230
|
-
|
|
238
|
+
var _a, _b, _c;
|
|
239
|
+
const { placeholder = 'Select an item', dropdownStyle, objectName, selectedItems, items, isLoading, onChange = () => { } } = props, restProps = __rest(props, ["placeholder", "dropdownStyle", "objectName", "selectedItems", "items", "isLoading", "onChange"]);
|
|
231
240
|
// State
|
|
232
|
-
const [state, setState] = useState(
|
|
233
|
-
//
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
241
|
+
const [state, setState] = useState(initialState);
|
|
242
|
+
// Variables
|
|
243
|
+
const { isOpenPopover } = state;
|
|
244
|
+
// Memo
|
|
245
|
+
const value = Array.isArray(selectedItems) && (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.length)
|
|
246
|
+
? `${(_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` : ''}` || []
|
|
247
|
+
: undefined;
|
|
248
|
+
// Handlers
|
|
249
|
+
const onApplyMatchesAny = (selectedItems) => {
|
|
250
|
+
onChange(selectedItems);
|
|
251
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false })));
|
|
252
|
+
};
|
|
253
|
+
return (React.createElement(Popover, { open: isOpenPopover, arrow: false, placement: "bottomLeft", content: React.createElement(MatchesAny, { items: items, selectedItems: selectedItems, isLoading: isLoading, objectName: objectName, style: { margin: '-8px 0px' }, onApply: onApplyMatchesAny, onCancel: () => setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false }))) }), overlayStyle: { width: 700 }, trigger: ['click'], destroyTooltipOnHide: true, onOpenChange: () => setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: !isOpenPopover }))) },
|
|
254
|
+
React.createElement(Tooltip, { mouseEnterDelay: 0.5, title: `${selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.map(item => item.title).join(', ')}` },
|
|
255
|
+
React.createElement(Select, Object.assign({}, restProps, { title: "", value: value, placeholder: placeholder, popupMatchSelectWidth: 700, dropdownStyle: Object.assign(Object.assign({}, dropdownStyle), { display: 'none', padding: 0 }) })))));
|
|
237
256
|
};
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export { MatchesAnySelect } from './MatchesAnySelect';
|
|
1
|
+
export { MatchesAnySelect, MatchesAny } from './MatchesAnySelect';
|
|
2
|
+
export type { MatchesAnyItem, MatchesAnyProps, MatchesAnySelectProps } from './types';
|
|
3
|
+
export { SAMPLE_DATA as MATCHES_ANY_SAMPLE_DATA } from './constants';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { MatchesAnySelect } from './MatchesAnySelect';
|
|
1
|
+
export { MatchesAnySelect, MatchesAny } from './MatchesAnySelect';
|
|
2
|
+
export { SAMPLE_DATA as MATCHES_ANY_SAMPLE_DATA } from './constants';
|
|
@@ -12,9 +12,30 @@ export interface MatchesAnySelectProps extends SelectProps {
|
|
|
12
12
|
isLoading?: boolean;
|
|
13
13
|
/** Indicates whether show the extend value button */
|
|
14
14
|
showExtendValue?: boolean;
|
|
15
|
+
/** An array of items. */
|
|
16
|
+
items?: MatchesAnyItem[];
|
|
17
|
+
/** An array of selected items. */
|
|
18
|
+
selectedItems?: MatchesAnyItem[];
|
|
19
|
+
/** Callback function that is called when the selected items change. */
|
|
20
|
+
onChange?: (selectedItems: MatchesAnyItem[]) => void;
|
|
15
21
|
}
|
|
16
22
|
export interface MatchesAnyProps extends Omit<FlexProps, 'children'> {
|
|
23
|
+
/** The name of the object, corresponding to the `objectName` property in `MatchesAnySelectProps`. */
|
|
17
24
|
objectName?: MatchesAnySelectProps['objectName'];
|
|
25
|
+
/** Indicates whether the component is in a loading state, corresponding to the `isLoading` property in `MatchesAnySelectProps`. */
|
|
18
26
|
isLoading?: MatchesAnySelectProps['isLoading'];
|
|
27
|
+
/** Determines whether to show the extended value, corresponding to the `showExtendValue` property in `MatchesAnySelectProps`. */
|
|
19
28
|
showExtendValue?: MatchesAnySelectProps['showExtendValue'];
|
|
29
|
+
/** An array of items. */
|
|
30
|
+
items?: MatchesAnySelectProps['items'];
|
|
31
|
+
/** An array of selected items. */
|
|
32
|
+
selectedItems?: MatchesAnySelectProps['selectedItems'];
|
|
33
|
+
/**
|
|
34
|
+
* Callback function that is called when the apply action is triggered.
|
|
35
|
+
*
|
|
36
|
+
* @param selectedItems - The array of selected items.
|
|
37
|
+
*/
|
|
38
|
+
onApply?: (selectedItems: MatchesAnyItem[]) => void;
|
|
39
|
+
/** Callback function that is called when the cancel action is triggered. */
|
|
40
|
+
onCancel?: () => void;
|
|
20
41
|
}
|
package/es/test.js
CHANGED
|
@@ -20,7 +20,7 @@ import axios from 'axios';
|
|
|
20
20
|
import { get } from 'lodash';
|
|
21
21
|
import { MENU_PERMISSION } from './components/molecules/ShareAccess/constants';
|
|
22
22
|
import { ConfigProvider } from './providers';
|
|
23
|
-
import { DataTableTest } from './tests';
|
|
23
|
+
import { DataTableTest, MatchesAnySelectTest } from './tests';
|
|
24
24
|
const SHARE_ACCESS_DEFAULT_VALUE = {
|
|
25
25
|
ownerId: 1600085510,
|
|
26
26
|
isPublic: 1,
|
|
@@ -106,6 +106,8 @@ export const App = () => {
|
|
|
106
106
|
const callbackSlideBar = (type, data) => {
|
|
107
107
|
console.log({ type, data });
|
|
108
108
|
};
|
|
109
|
+
/* MatchesAnySelect */
|
|
110
|
+
return React.createElement(MatchesAnySelectTest, null);
|
|
109
111
|
/* Data Table */
|
|
110
112
|
return React.createElement(DataTableTest, null);
|
|
111
113
|
// --------------------------- Test Layout 2.0 -------------------------------------------
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { MATCHES_ANY_SAMPLE_DATA, MatchesAnySelect } from '../components';
|
|
4
|
+
export const MatchesAnySelectTest = () => {
|
|
5
|
+
const [state, setState] = useState({
|
|
6
|
+
selectedItems: [],
|
|
7
|
+
items: MATCHES_ANY_SAMPLE_DATA,
|
|
8
|
+
});
|
|
9
|
+
return (React.createElement(MatchesAnySelect, { items: state.items, selectedItems: state.selectedItems, onChange: selectedItems => setState(prev => (Object.assign(Object.assign({}, prev), { selectedItems }))) }));
|
|
10
|
+
};
|
package/es/tests/index.d.ts
CHANGED
package/es/tests/index.js
CHANGED