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 1 commit
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
28 changes: 23 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 ? theme.dimensions.miniDrawerWidthDesktop : 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,19 @@ 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 = () => {
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 can be inlined.

setMiniVariant(!miniVariant);
};

return desktop ? (
<div className={classes.desktopRoot}>
<Drawer
Expand All @@ -82,10 +93,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
1 change: 1 addition & 0 deletions src/common/theme/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default {
sidebarWidth: '28%',
sidebarWidthTablet: '52px',
drawerWidthDesktop: '360px',
miniDrawerWidthDesktop: '56px',
Copy link
Member

Choose a reason for hiding this comment

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

Is there some standard size we can use from MUI?

drawerWidthTablet: '320px',
drawerHeightPhone: '250px',
filterFormWidth: '160px',
Expand Down
2 changes: 1 addition & 1 deletion src/reports/components/ReportsMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const MenuItem = ({
}) => (
<ListItemButton key={link} component={Link} to={link} selected={selected}>
<ListItemIcon>{icon}</ListItemIcon>
<ListItemText primary={title} />
<ListItemText primary={title} sx={{ 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.

What is this for? Also probably it should be set as a class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we change the width of the sidebar, multi word items break the line and then the height of the item grows

</ListItemButton>
);

Expand Down
2 changes: 1 addition & 1 deletion src/settings/components/SettingsMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const MenuItem = ({
}) => (
<ListItemButton key={link} component={Link} to={link} selected={selected}>
<ListItemIcon>{icon}</ListItemIcon>
<ListItemText primary={title} />
<ListItemText primary={title} sx={{ whiteSpace: 'nowrap' }} />
</ListItemButton>
);

Expand Down