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 4 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
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(7)} + 1px)` : theme.dimensions.drawerWidthDesktop),
Copy link
Member

Choose a reason for hiding this comment

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

calc(${theme.spacing(7)} + 1px) doesn't seem right. I know there is a version of a collapsed sidebar. Can we somehow use the size from there?

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe even use it as is instead of implementing our own thing.

https://mui.com/material-ui/react-drawer/#mini-variant-drawer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's exactly where that was taken from

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2024-11-14 at 18 12 47

Copy link
Member

Choose a reason for hiding this comment

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

But can we re-use the component instead of just copy-pasting the style?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not a component, it's an example how to do the mini variant.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I didn't realize that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I used the size they use for small screens (spacing(7)) in the example because using the other (spacing(8)) our icons wouldn't be centered. To use the mui example we should use spacing(8). Here's the difference:

using 7:
Screenshot 2024-11-14 at 20 28 55

using 8:
Screenshot 2024-11-14 at 20 28 13

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
22 changes: 16 additions & 6 deletions src/reports/components/ReportsMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,27 @@ 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 makeStyles from '@mui/styles/makeStyles';
import { useTranslation } from '../../common/components/LocalizationProvider';
import { useAdministrator, useRestriction } from '../../common/util/permissions';

const useStyles = makeStyles({
menuItemText: {
whiteSpace: 'nowrap',
},
});

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

const ReportsMenu = () => {
const t = useTranslation();
Expand Down
22 changes: 16 additions & 6 deletions src/settings/components/SettingsMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,30 @@ import HelpIcon from '@mui/icons-material/Help';
import CampaignIcon from '@mui/icons-material/Campaign';
import { Link, useLocation } from 'react-router-dom';
import { useSelector } from 'react-redux';
import makeStyles from '@mui/styles/makeStyles';
import { useTranslation } from '../../common/components/LocalizationProvider';
import {
useAdministrator, useManager, useRestriction,
} from '../../common/util/permissions';
import useFeatures from '../../common/util/useFeatures';

const useStyles = makeStyles({
menuItemText: {
whiteSpace: 'nowrap',
},
});

const MenuItem = ({
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can extract it as a common component to avoid duplication?

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

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