@antscorp/antsomi-ui 1.3.5-beta.456 → 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/components/organism/LeftMenu/components/common/ChildMenu/index.js +1 -1
- package/es/components/organism/LeftMenu/constants/variables.d.ts +1 -0
- package/es/components/organism/LeftMenu/constants/variables.js +4 -1
- package/es/components/organism/LeftMenu/hooks/useLeftMenu.js +3 -2
- package/es/components/organism/LeftMenu/hooks/useNavigatePath.d.ts +1 -1
- package/es/components/organism/LeftMenu/hooks/useNavigatePath.js +3 -2
- package/es/components/organism/LeftMenu/hooks/usePermission.d.ts +1 -0
- package/es/components/organism/LeftMenu/hooks/usePermission.js +32 -3
- package/es/components/organism/LeftMenu/index.d.ts +1 -1
- package/es/components/organism/LeftMenu/utils/index.d.ts +1 -0
- package/es/components/organism/LeftMenu/utils/index.js +36 -15
- package/es/components/template/Layout/Layout.js +3 -2
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/components/OldLeftMenu/index.js +2 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/index.js +2 -0
- package/es/components/template/Layout/constants/menuCode.d.ts +1 -0
- package/es/components/template/Layout/constants/menuCode.js +1 -0
- package/es/components/template/Layout/constants/permission.d.ts +1 -0
- package/es/components/template/Layout/constants/permission.js +1 -0
- package/es/components/template/Layout/utils/permission.d.ts +1 -1
- package/es/components/template/Layout/utils/permission.js +9 -3
- 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
|
}
|
|
@@ -182,7 +182,7 @@ export const ChildMenu = memo(props => {
|
|
|
182
182
|
return !!icon || !!logo_url ? (React.createElement(Flex, { style: { flexShrink: 0 }, align: "center" }, !isNil(icon) ? (React.createElement(IconWrapper, null,
|
|
183
183
|
React.createElement(Icon, { type: icon }))) : !isNil(logo_url) ? (React.createElement(MenuItemImage, { imageUrl: logo_url, fallbackIcon: (_a = args === null || args === void 0 ? void 0 : args.parent) === null || _a === void 0 ? void 0 : _a.icon, className: classNames({ isActive: currentActiveItem === key }) })) : null)) : null;
|
|
184
184
|
};
|
|
185
|
-
const renderTitle = () => !menu_item_path || isRecommendation ? (renderLabel()) : isPushDifferentDomain(menu_item_domain, menu_item_path) ? (React.createElement("div", { onClick: () => navigatePath(menu_item_domain, menu_item_path), className: "menu-link" }, renderLabel())) : (React.createElement(Link, { to: getPath(menu_item_path), className: "menu-link", onClick: e => e.stopPropagation() }, renderLabel()));
|
|
185
|
+
const renderTitle = () => !menu_item_path || isRecommendation ? (renderLabel()) : isPushDifferentDomain(menu_item_domain, menu_item_path) ? (React.createElement("div", { onClick: () => navigatePath(menu_item_domain, menu_item_path), className: "menu-link" }, renderLabel())) : (React.createElement(Link, { to: getPath(menu_item_path, key), className: "menu-link", onClick: e => e.stopPropagation() }, renderLabel()));
|
|
186
186
|
return {
|
|
187
187
|
key,
|
|
188
188
|
label: (React.createElement(Flex, { gap: 10, align: "center", justify: "space-between", style: { height: '100%' } },
|
|
@@ -54,7 +54,10 @@ export const MARKETING_ROUTES = {
|
|
|
54
54
|
CHANNEL: '/gen2/:networkId/:user_id/marketing-hub/journeys/:channelId',
|
|
55
55
|
};
|
|
56
56
|
export const MARKETING_CHANNEL_KEY = { ALL_CHANNEL: 0, JOURNEY_ORCHESTRATION: 8 };
|
|
57
|
-
export const RENDER_OPTION = {
|
|
57
|
+
export const RENDER_OPTION = {
|
|
58
|
+
CHANNEL: 'destination_channel',
|
|
59
|
+
CHANNEL_GEN2: 'destination_channel_gen2',
|
|
60
|
+
};
|
|
58
61
|
/** SETTING APP */
|
|
59
62
|
export const SETTING_APP = {
|
|
60
63
|
CHANNEL_INTEGRATION: {
|
|
@@ -46,7 +46,7 @@ export const useLeftMenu = (props) => {
|
|
|
46
46
|
isShowPopover: false,
|
|
47
47
|
isExpandMenu: expandMenu || isOpenMenu,
|
|
48
48
|
});
|
|
49
|
-
const { mappingChildrenMenu, flattenMenuPermission, permissionMenu, activeItemPath } = usePermission();
|
|
49
|
+
const { mappingChildrenMenu, flattenMenuPermission, menuListPermission, permissionMenu, activeItemPath, } = usePermission();
|
|
50
50
|
const onMenuClick = useCallback((key, keyPath) => {
|
|
51
51
|
if (isRecommendation) {
|
|
52
52
|
setLeftMenuContextState({ customActiveCurrentKey: key });
|
|
@@ -200,13 +200,14 @@ export const useLeftMenu = (props) => {
|
|
|
200
200
|
useEffect(() => {
|
|
201
201
|
if (!isCustomized && !isRecommendation) {
|
|
202
202
|
// Callback function using at Layout when url change
|
|
203
|
-
onActiveMenuCodeChange === null || onActiveMenuCodeChange === void 0 ? void 0 : onActiveMenuCodeChange(activeItemPath, flattenMenuPermission);
|
|
203
|
+
onActiveMenuCodeChange === null || onActiveMenuCodeChange === void 0 ? void 0 : onActiveMenuCodeChange(activeItemPath, flattenMenuPermission, menuListPermission);
|
|
204
204
|
}
|
|
205
205
|
}, [
|
|
206
206
|
activeItemPath,
|
|
207
207
|
flattenMenuPermission,
|
|
208
208
|
isCustomized,
|
|
209
209
|
isRecommendation,
|
|
210
|
+
menuListPermission,
|
|
210
211
|
onActiveMenuCodeChange,
|
|
211
212
|
]);
|
|
212
213
|
useEffect(() => clearTimeout(timeoutPopover === null || timeoutPopover === void 0 ? void 0 : timeoutPopover.current), [timeoutPopover]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const useNavigatePath: () => {
|
|
2
2
|
isPushDifferentDomain: (domain: string | null, path: string | null) => boolean;
|
|
3
|
-
getPath: (path: string | null) => string;
|
|
3
|
+
getPath: (path: string | null, itemKey?: string) => string;
|
|
4
4
|
navigatePath: (domain: string | null, path: string | null) => void;
|
|
5
5
|
};
|
|
@@ -10,6 +10,7 @@ import { getGeneratePath } from '../utils';
|
|
|
10
10
|
import { hasSelectAccountPermission } from '../../../template/Layout/utils';
|
|
11
11
|
// Constants
|
|
12
12
|
import { ENV } from '@antscorp/antsomi-ui/es/config';
|
|
13
|
+
import { KEEP_HASH_PATH_CODE } from '../../../template/Layout/constants';
|
|
13
14
|
// Hooks
|
|
14
15
|
import { usePermission } from './usePermission';
|
|
15
16
|
export const useNavigatePath = () => {
|
|
@@ -37,9 +38,9 @@ export const useNavigatePath = () => {
|
|
|
37
38
|
}
|
|
38
39
|
return !!customDomain && customDomain !== ((_f = window.location) === null || _f === void 0 ? void 0 : _f.origin);
|
|
39
40
|
}, [isDev]);
|
|
40
|
-
const getPath = useCallback((path) => {
|
|
41
|
+
const getPath = useCallback((path, itemKey) => {
|
|
41
42
|
var _a;
|
|
42
|
-
if (path === null || path === void 0 ? void 0 : path.includes('#')) {
|
|
43
|
+
if ((path === null || path === void 0 ? void 0 : path.includes('#')) && !KEEP_HASH_PATH_CODE.includes(`${itemKey}`)) {
|
|
43
44
|
const customPath = ((_a = path === null || path === void 0 ? void 0 : path.split('#')) === null || _a === void 0 ? void 0 : _a[1]) || '';
|
|
44
45
|
return getGeneratePath(customPath, auth);
|
|
45
46
|
}
|
|
@@ -2,5 +2,6 @@ export declare const usePermission: () => {
|
|
|
2
2
|
mappingChildrenMenu: import("@antscorp/antsomi-ui/es/models/LeftMenu").TFeatureMenu[];
|
|
3
3
|
permissionMenu: import("@antscorp/antsomi-ui/es/models/LeftMenu").TFeatureMenu[];
|
|
4
4
|
activeItemPath: import("@antscorp/antsomi-ui/es/models/LeftMenu").TFeatureMenu[];
|
|
5
|
+
menuListPermission: import("@antscorp/antsomi-ui/es/models/LeftMenu").FeatureMenuPermission[] | undefined;
|
|
5
6
|
flattenMenuPermission: import("@antscorp/antsomi-ui/es/models/LeftMenu").FeatureMenuPermission[];
|
|
6
7
|
};
|
|
@@ -58,7 +58,7 @@ export const usePermission = () => {
|
|
|
58
58
|
});
|
|
59
59
|
const { ownedDashboard = [], sharedDashboard = [] } = (dashboardData === null || dashboardData === void 0 ? void 0 : dashboardData.entries) || {};
|
|
60
60
|
const dashboardList = useMemo(() => uniqBy([...ownedDashboard, ...sharedDashboard], 'dashboardId'), [ownedDashboard, sharedDashboard]);
|
|
61
|
-
const { data:
|
|
61
|
+
const { data: destinationChannelGen2 } = useGetDestinationChannel({
|
|
62
62
|
args: {
|
|
63
63
|
auth: {
|
|
64
64
|
token: auth === null || auth === void 0 ? void 0 : auth.token,
|
|
@@ -72,6 +72,20 @@ export const usePermission = () => {
|
|
|
72
72
|
},
|
|
73
73
|
},
|
|
74
74
|
});
|
|
75
|
+
const { data: destinationChannel } = useGetDestinationChannel({
|
|
76
|
+
args: {
|
|
77
|
+
auth: {
|
|
78
|
+
token: auth === null || auth === void 0 ? void 0 : auth.token,
|
|
79
|
+
url: env ? `${CDP_API[env]}/hub` : '',
|
|
80
|
+
userId: auth === null || auth === void 0 ? void 0 : auth.userId,
|
|
81
|
+
portalId: auth === null || auth === void 0 ? void 0 : auth.portalId,
|
|
82
|
+
},
|
|
83
|
+
params: {
|
|
84
|
+
objectType: 'DESTINATION',
|
|
85
|
+
languageCode,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
});
|
|
75
89
|
const { data: menuListPermission } = useGetListMenuPermission({
|
|
76
90
|
args: {
|
|
77
91
|
auth: {
|
|
@@ -95,8 +109,16 @@ export const usePermission = () => {
|
|
|
95
109
|
auth,
|
|
96
110
|
dashboardList,
|
|
97
111
|
destinationChannelEntries: destinationChannel === null || destinationChannel === void 0 ? void 0 : destinationChannel.entries,
|
|
112
|
+
destinationChannelGen2Entries: destinationChannelGen2 === null || destinationChannelGen2 === void 0 ? void 0 : destinationChannelGen2.entries,
|
|
113
|
+
isRecommendation,
|
|
114
|
+
}), [
|
|
115
|
+
auth,
|
|
116
|
+
dashboardList,
|
|
117
|
+
destinationChannel === null || destinationChannel === void 0 ? void 0 : destinationChannel.entries,
|
|
118
|
+
destinationChannelGen2 === null || destinationChannelGen2 === void 0 ? void 0 : destinationChannelGen2.entries,
|
|
98
119
|
isRecommendation,
|
|
99
|
-
|
|
120
|
+
permissionMenu,
|
|
121
|
+
]);
|
|
100
122
|
const activeItemPath = useMemo(() => {
|
|
101
123
|
const url = `${pathname}${hash}`;
|
|
102
124
|
const matchedCode = findLastMatchedItemByUrl({
|
|
@@ -113,6 +135,7 @@ export const usePermission = () => {
|
|
|
113
135
|
: [];
|
|
114
136
|
}, [auth, env, hash, mappingChildrenMenu, pathname]);
|
|
115
137
|
useEffect(() => setLeftMenuState({ dashboardList }), [dashboardList, setLeftMenuState]);
|
|
138
|
+
console.log({ menuList, menuListPermission, mappingChildrenMenu });
|
|
116
139
|
useEffect(() => {
|
|
117
140
|
if (!isCustomized) {
|
|
118
141
|
const receivePostMessage = (event) => {
|
|
@@ -132,5 +155,11 @@ export const usePermission = () => {
|
|
|
132
155
|
}
|
|
133
156
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
134
157
|
}, []);
|
|
135
|
-
return {
|
|
158
|
+
return {
|
|
159
|
+
mappingChildrenMenu,
|
|
160
|
+
permissionMenu,
|
|
161
|
+
activeItemPath,
|
|
162
|
+
menuListPermission,
|
|
163
|
+
flattenMenuPermission,
|
|
164
|
+
};
|
|
136
165
|
};
|
|
@@ -20,6 +20,6 @@ export interface LeftMenuProps {
|
|
|
20
20
|
expandMenu?: boolean;
|
|
21
21
|
onMenuItemClick?: (key: string, keyPath: string[]) => void;
|
|
22
22
|
};
|
|
23
|
-
onActiveMenuCodeChange?: (activeItemPath: TFeatureMenu[], flattenPermissionList?: FeatureMenuPermission[]) => void;
|
|
23
|
+
onActiveMenuCodeChange?: (activeItemPath: TFeatureMenu[], flattenPermissionList?: FeatureMenuPermission[], menuListPermission?: FeatureMenuPermission[]) => void;
|
|
24
24
|
}
|
|
25
25
|
export declare const LeftMenu: React.MemoExoticComponent<(props: LeftMenuProps) => React.JSX.Element | null>;
|
|
@@ -66,6 +66,7 @@ export declare const getMappingAppChildren: (args: {
|
|
|
66
66
|
auth?: Partial<PayloadInfo>;
|
|
67
67
|
dashboardList?: TDashboard[];
|
|
68
68
|
destinationChannelEntries?: TDestinationChannel[];
|
|
69
|
+
destinationChannelGen2Entries?: TDestinationChannel[];
|
|
69
70
|
isRecommendation?: boolean;
|
|
70
71
|
}) => TFeatureMenu[];
|
|
71
72
|
/**
|
|
@@ -13,7 +13,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
import { cloneDeep, isArray, isEmpty, sortBy } from 'lodash';
|
|
14
14
|
// Constants
|
|
15
15
|
import { APP_KEYS, MARKETING_CHANNEL_KEY, HOME_MENU_ITEMS, MARKETING_ROUTES, MENU_ITEM_TYPE, RENDER_OPTION, HOME_REPORT_ROUTES, SETTING_APP, } from '../constants';
|
|
16
|
-
import { MARKETING_CHANNEL_CODE } from '../../../template/Layout/constants';
|
|
16
|
+
import { MARKETING_CHANNEL_CODE, KEEP_HASH_PATH_CODE } from '../../../template/Layout/constants';
|
|
17
17
|
// Utils
|
|
18
18
|
import { handleError } from '@antscorp/antsomi-ui/es/utils';
|
|
19
19
|
import { ENV } from '@antscorp/antsomi-ui/es/config';
|
|
@@ -132,7 +132,7 @@ export const recursiveGetMenuItemByPermission = (featureMenuItem) => {
|
|
|
132
132
|
};
|
|
133
133
|
/** Map children to each App Item */
|
|
134
134
|
export const getMappingAppChildren = (args) => {
|
|
135
|
-
const { menuList, dashboardList, auth, destinationChannelEntries, isRecommendation } = args;
|
|
135
|
+
const { menuList, dashboardList, auth, destinationChannelEntries, destinationChannelGen2Entries, isRecommendation, } = args;
|
|
136
136
|
const recursiveAddRenderOption = (menuItem) => {
|
|
137
137
|
var _a;
|
|
138
138
|
const cloneMenuItem = cloneDeep(menuItem);
|
|
@@ -140,8 +140,6 @@ export const getMappingAppChildren = (args) => {
|
|
|
140
140
|
case RENDER_OPTION.CHANNEL: {
|
|
141
141
|
const path = (() => {
|
|
142
142
|
switch (menuItem.menu_item_code) {
|
|
143
|
-
case MARKETING_CHANNEL_CODE.CAMPAIGN:
|
|
144
|
-
return MARKETING_ROUTES.CHANNEL;
|
|
145
143
|
case SETTING_APP.CHANNEL_INTEGRATION.code:
|
|
146
144
|
return SETTING_APP.CHANNEL_INTEGRATION.path;
|
|
147
145
|
default:
|
|
@@ -158,6 +156,25 @@ export const getMappingAppChildren = (args) => {
|
|
|
158
156
|
}))))) || [];
|
|
159
157
|
break;
|
|
160
158
|
}
|
|
159
|
+
case RENDER_OPTION.CHANNEL_GEN2: {
|
|
160
|
+
const path = (() => {
|
|
161
|
+
switch (menuItem.menu_item_code) {
|
|
162
|
+
case MARKETING_CHANNEL_CODE.CAMPAIGN:
|
|
163
|
+
return MARKETING_ROUTES.CHANNEL;
|
|
164
|
+
default:
|
|
165
|
+
return '';
|
|
166
|
+
}
|
|
167
|
+
})();
|
|
168
|
+
cloneMenuItem.children =
|
|
169
|
+
(destinationChannelGen2Entries === null || destinationChannelGen2Entries === void 0 ? void 0 : destinationChannelGen2Entries.map(item => (Object.assign({}, getInitialFeatureMenuItem({
|
|
170
|
+
menu_item_code: item.channelCode,
|
|
171
|
+
menu_item_name: item.translateLabel,
|
|
172
|
+
logo_url: item.logoUrl,
|
|
173
|
+
menu_item_parent: menuItem.menu_item,
|
|
174
|
+
menu_item_path: getGeneratePath(path, Object.assign(Object.assign({}, auth), { channelId: item.channelId })),
|
|
175
|
+
}))))) || [];
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
161
178
|
default:
|
|
162
179
|
break;
|
|
163
180
|
}
|
|
@@ -206,9 +223,6 @@ export const getMappingAppChildren = (args) => {
|
|
|
206
223
|
default:
|
|
207
224
|
break;
|
|
208
225
|
}
|
|
209
|
-
// if (isRecommendation) {
|
|
210
|
-
// childMenuItem.permission_code = MARKETING_CHANNEL_CODE?.[childMenuItem.menu_item_code];
|
|
211
|
-
// }
|
|
212
226
|
return childMenuItem;
|
|
213
227
|
});
|
|
214
228
|
break;
|
|
@@ -237,10 +251,14 @@ export const findActiveAppCodeByUrl = (args) => {
|
|
|
237
251
|
const recursiveCheckHasActiveChild = (items) => {
|
|
238
252
|
let matchAppCode = false;
|
|
239
253
|
for (const item of items) {
|
|
240
|
-
if (
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
254
|
+
if (item === null || item === void 0 ? void 0 : item.menu_item_path) {
|
|
255
|
+
const comparePath = KEEP_HASH_PATH_CODE.includes(item.menu_item_code)
|
|
256
|
+
? getGeneratePath(item.menu_item_path, auth)
|
|
257
|
+
: getComparePath(getGeneratePath(item.menu_item_path, auth), env);
|
|
258
|
+
if (url.includes(comparePath)) {
|
|
259
|
+
matchAppCode = true;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
244
262
|
}
|
|
245
263
|
if ((item === null || item === void 0 ? void 0 : item.children) && item.children.length) {
|
|
246
264
|
matchAppCode = recursiveCheckHasActiveChild(item.children);
|
|
@@ -279,10 +297,13 @@ export const findLastMatchedItemByUrl = (args) => {
|
|
|
279
297
|
const matchedItems = [];
|
|
280
298
|
const recursiveFindActiveItem = (items, parentId) => {
|
|
281
299
|
for (const item of items) {
|
|
282
|
-
if (
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
300
|
+
if (item === null || item === void 0 ? void 0 : item.menu_item_path) {
|
|
301
|
+
const comparePath = KEEP_HASH_PATH_CODE.includes(item.menu_item_code)
|
|
302
|
+
? getGeneratePath(item.menu_item_path, auth)
|
|
303
|
+
: getComparePath(getGeneratePath(item.menu_item_path, auth), env);
|
|
304
|
+
if (url.includes(comparePath) && (!parentId || item.menu_item_parent === parentId)) {
|
|
305
|
+
matchedItems.push(item);
|
|
306
|
+
}
|
|
286
307
|
}
|
|
287
308
|
if ((item === null || item === void 0 ? void 0 : item.children) && item.children.length) {
|
|
288
309
|
recursiveFindActiveItem(item.children, String(item.menu_item));
|
|
@@ -121,12 +121,13 @@ export const Layout = memo(props => {
|
|
|
121
121
|
const _c = useDeepCompareMemo(() => merge(cloneDeep(leftMenuProps), cloneDeep(leftMenu)), [leftMenuProps, leftMenu, appConfig]), { className: leftMenuClassName, show: showLeftMenu = true } = _c, mergeLeftMenuProps = __rest(_c, ["className", "show"]);
|
|
122
122
|
const leftMenuAppConfig = useDeepCompareMemo(() => omit(Object.assign(Object.assign({}, appConfig), { permissionDomain }), ['setAppConfig']), [appConfig]);
|
|
123
123
|
const antsProcessingNotificationConfig = useMemo(() => (Object.assign({ permissionDomain, socketDomain: SOCKET_API, token, accountId: userId, userId, lang: languageCode, networkId: portalId }, processingNotificationProps)), [permissionDomain, token, userId, languageCode, portalId, processingNotificationProps]);
|
|
124
|
-
const onActiveMenuCodeChange = useCallback((activeItemPath, flattenPermissionList) => {
|
|
124
|
+
const onActiveMenuCodeChange = useCallback((activeItemPath, flattenPermissionList, menuListPermission) => {
|
|
125
125
|
var _a;
|
|
126
126
|
const activeMenuCode = (_a = activeItemPath === null || activeItemPath === void 0 ? void 0 : activeItemPath[(activeItemPath === null || activeItemPath === void 0 ? void 0 : activeItemPath.length) - 1]) === null || _a === void 0 ? void 0 : _a.menu_item_code;
|
|
127
127
|
setActiveMenuCode(activeMenuCode);
|
|
128
128
|
onActiveMenuChange === null || onActiveMenuChange === void 0 ? void 0 : onActiveMenuChange(activeMenuCode);
|
|
129
|
-
|
|
129
|
+
console.log({ activeItemPath, flattenPermissionList });
|
|
130
|
+
const hasRole = hasSelectAccountPermission(activeItemPath, flattenPermissionList, menuListPermission);
|
|
130
131
|
setShowAccountSelection(hasRole);
|
|
131
132
|
}, [onActiveMenuChange]);
|
|
132
133
|
return (React.createElement(LayoutWrapper, { showLeftMenu: !!showLeftMenu },
|
|
@@ -3,10 +3,12 @@ import React, { useLayoutEffect } from 'react';
|
|
|
3
3
|
// Components
|
|
4
4
|
import { MenuMapping, RecommendationImage } from './components';
|
|
5
5
|
import { Flex } from '../../../../atoms';
|
|
6
|
+
// Stores
|
|
6
7
|
import { useLayoutStore } from '../../stores';
|
|
7
8
|
export const RecommendationWorkspace = () => {
|
|
8
9
|
const setHeaderState = useLayoutStore(store => store.setHeaderState);
|
|
9
10
|
useLayoutEffect(() => {
|
|
11
|
+
document.title = 'Recommendation';
|
|
10
12
|
setHeaderState({
|
|
11
13
|
pageTitle: 'Recommendation',
|
|
12
14
|
});
|
|
@@ -14,4 +14,4 @@ export declare const checkingRoleScope: (args: {
|
|
|
14
14
|
scope?: number;
|
|
15
15
|
isExactly?: boolean;
|
|
16
16
|
}) => boolean;
|
|
17
|
-
export declare const hasSelectAccountPermission: (activeItemPath: TFeatureMenu[], flattenPermissionList?: FeatureMenuPermission[]) => boolean;
|
|
17
|
+
export declare const hasSelectAccountPermission: (activeItemPath: TFeatureMenu[], flattenPermissionList?: FeatureMenuPermission[], menuListPermission?: FeatureMenuPermission[]) => boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MENU_CODE, APP_ROLE_SCOPE, MENU_PERMISSIONS } from '../constants';
|
|
1
|
+
import { MENU_CODE, APP_ROLE_SCOPE, MENU_PERMISSIONS, KEEP_HASH_PATH_CODE } from '../constants';
|
|
2
2
|
import { isEmpty } from 'lodash';
|
|
3
3
|
const EDIT_ROLE = new Set(['CREATE', 'UPDATE', 'DELETE']);
|
|
4
4
|
/**
|
|
@@ -19,6 +19,7 @@ export const checkingRoleScope = (args) => {
|
|
|
19
19
|
MENU_CODE.EMAIL_TEMPLATE,
|
|
20
20
|
MENU_CODE.BATCH_STREAMING,
|
|
21
21
|
MENU_CODE.REALTIME_STREAMING,
|
|
22
|
+
MENU_CODE.DATA_SOURCE,
|
|
22
23
|
// MENU_CODE.SEGMENT,
|
|
23
24
|
// MENU_CODE.DESTINATIONS_HUB,
|
|
24
25
|
MENU_CODE.BUSINESS_OBJECT,
|
|
@@ -49,7 +50,7 @@ export const checkingRoleScope = (args) => {
|
|
|
49
50
|
}
|
|
50
51
|
return isOK;
|
|
51
52
|
};
|
|
52
|
-
export const hasSelectAccountPermission = (activeItemPath, flattenPermissionList) => {
|
|
53
|
+
export const hasSelectAccountPermission = (activeItemPath, flattenPermissionList, menuListPermission) => {
|
|
53
54
|
if (isEmpty(activeItemPath))
|
|
54
55
|
return false;
|
|
55
56
|
let roleScope = false;
|
|
@@ -70,7 +71,12 @@ export const hasSelectAccountPermission = (activeItemPath, flattenPermissionList
|
|
|
70
71
|
else {
|
|
71
72
|
permissionCode = activeItem.permission_code;
|
|
72
73
|
}
|
|
73
|
-
const menuPermission =
|
|
74
|
+
const menuPermission = (() => {
|
|
75
|
+
if (KEEP_HASH_PATH_CODE.includes(activeItem.menu_item_code)) {
|
|
76
|
+
// return;
|
|
77
|
+
}
|
|
78
|
+
return flattenPermissionList === null || flattenPermissionList === void 0 ? void 0 : flattenPermissionList.find(item => permissionCode === item.menu_code);
|
|
79
|
+
})();
|
|
74
80
|
if (menuPermission) {
|
|
75
81
|
const checkRoleScope = menuPermission
|
|
76
82
|
? checkingRoleScope({
|
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