Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 83 additions & 85 deletions packages/webapp/src/components/Navigation/SideMenu/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ import styles from './styles.module.scss';
import { getLanguageFromLocalStorage } from '../../../util/getLanguageFromLocalStorage';

const MenuItem = forwardRef(({ history, onClick, path, children, className }, ref) => {
const isActive = matchPath(history.location.pathname, path);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inactiveListItem styles now applied to base style.

return (
<ListItemButton
onClick={onClick ?? (() => history.push(path))}
className={clsx(
styles.listItem,
matchPath(history.location.pathname, path)
? styles.activeListItem
: styles.inactiveListItem,
className,
)}
className={clsx(styles.listItem, isActive && styles.active, className)}
ref={ref}
>
{children}
Expand All @@ -44,15 +39,23 @@ MenuItem.displayName = 'MenuItem';
const SubMenu = ({ compact, children, isExpanded, ...props }) => {
if (compact) {
return (
<Menu open={isExpanded} {...props}>
<Menu
open={isExpanded}
className={clsx(styles.list, styles.subList, styles.tertiary)}
{...props}
>
{children}
</Menu>
);
}

return (
<Collapse in={isExpanded} timeout="auto" unmountOnExit>
<List component="div" disablePadding className={styles.subList}>
<List
component="div"
disablePadding
className={clsx(styles.list, styles.subList, styles.tertiary)}
>
{children}
</List>
</Collapse>
Expand Down Expand Up @@ -84,12 +87,12 @@ const SideMenuContent = ({ history, closeDrawer, isCompact, hasBeenExpanded }) =
<div
role="presentation"
className={clsx(
styles.container,
isCompact && styles.compactContainer,
!isCompact && hasBeenExpanded && styles.expandedContainer,
styles.sideMenuContent,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename css styles -- "container" seemed to generic to understand while working on it. This component function is called sideMenuContent so I labeled it as such for understanding while working on PR.

isCompact && styles.compactSideMenuContent,
!isCompact && hasBeenExpanded && styles.expandedSideMenuContent,
)}
>
<List className={styles.list}>
<List className={clsx(styles.list, styles.primary)}>
<ListItemButton
onClick={() => handleClick('/')}
className={clsx(styles.listItem, styles.logoListItem)}
Expand All @@ -99,85 +102,80 @@ const SideMenuContent = ({ history, closeDrawer, isCompact, hasBeenExpanded }) =
</div>
</ListItemButton>
{mainActions.map(({ icon, label, path, subMenu, key, badge }) => {
if (!subMenu) {
if (subMenu) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swapped the placement of the returns -- Rendering the exception is now done in the if statement instead of being the default.

return (
<MenuItem
history={history}
key={key}
path={path}
onClick={() => onMenuItemClick(path)}
>
<ListItemIcon className={styles.icon}>{icon}</ListItemIcon>
<ListItemText
primary={label}
className={clsx(
styles.listItemText,
styles.animatedContent,
isCompact && styles.hiddenContent,
)}
/>
{!isCompact && badge}
</MenuItem>
<React.Fragment key={key}>
<MenuItem
history={history}
onClick={() => toggleExpanded(key)}
path={path}
ref={(el) => (expandableItemsRef.current[key] = el)}
>
<ListItemIcon className={styles.icon}>{icon}</ListItemIcon>
<ListItemText
primary={label}
className={clsx(
styles.listItemText,
styles.animatedContent,
isCompact && styles.hiddenContent,
)}
/>
{!isCompact && badge}
<ExpandMore
className={clsx(
styles.expandCollapseIcon,
expandedIds.includes(key) && styles.collapseIcon,
isCompact && styles.compactExpandIcon,
)}
/>
</MenuItem>
<SubMenu
compact={isCompact}
isExpanded={expandedIds.includes(key)}
onClose={resetExpanded}
anchorEl={expandableItemsRef.current[key]}
anchorOrigin={{
vertical: 'top',
horizontal: 'right',
}}
>
{subMenu.map(({ label: subMenuLabel, path: subMenuPath, key: subMenuKey }) => {
return (
<MenuItem
history={history}
key={subMenuKey}
path={subMenuPath}
className={styles.subItem}
onClick={() =>
isCompact ? onMenuItemClick(subMenuPath) : handleClick(subMenuPath)
}
>
<ListItemText primary={subMenuLabel} className={styles.subItemText} />
</MenuItem>
);
})}
</SubMenu>
</React.Fragment>
);
}

return (
<React.Fragment key={key}>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same - Swapped the placement of the returns -- Rendering the exception is now done in the if statement instead of being the default.

<MenuItem
history={history}
onClick={() => toggleExpanded(key)}
path={path}
ref={(el) => (expandableItemsRef.current[key] = el)}
>
<ListItemIcon className={styles.icon}>{icon}</ListItemIcon>
<ListItemText
primary={label}
className={clsx(
styles.listItemText,
styles.animatedContent,
isCompact && styles.hiddenContent,
)}
/>
{!isCompact && badge}
<ExpandMore
className={clsx(
styles.expandCollapseIcon,
expandedIds.includes(key) && styles.collapseIcon,
isCompact && styles.compactExpandIcon,
)}
/>
</MenuItem>
<SubMenu
compact={isCompact}
isExpanded={expandedIds.includes(key)}
onClose={resetExpanded}
anchorEl={expandableItemsRef.current[key]}
anchorOrigin={{
vertical: 'top',
horizontal: 'right',
}}
>
{subMenu.map(({ label: subMenuLabel, path: subMenuPath, key: subMenuKey }) => {
return (
<MenuItem
history={history}
key={subMenuKey}
path={subMenuPath}
className={styles.subItem}
onClick={() =>
isCompact ? onMenuItemClick(subMenuPath) : handleClick(subMenuPath)
}
>
<ListItemText primary={subMenuLabel} className={styles.subItemText} />
</MenuItem>
);
})}
</SubMenu>
</React.Fragment>
<MenuItem history={history} key={key} path={path} onClick={() => onMenuItemClick(path)}>
<ListItemIcon className={styles.icon}>{icon}</ListItemIcon>
<ListItemText
primary={label}
className={clsx(
styles.listItemText,
styles.animatedContent,
isCompact && styles.hiddenContent,
)}
/>
{!isCompact && badge}
</MenuItem>
);
})}
</List>
<List className={styles.list}>
<List className={clsx(styles.list, styles.secondary)}>
{adminActions.map(({ icon, label, path, key }) => {
return (
<MenuItem
Expand Down Expand Up @@ -230,7 +228,7 @@ const PureSideMenu = ({
};

return isMobile ? (
<div className={styles.sideMenu}>
<div className={styles.drawer}>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSS classname rename -- sideMenu was too generic to follow while updating -- this is the drawer version of the side menu only.

<Drawer
isOpen={isDrawerOpen}
onClose={onDrawerClose}
Expand Down
Loading