@antscorp/antsomi-ui 1.3.5-beta.533 → 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;
@@ -34,7 +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}/detail`,
37
+ menu_item_path: HOME_ROUTE,
38
38
  page_title: '_dashboard',
39
39
  },
40
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;
@@ -36,6 +38,8 @@ export const useLeftMenu = (props) => {
36
38
  }, [activeKey, isRecommendation]);
37
39
  const cookies = new ReactCookies();
38
40
  const { pathname, hash, origin } = window.location;
41
+ const { navigate } = useCustomRouter();
42
+ const { isPushDifferentDomain, getPath, navigatePath } = useNavigatePath();
39
43
  const activeAppCode = useLeftMenuContext(store => store.activeAppCode);
40
44
  const customActiveAppKey = useLeftMenuContext(store => store.customActiveAppKey);
41
45
  const setLeftMenuContextState = useLeftMenuContext(store => store.setState);
@@ -244,6 +248,38 @@ export const useLeftMenu = (props) => {
244
248
  const onHoverMenuBar = useCallback(() => {
245
249
  onMouseEnter(isCustomized ? customActiveAppKey : activeAppCode);
246
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]);
247
283
  return {
248
284
  state,
249
285
  activeAppCode,
@@ -254,5 +290,6 @@ export const useLeftMenu = (props) => {
254
290
  onMouseLeave,
255
291
  onHoverMenuBar,
256
292
  onShowPopover,
293
+ onClickFeatureMenuItem,
257
294
  };
258
295
  };
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.533",
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/*",