@antscorp/antsomi-ui 2.0.6 → 2.0.8
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.
|
@@ -37,6 +37,7 @@ import { getSelectedTreeData } from './utils';
|
|
|
37
37
|
import { DataIcon, WarningIcon } from '../../icons';
|
|
38
38
|
const initialState = {
|
|
39
39
|
isOpenPopover: false,
|
|
40
|
+
searchValue: '',
|
|
40
41
|
};
|
|
41
42
|
const matchesAnyInitialState = {
|
|
42
43
|
searchValue: '',
|
|
@@ -48,11 +49,11 @@ const { t } = i18nInstance;
|
|
|
48
49
|
const { Text } = Typography;
|
|
49
50
|
export function MatchesAny(props) {
|
|
50
51
|
// Props
|
|
51
|
-
const { objectName, loading = false, showExtendValue = true, selectedItems: selectedItemsProp, items, groupSelectProps, renderExtraValues, customItemRenders, listEmptyProps, selectedListEmptyProps, selectedTreeData: selectedTreeDataProp, onApply = () => { }, onCancel = () => { }, onLoadMore = () => { }, onChangeSearch } = props, restOfProps = __rest(props, ["objectName", "loading", "showExtendValue", "selectedItems", "items", "groupSelectProps", "renderExtraValues", "customItemRenders", "listEmptyProps", "selectedListEmptyProps", "selectedTreeData", "onApply", "onCancel", "onLoadMore", "onChangeSearch"]);
|
|
52
|
+
const { objectName, loading = false, showExtendValue = true, selectedItems: selectedItemsProp, items, groupSelectProps, renderExtraValues, customItemRenders, listEmptyProps, selectedListEmptyProps, selectedTreeData: selectedTreeDataProp, searchValue = '', isExternalSearch, onApply = () => { }, onCancel = () => { }, onLoadMore = () => { }, onChangeSearch } = props, restOfProps = __rest(props, ["objectName", "loading", "showExtendValue", "selectedItems", "items", "groupSelectProps", "renderExtraValues", "customItemRenders", "listEmptyProps", "selectedListEmptyProps", "selectedTreeData", "searchValue", "isExternalSearch", "onApply", "onCancel", "onLoadMore", "onChangeSearch"]);
|
|
52
53
|
// State
|
|
53
54
|
const [state, setState] = useState(matchesAnyInitialState);
|
|
54
55
|
// Variables
|
|
55
|
-
const {
|
|
56
|
+
const { selectedItems, selectedTreeData, isShowLoadMoreEl } = state;
|
|
56
57
|
const _a = listEmptyProps || {}, { icon: listEmptyIcon, description: listEmptyDescription = t(translations.global.noResultsMatchesKeyWord).toString() } = _a, restListEmptyProps = __rest(_a, ["icon", "description"]);
|
|
57
58
|
const _b = selectedListEmptyProps || {}, { description: selectedListEmptyDescription = t(translations.global.selectItemsFromList).toString(), icon: selectedListEmptyIcon = React.createElement(DataIcon, { color: globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw5, size: 48 }) } = _b, restSelectedListEmptyProps = __rest(_b, ["description", "icon"]);
|
|
58
59
|
// Refs
|
|
@@ -115,13 +116,6 @@ export function MatchesAny(props) {
|
|
|
115
116
|
const newSelectedTreeData = getSelectedTreeData(items || [], newSelectedItems || [], selectedTreeData || []);
|
|
116
117
|
setState(prev => (Object.assign(Object.assign({}, prev), { selectedItems: newSelectedItems, selectedTreeData: newSelectedTreeData })));
|
|
117
118
|
};
|
|
118
|
-
const onSelectAll = () => {
|
|
119
|
-
const flattenTreeData = flatTree(items, 'children').filter(item => !item.children &&
|
|
120
|
-
!(selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.some(selectedItem => selectedItem.key === item.key || selectedItem.title === item.title)));
|
|
121
|
-
const newSelectedItems = uniqBy([...(state.selectedItems || []), ...flattenTreeData], 'key');
|
|
122
|
-
const newSelectedTreeData = getSelectedTreeData(items || [], newSelectedItems || [], selectedTreeData);
|
|
123
|
-
setState(prev => (Object.assign(Object.assign({}, prev), { selectedItems: newSelectedItems, selectedTreeData: newSelectedTreeData })));
|
|
124
|
-
};
|
|
125
119
|
const onRemoveAll = () => {
|
|
126
120
|
setState(prev => (Object.assign(Object.assign({}, prev), { selectedItems: [], selectedTreeData: [] })));
|
|
127
121
|
};
|
|
@@ -172,7 +166,7 @@ export function MatchesAny(props) {
|
|
|
172
166
|
const { results, matchedParents } = recursiveSearchItems({
|
|
173
167
|
list: items || [],
|
|
174
168
|
searchKeys: ['title', 'key'],
|
|
175
|
-
searchValue: !
|
|
169
|
+
searchValue: !isExternalSearch ? searchValue : '',
|
|
176
170
|
childrenKey: 'children',
|
|
177
171
|
});
|
|
178
172
|
const serializeTreeData = (list) => list.map(item => {
|
|
@@ -205,6 +199,7 @@ export function MatchesAny(props) {
|
|
|
205
199
|
title: '',
|
|
206
200
|
isLoadMore: true,
|
|
207
201
|
className: 'load-more-node',
|
|
202
|
+
disabled: true,
|
|
208
203
|
});
|
|
209
204
|
return { treeData, matchedParents };
|
|
210
205
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -214,6 +209,13 @@ export function MatchesAny(props) {
|
|
|
214
209
|
const flattenTreeData = flatTree(treeData, 'children');
|
|
215
210
|
return !(flattenTreeData === null || flattenTreeData === void 0 ? void 0 : flattenTreeData.some(item => !item.disabled));
|
|
216
211
|
}, [treeData]);
|
|
212
|
+
const isDisableApply = useDeepCompareMemo(() => isEmpty(selectedTreeData), [selectedTreeData]);
|
|
213
|
+
const onSelectAll = () => {
|
|
214
|
+
const flattenTreeData = flatTree(treeData, 'children').filter(item => !item.children && !item.disabled);
|
|
215
|
+
const newSelectedItems = uniqBy([...(state.selectedItems || []), ...flattenTreeData], 'key');
|
|
216
|
+
const newSelectedTreeData = getSelectedTreeData(items || [], newSelectedItems || [], selectedTreeData);
|
|
217
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { selectedItems: newSelectedItems, selectedTreeData: newSelectedTreeData })));
|
|
218
|
+
};
|
|
217
219
|
// Renders
|
|
218
220
|
const renderExtraValueLabels = () => {
|
|
219
221
|
if (renderExtraValues === null || renderExtraValues === void 0 ? void 0 : renderExtraValues.length) {
|
|
@@ -233,8 +235,7 @@ export function MatchesAny(props) {
|
|
|
233
235
|
":"),
|
|
234
236
|
`${((_a = groupSelectProps === null || groupSelectProps === void 0 ? void 0 : groupSelectProps.selected) === null || _a === void 0 ? void 0 : _a.length) || 0} ${t(translations.global.selected)}`))),
|
|
235
237
|
React.createElement("div", { style: { width: '100%' } },
|
|
236
|
-
React.createElement(Input.CustomSearch, { placeholder: `${(_b = t(translations.global.search)) === null || _b === void 0 ? void 0 : _b.toString()}...`, onAfterChange: searchValue => {
|
|
237
|
-
setState(prev => (Object.assign(Object.assign({}, prev), { searchValue })));
|
|
238
|
+
React.createElement(Input.CustomSearch, { value: searchValue, placeholder: `${(_b = t(translations.global.search)) === null || _b === void 0 ? void 0 : _b.toString()}...`, onAfterChange: searchValue => {
|
|
238
239
|
if (onChangeSearch) {
|
|
239
240
|
onChangeSearch(searchValue);
|
|
240
241
|
}
|
|
@@ -295,7 +296,7 @@ export function MatchesAny(props) {
|
|
|
295
296
|
renderSelectedList()),
|
|
296
297
|
React.createElement(Flex, { className: "matches-any__footer", align: "center", justify: "space-between" },
|
|
297
298
|
React.createElement(Flex, { align: "center", gap: 10 },
|
|
298
|
-
React.createElement(Button, { type: "primary", onClick: onClickApply }, t(translations.apply.title).toString()),
|
|
299
|
+
React.createElement(Button, { type: "primary", disabled: isDisableApply, onClick: onClickApply }, t(translations.apply.title).toString()),
|
|
299
300
|
React.createElement(Button, { onClick: () => onCancel() }, t(translations.cancel.title).toString())),
|
|
300
301
|
showExtendValue && (React.createElement(ExtendValuePopup, { getPopupContainer: trigger => trigger.parentElement || document.body, onApply: onApplyExtendValue },
|
|
301
302
|
React.createElement(Button, { icon: React.createElement(Icon, { type: "icon-ants-empty-flag" }) }, t(translations.extendValue.title).toString())))))));
|
|
@@ -310,12 +311,22 @@ export function MatchesAnySelect(props) {
|
|
|
310
311
|
const value = Array.isArray(selectedItems) && (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.length)
|
|
311
312
|
? `${(_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` : ''}` || []
|
|
312
313
|
: undefined;
|
|
314
|
+
// Effects
|
|
315
|
+
useDeepCompareEffect(() => {
|
|
316
|
+
if (props.searchValue && props.searchValue !== state.searchValue) {
|
|
317
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { searchValue: props.searchValue || '' })));
|
|
318
|
+
}
|
|
319
|
+
}, [props.searchValue, state.searchValue]);
|
|
313
320
|
// Handlers
|
|
314
321
|
const onApplyMatchesAny = (selectedItems, selectedTreeData) => {
|
|
315
322
|
onChange(selectedItems, selectedTreeData);
|
|
316
323
|
setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false })));
|
|
317
324
|
};
|
|
318
|
-
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:
|
|
325
|
+
return (React.createElement(Popover, Object.assign({ open: isOpenPopover, arrow: false, placement: "bottomLeft", content: React.createElement(MatchesAny, { isExternalSearch: !!onChangeSearch, searchValue: state.searchValue, className: popupClassName, items: items, selectedItems: selectedItems, loading: loading, objectName: objectName, groupSelectProps: groupSelectProps, renderExtraValues: renderExtraValues, customItemRenders: customItemRenders, listEmptyProps: listEmptyProps, selectedListEmptyProps: selectedListEmptyProps, selectedTreeData: selectedTreeData, onChangeSearch: searchValue => {
|
|
326
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { searchValue })));
|
|
327
|
+
if (onChangeSearch)
|
|
328
|
+
onChangeSearch(searchValue);
|
|
329
|
+
}, onApply: onApplyMatchesAny, onCancel: () => setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false }))), onLoadMore: onLoadMore }), align: {
|
|
319
330
|
overflow: {
|
|
320
331
|
shiftY: 0,
|
|
321
332
|
shiftX: 0,
|
|
@@ -50,6 +50,8 @@ export interface MatchesAnySelectProps<TItem = any> extends Omit<SelectProps, 'o
|
|
|
50
50
|
listEmptyProps?: EmptyDataProps;
|
|
51
51
|
/** Empty UI for selected list items */
|
|
52
52
|
selectedListEmptyProps?: EmptyDataProps;
|
|
53
|
+
/** Search value */
|
|
54
|
+
searchValue?: string;
|
|
53
55
|
/** Callback function that is called when the selected items change. */
|
|
54
56
|
onChange?: (selectedItems: MatchesAnyItem<TItem>[], selectedTreeData?: MatchesAnyItem<TItem>[]) => void;
|
|
55
57
|
/** Callback function that is called when the search value changes */
|
|
@@ -57,7 +59,9 @@ export interface MatchesAnySelectProps<TItem = any> extends Omit<SelectProps, 'o
|
|
|
57
59
|
/** Callback function that is called when the user scroll */
|
|
58
60
|
onLoadMore?: () => void;
|
|
59
61
|
}
|
|
60
|
-
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'> {
|
|
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' | 'searchValue'> {
|
|
63
|
+
/** Indicates handle search out of component */
|
|
64
|
+
isExternalSearch?: boolean;
|
|
61
65
|
/**
|
|
62
66
|
* Callback function that is called when the apply action is triggered.
|
|
63
67
|
*
|