@antscorp/antsomi-ui 1.3.5-beta.194 → 1.3.5-beta.196
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/ThumbnailCard/ThumbnailCard.js +2 -1
- package/es/components/organism/LeftMenu/components/ContentMenu/index.js +2 -2
- package/es/components/organism/LeftMenu/components/ContentMenu/useContentMenu.js +7 -7
- package/es/components/organism/LeftMenu/components/DataMenu/index.js +2 -2
- package/es/components/organism/LeftMenu/components/DataMenu/useDataMenu.js +5 -5
- package/es/components/organism/LeftMenu/components/HomeMenu/constants.d.ts +0 -2
- package/es/components/organism/LeftMenu/components/HomeMenu/constants.js +0 -17
- package/es/components/organism/LeftMenu/components/HomeMenu/index.js +2 -2
- package/es/components/organism/LeftMenu/components/HomeMenu/useHomeMenu.js +25 -68
- package/es/components/organism/LeftMenu/components/InsightsMenu/index.js +2 -2
- package/es/components/organism/LeftMenu/components/InsightsMenu/useInsightsMenu.js +5 -5
- package/es/components/organism/LeftMenu/components/MarketingMenu/index.js +2 -2
- package/es/components/organism/LeftMenu/components/MarketingMenu/useMarketingMenu.d.ts +1 -1
- package/es/components/organism/LeftMenu/components/MarketingMenu/useMarketingMenu.js +5 -53
- package/es/components/organism/LeftMenu/components/ProfilesMenu/index.js +2 -2
- package/es/components/organism/LeftMenu/components/ProfilesMenu/useProfilesMenu.js +5 -5
- package/es/components/organism/LeftMenu/components/SettingsMenu/index.js +2 -2
- package/es/components/organism/LeftMenu/components/SettingsMenu/useSettingsMenu.js +5 -5
- package/es/components/organism/LeftMenu/components/TemplatesMenu/index.js +2 -2
- package/es/components/organism/LeftMenu/components/TemplatesMenu/useTemplatesMenu.js +5 -5
- package/es/components/organism/LeftMenu/components/common/ChildMenu/index.js +37 -29
- package/es/components/organism/LeftMenu/components/common/ChildMenu/utils.d.ts +18 -0
- package/es/components/organism/LeftMenu/components/common/ChildMenu/utils.js +80 -0
- package/es/components/organism/LeftMenu/constants/index.d.ts +0 -1
- package/es/components/organism/LeftMenu/constants/index.js +0 -1
- package/es/components/organism/LeftMenu/constants/sampleData.js +9 -9
- package/es/components/organism/LeftMenu/constants/variables.d.ts +17 -1
- package/es/components/organism/LeftMenu/constants/variables.js +29 -1
- package/es/components/organism/LeftMenu/hooks/useLeftMenu.d.ts +2 -1
- package/es/components/organism/LeftMenu/hooks/useLeftMenu.js +59 -8
- package/es/components/organism/LeftMenu/index.js +35 -45
- package/es/components/organism/LeftMenu/stores/index.d.ts +12 -1
- package/es/components/organism/LeftMenu/stores/index.js +11 -1
- package/es/components/organism/LeftMenu/styled.js +2 -2
- package/es/components/organism/LeftMenu/utils/index.d.ts +45 -3
- package/es/components/organism/LeftMenu/utils/index.js +134 -3
- package/es/components/template/TemplateListing/index.js +2 -2
- package/es/models/LeftMenu/FeatureMenu.d.ts +1 -0
- package/es/providers/ConfigProvider/GlobalStyle.js +1 -0
- package/es/utils/common.d.ts +1 -1
- package/es/utils/common.js +2 -4
- package/package.json +1 -1
- package/es/components/organism/LeftMenu/constants/links.d.ts +0 -1
- package/es/components/organism/LeftMenu/constants/links.js +0 -1
- package/es/components/organism/LeftMenu/contexts/index.d.ts +0 -15
- package/es/components/organism/LeftMenu/contexts/index.js +0 -10
- package/es/components/organism/LeftMenu/stores/useLeftMenuStore.d.ts +0 -9
- package/es/components/organism/LeftMenu/stores/useLeftMenuStore.js +0 -11
|
@@ -29,6 +29,7 @@ import { Button, Flex, Typography, Spin } from '../../atoms';
|
|
|
29
29
|
// Constants
|
|
30
30
|
import { THUMBNAIL_CARD_DEFAULT_HEIGHT, THUMBNAIL_CARD_DEFAULT_WIDTH } from './constants';
|
|
31
31
|
import { getUrlNoCache } from '@antscorp/antsomi-ui/es/utils';
|
|
32
|
+
const cacheValue = new Date().getTime();
|
|
32
33
|
export const ThumbnailCard = memo(props => {
|
|
33
34
|
const [modal, contextHolder] = Modal.useModal();
|
|
34
35
|
const { id, name, width = THUMBNAIL_CARD_DEFAULT_WIDTH, height = THUMBNAIL_CARD_DEFAULT_HEIGHT, thumbnail, removable = true, actionAvailable = true, showSkeleton = true, loading = false, removeModalProps, editBtnProps, previewBtnProps, onClickWrapper } = props, restOfProps = __rest(props, ["id", "name", "width", "height", "thumbnail", "removable", "actionAvailable", "showSkeleton", "loading", "removeModalProps", "editBtnProps", "previewBtnProps", "onClickWrapper"]);
|
|
@@ -53,7 +54,7 @@ export const ThumbnailCard = memo(props => {
|
|
|
53
54
|
};
|
|
54
55
|
return (React.createElement(Flex, Object.assign({ gap: 10, vertical: true }, restOfProps, { style: Object.assign({ width }, restOfProps.style) }),
|
|
55
56
|
React.createElement(ThumbnailCardWrapper, { "$showSkeleton": showSkeletonMemo, style: { height, cursor: actionAvailable ? 'default' : 'pointer' }, onClick: handleWrapperClick },
|
|
56
|
-
React.createElement("div", { className: "screen" }, thumbnail && React.createElement("img", { src: getUrlNoCache(thumbnail), alt: "" })),
|
|
57
|
+
React.createElement("div", { className: "screen" }, thumbnail && React.createElement("img", { src: getUrlNoCache(thumbnail, cacheValue), alt: "" })),
|
|
57
58
|
actionAvailable && !loading && (React.createElement(React.Fragment, null,
|
|
58
59
|
React.createElement(Flex, { className: "center-action", align: "center", gap: 10, vertical: true },
|
|
59
60
|
React.createElement(Button, Object.assign({ type: "primary", className: "animate__animated animate__fadeIn" }, restOfEditBtnProps, { onClick: e => {
|
|
@@ -5,8 +5,8 @@ import { ChildMenu } from '../common';
|
|
|
5
5
|
// Hooks
|
|
6
6
|
import { useContentMenu } from './useContentMenu';
|
|
7
7
|
// Constants
|
|
8
|
-
import {
|
|
8
|
+
import { APP_KEYS } from '../../constants';
|
|
9
9
|
export const ContentMenu = memo(() => {
|
|
10
10
|
const { children } = useContentMenu();
|
|
11
|
-
return React.createElement(ChildMenu, { items: children, parentKey:
|
|
11
|
+
return React.createElement(ChildMenu, { items: children, parentKey: APP_KEYS.CONTENT });
|
|
12
12
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Libraries
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
// Contexts
|
|
5
|
-
import { LeftMenuContext } from '../../contexts';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
// Utils
|
|
6
4
|
import { getMenuItem } from '../../utils';
|
|
5
|
+
// Stores
|
|
6
|
+
import { useLeftMenuStore } from '../../stores';
|
|
7
7
|
export const useContentMenu = () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const customChildren = useMemo(() =>
|
|
8
|
+
// Selectors
|
|
9
|
+
const appMenuChildren = useLeftMenuStore(store => store.state.appMenuChildren);
|
|
10
|
+
const customChildren = useMemo(() => appMenuChildren === null || appMenuChildren === void 0 ? void 0 : appMenuChildren.map(item => getMenuItem(item)), [appMenuChildren]);
|
|
11
11
|
return {
|
|
12
12
|
children: customChildren,
|
|
13
13
|
};
|
|
@@ -5,8 +5,8 @@ import { ChildMenu } from '../common';
|
|
|
5
5
|
// Hooks
|
|
6
6
|
import { useDataMenu } from './useDataMenu';
|
|
7
7
|
// Constants
|
|
8
|
-
import {
|
|
8
|
+
import { APP_KEYS } from '../../constants';
|
|
9
9
|
export const DataMenu = memo(() => {
|
|
10
10
|
const { children } = useDataMenu();
|
|
11
|
-
return React.createElement(ChildMenu, { items: children, parentKey:
|
|
11
|
+
return React.createElement(ChildMenu, { items: children, parentKey: APP_KEYS.DATA });
|
|
12
12
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Libraries
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
-
import { useContextSelector } from 'use-context-selector';
|
|
4
|
-
// Contexts
|
|
5
|
-
import { LeftMenuContext } from '../../contexts';
|
|
6
3
|
// Utils
|
|
7
4
|
import { getMenuItem } from '../../utils';
|
|
5
|
+
// Stores
|
|
6
|
+
import { useLeftMenuStore } from '../../stores';
|
|
8
7
|
export const useDataMenu = () => {
|
|
9
|
-
|
|
10
|
-
const
|
|
8
|
+
// Selectors
|
|
9
|
+
const appMenuChildren = useLeftMenuStore(store => store.state.appMenuChildren);
|
|
10
|
+
const customChildren = useMemo(() => appMenuChildren === null || appMenuChildren === void 0 ? void 0 : appMenuChildren.map(item => getMenuItem(item)), [appMenuChildren]);
|
|
11
11
|
return { children: customChildren };
|
|
12
12
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { TMenuFeatureItem } from '../../types';
|
|
2
1
|
export declare const HOME_REPORT_ROUTES: {
|
|
3
2
|
DETAIL: string;
|
|
4
3
|
CONFIGURE: string;
|
|
@@ -14,4 +13,3 @@ export declare const CONFIG_OPTIONS: {
|
|
|
14
13
|
label: string;
|
|
15
14
|
};
|
|
16
15
|
};
|
|
17
|
-
export declare const HOME_MENU_ITEMS: Record<string, TMenuFeatureItem>;
|
|
@@ -13,20 +13,3 @@ export const CONFIG_OPTIONS = {
|
|
|
13
13
|
label: 'Remove',
|
|
14
14
|
},
|
|
15
15
|
};
|
|
16
|
-
export const HOME_MENU_ITEMS = {
|
|
17
|
-
RECENT: {
|
|
18
|
-
menu_item_name: 'Recent',
|
|
19
|
-
menu_item_code: 'recentDashboard',
|
|
20
|
-
icon_name: null,
|
|
21
|
-
},
|
|
22
|
-
OWNERS: {
|
|
23
|
-
menu_item_name: 'Owners',
|
|
24
|
-
menu_item_code: 'ownedDashboard',
|
|
25
|
-
icon_name: null,
|
|
26
|
-
},
|
|
27
|
-
SHARED_WITH_ME: {
|
|
28
|
-
menu_item_name: 'Shared with me',
|
|
29
|
-
menu_item_code: 'sharedDashboard',
|
|
30
|
-
icon_name: null,
|
|
31
|
-
},
|
|
32
|
-
};
|
|
@@ -5,7 +5,7 @@ import { ChildMenu } from '../common';
|
|
|
5
5
|
import { Flex } from '../../../../atoms';
|
|
6
6
|
// Constants
|
|
7
7
|
import Icon from '@antscorp/icons';
|
|
8
|
-
import {
|
|
8
|
+
import { APP_KEYS } from '../../constants';
|
|
9
9
|
// Styled
|
|
10
10
|
import { CreateButton, HomeMenuWrapper } from './styled';
|
|
11
11
|
// Hooks
|
|
@@ -19,5 +19,5 @@ export const HomeMenu = memo(() => {
|
|
|
19
19
|
React.createElement(Icon, { type: "icon-ants-plus-slim", style: { fontSize: 14 } }),
|
|
20
20
|
React.createElement("span", null, "Create"))),
|
|
21
21
|
React.createElement("div", { className: "menu-list" },
|
|
22
|
-
React.createElement(ChildMenu, { items: children, parentKey:
|
|
22
|
+
React.createElement(ChildMenu, { items: children, parentKey: APP_KEYS.HOME, onMenuClick: onMenuClick }))));
|
|
23
23
|
});
|
|
@@ -1,50 +1,26 @@
|
|
|
1
1
|
// Libraries
|
|
2
2
|
import { useCallback, useMemo } from 'react';
|
|
3
3
|
import { useContextSelector } from 'use-context-selector';
|
|
4
|
-
import { useHistory } from 'react-router-dom';
|
|
5
|
-
// Queries
|
|
6
|
-
import { useGetDashboard } from '@antscorp/antsomi-ui/es/queries/LeftMenu';
|
|
4
|
+
import { useHistory, useLocation } from 'react-router-dom';
|
|
7
5
|
// Constants
|
|
8
|
-
import { CONFIG_OPTIONS,
|
|
6
|
+
import { CONFIG_OPTIONS, HOME_REPORT_ROUTES } from './constants';
|
|
9
7
|
// Utils
|
|
10
8
|
import { getGeneratePath, getMenuItem } from '../../utils';
|
|
11
9
|
// Contexts
|
|
12
10
|
import { AppConfigContext } from '@antscorp/antsomi-ui/es/providers';
|
|
13
|
-
|
|
11
|
+
// Types
|
|
12
|
+
import { useLeftMenuStore } from '../../stores';
|
|
14
13
|
export const useHomeMenu = () => {
|
|
15
14
|
// Hooks
|
|
15
|
+
const { pathname } = useLocation();
|
|
16
16
|
const history = useHistory();
|
|
17
|
+
const activeAppCode = useLeftMenuStore(store => store.state.activeAppCode);
|
|
18
|
+
const appMenuChildren = useLeftMenuStore(store => store.state.appMenuChildren);
|
|
19
|
+
const menuItems = useLeftMenuStore(store => store.state.menuItems);
|
|
17
20
|
// Contexts
|
|
18
|
-
const
|
|
19
|
-
const { activeItem, permissionMenu, objectId = 0, objectType = '', isGrouped = false, } = useContextSelector(LeftMenuContext, state => state);
|
|
20
|
-
const { auth, languageCode } = appConfig;
|
|
21
|
-
// Queries
|
|
22
|
-
const { data: dashboardData } = useGetDashboard({
|
|
23
|
-
args: {
|
|
24
|
-
auth: {
|
|
25
|
-
token: auth === null || auth === void 0 ? void 0 : auth.token,
|
|
26
|
-
url: 'https://sandbox-app.cdp.asia/hub',
|
|
27
|
-
portalId: auth === null || auth === void 0 ? void 0 : auth.portalId,
|
|
28
|
-
userId: auth === null || auth === void 0 ? void 0 : auth.userId,
|
|
29
|
-
},
|
|
30
|
-
params: {
|
|
31
|
-
objectType,
|
|
32
|
-
objectId,
|
|
33
|
-
isGrouped,
|
|
34
|
-
languageCode,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
const dashboardObject = useMemo(() => {
|
|
39
|
-
var _a, _b;
|
|
40
|
-
return ({
|
|
41
|
-
sharedDashboard: ((_a = dashboardData === null || dashboardData === void 0 ? void 0 : dashboardData.entries) === null || _a === void 0 ? void 0 : _a.sharedDashboard) || [],
|
|
42
|
-
ownedDashboard: ((_b = dashboardData === null || dashboardData === void 0 ? void 0 : dashboardData.entries) === null || _b === void 0 ? void 0 : _b.ownedDashboard) || [],
|
|
43
|
-
recentDashboard: [],
|
|
44
|
-
});
|
|
45
|
-
}, [dashboardData]);
|
|
21
|
+
const auth = useContextSelector(AppConfigContext, state => state === null || state === void 0 ? void 0 : state.auth);
|
|
46
22
|
// Memos
|
|
47
|
-
const homeItem = useMemo(() =>
|
|
23
|
+
const homeItem = useMemo(() => menuItems === null || menuItems === void 0 ? void 0 : menuItems.find(item => item.menu_item_code === activeAppCode), [activeAppCode, menuItems]);
|
|
48
24
|
// const listDashboardName = useMemo(
|
|
49
25
|
// () =>
|
|
50
26
|
// get(dashboardData, 'entries.ownedDashboard', [])?.map(overview =>
|
|
@@ -56,35 +32,33 @@ export const useHomeMenu = () => {
|
|
|
56
32
|
const onOptionCallback = useCallback((args) => {
|
|
57
33
|
const { optionKey, menuItemKey } = args;
|
|
58
34
|
switch (optionKey) {
|
|
59
|
-
case CONFIG_OPTIONS.CONFIGURE.key:
|
|
60
|
-
|
|
35
|
+
case CONFIG_OPTIONS.CONFIGURE.key: {
|
|
36
|
+
const newPathName = getGeneratePath(getHomePath(HOME_REPORT_ROUTES.CONFIGURE), Object.assign(Object.assign({}, auth), { reportId: menuItemKey }));
|
|
37
|
+
if (newPathName !== pathname) {
|
|
38
|
+
history.push(newPathName);
|
|
39
|
+
}
|
|
61
40
|
break;
|
|
41
|
+
}
|
|
62
42
|
case CONFIG_OPTIONS.REMOVE.key:
|
|
63
43
|
break;
|
|
64
44
|
default:
|
|
65
45
|
break;
|
|
66
46
|
}
|
|
67
|
-
}, [auth,
|
|
68
|
-
const customChildren = useMemo(() => {
|
|
47
|
+
}, [getHomePath, auth, pathname, history]);
|
|
48
|
+
const customChildren = useMemo(() => appMenuChildren === null || appMenuChildren === void 0 ? void 0 : appMenuChildren.map(appMenuItem => {
|
|
69
49
|
var _a;
|
|
70
|
-
return (_a =
|
|
71
|
-
|
|
72
|
-
return getMenuItem(Object.assign(Object.assign({}, item), { children: (_a = (((dashboardObject === null || dashboardObject === void 0 ? void 0 : dashboardObject[item.menu_item_code]) || []))) === null || _a === void 0 ? void 0 : _a.map(item => ({
|
|
73
|
-
menu_item_name: item.dashboardName,
|
|
74
|
-
menu_item_code: String(item.dashboardId),
|
|
75
|
-
icon_name: null,
|
|
76
|
-
options: Object.values(CONFIG_OPTIONS),
|
|
77
|
-
optionCallback: onOptionCallback,
|
|
78
|
-
})) }));
|
|
79
|
-
});
|
|
80
|
-
}, [dashboardObject, onOptionCallback]);
|
|
50
|
+
return getMenuItem(Object.assign(Object.assign({}, appMenuItem), { children: (_a = appMenuItem === null || appMenuItem === void 0 ? void 0 : appMenuItem.children) === null || _a === void 0 ? void 0 : _a.map(item => (Object.assign(Object.assign({}, item), { options: Object.values(CONFIG_OPTIONS), optionCallback: onOptionCallback }))) }));
|
|
51
|
+
}), [appMenuChildren, onOptionCallback]);
|
|
81
52
|
// Callbacks
|
|
82
53
|
const onCreateNewReport = useCallback(() => {
|
|
83
54
|
history.push(getGeneratePath(getHomePath(HOME_REPORT_ROUTES.CREATE), auth));
|
|
84
55
|
}, [auth, history, getHomePath]);
|
|
85
56
|
const onMenuClick = useCallback((key, _) => {
|
|
86
|
-
|
|
87
|
-
|
|
57
|
+
const newPathName = getGeneratePath(getHomePath(HOME_REPORT_ROUTES.DETAIL), Object.assign(Object.assign({}, auth), { reportId: key }));
|
|
58
|
+
if (newPathName !== pathname) {
|
|
59
|
+
history.push(newPathName);
|
|
60
|
+
}
|
|
61
|
+
}, [getHomePath, auth, pathname, history]);
|
|
88
62
|
// const onCreateNewReport = useCallback(() => {
|
|
89
63
|
// const configTab = {
|
|
90
64
|
// id: generateKey(),
|
|
@@ -102,23 +76,6 @@ export const useHomeMenu = () => {
|
|
|
102
76
|
// }, [listDashboardName]);
|
|
103
77
|
return {
|
|
104
78
|
children: customChildren,
|
|
105
|
-
// children: [
|
|
106
|
-
// ...customChildren,
|
|
107
|
-
// ...customChildren,
|
|
108
|
-
// ...customChildren,
|
|
109
|
-
// ...customChildren,
|
|
110
|
-
// ...customChildren,
|
|
111
|
-
// ...customChildren,
|
|
112
|
-
// ...customChildren,
|
|
113
|
-
// ...customChildren,
|
|
114
|
-
// ...customChildren,
|
|
115
|
-
// ...customChildren,
|
|
116
|
-
// ...customChildren,
|
|
117
|
-
// ...customChildren,
|
|
118
|
-
// ...customChildren,
|
|
119
|
-
// ...customChildren,
|
|
120
|
-
// ...customChildren,
|
|
121
|
-
// ],
|
|
122
79
|
/* Callbacks */
|
|
123
80
|
onCreateNewReport,
|
|
124
81
|
onOptionCallback,
|
|
@@ -5,8 +5,8 @@ import { ChildMenu } from '../common';
|
|
|
5
5
|
// Contexts
|
|
6
6
|
import { useInsightsMenu } from './useInsightsMenu';
|
|
7
7
|
// Constants
|
|
8
|
-
import {
|
|
8
|
+
import { APP_KEYS } from '../../constants';
|
|
9
9
|
export const InsightsMenu = memo(() => {
|
|
10
10
|
const { children } = useInsightsMenu();
|
|
11
|
-
return React.createElement(ChildMenu, { items: children, parentKey:
|
|
11
|
+
return React.createElement(ChildMenu, { items: children, parentKey: APP_KEYS.INSIGHTS });
|
|
12
12
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Libraries
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
-
import { useContextSelector } from 'use-context-selector';
|
|
4
|
-
// Contexts
|
|
5
|
-
import { LeftMenuContext } from '../../contexts';
|
|
6
3
|
// Utils
|
|
7
4
|
import { getMenuItem } from '../../utils';
|
|
5
|
+
// Stores
|
|
6
|
+
import { useLeftMenuStore } from '../../stores';
|
|
8
7
|
export const useInsightsMenu = () => {
|
|
9
|
-
|
|
10
|
-
const
|
|
8
|
+
// Selectors
|
|
9
|
+
const appMenuChildren = useLeftMenuStore(store => store.state.appMenuChildren);
|
|
10
|
+
const customChildren = useMemo(() => appMenuChildren === null || appMenuChildren === void 0 ? void 0 : appMenuChildren.map(item => getMenuItem(item)), [appMenuChildren]);
|
|
11
11
|
return {
|
|
12
12
|
children: customChildren,
|
|
13
13
|
};
|
|
@@ -5,8 +5,8 @@ import { ChildMenu } from '../common';
|
|
|
5
5
|
// Hooks
|
|
6
6
|
import { useMarketingMenu } from './useMarketingMenu';
|
|
7
7
|
// Constants
|
|
8
|
-
import {
|
|
8
|
+
import { APP_KEYS } from '../../constants';
|
|
9
9
|
export const MarketingMenu = memo(() => {
|
|
10
10
|
const { children } = useMarketingMenu();
|
|
11
|
-
return React.createElement(ChildMenu, { items: children, parentKey:
|
|
11
|
+
return React.createElement(ChildMenu, { items: children, parentKey: APP_KEYS.MARKETING });
|
|
12
12
|
});
|
|
@@ -1,62 +1,14 @@
|
|
|
1
1
|
// Libraries
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
-
import { useContextSelector } from 'use-context-selector';
|
|
4
3
|
import { isEmpty } from 'lodash';
|
|
5
|
-
// Contexts
|
|
6
|
-
import { LeftMenuContext } from '../../contexts';
|
|
7
|
-
import { AppConfigContext } from '@antscorp/antsomi-ui/es/providers';
|
|
8
|
-
// Queries
|
|
9
|
-
import { useGetDestinationChannel } from '@antscorp/antsomi-ui/es/queries/LeftMenu';
|
|
10
4
|
// Utils
|
|
11
|
-
import {
|
|
5
|
+
import { getMenuItem } from '../../utils';
|
|
12
6
|
// Constants
|
|
13
|
-
import {
|
|
7
|
+
import { useLeftMenuStore } from '../../stores';
|
|
14
8
|
export const useMarketingMenu = () => {
|
|
15
|
-
//
|
|
16
|
-
const
|
|
17
|
-
const featureChildren = useContextSelector(LeftMenuContext, state => state.featureChildren);
|
|
18
|
-
// Destructuring variables
|
|
19
|
-
const { auth, languageCode } = appConfig;
|
|
20
|
-
// Queries
|
|
21
|
-
const { data: destinationChannel } = useGetDestinationChannel({
|
|
22
|
-
args: {
|
|
23
|
-
auth: {
|
|
24
|
-
token: '5474r2x214z2a46403e4y4749426s2v544r2i4u2k5t5' || (auth === null || auth === void 0 ? void 0 : auth.token),
|
|
25
|
-
url: 'https://sandbox-app.cdp.asia/hub',
|
|
26
|
-
userId: '1600085179' || (auth === null || auth === void 0 ? void 0 : auth.userId),
|
|
27
|
-
portalId: auth === null || auth === void 0 ? void 0 : auth.portalId,
|
|
28
|
-
},
|
|
29
|
-
params: {
|
|
30
|
-
objectType: 'STORIES',
|
|
31
|
-
languageCode,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
});
|
|
9
|
+
// Selectors
|
|
10
|
+
const appMenuChildren = useLeftMenuStore(store => store.state.appMenuChildren);
|
|
35
11
|
// Memos
|
|
36
|
-
const customChildren = useMemo(() =>
|
|
37
|
-
var _a, _b;
|
|
38
|
-
let children = [];
|
|
39
|
-
switch (item.menu_item_code) {
|
|
40
|
-
case 'ALL_CHANNEL':
|
|
41
|
-
item.menu_item_path = getGeneratePath(MARKETING_ROUTES.CHANNEL, Object.assign(Object.assign({}, auth), { channelId: CHANNEL_KEY.ALL_CHANNEL }));
|
|
42
|
-
break;
|
|
43
|
-
case 'ORCHESTRATION':
|
|
44
|
-
item.menu_item_path = getGeneratePath(MARKETING_ROUTES.CHANNEL, Object.assign(Object.assign({}, auth), { channelId: CHANNEL_KEY.ORCHESTRATION }));
|
|
45
|
-
break;
|
|
46
|
-
default:
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
if ((item === null || item === void 0 ? void 0 : item.render_option) === 'destination_channel') {
|
|
50
|
-
children =
|
|
51
|
-
((_b = (_a = destinationChannel === null || destinationChannel === void 0 ? void 0 : destinationChannel.entries) === null || _a === void 0 ? void 0 : _a.filter(item => item.channelId !== CHANNEL_KEY.ORCHESTRATION)) === null || _b === void 0 ? void 0 : _b.map(item => ({
|
|
52
|
-
menu_item_code: item.channelCode,
|
|
53
|
-
menu_item_name: item.translateLabel,
|
|
54
|
-
logo_url: item.logoUrl,
|
|
55
|
-
menu_item_path: getGeneratePath(MARKETING_ROUTES.CHANNEL, Object.assign(Object.assign({}, auth), { channelId: item.channelId })),
|
|
56
|
-
icon_name: null,
|
|
57
|
-
}))) || [];
|
|
58
|
-
}
|
|
59
|
-
return getMenuItem(Object.assign(Object.assign({}, item), (isEmpty(children) ? {} : { children })));
|
|
60
|
-
}), [auth, destinationChannel === null || destinationChannel === void 0 ? void 0 : destinationChannel.entries, featureChildren]);
|
|
12
|
+
const customChildren = useMemo(() => appMenuChildren === null || appMenuChildren === void 0 ? void 0 : appMenuChildren.map(item => getMenuItem(Object.assign(Object.assign({}, item), (isEmpty(item.children) ? {} : { children: item.children })))), [appMenuChildren]);
|
|
61
13
|
return { children: customChildren };
|
|
62
14
|
};
|
|
@@ -5,8 +5,8 @@ import { ChildMenu } from '../common';
|
|
|
5
5
|
// Hooks
|
|
6
6
|
import { useProfilesMenu } from './useProfilesMenu';
|
|
7
7
|
// Constants
|
|
8
|
-
import {
|
|
8
|
+
import { APP_KEYS } from '../../constants';
|
|
9
9
|
export const ProfilesMenu = memo(() => {
|
|
10
10
|
const { children } = useProfilesMenu();
|
|
11
|
-
return React.createElement(ChildMenu, { items: children, parentKey:
|
|
11
|
+
return React.createElement(ChildMenu, { items: children, parentKey: APP_KEYS.PROFILES });
|
|
12
12
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Libraries
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
-
import { useContextSelector } from 'use-context-selector';
|
|
4
|
-
// Contexts
|
|
5
|
-
import { LeftMenuContext } from '../../contexts';
|
|
6
3
|
// Utils
|
|
7
4
|
import { getMenuItem } from '../../utils';
|
|
5
|
+
// Stores
|
|
6
|
+
import { useLeftMenuStore } from '../../stores';
|
|
8
7
|
export const useProfilesMenu = () => {
|
|
9
|
-
|
|
10
|
-
const
|
|
8
|
+
// Selectors
|
|
9
|
+
const appMenuChildren = useLeftMenuStore(store => store.state.appMenuChildren);
|
|
10
|
+
const customChildren = useMemo(() => appMenuChildren === null || appMenuChildren === void 0 ? void 0 : appMenuChildren.map(item => getMenuItem(item)), [appMenuChildren]);
|
|
11
11
|
return {
|
|
12
12
|
children: customChildren,
|
|
13
13
|
};
|
|
@@ -5,8 +5,8 @@ import { ChildMenu } from '../common';
|
|
|
5
5
|
// Hooks
|
|
6
6
|
import { useSettingsMenu } from './useSettingsMenu';
|
|
7
7
|
// Constants
|
|
8
|
-
import {
|
|
8
|
+
import { APP_KEYS } from '../../constants';
|
|
9
9
|
export const SettingsMenu = memo(() => {
|
|
10
10
|
const { children } = useSettingsMenu();
|
|
11
|
-
return React.createElement(ChildMenu, { items: children, parentKey:
|
|
11
|
+
return React.createElement(ChildMenu, { items: children, parentKey: APP_KEYS.SETTINGS });
|
|
12
12
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Libraries
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
-
import { useContextSelector } from 'use-context-selector';
|
|
4
|
-
// Contexts
|
|
5
|
-
import { LeftMenuContext } from '../../contexts';
|
|
6
3
|
// Utils
|
|
7
4
|
import { getMenuItem } from '../../utils';
|
|
5
|
+
// Stores
|
|
6
|
+
import { useLeftMenuStore } from '../../stores';
|
|
8
7
|
export const useSettingsMenu = () => {
|
|
9
|
-
|
|
10
|
-
const
|
|
8
|
+
// Selectors
|
|
9
|
+
const appMenuChildren = useLeftMenuStore(store => store.state.appMenuChildren);
|
|
10
|
+
const customChildren = useMemo(() => appMenuChildren === null || appMenuChildren === void 0 ? void 0 : appMenuChildren.map(item => getMenuItem(item)), [appMenuChildren]);
|
|
11
11
|
return { children: customChildren };
|
|
12
12
|
};
|
|
@@ -5,8 +5,8 @@ import { ChildMenu } from '../common';
|
|
|
5
5
|
// Hooks
|
|
6
6
|
import { useTemplatesMenu } from './useTemplatesMenu';
|
|
7
7
|
// Constants
|
|
8
|
-
import {
|
|
8
|
+
import { APP_KEYS } from '../../constants';
|
|
9
9
|
export const TemplatesMenu = memo(() => {
|
|
10
10
|
const { children } = useTemplatesMenu();
|
|
11
|
-
return React.createElement(ChildMenu, { items: children, parentKey:
|
|
11
|
+
return React.createElement(ChildMenu, { items: children, parentKey: APP_KEYS.TEMPLATES });
|
|
12
12
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Libraries
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
|
-
import { useContextSelector } from 'use-context-selector';
|
|
4
|
-
// Contexts
|
|
5
|
-
import { LeftMenuContext } from '../../contexts';
|
|
6
3
|
// Utils
|
|
7
4
|
import { getMenuItem } from '../../utils';
|
|
5
|
+
// Stores
|
|
6
|
+
import { useLeftMenuStore } from '../../stores';
|
|
8
7
|
export const useTemplatesMenu = () => {
|
|
9
|
-
|
|
10
|
-
const
|
|
8
|
+
// Selectors
|
|
9
|
+
const appMenuChildren = useLeftMenuStore(store => store.state.appMenuChildren);
|
|
10
|
+
const customChildren = useMemo(() => appMenuChildren === null || appMenuChildren === void 0 ? void 0 : appMenuChildren.map(item => getMenuItem(item)), [appMenuChildren]);
|
|
11
11
|
return {
|
|
12
12
|
children: customChildren,
|
|
13
13
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Libraries
|
|
2
2
|
import React, { memo, useEffect, useState } from 'react';
|
|
3
3
|
import Icon from '@antscorp/icons';
|
|
4
|
-
import { isEmpty, isNil, isString } from 'lodash';
|
|
4
|
+
import { isEmpty, isNil, isString, uniq } from 'lodash';
|
|
5
5
|
import { Link, useLocation } from 'react-router-dom';
|
|
6
6
|
import { useContextSelector } from 'use-context-selector';
|
|
7
7
|
// Components
|
|
@@ -15,48 +15,54 @@ import { ICON_SIZE } from '../../../constants';
|
|
|
15
15
|
import { ENV } from '@antscorp/antsomi-ui/es/config';
|
|
16
16
|
// Contexts
|
|
17
17
|
import { AppConfigContext } from '@antscorp/antsomi-ui/es/providers';
|
|
18
|
-
//
|
|
19
|
-
import { getGeneratePath } from '../../../utils';
|
|
18
|
+
// Stores
|
|
20
19
|
import { useLeftMenuStore } from '../../../stores';
|
|
20
|
+
// Utils
|
|
21
|
+
import { findActiveAppCodeByUrl, getGeneratePath } from '../../../utils';
|
|
22
|
+
import { findActiveMenuItemByUrl, recursiveFindParentOfActiveItem } from './utils';
|
|
21
23
|
export const ChildMenu = memo(props => {
|
|
22
24
|
const { items = [], parentKey, onMenuClick } = props;
|
|
23
25
|
// Selectors
|
|
24
26
|
const auth = useContextSelector(AppConfigContext, state => state === null || state === void 0 ? void 0 : state.auth);
|
|
25
27
|
const env = useContextSelector(AppConfigContext, state => state === null || state === void 0 ? void 0 : state.env);
|
|
26
|
-
const setLeftMenuStoreState = useLeftMenuStore(
|
|
28
|
+
const setLeftMenuStoreState = useLeftMenuStore(store => store.setState);
|
|
29
|
+
const activeAppCode = useLeftMenuStore(store => store.state.activeAppCode);
|
|
30
|
+
const menuItems = useLeftMenuStore(store => store.state.menuItems);
|
|
27
31
|
// States
|
|
28
32
|
const [currentActiveItem, setCurrentActiveItem] = useState('');
|
|
33
|
+
const [openKeys, setOpenKeys] = useState([]);
|
|
29
34
|
// Hooks
|
|
30
35
|
const { pathname, hash, search } = useLocation();
|
|
31
36
|
// Side Effects
|
|
32
37
|
useEffect(() => {
|
|
33
|
-
var _a;
|
|
34
38
|
const url = `${pathname}${hash}${search}`;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
}
|
|
39
|
+
/** Active menu item by current url */
|
|
40
|
+
const activeMenuItem = findActiveMenuItemByUrl({ url, menuItems, auth });
|
|
41
|
+
if (activeMenuItem && activeMenuItem !== currentActiveItem) {
|
|
42
|
+
setCurrentActiveItem(activeMenuItem);
|
|
43
|
+
/** Find parent key of active menu item to open it */
|
|
44
|
+
const parentKey = recursiveFindParentOfActiveItem({ activeMenuItem, menuItems });
|
|
45
|
+
if (parentKey) {
|
|
46
|
+
setOpenKeys(prev => [...prev, parentKey]);
|
|
47
|
+
}
|
|
48
|
+
/** Active App Item having code matching url */
|
|
49
|
+
const matchAppCode = findActiveAppCodeByUrl({ menuItems, url, auth });
|
|
50
|
+
if (matchAppCode && matchAppCode !== activeAppCode) {
|
|
51
|
+
setLeftMenuStoreState({ activeAppCode: matchAppCode });
|
|
50
52
|
}
|
|
51
|
-
return activeItem;
|
|
52
|
-
};
|
|
53
|
-
const activeItem = (_a = recursiveFindActiveItem(items)) === null || _a === void 0 ? void 0 : _a.key;
|
|
54
|
-
if (activeItem && activeItem !== currentActiveItem) {
|
|
55
|
-
setCurrentActiveItem(activeItem);
|
|
56
53
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
}, [
|
|
55
|
+
auth,
|
|
56
|
+
currentActiveItem,
|
|
57
|
+
hash,
|
|
58
|
+
items,
|
|
59
|
+
pathname,
|
|
60
|
+
search,
|
|
61
|
+
parentKey,
|
|
62
|
+
activeAppCode,
|
|
63
|
+
setLeftMenuStoreState,
|
|
64
|
+
menuItems,
|
|
65
|
+
]);
|
|
60
66
|
// Handlers
|
|
61
67
|
const onClick = e => {
|
|
62
68
|
onMenuClick === null || onMenuClick === void 0 ? void 0 : onMenuClick(e.key, e.keyPath);
|
|
@@ -88,7 +94,9 @@ export const ChildMenu = memo(props => {
|
|
|
88
94
|
});
|
|
89
95
|
};
|
|
90
96
|
return (React.createElement(MenuWrapper, { className: "child-menu" },
|
|
91
|
-
React.createElement(Menu, { selectedKeys: [currentActiveItem], defaultOpenKeys: [currentActiveItem], mode: "inline", items: customMenuItems({ items }), inlineIndent: 10,
|
|
97
|
+
React.createElement(Menu, { selectedKeys: [currentActiveItem], defaultOpenKeys: [currentActiveItem], openKeys: uniq(openKeys), mode: "inline", items: customMenuItems({ items }), inlineIndent: 10, onOpenChange: openKeys => {
|
|
98
|
+
setOpenKeys(openKeys);
|
|
99
|
+
}, expandIcon: ({ isOpen }) => (React.createElement(Icon, { type: "icon-ants-expand-more", style: {
|
|
92
100
|
fontSize: ICON_SIZE,
|
|
93
101
|
color: 'inherit',
|
|
94
102
|
// color: THEME.token?.bw8,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TFeatureMenu } from '@antscorp/antsomi-ui/es/models/LeftMenu';
|
|
2
|
+
import { PayloadInfo } from '@antscorp/antsomi-ui/es/types';
|
|
3
|
+
export declare const findActiveMenuItemByUrl: (args: {
|
|
4
|
+
url: string;
|
|
5
|
+
menuItems: TFeatureMenu[];
|
|
6
|
+
auth?: Partial<PayloadInfo>;
|
|
7
|
+
}) => string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Recursively finds the parent key of the active menu item within the given menu items.
|
|
10
|
+
* @param {object} args - The arguments object.
|
|
11
|
+
* @param {string} args.activeMenuItem - The key of the active menu item.
|
|
12
|
+
* @param {TFeatureMenu[]} args.menuItems - The array of menu items to search within.
|
|
13
|
+
* @returns {string | undefined} The key of the parent menu item or undefined if not found.
|
|
14
|
+
*/
|
|
15
|
+
export declare const recursiveFindParentOfActiveItem: (args: {
|
|
16
|
+
activeMenuItem: string;
|
|
17
|
+
menuItems: TFeatureMenu[];
|
|
18
|
+
}) => string | undefined;
|