@antscorp/antsomi-ui 1.3.5-beta.531 → 1.3.5-beta.534

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.
@@ -3,8 +3,7 @@ import React, { memo, useCallback, useMemo } from 'react';
3
3
  import Icon from '@antscorp/icons';
4
4
  import { Typography } from 'antd';
5
5
  import classNames from 'classnames';
6
- import { isNil, isString } from 'lodash';
7
- import { Link } from 'react-router-dom';
6
+ import { isNil } from 'lodash';
8
7
  import isEqual from 'react-fast-compare';
9
8
  // Styled
10
9
  import { ChildMenuWrapper, ExpandWrapper, FeatureMenu, FeatureMenuItem, LeftMenuNav, LeftMenuNavWrapper, PopoverWrapper, NavLogoWrapper, FeatureMenuWrapper, IconWrapper, } from './styled';
@@ -13,13 +12,12 @@ import { APP_KEYS } from './constants';
13
12
  // Components
14
13
  import { CustomMenu, CommonMenu, HomeMenu } from './components';
15
14
  // Hooks
16
- import { useLeftMenu, useNavigatePath } from './hooks';
15
+ import { useLeftMenu } from './hooks';
17
16
  const SubLogoAntsomi = 'https://st-media-template.antsomi.com/icons/antsomi/antsomi.png';
18
17
  export const LeftMenuComponent = memo(props => {
19
18
  const { style, className, customization, showLogo = true } = props;
20
19
  const { isExpandable = true, isCustomized, isRecommendation, items = [], onMenuItemClick, } = customization || {};
21
- const { state, activeAppCode, permissionMenu, customActiveAppKey, onToggleChildMenu, onMouseEnter, onMouseLeave, onHoverMenuBar, onShowPopover, } = useLeftMenu(props);
22
- const { isPushDifferentDomain, getPath, navigatePath } = useNavigatePath();
20
+ const { state, activeAppCode, permissionMenu, customActiveAppKey, onToggleChildMenu, onMouseEnter, onMouseLeave, onHoverMenuBar, onShowPopover, onClickFeatureMenuItem, } = useLeftMenu(props);
23
21
  const childActiveMenu = useMemo(() => {
24
22
  const appActiveKey = isCustomized || isRecommendation ? customActiveAppKey : activeAppCode;
25
23
  if (isCustomized)
@@ -43,15 +41,16 @@ export const LeftMenuComponent = memo(props => {
43
41
  }
44
42
  }, [isCustomized, isRecommendation, state.hoverItem]);
45
43
  const renderFeatureMenuItem = useCallback((item) => {
46
- const { menu_item_name, menu_item, icon_name, menu_item_code, menu_item_path, menu_item_domain, } = item;
44
+ const { menu_item_name, menu_item, icon_name, menu_item_code } = item;
47
45
  const isActive = activeAppCode === menu_item_code;
48
46
  const isHover = state.hoverItem === menu_item_code;
49
47
  const renderLabel = () => (React.createElement("li", { role: "menuitem", className: classNames({ isActive, isHover }) },
50
48
  React.createElement(IconWrapper, null, isNil(icon_name) ? null : React.createElement(Icon, { type: icon_name })),
51
49
  React.createElement(Typography.Text, null, menu_item_name),
52
50
  React.createElement("div", { className: "popup-triangle" })));
53
- 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())));
54
- }, [activeAppCode, getPath, isPushDifferentDomain, navigatePath, onMouseEnter, state.hoverItem]);
51
+ return (React.createElement(FeatureMenuItem, { key: menu_item, onMouseEnter: () => onMouseEnter(menu_item_code) },
52
+ React.createElement("div", { onClick: () => onClickFeatureMenuItem(item) }, renderLabel())));
53
+ }, [activeAppCode, state.hoverItem, onClickFeatureMenuItem, onMouseEnter]);
55
54
  const renderRecommendationMenuItem = useCallback((item) => {
56
55
  const { menu_item_name, menu_item, icon_name, permission_code } = item;
57
56
  const isActive = customActiveAppKey === permission_code;
@@ -54,6 +54,9 @@ export const ChildMenu = memo(props => {
54
54
  const [openKeys, setOpenKeys] = useState([]);
55
55
  const { pathname, hash } = window.location;
56
56
  const { isPushDifferentDomain, getPath, navigatePath } = useNavigatePath();
57
+ useDeepCompareEffect(() => {
58
+ setOpenKeys((items === null || items === void 0 ? void 0 : items.map(item => item.key)) || []);
59
+ }, [items]);
57
60
  useDeepCompareEffect(() => {
58
61
  switch (true) {
59
62
  case isCustomized: {
@@ -132,25 +135,31 @@ export const ChildMenu = memo(props => {
132
135
  env,
133
136
  ]);
134
137
  const onClick = e => {
135
- var _a;
136
138
  if (isRecommendation) {
137
- const permissionCode = (_a = recursiveFindItemByKey({
138
- activeKey: e.key,
139
- menuItems: items || [],
140
- })) === null || _a === void 0 ? void 0 : _a.permission_code;
141
- const permissionCodePath = (() => {
139
+ const [permissionCode, permissionCodePath] = (() => {
142
140
  var _a;
143
- const array = [];
144
- (_a = e.keyPath) === null || _a === void 0 ? void 0 : _a.forEach(item => {
141
+ if (e.key === 'WEB_PERSONALIZE') {
142
+ return ['WEB_PERSONALIZE-JOURNEY', ['WEB_PERSONALIZE-JOURNEY']];
143
+ }
144
+ const permissionCode = (_a = recursiveFindItemByKey({
145
+ activeKey: e.key,
146
+ menuItems: items || [],
147
+ })) === null || _a === void 0 ? void 0 : _a.permission_code;
148
+ const permissionCodePath = (() => {
145
149
  var _a;
146
- const permissionCode = (_a = recursiveFindItemByKey({
147
- activeKey: item,
148
- menuItems: items || [],
149
- })) === null || _a === void 0 ? void 0 : _a.permission_code;
150
- if (permissionCode)
151
- array.push(permissionCode);
152
- });
153
- return uniq(array);
150
+ const array = [];
151
+ (_a = e.keyPath) === null || _a === void 0 ? void 0 : _a.forEach(item => {
152
+ var _a;
153
+ const permissionCode = (_a = recursiveFindItemByKey({
154
+ activeKey: item,
155
+ menuItems: items || [],
156
+ })) === null || _a === void 0 ? void 0 : _a.permission_code;
157
+ if (permissionCode)
158
+ array.push(permissionCode);
159
+ });
160
+ return uniq(array);
161
+ })();
162
+ return [permissionCode, permissionCodePath];
154
163
  })();
155
164
  if (permissionCode)
156
165
  onMenuClick === null || onMenuClick === void 0 ? void 0 : onMenuClick(permissionCode, permissionCodePath);
@@ -34,6 +34,7 @@ export const HOME_MENU_ITEMS = {
34
34
  menu_item_name: 'Dashboard',
35
35
  menu_item_code: 'ownedDashboard',
36
36
  icon_name: 'icon-ants-dashboard',
37
+ menu_item_path: HOME_ROUTE,
37
38
  page_title: '_dashboard',
38
39
  },
39
40
  };
@@ -1,4 +1,5 @@
1
1
  import { LeftMenuProps } from '..';
2
+ import { TFeatureMenu } from '@antscorp/antsomi-ui/es/models/LeftMenu';
2
3
  interface TState {
3
4
  hoverItem: string;
4
5
  isExpandMenu: boolean;
@@ -7,12 +8,13 @@ interface TState {
7
8
  export declare const useLeftMenu: (props: LeftMenuProps) => {
8
9
  state: TState;
9
10
  activeAppCode: string;
10
- permissionMenu: import("../../../../models/LeftMenu").TFeatureMenu[];
11
+ permissionMenu: TFeatureMenu[];
11
12
  customActiveAppKey: string;
12
13
  onToggleChildMenu: () => void;
13
14
  onMouseEnter: (key: string) => void;
14
15
  onMouseLeave: () => void;
15
16
  onHoverMenuBar: () => void;
16
17
  onShowPopover: (hoverItem?: string) => void;
18
+ onClickFeatureMenuItem: (item: TFeatureMenu) => void;
17
19
  };
18
20
  export {};
@@ -10,7 +10,9 @@ import { useLeftMenuContext } from '../contexts';
10
10
  import { DASHBOARD_MODULE_CONFIG } from '../../../template/Layout/constants';
11
11
  // Hooks
12
12
  import { usePermission } from './usePermission';
13
- import { useDeepCompareEffect } from '@antscorp/antsomi-ui/es/hooks';
13
+ import { useCustomRouter, useDeepCompareEffect } from '@antscorp/antsomi-ui/es/hooks';
14
+ import { useNavigatePath } from './useNavigatePath';
15
+ import { flatTree } from '@antscorp/antsomi-ui/es/utils';
14
16
  export const useLeftMenu = (props) => {
15
17
  // Props
16
18
  const { objectType = DASHBOARD_MODULE_CONFIG.objectType, objectId = DASHBOARD_MODULE_CONFIG.objectId, isGrouped = DASHBOARD_MODULE_CONFIG.isGrouped, appConfig, customization, onActiveMenuCodeChange, } = props;
@@ -28,12 +30,16 @@ export const useLeftMenu = (props) => {
28
30
  return 'SQL_WORKSPACE';
29
31
  case 'DATASOURCES-APP_ANTALYSER':
30
32
  return 'DATASOURCES-SQL_WORKSPACE';
33
+ case 'WEB_PERSONALIZE-JOURNEY':
34
+ return 'WEB_PERSONALIZE';
31
35
  default:
32
36
  return activeKey;
33
37
  }
34
38
  }, [activeKey, isRecommendation]);
35
39
  const cookies = new ReactCookies();
36
40
  const { pathname, hash, origin } = window.location;
41
+ const { navigate } = useCustomRouter();
42
+ const { isPushDifferentDomain, getPath, navigatePath } = useNavigatePath();
37
43
  const activeAppCode = useLeftMenuContext(store => store.activeAppCode);
38
44
  const customActiveAppKey = useLeftMenuContext(store => store.customActiveAppKey);
39
45
  const setLeftMenuContextState = useLeftMenuContext(store => store.setState);
@@ -242,6 +248,38 @@ export const useLeftMenu = (props) => {
242
248
  const onHoverMenuBar = useCallback(() => {
243
249
  onMouseEnter(isCustomized ? customActiveAppKey : activeAppCode);
244
250
  }, [activeAppCode, customActiveAppKey, isCustomized, onMouseEnter]);
251
+ const onClickFeatureMenuItem = useCallback((item) => {
252
+ // Destructure permission_code from the item object
253
+ const { permission_code } = item;
254
+ // Initialize navigateInfo object with menu_item_domain and menu_item_path from the item
255
+ let navigateInfo = {
256
+ menu_item_domain: item.menu_item_domain,
257
+ menu_item_path: item.menu_item_path,
258
+ };
259
+ // Check if permission_code exists
260
+ if (permission_code) {
261
+ // Flatten the tree structure of item.children into a single array, filtering out items that have children
262
+ const flattenChildMenu = flatTree(item.children, 'children').filter(item => !item.children);
263
+ // Find the first child menu item that matches the permission_code or fallback to the first item in the array or the original item
264
+ const matchedChildMenu = (flattenChildMenu === null || flattenChildMenu === void 0 ? void 0 : flattenChildMenu.find(child => child.permission_code === permission_code)) ||
265
+ (flattenChildMenu === null || flattenChildMenu === void 0 ? void 0 : flattenChildMenu[0]) ||
266
+ item;
267
+ // If a matching child menu item is found, update navigateInfo with its domain and path
268
+ if (matchedChildMenu) {
269
+ navigateInfo = {
270
+ menu_item_domain: matchedChildMenu.menu_item_domain,
271
+ menu_item_path: matchedChildMenu.menu_item_path,
272
+ };
273
+ }
274
+ }
275
+ // Check if navigating to a different domain
276
+ if (!isPushDifferentDomain(navigateInfo.menu_item_domain, navigateInfo.menu_item_path)) {
277
+ // If not, navigate to the path using getPath and return
278
+ return navigate(getPath(navigateInfo.menu_item_path));
279
+ }
280
+ // If navigating to a different domain, use navigatePath with domain and path
281
+ navigatePath(navigateInfo.menu_item_domain, navigateInfo.menu_item_path);
282
+ }, [getPath, isPushDifferentDomain, navigate, navigatePath]);
245
283
  return {
246
284
  state,
247
285
  activeAppCode,
@@ -252,5 +290,6 @@ export const useLeftMenu = (props) => {
252
290
  onMouseLeave,
253
291
  onHoverMenuBar,
254
292
  onShowPopover,
293
+ onClickFeatureMenuItem,
255
294
  };
256
295
  };
@@ -132,7 +132,7 @@ export const recursiveGetInitialFeatureMenuItem = (featureMenuItem) => (Object.a
132
132
  export const recursiveGetMenuItemByPermission = (featureMenuItem) => {
133
133
  var _a;
134
134
  return ({
135
- key: featureMenuItem.permission_code || 'null',
135
+ key: featureMenuItem.permission_code || featureMenuItem.menu_item_code || 'null',
136
136
  label: featureMenuItem.menu_item_name,
137
137
  icon: featureMenuItem.icon_name,
138
138
  logo_url: featureMenuItem.logo_url,
@@ -339,6 +339,10 @@ export const findLastMatchedItemByUrl = (args) => {
339
339
  }
340
340
  };
341
341
  recursiveFindActiveItem(menuItems || []);
342
+ const recommendationItem = matchedItems.find(item => item.menu_item_code === HOME_MENU_ITEMS.RECOMMENDATION.menu_item_code);
343
+ if (recommendationItem) {
344
+ return recommendationItem;
345
+ }
342
346
  return matchedItems === null || matchedItems === void 0 ? void 0 : matchedItems.pop();
343
347
  }
344
348
  catch (error) {
@@ -142,11 +142,12 @@ export const Layout = memo(props => {
142
142
  return (React.createElement(LayoutWrapper, { showLeftMenu: !!showLeftMenu },
143
143
  React.createElement(Helmet, null,
144
144
  React.createElement("meta", { charSet: "utf-8" }),
145
- React.createElement("title", null, (header === null || header === void 0 ? void 0 : header.browserTitle) || (header === null || header === void 0 ? void 0 : header.pageTitle)
146
- ? isString(header === null || header === void 0 ? void 0 : header.pageTitle)
147
- ? header === null || header === void 0 ? void 0 : header.pageTitle
148
- : ''
149
- : activePageTitle)),
145
+ React.createElement("title", null, (header === null || header === void 0 ? void 0 : header.browserTitle) ||
146
+ ((header === null || header === void 0 ? void 0 : header.pageTitle)
147
+ ? isString(header === null || header === void 0 ? void 0 : header.pageTitle)
148
+ ? header === null || header === void 0 ? void 0 : header.pageTitle
149
+ : ''
150
+ : activePageTitle))),
150
151
  React.createElement(HeaderV2, Object.assign({}, mergeHeaderProps, { showLogo: !showLeftMenu })),
151
152
  React.createElement(Flex, { className: "layout-body" },
152
153
  showLeftMenu && (React.createElement(LeftMenu, Object.assign({ className: `layout-body__menu ${leftMenuClassName}` }, mergeLeftMenuProps, { appConfig: leftMenuAppConfig, onActiveMenuCodeChange: onActiveMenuCodeChange }))),
@@ -31,6 +31,8 @@ export const OldLeftMenu = memo(props => {
31
31
  return 'DATASOURCES-APP_ANTALYSER';
32
32
  case 'EXPLORERS':
33
33
  return 'ANALYSIS';
34
+ case 'WEB_PERSONALIZE-JOURNEY':
35
+ return 'JOURNEY';
34
36
  default:
35
37
  return activeKey;
36
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.531",
3
+ "version": "1.3.5-beta.534",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",