@antscorp/antsomi-ui 1.3.5-beta.375 → 1.3.5-beta.377
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/assets/images/components/Layout/recommendation-human.png +0 -0
- package/es/assets/images/logo/antsomi_logo.png +0 -0
- package/es/assets/images/logo/favicon.png +0 -0
- package/es/components/organism/DataTable/components/ToolbarActionButton/index.js +1 -1
- package/es/components/organism/DataTable/contexts/DataTableContext.js +0 -1
- package/es/components/organism/LeftMenu/LeftMenu.d.ts +3 -0
- package/es/components/organism/LeftMenu/LeftMenu.js +107 -0
- package/es/components/organism/LeftMenu/components/CommonMenu/index.js +2 -2
- package/es/components/organism/LeftMenu/components/CustomMenu/index.d.ts +0 -1
- package/es/components/organism/LeftMenu/components/CustomMenu/index.js +5 -8
- package/es/components/organism/LeftMenu/components/HomeMenu/index.js +3 -3
- package/es/components/organism/LeftMenu/components/HomeMenu/useHomeMenu.d.ts +2 -1
- package/es/components/organism/LeftMenu/components/HomeMenu/useHomeMenu.js +9 -8
- package/es/components/organism/LeftMenu/components/common/ChildMenu/index.js +96 -48
- package/es/components/organism/LeftMenu/components/common/ChildMenu/styled.d.ts +3 -1
- package/es/components/organism/LeftMenu/components/common/ChildMenu/styled.js +29 -0
- package/es/components/organism/LeftMenu/components/common/ChildMenu/utils.d.ts +8 -0
- package/es/components/organism/LeftMenu/components/common/ChildMenu/utils.js +46 -0
- package/es/components/organism/LeftMenu/constants/variables.d.ts +1 -1
- package/es/components/organism/LeftMenu/constants/variables.js +28 -17
- package/es/components/organism/LeftMenu/contexts/index.d.ts +5 -0
- package/es/components/organism/LeftMenu/contexts/index.js +15 -0
- package/es/components/organism/LeftMenu/hooks/useLeftMenu.js +119 -46
- package/es/components/organism/LeftMenu/hooks/usePermission.js +7 -5
- package/es/components/organism/LeftMenu/index.d.ts +5 -5
- package/es/components/organism/LeftMenu/index.js +16 -85
- package/es/components/organism/LeftMenu/providers/index.d.ts +8 -0
- package/es/components/organism/LeftMenu/providers/index.js +8 -0
- package/es/components/organism/LeftMenu/stores/index.d.ts +7 -6
- package/es/components/organism/LeftMenu/stores/index.js +4 -7
- package/es/components/organism/LeftMenu/styled.d.ts +1 -0
- package/es/components/organism/LeftMenu/styled.js +2 -2
- package/es/components/organism/LeftMenu/utils/index.d.ts +6 -0
- package/es/components/organism/LeftMenu/utils/index.js +69 -18
- package/es/components/template/Layout/Layout.js +13 -8
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/components/OldLeftMenu/constants/index.d.ts +0 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/components/OldLeftMenu/constants/index.js +1 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/components/OldLeftMenu/index.d.ts +10 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/components/OldLeftMenu/index.js +65 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/components/OldLeftMenu/styled.d.ts +6 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/components/OldLeftMenu/styled.js +63 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/components/OldLeftMenu/types/index.d.ts +2 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/components/OldLeftMenu/types/index.js +1 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/components/OldLeftMenu/utils/index.d.ts +12 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/components/OldLeftMenu/utils/index.js +39 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/components/index.d.ts +1 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/components/index.js +1 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/index.d.ts +2 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/index.js +27 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/styled.d.ts +3 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/MenuMapping/styled.js +48 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/RecommendationImage/index.d.ts +2 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/RecommendationImage/index.js +14 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/RecommendationImage/styled.d.ts +4 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/RecommendationImage/styled.js +46 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/index.d.ts +2 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/components/index.js +2 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/index.d.ts +2 -0
- package/es/components/template/Layout/components/RecommendationWorkspace/index.js +9 -0
- package/es/components/template/Layout/components/index.d.ts +1 -0
- package/es/components/template/Layout/components/index.js +1 -0
- package/es/components/template/Layout/stores/index.d.ts +1 -0
- package/es/components/template/Layout/stores/index.js +1 -1
- package/es/components/template/TemplateListing/hooks/useTemplateListing.d.ts +6 -4
- package/es/components/template/TemplateListing/hooks/useTemplateListing.js +16 -2
- package/es/components/template/TemplateListing/utils.d.ts +11 -0
- package/es/components/template/TemplateListing/utils.js +18 -0
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +1 -0
- package/es/utils/variables.d.ts +1 -0
- package/es/utils/variables.js +9 -0
- package/package.json +1 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -23,7 +23,7 @@ export const ToolbarActionButtons = memo(props => {
|
|
|
23
23
|
const restProps = __rest(props, []);
|
|
24
24
|
// Store
|
|
25
25
|
const actionButtons = useDataTableContext(useShallow(store => store.toolbar.actionButtons));
|
|
26
|
-
console.log('🚀 ~
|
|
26
|
+
console.log('🚀 ~ actionButtons:', actionButtons);
|
|
27
27
|
if (!actionButtons)
|
|
28
28
|
return null;
|
|
29
29
|
// Handlers
|
|
@@ -10,6 +10,5 @@ export function useDataTableContext(selector) {
|
|
|
10
10
|
throw new Error('Missing DataTableContext.Provider in the tree');
|
|
11
11
|
const selectedState = useStore(store, selector);
|
|
12
12
|
const memoizedState = useDeepCompareMemo(() => selectedState, [selectedState]);
|
|
13
|
-
console.log('🚀 ~ state:', selectedState);
|
|
14
13
|
return useDeepCompareMemo(() => (isEqual(selectedState, memoizedState) ? memoizedState : selectedState), [selectedState, memoizedState]);
|
|
15
14
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
import React, { memo, useCallback, useMemo } from 'react';
|
|
3
|
+
import Icon from '@antscorp/icons';
|
|
4
|
+
import { Typography } from 'antd';
|
|
5
|
+
import classNames from 'classnames';
|
|
6
|
+
import { isNil, isString } from 'lodash';
|
|
7
|
+
import { Link } from 'react-router-dom';
|
|
8
|
+
// Styled
|
|
9
|
+
import { ChildMenuWrapper, ExpandWrapper, FeatureMenu, FeatureMenuItem, LeftMenuNav, LeftMenuNavWrapper, PopoverWrapper, NavLogoWrapper, FeatureMenuWrapper, IconWrapper, } from './styled';
|
|
10
|
+
// Constants
|
|
11
|
+
import { APP_KEYS } from './constants';
|
|
12
|
+
// Components
|
|
13
|
+
import { CustomMenu, CommonMenu, HomeMenu } from './components';
|
|
14
|
+
// Hooks
|
|
15
|
+
import { useLeftMenu, useNavigatePath } from './hooks';
|
|
16
|
+
const SubLogoAntsomi = 'https://st-media-template.antsomi.com/icons/antsomi/antsomi.png';
|
|
17
|
+
export const LeftMenuComponent = memo(props => {
|
|
18
|
+
const { style, className, customization, showLogo = true } = props;
|
|
19
|
+
const { isExpandable = true, isCustomized, isRecommendation, items = [], onMenuItemClick, } = customization || {};
|
|
20
|
+
const { state, activeAppCode, permissionMenu, customActiveAppKey, onToggleChildMenu, onMouseEnter, onMouseLeave, onHoverMenuBar, } = useLeftMenu(props);
|
|
21
|
+
const { isPushDifferentDomain, getPath, navigatePath } = useNavigatePath();
|
|
22
|
+
const childMenu = useMemo(() => {
|
|
23
|
+
const selectedFeatureKey = state.hoverItem ? state.hoverItem : activeAppCode;
|
|
24
|
+
if (isCustomized)
|
|
25
|
+
return React.createElement(CustomMenu, null);
|
|
26
|
+
switch (selectedFeatureKey) {
|
|
27
|
+
case APP_KEYS.HOME:
|
|
28
|
+
return React.createElement(HomeMenu, null);
|
|
29
|
+
default:
|
|
30
|
+
return React.createElement(CommonMenu, null);
|
|
31
|
+
}
|
|
32
|
+
}, [activeAppCode, isCustomized, state.hoverItem]);
|
|
33
|
+
const renderFeatureMenuItem = useCallback((item) => {
|
|
34
|
+
const { menu_item_name, menu_item, icon_name, menu_item_code, menu_item_path, menu_item_domain, } = item;
|
|
35
|
+
const isActive = activeAppCode === menu_item_code;
|
|
36
|
+
const isHover = state.hoverItem === menu_item_code;
|
|
37
|
+
const renderLabel = () => (React.createElement("li", { role: "menuitem", className: classNames({ isActive, isHover }) },
|
|
38
|
+
React.createElement(IconWrapper, null, isNil(icon_name) ? null : React.createElement(Icon, { type: icon_name })),
|
|
39
|
+
React.createElement(Typography.Text, null, menu_item_name),
|
|
40
|
+
React.createElement("div", { className: "popup-triangle" })));
|
|
41
|
+
return (React.createElement(FeatureMenuItem, { key: menu_item, onMouseEnter: () => onMouseEnter(menu_item_code) }, isString(menu_item_path) ? (isPushDifferentDomain(menu_item_domain, menu_item_path) ? (React.createElement("div", { onClick: () => navigatePath(menu_item_domain, menu_item_path) }, renderLabel())) : (React.createElement(Link, { to: getPath(menu_item_path), className: "menu-link" }, renderLabel()))) : (renderLabel())));
|
|
42
|
+
}, [activeAppCode, getPath, isPushDifferentDomain, navigatePath, onMouseEnter, state.hoverItem]);
|
|
43
|
+
const renderRecommendationMenuItem = useCallback((item) => {
|
|
44
|
+
const { menu_item_name, menu_item, icon_name, permission_code } = item;
|
|
45
|
+
const isActive = customActiveAppKey === permission_code;
|
|
46
|
+
const isHover = state.hoverItem === permission_code;
|
|
47
|
+
const renderLabel = () => (React.createElement("li", { role: "menuitem", className: classNames({ isActive, isHover }), onClick: () => onMenuItemClick === null || onMenuItemClick === void 0 ? void 0 : onMenuItemClick(permission_code || 'null', [permission_code || 'null']) },
|
|
48
|
+
React.createElement(IconWrapper, null, isNil(icon_name) ? null : React.createElement(Icon, { type: icon_name })),
|
|
49
|
+
React.createElement(Typography.Text, null, menu_item_name),
|
|
50
|
+
React.createElement("div", { className: "popup-triangle" })));
|
|
51
|
+
return (React.createElement(FeatureMenuItem, { key: menu_item, onMouseEnter: () => onMouseEnter(permission_code || 'null') }, renderLabel()));
|
|
52
|
+
}, [customActiveAppKey, onMenuItemClick, onMouseEnter, state.hoverItem]);
|
|
53
|
+
const renderCustomizedMenuItems = useCallback((items) => items === null || items === void 0 ? void 0 : items.map(item => {
|
|
54
|
+
const { key, icon, label } = item;
|
|
55
|
+
const isActive = key === customActiveAppKey;
|
|
56
|
+
const isHover = key === state.hoverItem;
|
|
57
|
+
return (React.createElement(FeatureMenuItem, { key: key, onClick: () => onMenuItemClick === null || onMenuItemClick === void 0 ? void 0 : onMenuItemClick(key, [key]), onMouseEnter: () => onMouseEnter(key) },
|
|
58
|
+
React.createElement("li", { role: "menuitem", className: classNames({ isActive, isHover }) },
|
|
59
|
+
React.createElement(IconWrapper, null, isNil(icon) ? null : React.createElement(Icon, { type: icon })),
|
|
60
|
+
React.createElement(Typography.Text, null, label),
|
|
61
|
+
isExpandable && React.createElement("div", { className: "popup-triangle" }))));
|
|
62
|
+
}), [customActiveAppKey, state.hoverItem, isExpandable, onMenuItemClick, onMouseEnter]);
|
|
63
|
+
const renderAppMenuItems = useCallback(() => {
|
|
64
|
+
var _a;
|
|
65
|
+
return isCustomized
|
|
66
|
+
? renderCustomizedMenuItems(items)
|
|
67
|
+
: (_a = permissionMenu === null || permissionMenu === void 0 ? void 0 : permissionMenu.filter(item => item.menu_item_code !== APP_KEYS.SETTINGS)) === null || _a === void 0 ? void 0 : _a.map(item => isRecommendation ? renderRecommendationMenuItem(item) : renderFeatureMenuItem(item));
|
|
68
|
+
}, [
|
|
69
|
+
isCustomized,
|
|
70
|
+
isRecommendation,
|
|
71
|
+
items,
|
|
72
|
+
permissionMenu,
|
|
73
|
+
renderCustomizedMenuItems,
|
|
74
|
+
renderFeatureMenuItem,
|
|
75
|
+
renderRecommendationMenuItem,
|
|
76
|
+
]);
|
|
77
|
+
const renderSettings = () => {
|
|
78
|
+
if (!isCustomized) {
|
|
79
|
+
const settingApp = permissionMenu === null || permissionMenu === void 0 ? void 0 : permissionMenu.find(item => item.menu_item_code === APP_KEYS.SETTINGS);
|
|
80
|
+
if (settingApp)
|
|
81
|
+
return isRecommendation
|
|
82
|
+
? renderRecommendationMenuItem(settingApp)
|
|
83
|
+
: renderFeatureMenuItem(settingApp);
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
};
|
|
87
|
+
return (React.createElement(LeftMenuNavWrapper, { style: style, "$isExpandMenu": state.isExpandMenu, className: className },
|
|
88
|
+
React.createElement(LeftMenuNav, { className: "left-menu-nav" },
|
|
89
|
+
React.createElement(FeatureMenuWrapper, { isExpandMenu: state.isExpandMenu, vertical: true },
|
|
90
|
+
showLogo && (React.createElement(NavLogoWrapper, { align: "center", justify: "center", onMouseEnter: onHoverMenuBar },
|
|
91
|
+
React.createElement("div", { className: "image-wrapper" },
|
|
92
|
+
React.createElement("img", { src: SubLogoAntsomi, alt: "Antsomi sub logo" })))),
|
|
93
|
+
React.createElement(FeatureMenu, { role: "menu", className: "antsomi-scroll-box", onMouseLeave: onMouseLeave },
|
|
94
|
+
React.createElement("div", { className: "menu-content scroll-content" }, renderAppMenuItems()),
|
|
95
|
+
React.createElement("div", { className: "nav-blank", onMouseEnter: onHoverMenuBar }),
|
|
96
|
+
React.createElement(PopoverWrapper, { className: "antsomi-scroll-box antsomi-child-menu-popover", onMouseLeave: onMouseLeave },
|
|
97
|
+
React.createElement("div", { className: "scroll-content", style: { width: '200px', maxHeight: '100%' } }, childMenu))),
|
|
98
|
+
React.createElement("div", { style: { flexShrink: 0 } }, renderSettings())),
|
|
99
|
+
isExpandable && !isRecommendation && (React.createElement(ExpandWrapper, { onMouseEnter: onMouseLeave },
|
|
100
|
+
React.createElement(Icon, { type: "icon-ants-expand-more", style: {
|
|
101
|
+
cursor: 'pointer',
|
|
102
|
+
fontSize: '20px',
|
|
103
|
+
transform: `rotate(${state.isExpandMenu ? '90deg' : '270deg'})`,
|
|
104
|
+
}, onClick: onToggleChildMenu })))),
|
|
105
|
+
React.createElement(ChildMenuWrapper, { isExpand: state.isExpandMenu && isExpandable, isMarginTop: showLogo, className: "antsomi-scroll-box" },
|
|
106
|
+
React.createElement("div", { className: "scroll-content", style: { width: '200px', maxHeight: '100%' } }, childMenu))));
|
|
107
|
+
});
|
|
@@ -3,11 +3,11 @@ import React, { memo, useMemo } from 'react';
|
|
|
3
3
|
// Components
|
|
4
4
|
import { ChildMenu } from '../common';
|
|
5
5
|
// Stores
|
|
6
|
-
import {
|
|
6
|
+
import { useLeftMenuContext } from '../../contexts';
|
|
7
7
|
// Utils
|
|
8
8
|
import { getMenuItem } from '../../utils';
|
|
9
9
|
export const CommonMenu = memo(() => {
|
|
10
|
-
const appMenuChildren =
|
|
10
|
+
const appMenuChildren = useLeftMenuContext(store => store.appMenuChildren);
|
|
11
11
|
const customChildren = useMemo(() => appMenuChildren === null || appMenuChildren === void 0 ? void 0 : appMenuChildren.map(item => getMenuItem(item)), [appMenuChildren]);
|
|
12
12
|
return React.createElement(ChildMenu, { items: customChildren });
|
|
13
13
|
});
|
|
@@ -3,12 +3,9 @@ import React, { memo } from 'react';
|
|
|
3
3
|
// Components
|
|
4
4
|
import { ChildMenu } from '../common';
|
|
5
5
|
// Hooks
|
|
6
|
-
import {
|
|
7
|
-
export const CustomMenu = memo((
|
|
8
|
-
const appCustomMenuChildren =
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
onMenuItemClick === null || onMenuItemClick === void 0 ? void 0 : onMenuItemClick(key, [...keyPath, customActiveAppKey]);
|
|
12
|
-
};
|
|
13
|
-
return React.createElement(ChildMenu, { items: appCustomMenuChildren, onMenuClick: handleMenuItemClick });
|
|
6
|
+
import { useLeftMenuContext } from '../../contexts';
|
|
7
|
+
export const CustomMenu = memo(() => {
|
|
8
|
+
const appCustomMenuChildren = useLeftMenuContext(store => store.customMenuChildren);
|
|
9
|
+
const onMenuClick = useLeftMenuContext(store => store.onMenuClick);
|
|
10
|
+
return React.createElement(ChildMenu, { items: appCustomMenuChildren, onMenuClick: onMenuClick });
|
|
14
11
|
});
|
|
@@ -46,13 +46,13 @@ import { useHomeMenu } from './useHomeMenu';
|
|
|
46
46
|
// },
|
|
47
47
|
// };
|
|
48
48
|
export const HomeMenu = memo(() => {
|
|
49
|
-
const { children, removedDashboardId, isDashboardRemoving, setRemovedDashboardId, onCreateNewReport, onMenuClick, onRemoveDashboard, } = useHomeMenu();
|
|
49
|
+
const { children, removedDashboardId, isDashboardRemoving, isRecommendation, setRemovedDashboardId, onCreateNewReport, onMenuClick, onRemoveDashboard, } = useHomeMenu();
|
|
50
50
|
return (React.createElement(React.Fragment, null,
|
|
51
51
|
React.createElement(HomeMenuWrapper, { gap: 10, vertical: true },
|
|
52
|
-
React.createElement(CreateButton, { type: "primary", onClick: onCreateNewReport },
|
|
52
|
+
!isRecommendation && (React.createElement(CreateButton, { type: "primary", onClick: onCreateNewReport },
|
|
53
53
|
React.createElement(Flex, { gap: 10, align: "center" },
|
|
54
54
|
React.createElement(Icon, { type: "icon-ants-plus-slim", style: { fontSize: 14 } }),
|
|
55
|
-
React.createElement("span", null, "Create"))),
|
|
55
|
+
React.createElement("span", null, "Create")))),
|
|
56
56
|
React.createElement("div", { className: "menu-list" },
|
|
57
57
|
React.createElement(ChildMenu, { items: children, onMenuClick: onMenuClick }))),
|
|
58
58
|
React.createElement(ModalWrapper, { open: !!removedDashboardId, centered: true, onCancel: () => setRemovedDashboardId(''), title: "Remove this dashboard", okText: "Confirm", cancelText: "Cancel", closable: false, okButtonProps: { loading: isDashboardRemoving }, onOk: onRemoveDashboard }, "Removing this dashboard will delete it permanently. Are you sure you want to perform this action?")));
|
|
@@ -3,12 +3,13 @@ export declare const useHomeMenu: () => {
|
|
|
3
3
|
children: import("@antscorp/antsomi-ui/es/components/organism/LeftMenu/types").TMenuItem[];
|
|
4
4
|
removedDashboardId: string;
|
|
5
5
|
isDashboardRemoving: boolean;
|
|
6
|
+
isRecommendation: boolean | undefined;
|
|
6
7
|
setRemovedDashboardId: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
7
8
|
onCreateNewReport: import("react").MouseEventHandler<HTMLElement>;
|
|
8
9
|
onOptionCallback: (args: {
|
|
9
10
|
menuItemKey: string;
|
|
10
11
|
optionKey: string;
|
|
11
12
|
}) => void;
|
|
12
|
-
onMenuClick: (key: string,
|
|
13
|
+
onMenuClick: (key: string, _keyPath: string[]) => void;
|
|
13
14
|
onRemoveDashboard: () => Promise<void>;
|
|
14
15
|
};
|
|
@@ -15,8 +15,8 @@ import { HOME_REPORT_ROUTES, HOME_ROUTE } from '../../constants';
|
|
|
15
15
|
import { API_RESPONSE_CODE, CDP_API } from '@antscorp/antsomi-ui/es/constants';
|
|
16
16
|
// Utils
|
|
17
17
|
import { getGeneratePath, getMenuItem } from '../../utils';
|
|
18
|
-
// Hooks
|
|
19
|
-
import {
|
|
18
|
+
// Hooks;
|
|
19
|
+
import { useLeftMenuContext } from '../../contexts';
|
|
20
20
|
import { useLayoutStore } from '@antscorp/antsomi-ui/es/components/template';
|
|
21
21
|
import { useCustomRouter } from '@antscorp/antsomi-ui/es/hooks';
|
|
22
22
|
// Queries
|
|
@@ -24,10 +24,11 @@ import { useUpdateTask } from '@antscorp/antsomi-ui/es/queries/LeftMenu';
|
|
|
24
24
|
export const useHomeMenu = () => {
|
|
25
25
|
const { pathname, search } = window.location;
|
|
26
26
|
const { navigate, replace } = useCustomRouter();
|
|
27
|
-
const appMenuChildren =
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
27
|
+
const appMenuChildren = useLeftMenuContext(store => store.appMenuChildren);
|
|
28
|
+
const isRecommendation = useLeftMenuContext(store => store.isRecommendation);
|
|
29
|
+
const auth = useLeftMenuContext(store => { var _a; return (_a = store.appConfig) === null || _a === void 0 ? void 0 : _a.auth; });
|
|
30
|
+
const env = useLeftMenuContext(store => { var _a; return (_a = store.appConfig) === null || _a === void 0 ? void 0 : _a.env; });
|
|
31
|
+
const dashboardParams = useLeftMenuContext(store => store.dashboardParams);
|
|
31
32
|
const onClickCreateDashboard = useLayoutStore(store => store.state.leftMenu.onClickCreateDashboard);
|
|
32
33
|
const [removedDashboardId, setRemovedDashboardId] = useState('');
|
|
33
34
|
const urlParams = useMemo(() => new URLSearchParams(search), [search]);
|
|
@@ -63,9 +64,8 @@ export const useHomeMenu = () => {
|
|
|
63
64
|
replace({ search: urlParams.toString() });
|
|
64
65
|
}
|
|
65
66
|
}, [auth, navigate, onClickCreateDashboard, replace, urlParams]);
|
|
66
|
-
const onMenuClick = useCallback((key,
|
|
67
|
+
const onMenuClick = useCallback((key, _keyPath) => {
|
|
67
68
|
const newPathName = getGeneratePath(HOME_REPORT_ROUTES.DETAIL, Object.assign(Object.assign({}, auth), { dashboardId: key }));
|
|
68
|
-
console.log('newPathName', newPathName);
|
|
69
69
|
if (newPathName !== pathname) {
|
|
70
70
|
navigate(newPathName);
|
|
71
71
|
}
|
|
@@ -86,6 +86,7 @@ export const useHomeMenu = () => {
|
|
|
86
86
|
children: customChildren,
|
|
87
87
|
removedDashboardId,
|
|
88
88
|
isDashboardRemoving,
|
|
89
|
+
isRecommendation,
|
|
89
90
|
setRemovedDashboardId,
|
|
90
91
|
onCreateNewReport,
|
|
91
92
|
onOptionCallback,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Libraries
|
|
2
|
-
import React, { memo,
|
|
2
|
+
import React, { memo, useLayoutEffect, useState } from 'react';
|
|
3
3
|
import Icon from '@antscorp/icons';
|
|
4
|
-
import {
|
|
4
|
+
import { isNil, uniq } from 'lodash';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
6
|
import { Link } from 'react-router-dom';
|
|
7
7
|
// Components
|
|
@@ -15,10 +15,11 @@ import { IconWrapper } from '../../../styled';
|
|
|
15
15
|
import { ICON_SIZE } from '../../../constants';
|
|
16
16
|
// Utils
|
|
17
17
|
import { findActiveAppCodeByUrl, findLastMatchedItemByUrl, getMenuItem } from '../../../utils';
|
|
18
|
-
import { recursiveFindParentOfActiveItem } from './utils';
|
|
18
|
+
import { findItemByPermissionCode, recursiveFindItemByKey, recursiveFindParentOfActiveItem, } from './utils';
|
|
19
19
|
// Hooks
|
|
20
|
-
import { useLeftMenuStore } from '../../../stores';
|
|
21
20
|
import { useNavigatePath } from '../../../hooks';
|
|
21
|
+
// Contexts
|
|
22
|
+
import { useLeftMenuContext } from '../../../contexts';
|
|
22
23
|
const styles = {
|
|
23
24
|
dropdownMenu: { width: '130px', padding: '8px 0' },
|
|
24
25
|
dotIcon: { marginTop: '2px', zIndex: 1000, flexShrink: 0, fontSize: 16 },
|
|
@@ -26,58 +27,77 @@ const styles = {
|
|
|
26
27
|
fontSize: ICON_SIZE,
|
|
27
28
|
color: 'inherit',
|
|
28
29
|
},
|
|
29
|
-
menuItemTitle: { flex: '1 1 0%', maxWidth: '100%' },
|
|
30
|
+
menuItemTitle: { flex: '1 1 0%', maxWidth: '100%', overflow: 'hidden' },
|
|
30
31
|
};
|
|
31
32
|
export const ChildMenu = memo(props => {
|
|
32
33
|
const { items = [], onMenuClick } = props;
|
|
33
|
-
const
|
|
34
|
-
const activeAppCode =
|
|
35
|
-
const menuItems =
|
|
36
|
-
const customItems =
|
|
37
|
-
const isCustomized =
|
|
38
|
-
const
|
|
39
|
-
const
|
|
34
|
+
const auth = useLeftMenuContext(store => { var _a; return (_a = store.appConfig) === null || _a === void 0 ? void 0 : _a.auth; });
|
|
35
|
+
const activeAppCode = useLeftMenuContext(store => store.activeAppCode);
|
|
36
|
+
const menuItems = useLeftMenuContext(store => store.menuItems);
|
|
37
|
+
const customItems = useLeftMenuContext(store => store.customItems);
|
|
38
|
+
const isCustomized = useLeftMenuContext(store => store.isCustomized);
|
|
39
|
+
const isRecommendation = useLeftMenuContext(store => store.isRecommendation);
|
|
40
|
+
const customActiveCurrentKey = useLeftMenuContext(store => store.customActiveCurrentKey);
|
|
41
|
+
const setLeftMenuState = useLeftMenuContext(store => store.setState);
|
|
40
42
|
const [currentActiveItem, setCurrentActiveItem] = useState('');
|
|
41
43
|
const [openKeys, setOpenKeys] = useState([]);
|
|
42
44
|
const { pathname, hash } = window.location;
|
|
43
45
|
const { isPushDifferentDomain, getPath, navigatePath } = useNavigatePath();
|
|
44
|
-
|
|
46
|
+
useLayoutEffect(() => {
|
|
45
47
|
var _a;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const parentKey = recursiveFindParentOfActiveItem({
|
|
50
|
-
activeMenuItem: customActiveCurrentKey,
|
|
51
|
-
menuItems: customItems,
|
|
52
|
-
});
|
|
53
|
-
if (parentKey) {
|
|
54
|
-
setOpenKeys(prev => [...prev, parentKey]);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
const url = `${pathname}${hash}`;
|
|
59
|
-
// Active menu item by current url
|
|
60
|
-
const activeMenuItem = (_a = findLastMatchedItemByUrl({
|
|
61
|
-
url,
|
|
62
|
-
menuItems,
|
|
63
|
-
auth,
|
|
64
|
-
env,
|
|
65
|
-
})) === null || _a === void 0 ? void 0 : _a.menu_item_code;
|
|
66
|
-
if (activeMenuItem && activeMenuItem !== currentActiveItem) {
|
|
67
|
-
setCurrentActiveItem(activeMenuItem);
|
|
48
|
+
switch (true) {
|
|
49
|
+
case isCustomized: {
|
|
50
|
+
setCurrentActiveItem(customActiveCurrentKey);
|
|
68
51
|
// Find parent key of active menu item to open it
|
|
69
52
|
const parentKey = recursiveFindParentOfActiveItem({
|
|
70
|
-
activeMenuItem,
|
|
71
|
-
menuItems:
|
|
53
|
+
activeMenuItem: customActiveCurrentKey,
|
|
54
|
+
menuItems: customItems,
|
|
72
55
|
});
|
|
73
56
|
if (parentKey) {
|
|
74
57
|
setOpenKeys(prev => [...prev, parentKey]);
|
|
75
58
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case isRecommendation: {
|
|
62
|
+
const activeItem = findItemByPermissionCode({
|
|
63
|
+
permissionCode: customActiveCurrentKey,
|
|
64
|
+
menuItems: items,
|
|
65
|
+
});
|
|
66
|
+
if (activeItem) {
|
|
67
|
+
if (activeItem.permission_code !== 'JOURNEY')
|
|
68
|
+
setCurrentActiveItem(activeItem === null || activeItem === void 0 ? void 0 : activeItem.key);
|
|
69
|
+
// Find parent key of active menu item to open it
|
|
70
|
+
const parentKey = recursiveFindParentOfActiveItem({
|
|
71
|
+
activeMenuItem: activeItem === null || activeItem === void 0 ? void 0 : activeItem.key,
|
|
72
|
+
menuItems: menuItems === null || menuItems === void 0 ? void 0 : menuItems.map(item => (Object.assign(Object.assign({}, getMenuItem(item)), { key: (item === null || item === void 0 ? void 0 : item.permission_code) || '' }))),
|
|
73
|
+
});
|
|
74
|
+
if (parentKey) {
|
|
75
|
+
setOpenKeys(prev => [...prev, parentKey]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
default: {
|
|
81
|
+
const url = `${pathname}${hash}`;
|
|
82
|
+
// Active menu item by current url
|
|
83
|
+
const activeMenuItem = (_a = findLastMatchedItemByUrl({ url, menuItems, auth })) === null || _a === void 0 ? void 0 : _a.menu_item_code;
|
|
84
|
+
if (activeMenuItem && activeMenuItem !== currentActiveItem) {
|
|
85
|
+
setCurrentActiveItem(activeMenuItem);
|
|
86
|
+
// Find parent key of active menu item to open it
|
|
87
|
+
const parentKey = recursiveFindParentOfActiveItem({
|
|
88
|
+
activeMenuItem,
|
|
89
|
+
menuItems: menuItems === null || menuItems === void 0 ? void 0 : menuItems.map(item => getMenuItem(item)),
|
|
90
|
+
});
|
|
91
|
+
if (parentKey) {
|
|
92
|
+
setOpenKeys(prev => [...prev, parentKey]);
|
|
93
|
+
}
|
|
94
|
+
// Active App Item having code matching url
|
|
95
|
+
const matchAppCode = findActiveAppCodeByUrl({ menuItems, url, auth });
|
|
96
|
+
if (matchAppCode && matchAppCode !== activeAppCode) {
|
|
97
|
+
setLeftMenuState({ activeAppCode: matchAppCode });
|
|
98
|
+
}
|
|
80
99
|
}
|
|
100
|
+
break;
|
|
81
101
|
}
|
|
82
102
|
}
|
|
83
103
|
}, [
|
|
@@ -92,18 +112,44 @@ export const ChildMenu = memo(props => {
|
|
|
92
112
|
isCustomized,
|
|
93
113
|
customActiveCurrentKey,
|
|
94
114
|
customItems,
|
|
95
|
-
|
|
115
|
+
isRecommendation,
|
|
96
116
|
]);
|
|
97
117
|
const onClick = e => {
|
|
98
|
-
|
|
118
|
+
var _a;
|
|
119
|
+
if (isRecommendation) {
|
|
120
|
+
const permissionCode = (_a = recursiveFindItemByKey({
|
|
121
|
+
activeKey: e.key,
|
|
122
|
+
menuItems: items || [],
|
|
123
|
+
})) === null || _a === void 0 ? void 0 : _a.permission_code;
|
|
124
|
+
const permissionCodePath = (() => {
|
|
125
|
+
var _a;
|
|
126
|
+
const array = [];
|
|
127
|
+
(_a = e.keyPath) === null || _a === void 0 ? void 0 : _a.forEach(item => {
|
|
128
|
+
var _a;
|
|
129
|
+
const permissionCode = (_a = recursiveFindItemByKey({
|
|
130
|
+
activeKey: item,
|
|
131
|
+
menuItems: items || [],
|
|
132
|
+
})) === null || _a === void 0 ? void 0 : _a.permission_code;
|
|
133
|
+
if (permissionCode)
|
|
134
|
+
array.push(permissionCode);
|
|
135
|
+
});
|
|
136
|
+
return uniq(array);
|
|
137
|
+
})();
|
|
138
|
+
if (permissionCode)
|
|
139
|
+
onMenuClick === null || onMenuClick === void 0 ? void 0 : onMenuClick(permissionCode, permissionCodePath);
|
|
140
|
+
setCurrentActiveItem(e.key);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
onMenuClick === null || onMenuClick === void 0 ? void 0 : onMenuClick(e.key, e.keyPath);
|
|
144
|
+
}
|
|
99
145
|
};
|
|
100
146
|
const customMenuItems = (args) => {
|
|
101
147
|
var _a;
|
|
102
148
|
return (_a = args === null || args === void 0 ? void 0 : args.items) === null || _a === void 0 ? void 0 : _a.map(item => {
|
|
103
149
|
const { key, label, children, icon, logo_url, menu_item_path = null, menu_item_domain = null, options, optionCallback, } = item;
|
|
104
|
-
const renderLabel = () => (
|
|
105
|
-
React.createElement(LabelCustom, { ellipsis: { tooltip: label }
|
|
106
|
-
React.createElement(OptionDropdownWrapper, null,
|
|
150
|
+
const renderLabel = () => (React.createElement(LabelWrapper, { hasOption: !!(options === null || options === void 0 ? void 0 : options.length) },
|
|
151
|
+
React.createElement(LabelCustom, { ellipsis: { tooltip: label } }, label),
|
|
152
|
+
(options === null || options === void 0 ? void 0 : options.length) && !isRecommendation && (React.createElement(OptionDropdownWrapper, null,
|
|
107
153
|
React.createElement(Dropdown, { menu: {
|
|
108
154
|
items: options,
|
|
109
155
|
onClick: e => {
|
|
@@ -113,13 +159,15 @@ export const ChildMenu = memo(props => {
|
|
|
113
159
|
},
|
|
114
160
|
style: styles.dropdownMenu,
|
|
115
161
|
}, trigger: ['click'] },
|
|
116
|
-
React.createElement(Icon, { className: "child-menu-item-icon", type: "icon-ants-three-dot-vertical", style: styles.dotIcon }))))
|
|
162
|
+
React.createElement(Icon, { className: "child-menu-item-icon", type: "icon-ants-three-dot-vertical", style: styles.dotIcon })))),
|
|
163
|
+
!(children === null || children === void 0 ? void 0 : children.length) && isRecommendation && !!menu_item_path && (React.createElement(Link, { to: getPath(menu_item_path), className: "icon-link", onClick: e => e.stopPropagation() },
|
|
164
|
+
React.createElement(Icon, { type: "icon-ants-open-in-new-window" })))));
|
|
117
165
|
const renderIcon = () => {
|
|
118
166
|
var _a;
|
|
119
167
|
return !!icon || !!logo_url ? (React.createElement(Flex, { style: { flexShrink: 0 }, align: "center" }, !isNil(icon) ? (React.createElement(IconWrapper, null,
|
|
120
168
|
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;
|
|
121
169
|
};
|
|
122
|
-
const renderTitle = () => !menu_item_path ? (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" }, renderLabel()));
|
|
170
|
+
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()));
|
|
123
171
|
return {
|
|
124
172
|
key,
|
|
125
173
|
label: (React.createElement(Flex, { gap: 10, align: "center", justify: "space-between", style: { height: '100%' } },
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export declare const LabelWrapper: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("antd/es/flex/interface").FlexProps<import("antd/es/_util/type").AnyObject> & import("react").RefAttributes<HTMLElement>>, any, {
|
|
2
|
+
export declare const LabelWrapper: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("antd/es/flex/interface").FlexProps<import("antd/es/_util/type").AnyObject> & import("react").RefAttributes<HTMLElement>>, any, {
|
|
3
|
+
hasOption?: boolean | undefined;
|
|
4
|
+
}, never>;
|
|
3
5
|
export declare const LabelCustom: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("antd/es/typography/Text").TextProps & import("react").RefAttributes<HTMLSpanElement>>, any, {}, never>;
|
|
4
6
|
export declare const OptionDropdownWrapper: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("antd/es/flex/interface").FlexProps<import("antd/es/_util/type").AnyObject> & import("react").RefAttributes<HTMLElement>>, any, {}, never>;
|
|
5
7
|
export declare const MenuWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -8,6 +8,33 @@ import { THEME } from '@antscorp/antsomi-ui/es/constants';
|
|
|
8
8
|
import { ICON_SIZE } from '../../../constants';
|
|
9
9
|
export const LabelWrapper = styled(Flex) `
|
|
10
10
|
width: 100%;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
${({ hasOption }) => hasOption
|
|
13
|
+
? `
|
|
14
|
+
font-weight: 400 !important;
|
|
15
|
+
font-size: 11px !important;
|
|
16
|
+
`
|
|
17
|
+
: ''}
|
|
18
|
+
|
|
19
|
+
.icon-link {
|
|
20
|
+
flex-shrink: 0;
|
|
21
|
+
width: fit-content;
|
|
22
|
+
display: none;
|
|
23
|
+
|
|
24
|
+
i {
|
|
25
|
+
font-size: 15px !important;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&::before {
|
|
29
|
+
width: fit-content !important;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&:hover {
|
|
34
|
+
.icon-link {
|
|
35
|
+
display: flex;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
11
38
|
`;
|
|
12
39
|
LabelWrapper.defaultProps = {
|
|
13
40
|
gap: 10,
|
|
@@ -17,6 +44,8 @@ LabelWrapper.defaultProps = {
|
|
|
17
44
|
export const LabelCustom = styled(Typography.Text) `
|
|
18
45
|
font-size: inherit !important;
|
|
19
46
|
color: inherit !important;
|
|
47
|
+
flex: 1 1 0%;
|
|
48
|
+
overflow: hidden;
|
|
20
49
|
`;
|
|
21
50
|
export const OptionDropdownWrapper = styled(Flex) `
|
|
22
51
|
width: 20px;
|
|
@@ -29,3 +29,11 @@ export declare const recursiveFindParentOfActiveItem: (args: {
|
|
|
29
29
|
activeMenuItem: string;
|
|
30
30
|
menuItems: TMenuItem[];
|
|
31
31
|
}) => string | undefined;
|
|
32
|
+
export declare const recursiveFindItemByKey: (args: {
|
|
33
|
+
activeKey: string;
|
|
34
|
+
menuItems: TMenuItem[];
|
|
35
|
+
}) => TMenuItem | undefined;
|
|
36
|
+
export declare const findItemByPermissionCode: (args: {
|
|
37
|
+
permissionCode: string;
|
|
38
|
+
menuItems: TMenuItem[];
|
|
39
|
+
}) => TMenuItem | undefined;
|
|
@@ -88,3 +88,49 @@ export const recursiveFindParentOfActiveItem = (args) => {
|
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
|
+
export const recursiveFindItemByKey = (args) => {
|
|
92
|
+
try {
|
|
93
|
+
const { activeKey, menuItems } = args;
|
|
94
|
+
for (const item of menuItems) {
|
|
95
|
+
if (item.key === activeKey) {
|
|
96
|
+
return item;
|
|
97
|
+
}
|
|
98
|
+
const childActiveItem = recursiveFindItemByKey({
|
|
99
|
+
activeKey,
|
|
100
|
+
menuItems: (item === null || item === void 0 ? void 0 : item.children) || [],
|
|
101
|
+
});
|
|
102
|
+
if (childActiveItem)
|
|
103
|
+
return childActiveItem;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
handleError(error, {
|
|
108
|
+
path: PATH,
|
|
109
|
+
name: recursiveFindItemByKey.name,
|
|
110
|
+
args,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
export const findItemByPermissionCode = (args) => {
|
|
115
|
+
try {
|
|
116
|
+
const { permissionCode, menuItems } = args;
|
|
117
|
+
const matchedItems = [];
|
|
118
|
+
const recursiveFindItemByPermissionCode = (items) => {
|
|
119
|
+
for (const item of items) {
|
|
120
|
+
if (item.permission_code === permissionCode) {
|
|
121
|
+
matchedItems.push(item);
|
|
122
|
+
}
|
|
123
|
+
recursiveFindItemByPermissionCode((item === null || item === void 0 ? void 0 : item.children) || []);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
recursiveFindItemByPermissionCode(menuItems);
|
|
127
|
+
return matchedItems === null || matchedItems === void 0 ? void 0 : matchedItems.pop();
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
handleError(error, {
|
|
131
|
+
path: PATH,
|
|
132
|
+
name: findItemByPermissionCode.name,
|
|
133
|
+
args,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
};
|
|
@@ -15,13 +15,13 @@ export declare const MENU_ITEM_TYPE: {
|
|
|
15
15
|
GROUP_MENU: number;
|
|
16
16
|
};
|
|
17
17
|
export declare const ICON_SIZE = 20;
|
|
18
|
-
export declare const HOME_MENU_ITEMS: Record<string, TMenuFeatureItem>;
|
|
19
18
|
export declare const HOME_ROUTE = "/gen2/:networkId/dashboard";
|
|
20
19
|
export declare const HOME_REPORT_ROUTES: {
|
|
21
20
|
DETAIL: string;
|
|
22
21
|
CONFIGURE: string;
|
|
23
22
|
CREATE: string;
|
|
24
23
|
};
|
|
24
|
+
export declare const HOME_MENU_ITEMS: Record<string, TMenuFeatureItem>;
|
|
25
25
|
export declare const MARKETING_ROUTES: {
|
|
26
26
|
CHANNEL: string;
|
|
27
27
|
};
|