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

frontend: Improve scroll bars #2715

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
75 changes: 47 additions & 28 deletions frontend/src/components/App/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Box, Button } from '@mui/material';
import Container from '@mui/material/Container';
import CssBaseline from '@mui/material/CssBaseline';
import Link from '@mui/material/Link';
import { useTheme } from '@mui/material/styles';
import { styled } from '@mui/material/styles';
import { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -103,7 +102,6 @@ export default function Layout({}: LayoutProps) {
const isFullWidth = useTypedSelector(state => state.ui.isFullWidth);
const { t } = useTranslation();
const allClusters = useClustersConf();
const theme = useTheme();

/** This fetches the cluster config from the backend and updates the redux store on an interval.
* When stateless clusters are enabled, it also fetches the stateless cluster config from the
Expand Down Expand Up @@ -209,33 +207,54 @@ export default function Layout({}: LayoutProps) {
>
{t('Skip to main content')}
</Link>
<Box sx={{ display: 'flex', [theme.breakpoints.down('sm')]: { display: 'block' } }}>
<VersionDialog />
<CssBaseline enableColorScheme />
<VersionDialog />
<CssBaseline enableColorScheme />
<ActionsNotifier />
<Box
sx={{
display: 'flex',
overflow: 'auto',
flexDirection: 'column',
height: '100dvh',
}}
>
<TopBar />
<Sidebar />
<Main id="main" sx={{ flexGrow: 1, marginLeft: 'initial' }}>
{clustersNotInURL.slice(0, MAXIMUM_NUM_ALERTS).map(clusterName => (
<ClusterNotFoundPopup key={clusterName} cluster={clusterName} />
))}
<AlertNotification />
<Box>
<Div sx={theme.mixins.toolbar} />
<Container {...containerProps}>
<NavigationTabs />
{arePluginsLoaded && (
<RouteSwitcher
requiresToken={() => {
const clusterName = getCluster() || '';
const cluster = clusters ? clusters[clusterName] : undefined;
return cluster?.useToken === undefined || cluster?.useToken;
}}
/>
)}
</Container>
</Box>
</Main>
<ActionsNotifier />
<Box
sx={{
display: 'flex',
overflow: 'hidden',
}}
>
<Sidebar />
<Main
id="main"
sx={{
flexGrow: 1,
marginLeft: 'initial',
overflow: 'auto',
}}
>
{clustersNotInURL.slice(0, MAXIMUM_NUM_ALERTS).map(clusterName => (
<ClusterNotFoundPopup key={clusterName} cluster={clusterName} />
))}
<AlertNotification />
<Box>
<Div />
<Container {...containerProps}>
<NavigationTabs />
{arePluginsLoaded && (
<RouteSwitcher
requiresToken={() => {
const clusterName = getCluster() || '';
const cluster = clusters ? clusters[clusterName] : undefined;
return cluster?.useToken === undefined || cluster?.useToken;
}}
/>
)}
</Container>
</Box>
</Main>
</Box>
</Box>
</>
);
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/components/App/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { SettingsButton } from '../App/Settings';
import { ClusterTitle } from '../cluster/Chooser';
import ErrorBoundary from '../common/ErrorBoundary';
import { GlobalSearch } from '../globalSearch/GlobalSearch';
import { drawerWidth } from '../Sidebar';
import HeadlampButton from '../Sidebar/HeadlampButton';
import { setWhetherSidebarOpen } from '../Sidebar/sidebarSlice';
import { AppLogo } from './AppLogo';
Expand Down Expand Up @@ -408,9 +407,8 @@ export const PureTopBar = memo(
return (
<>
<AppBar
position="fixed"
position="static"
sx={theme => ({
marginLeft: drawerWidth,
zIndex: theme.zIndex.drawer + 1,
'& > *': {
color: theme.palette.text.primary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<div>
<nav
aria-label="Appbar Tools"
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation1 MuiAppBar-root MuiAppBar-colorPrimary MuiAppBar-positionFixed mui-fixed css-1nczbvg-MuiPaper-root-MuiAppBar-root"
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation1 MuiAppBar-root MuiAppBar-colorPrimary MuiAppBar-positionStatic css-uuamzf-MuiPaper-root-MuiAppBar-root"
>
<div
class="MuiToolbar-root MuiToolbar-gutters MuiToolbar-regular css-b3zdwt-MuiToolbar-root"
class="MuiToolbar-root MuiToolbar-gutters MuiToolbar-regular css-1g5gxk7-MuiToolbar-root"
>
<svg
fill="none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<div>
<nav
aria-label="Appbar Tools"
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation1 MuiAppBar-root MuiAppBar-colorPrimary MuiAppBar-positionFixed mui-fixed css-1nczbvg-MuiPaper-root-MuiAppBar-root"
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation1 MuiAppBar-root MuiAppBar-colorPrimary MuiAppBar-positionStatic css-uuamzf-MuiPaper-root-MuiAppBar-root"
>
<div
class="MuiToolbar-root MuiToolbar-gutters MuiToolbar-regular css-b3zdwt-MuiToolbar-root"
class="MuiToolbar-root MuiToolbar-gutters MuiToolbar-regular css-1g5gxk7-MuiToolbar-root"
>
<svg
fill="none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<div>
<nav
aria-label="Appbar Tools"
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation1 MuiAppBar-root MuiAppBar-colorPrimary MuiAppBar-positionFixed mui-fixed css-1nczbvg-MuiPaper-root-MuiAppBar-root"
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation1 MuiAppBar-root MuiAppBar-colorPrimary MuiAppBar-positionStatic css-uuamzf-MuiPaper-root-MuiAppBar-root"
>
<div
class="MuiToolbar-root MuiToolbar-gutters MuiToolbar-regular css-b3zdwt-MuiToolbar-root"
class="MuiToolbar-root MuiToolbar-gutters MuiToolbar-regular css-1g5gxk7-MuiToolbar-root"
>
<svg
fill="none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<div>
<nav
aria-label="Appbar Tools"
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation1 MuiAppBar-root MuiAppBar-colorPrimary MuiAppBar-positionFixed mui-fixed css-1nczbvg-MuiPaper-root-MuiAppBar-root"
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation1 MuiAppBar-root MuiAppBar-colorPrimary MuiAppBar-positionStatic css-uuamzf-MuiPaper-root-MuiAppBar-root"
>
<div
class="MuiToolbar-root MuiToolbar-gutters MuiToolbar-regular css-b3zdwt-MuiToolbar-root"
class="MuiToolbar-root MuiToolbar-gutters MuiToolbar-regular css-1g5gxk7-MuiToolbar-root"
>
<svg
fill="none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<div>
<nav
aria-label="Appbar Tools"
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation1 MuiAppBar-root MuiAppBar-colorPrimary MuiAppBar-positionFixed mui-fixed css-1nczbvg-MuiPaper-root-MuiAppBar-root"
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation1 MuiAppBar-root MuiAppBar-colorPrimary MuiAppBar-positionStatic css-uuamzf-MuiPaper-root-MuiAppBar-root"
>
<div
class="MuiToolbar-root MuiToolbar-gutters MuiToolbar-regular css-b3zdwt-MuiToolbar-root"
class="MuiToolbar-root MuiToolbar-gutters MuiToolbar-regular css-1g5gxk7-MuiToolbar-root"
>
<svg
fill="none"
Expand Down
33 changes: 23 additions & 10 deletions frontend/src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ export const PureSidebar = memo(
linkArea,
}: PureSidebarProps) => {
const { t } = useTranslation();
const listContainerRef = React.useRef<HTMLDivElement | null>(null);
const [isOverflowing, setIsOverflowing] = React.useState(false);
const adjustedDrawerWidthClosed = isOverflowing ? 84 : 72;
const temporarySideBarOpen = open === true && isTemporaryDrawer && openUserSelected === true;

// The large sidebar does not open in medium view (600-960px).
Expand Down Expand Up @@ -303,8 +306,10 @@ export const PureSidebar = memo(
})}
/>
<Grid
ref={listContainerRef}
sx={{
height: '100%',
overflowY: 'auto',
}}
container
direction="column"
Expand Down Expand Up @@ -363,6 +368,23 @@ export const PureSidebar = memo(
}
: {};

React.useEffect(() => {
const el = listContainerRef.current;
if (!el) {
return;
}

const observer = new ResizeObserver(() => {
setIsOverflowing(el.scrollHeight > el.clientHeight);
});

observer.observe(el);

setIsOverflowing(el.scrollHeight > el.clientHeight);

return () => observer.disconnect();
}, [items]);

return (
<Box component="nav" aria-label={t('translation|Navigation')}>
<Drawer
Expand All @@ -389,16 +411,7 @@ export const PureSidebar = memo(
duration: theme.transitions.duration.leavingScreen,
}),
overflowX: 'hidden',
width: '56px',
[theme.breakpoints.down('xs')]: {
background: 'initial',
},
[theme.breakpoints.down('sm')]: {
width: theme.spacing(0),
},
[theme.breakpoints.up('sm')]: {
width: '72px',
},
width: `${adjustedDrawerWidthClosed}px`,
background: theme.palette.sidebarBg,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
class="MuiBox-root css-0"
>
<div
class="MuiDrawer-root MuiDrawer-docked css-1p9jtjb-MuiDrawer-docked"
class="MuiDrawer-root MuiDrawer-docked css-1g0cdoa-MuiDrawer-docked"
>
<div
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation0 MuiDrawer-paper MuiDrawer-paperAnchorLeft MuiDrawer-paperAnchorDockedLeft css-12i7wg6-MuiPaper-root-MuiDrawer-paper"
>
<div
class="MuiBox-root css-6r4z7i"
class="MuiBox-root css-dak3i4"
/>
<div
class="MuiGrid-root MuiGrid-container MuiGrid-direction-xs-column MuiGrid-wrap-xs-nowrap css-tf9pd2-MuiGrid-root"
class="MuiGrid-root MuiGrid-container MuiGrid-direction-xs-column MuiGrid-wrap-xs-nowrap css-opqjvv-MuiGrid-root"
>
<div
class="MuiGrid-root MuiGrid-item css-13i4rnv-MuiGrid-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation0 MuiDrawer-paper MuiDrawer-paperAnchorLeft MuiDrawer-paperAnchorDockedLeft css-12i7wg6-MuiPaper-root-MuiDrawer-paper"
>
<div
class="MuiBox-root css-6r4z7i"
class="MuiBox-root css-dak3i4"
/>
<div
class="MuiGrid-root MuiGrid-container MuiGrid-direction-xs-column MuiGrid-wrap-xs-nowrap css-tf9pd2-MuiGrid-root"
class="MuiGrid-root MuiGrid-container MuiGrid-direction-xs-column MuiGrid-wrap-xs-nowrap css-opqjvv-MuiGrid-root"
>
<div
class="MuiGrid-root MuiGrid-item css-13i4rnv-MuiGrid-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
class="MuiBox-root css-0"
>
<div
class="MuiDrawer-root MuiDrawer-docked css-1p9jtjb-MuiDrawer-docked"
class="MuiDrawer-root MuiDrawer-docked css-1g0cdoa-MuiDrawer-docked"
>
<div
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation0 MuiDrawer-paper MuiDrawer-paperAnchorLeft MuiDrawer-paperAnchorDockedLeft css-12i7wg6-MuiPaper-root-MuiDrawer-paper"
>
<div
class="MuiBox-root css-6r4z7i"
class="MuiBox-root css-dak3i4"
/>
<div
class="MuiGrid-root MuiGrid-container MuiGrid-direction-xs-column MuiGrid-wrap-xs-nowrap css-tf9pd2-MuiGrid-root"
class="MuiGrid-root MuiGrid-container MuiGrid-direction-xs-column MuiGrid-wrap-xs-nowrap css-opqjvv-MuiGrid-root"
>
<div
class="MuiGrid-root MuiGrid-item css-13i4rnv-MuiGrid-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation0 MuiDrawer-paper MuiDrawer-paperAnchorLeft MuiDrawer-paperAnchorDockedLeft css-12i7wg6-MuiPaper-root-MuiDrawer-paper"
>
<div
class="MuiBox-root css-6r4z7i"
class="MuiBox-root css-dak3i4"
/>
<div
class="MuiGrid-root MuiGrid-container MuiGrid-direction-xs-column MuiGrid-wrap-xs-nowrap css-tf9pd2-MuiGrid-root"
class="MuiGrid-root MuiGrid-container MuiGrid-direction-xs-column MuiGrid-wrap-xs-nowrap css-opqjvv-MuiGrid-root"
>
<div
class="MuiGrid-root MuiGrid-item css-13i4rnv-MuiGrid-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation0 MuiDrawer-paper MuiDrawer-paperAnchorLeft MuiDrawer-paperAnchorDockedLeft css-12i7wg6-MuiPaper-root-MuiDrawer-paper"
>
<div
class="MuiBox-root css-6r4z7i"
class="MuiBox-root css-dak3i4"
/>
<div
class="MuiGrid-root MuiGrid-container MuiGrid-direction-xs-column MuiGrid-wrap-xs-nowrap css-tf9pd2-MuiGrid-root"
class="MuiGrid-root MuiGrid-container MuiGrid-direction-xs-column MuiGrid-wrap-xs-nowrap css-opqjvv-MuiGrid-root"
>
<div
class="MuiGrid-root MuiGrid-item css-13i4rnv-MuiGrid-root"
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/lib/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ const commonRules = {
xl: 1920,
},
},
mixins: {
toolbar: {
minHeight: 64,
'@media (max-width:600px)': {
minHeight: 60,
},
},
},
palette: {
primary: {
contrastText: '#fff',
Expand Down
Loading