Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize drawer width to reduce wasted space in reports and settings #1295

Merged
merged 8 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
22 changes: 22 additions & 0 deletions src/common/components/MenuItem.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import makeStyles from '@mui/styles/makeStyles';
import { ListItemButton, ListItemIcon, ListItemText } from '@mui/material';
import { Link } from 'react-router-dom';
import React from 'react';

const MenuItem = ({
title, link, icon, selected,
}) => {
const classes = makeStyles({
menuItemText: {
whiteSpace: 'nowrap',
},
});
Copy link
Member

Choose a reason for hiding this comment

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

Can you please move this outside for consistency. Similar to how we have it in other places.

return (
<ListItemButton key={link} component={Link} to={link} selected={selected}>
<ListItemIcon>{icon}</ListItemIcon>
<ListItemText primary={title} className={classes.menuItemText} />
</ListItemButton>
);
};

export default MenuItem;
26 changes: 21 additions & 5 deletions src/common/components/PageLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
} from '@mui/material';
import makeStyles from '@mui/styles/makeStyles';
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
import MenuIcon from '@mui/icons-material/Menu';
import { useNavigate } from 'react-router-dom';
import { useTranslation } from './LocalizationProvider';
Expand All @@ -27,7 +29,11 @@ const useStyles = makeStyles((theme) => ({
flexDirection: 'column',
},
desktopDrawer: {
width: theme.dimensions.drawerWidthDesktop,
width: (props) => (props.miniVariant ? `calc(${theme.spacing(8)} + 1px)` : theme.dimensions.drawerWidthDesktop),
transition: theme.transitions.create('width', {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen,
}),
},
mobileDrawer: {
width: theme.dimensions.drawerWidthTablet,
Expand Down Expand Up @@ -66,14 +72,17 @@ const PageTitle = ({ breadcrumbs }) => {
};

const PageLayout = ({ menu, breadcrumbs, children }) => {
const classes = useStyles();
const [miniVariant, setMiniVariant] = useState(false);
const classes = useStyles({ miniVariant });
const theme = useTheme();
const navigate = useNavigate();

const desktop = useMediaQuery(theme.breakpoints.up('md'));

const [openDrawer, setOpenDrawer] = useState(false);

const toggleDrawer = () => setMiniVariant(!miniVariant);

return desktop ? (
<div className={classes.desktopRoot}>
<Drawer
Expand All @@ -82,10 +91,17 @@ const PageLayout = ({ menu, breadcrumbs, children }) => {
classes={{ paper: classes.desktopDrawer }}
>
<Toolbar>
<IconButton color="inherit" edge="start" sx={{ mr: 2 }} onClick={() => navigate('/')}>
<ArrowBackIcon />
{!miniVariant && (
<>
<IconButton color="inherit" edge="start" sx={{ mr: 2 }} onClick={() => navigate('/')}>
<ArrowBackIcon />
</IconButton>
<PageTitle breadcrumbs={breadcrumbs} />
</>
)}
<IconButton color="inherit" edge="start" sx={{ ml: miniVariant ? -2 : 'auto' }} onClick={toggleDrawer}>
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs to be reformatted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

which part?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it

Copy link
Member

Choose a reason for hiding this comment

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

I think we should probably apply classes here as well for readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I followed the same pattern as the upper IconButton

{miniVariant ? <ChevronRightIcon /> : <ChevronLeftIcon />}
</IconButton>
<PageTitle breadcrumbs={breadcrumbs} />
</Toolbar>
<Divider />
{menu}
Expand Down
16 changes: 3 additions & 13 deletions src/reports/components/ReportsMenu.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react';
import {
Divider, List, ListItemButton, ListItemIcon, ListItemText,
} from '@mui/material';
import { Divider, List } from '@mui/material';
import StarIcon from '@mui/icons-material/Star';
import TimelineIcon from '@mui/icons-material/Timeline';
import PauseCircleFilledIcon from '@mui/icons-material/PauseCircleFilled';
Expand All @@ -13,18 +11,10 @@ import BarChartIcon from '@mui/icons-material/BarChart';
import RouteIcon from '@mui/icons-material/Route';
import EventRepeatIcon from '@mui/icons-material/EventRepeat';
import NotesIcon from '@mui/icons-material/Notes';
import { Link, useLocation } from 'react-router-dom';
import { useLocation } from 'react-router-dom';
import { useTranslation } from '../../common/components/LocalizationProvider';
import { useAdministrator, useRestriction } from '../../common/util/permissions';

const MenuItem = ({
title, link, icon, selected,
}) => (
<ListItemButton key={link} component={Link} to={link} selected={selected}>
<ListItemIcon>{icon}</ListItemIcon>
<ListItemText primary={title} />
</ListItemButton>
);
import MenuItem from '../../common/components/MenuItem';

const ReportsMenu = () => {
const t = useTranslation();
Expand Down
14 changes: 3 additions & 11 deletions src/settings/components/SettingsMenu.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import {
Divider, List, ListItemButton, ListItemIcon, ListItemText,
Divider, List,
} from '@mui/material';
import SettingsIcon from '@mui/icons-material/Settings';
import CreateIcon from '@mui/icons-material/Create';
Expand All @@ -15,22 +15,14 @@ import PublishIcon from '@mui/icons-material/Publish';
import SmartphoneIcon from '@mui/icons-material/Smartphone';
import HelpIcon from '@mui/icons-material/Help';
import CampaignIcon from '@mui/icons-material/Campaign';
import { Link, useLocation } from 'react-router-dom';
import { useLocation } from 'react-router-dom';
import { useSelector } from 'react-redux';
import { useTranslation } from '../../common/components/LocalizationProvider';
import {
useAdministrator, useManager, useRestriction,
} from '../../common/util/permissions';
import useFeatures from '../../common/util/useFeatures';

const MenuItem = ({
title, link, icon, selected,
}) => (
<ListItemButton key={link} component={Link} to={link} selected={selected}>
<ListItemIcon>{icon}</ListItemIcon>
<ListItemText primary={title} />
</ListItemButton>
);
import MenuItem from '../../common/components/MenuItem';

const SettingsMenu = () => {
const t = useTranslation();
Expand Down