feat: rename item sku to code.

feat: fix sidebar current tab issue.
This commit is contained in:
Ahmed Bouhuolia
2020-11-24 11:30:27 +02:00
parent a7e5401b7d
commit 0321f29442
20 changed files with 75 additions and 50 deletions

View File

@@ -1,5 +1,5 @@
import React from 'react';
import { Menu, MenuDivider } from '@blueprintjs/core';
import React, { useMemo } from 'react';
import { Menu, MenuDivider, Button } from '@blueprintjs/core';
import { useHistory, useLocation } from 'react-router-dom';
import sidebarMenuList from 'config/sidebarMenu';
import Icon from 'components/Icon';
@@ -16,16 +16,31 @@ export default function SidebarMenu() {
const children = Array.isArray(item.children)
? menuItemsMapper(item.children)
: null;
const isActive =
(item.href && item.href === location.pathname) ||
(item.children &&
item.children.some((c) => c.href === location.pathname));
const matchPath = (pathname, path) => {
return item.matchExact ? pathname === path : pathname.indexOf(path) !== -1;
};
const isActive = (item.children) ?
item.children.some((c) => matchPath(location.pathname, c.href)) :
(item.href && matchPath(location.pathname, item.href));
const handleItemClick = () => {
if (item.href) {
history.push(item.href);
}
};
const maybeRenderLabel = (item) => item.newTabHref ? (
<Button
className="menu-item__add-btn"
icon={<Icon icon={'plus'} iconSize={16} />}
onClick={(event) => {
history.push(item.newTabHref);
event.stopPropagation();
}}
/>
) : null;
return item.spacer ? (
<div class="bp3-menu-spacer"></div>
) : item.divider ? (
@@ -38,7 +53,7 @@ export default function SidebarMenu() {
active={isActive}
icon={<Icon icon={item.icon} iconSize={item.iconSize} />}
text={item.text}
label={item.label}
label={maybeRenderLabel(item)}
disabled={item.disabled}
children={children}
dropdownType={item.dropdownType || 'collapse'}