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

PKPD-30 collapsible sidebar #568

Merged
merged 20 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7406395
PKPDX-29 Add headers to results tables
wniestroj Nov 8, 2024
4eec168
Remove unnecessary quotation mark
wniestroj Nov 8, 2024
569a3fb
Fix plots being constantly resized when changing layout
wniestroj Nov 12, 2024
1c80400
Fix plots being constantly resized when changing layout
wniestroj Nov 12, 2024
0f4610e
Merge branch 'ui-enhancements' into PKPDX-29
eatyourgreens Nov 13, 2024
bf836af
Added controlling of plots width in dependence to resolution/scale
wniestroj Nov 13, 2024
8b99168
Merge branch 'PKPDX-29' of https://github.com/pkpdapp-team/pkpdapp in…
wniestroj Nov 13, 2024
478d66f
PKPDX-30 Added collapsible sidebar, added animations for main content…
wniestroj Nov 20, 2024
2bd9dda
Merge branch 'ui-enhancements' into PKPDX-29
eatyourgreens Nov 20, 2024
4c330b4
Merge branch 'ui-enhancements' into PKPDX-29
eatyourgreens Nov 20, 2024
7b620d3
Refactor of collapsible sidebar, added context controlling the classe…
wniestroj Nov 20, 2024
7be26bf
Revert div to box
wniestroj Nov 20, 2024
8e0e05c
Resolved conflicts, fixed simulations animation bug
wniestroj Nov 20, 2024
e203f00
Merge branch 'ui-enhancements' into PKPDX-29
eatyourgreens Nov 21, 2024
74c4700
fix: merge conflict
eatyourgreens Nov 21, 2024
2501e39
Update frontend-v2/src/features/main/Sidebar.tsx
wniestroj Nov 21, 2024
1e5268e
Merge remote-tracking branch 'origin/ui-enhancements' into PKPDX-29
wniestroj Nov 21, 2024
42734a0
Merge branch 'PKPDX-29' of https://github.com/pkpdapp-team/pkpdapp in…
wniestroj Nov 21, 2024
15b462e
Changed aria-label for main navigation; added resizing of plots on wi…
wniestroj Nov 21, 2024
7edb41d
Refactored plot widths to be calucalated on container width; Simulati…
wniestroj Nov 22, 2024
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 frontend-v2/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@
color: rgb(112, 76, 182);
}

@keyframes onExpand {
0% {transform: translate(-190px); overflow-X: 'visible';}
100% {transform: translate(0); overflow-x: 'hidden';}
}

@keyframes onCollapse {
0% {transform: translate(190px); overflow-X: 'visible';}
100% {transform: translate(0); overflow-x: 'hidden';}
}

.on-expand {
animation-name: onExpand;
animation-duration: .35s;
animation-timing-function: linear;
}

.on-collapse {
animation-name: onCollapse;
animation-duration: .35s;
animation-timing-function: linear;
}

@keyframes App-logo-float {
0% {
transform: translateY(0);
Expand Down
7 changes: 5 additions & 2 deletions frontend-v2/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import "react-toastify/dist/ReactToastify.css";

import { SimulationContext } from "./contexts/SimulationContext";
import { SimulateResponse } from "./app/backendApi";
import { CollapsibleSidebarProvider } from "./shared/contexts/CollapsibleSidebarContext";

export type TimeInterval = {
start: number;
Expand Down Expand Up @@ -80,8 +81,10 @@ function App() {
<SimulationContext.Provider value={simulationContext}>
{isAuth ? (
<>
<Sidebar />
<ToastContainer />
<CollapsibleSidebarProvider>
<Sidebar />
<ToastContainer />
</CollapsibleSidebarProvider>
</>
) : (
<Login onLogin={onLogin} isLoading={false} errorMessage={error} />
Expand Down
1 change: 1 addition & 0 deletions frontend-v2/src/features/main/MainContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function TabPanel(props: TabPanelProps) {
hidden={value !== index}
id={`simple-tabpanel-${index}`}
aria-labelledby={`simple-tab-${index}`}
style={{ width: '100%'}}
{...other}
>
<Box sx={{ p: 3, zIndex: value === index ? 1000 : 1, paddingBottom: 0 }}>{children}</Box>
Expand Down
137 changes: 121 additions & 16 deletions frontend-v2/src/features/main/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ import ContactSupportIcon from "@mui/icons-material/ContactSupport";
import TableViewIcon from "@mui/icons-material/TableView";
import "@fontsource/comfortaa"; // Defaults to weight 400
import useSubjectGroups from "../../hooks/useSubjectGroups";
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import ArrowForwardIcon from "@mui/icons-material/ArrowForward";
import { useCollapsibleSidebar } from "../../shared/contexts/CollapsibleSidebarContext";
import '../../App.css'

const drawerWidth = 240;
const drawerExpandedWidth = 240;
const drawerCollapsedWidth = 50;

export default function Sidebar() {
const dispatch = useAppDispatch();
Expand Down Expand Up @@ -149,6 +154,8 @@ export default function Sidebar() {
setMobileOpen(!mobileOpen);
};

const { onCollapse, onExpand, setHasSimulationsExpandedChanged, isExpanded, animationClasses } = useCollapsibleSidebar();

const pageKeys = Object.keys(PageName);
const pageValues = Object.values(PageName);

Expand All @@ -161,6 +168,9 @@ export default function Sidebar() {

const handlePageClick = (key: string) => () => {
const chosenPage = PageName[key as keyof typeof PageName];
if (key !== PageName.SIMULATIONS) {
setHasSimulationsExpandedChanged(false);
}
dispatch(setPage(chosenPage));

switch (chosenPage) {
Expand Down Expand Up @@ -214,7 +224,7 @@ export default function Sidebar() {
(step) => step !== projectsPage && step !== helpPage,
);

const drawer = (
const drawerMobile = (
<div style={{ marginTop: "7rem" }}>
<List>
<ListItem key={projectsPage?.key} disablePadding>
Expand Down Expand Up @@ -282,14 +292,100 @@ export default function Sidebar() {
</div>
);

const drawer = (
<div style={{ marginTop: "7rem", transition: "all .35s linear" }}>
{isExpanded ? (
<IconButton aria-label='collapse-navigation' onClick={onCollapse} sx={{ marginLeft: ".5rem" }}>
<ArrowBackIcon />
</IconButton>
) : (
<IconButton aria-label='expand-navigation' onClick={onExpand} sx={{ marginLeft: ".5rem" }}>
<ArrowForwardIcon />
</IconButton>
)}
<List>
<ListItem key={projectsPage?.key} disablePadding>
<ListItemButton
onClick={handlePageClick(projectsPage?.key)}
disabled={isPageDisabled(projectsPage?.key)}
disableRipple={true}
selected={isPageSelected(projectsPage?.key)}
>
<ListItemIcon>
{projectsPage?.value in errorComponents
? errorComponents[projectsPage?.value]
: icons[projectsPage?.value]}
</ListItemIcon>
<ListItemText primary={projectsPage?.value} />
</ListItemButton>
</ListItem>
</List>
{projectIdOrZero !== 0 && (
<>
{isExpanded ? (
<Typography
variant="subtitle1"
component="div"
sx={{
flexGrow: 1,
color: "gray",
paddingLeft: "1rem",
paddingTop: "1rem",
}}
>
STEPS
</Typography>
) : (
<Divider sx={{ paddingTop: "21px", marginBottom: "22px" }} />
)}

<List>
{steps.map(({ key, value }) => (
<ListItem key={key} disablePadding>
<ListItemButton
onClick={handlePageClick(key)}
disabled={isPageDisabled(key)}
disableRipple={true}
selected={isPageSelected(key)}
>
<ListItemIcon>
{value in errorComponents
? errorComponents[value]
: icons[value]}
</ListItemIcon>
<ListItemText sx={{ textWrap: "nowrap" }} primary={value} />
</ListItemButton>
</ListItem>
))}
</List>
</>
)}
{isExpanded && (
<Typography
sx={{
position: "absolute",
bottom: 0,
margin: ".5rem",
color: "gray",
textWrap: "nowrap",
}}
>
pkpdx version {import.meta.env.VITE_APP_VERSION?.slice(0, 7) || "dev"}
</Typography>
)}
</div>
);

return (
<Box sx={{ display: "flex" }}>
<Box sx={{ display: "flex", overflowX: "hidden" }}>
<CssBaseline />
<AppBar
position="fixed"
sx={{
width: { sm: `100%` },
ml: { sm: `${drawerWidth}px` },
ml: {
sm: `${isExpanded ? drawerExpandedWidth : drawerCollapsedWidth}px`,
},
zIndex: 9998,
backgroundColor: "white",
}}
Expand Down Expand Up @@ -368,8 +464,13 @@ export default function Sidebar() {
</AppBar>
<Box
component="nav"
sx={{ width: { sm: drawerWidth }, flexShrink: { sm: 0 } }}
aria-label="mailbox folders"
sx={{
width: {
sm: isExpanded ? drawerExpandedWidth : drawerCollapsedWidth,
},
flexShrink: { sm: 0 },
}}
aria-label="navigation"
wniestroj marked this conversation as resolved.
Show resolved Hide resolved
>
{/* The implementation can be swapped with js to avoid SEO duplication of links. */}
<Drawer
Expand All @@ -383,19 +484,21 @@ export default function Sidebar() {
display: { xs: "block", sm: "none" },
"& .MuiDrawer-paper": {
boxSizing: "border-box",
width: drawerWidth,
width: drawerExpandedWidth,
},
}}
>
{drawer}
{drawerMobile}
</Drawer>
<Drawer
variant="permanent"
sx={{
display: { xs: "none", sm: "block" },
"& .MuiDrawer-paper": {
boxSizing: "border-box",
width: drawerWidth,
width: isExpanded ? drawerExpandedWidth : drawerCollapsedWidth,
transition: "width .35s linear",
overflowX: "hidden",
},
}}
open
Expand All @@ -407,23 +510,25 @@ export default function Sidebar() {
<Box
component="nav"
sx={{
width: { sm: drawerWidth },
width: {
sm: drawerExpandedWidth,
},
flexShrink: { sm: 0 },
height: "100vh",
backgroundColor: '#FBFBFA',
borderRight: '1px solid #DBD6D1'
}}
aria-label="mailbox folders"
id='simulations-portal'
aria-label="simulations-sidebar"
id="simulations-portal"
/>
)}
<Box
component="main"
id="main-content"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd be inclined to set the expanded/collapsed className here, rather than modify the DOM directly.

className={animationClasses}
sx={{
flexGrow: 1,
p: 3,
width: { sm: `calc(100% - ${drawerWidth}px)` },
paddingBottom: 0
overflowX: "hidden",
paddingBottom: 0,
}}
>
<Toolbar />
Expand Down
34 changes: 1 addition & 33 deletions frontend-v2/src/features/simulation/Simulations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,6 @@ import { getConstVariables } from "../model/resetToSpeciesDefaults";
import useSubjectGroups from "../../hooks/useSubjectGroups";
import useExportSimulation from "./useExportSimulation";
import { SimulationsSidePanel } from "./SimulationsSidePanel";
import { getTableHeight } from "../../shared/calculateTableHeights";

const PlotsWidthSteps = [
{
minHeight: 1100,
tableHeight: "75vw",
},
{
minHeight: 1000,
tableHeight: "72vw",
},
{
minHeight: 900,
tableHeight: "70vw",
},
{
minHeight: 800,
tableHeight: "65vw",
},
{
minHeight: 700,
tableHeight: "60vw",
},
{
minHeight: 600,
tableHeight: "55vw",
},
{
minHeight: 500,
tableHeight: "53vw",
},
];

type SliderValues = { [key: number]: number };

Expand Down Expand Up @@ -464,7 +432,7 @@ const Simulations: FC = () => {
<Box
sx={{
maxHeight: "80vh",
maxWidth: getTableHeight({ steps: PlotsWidthSteps }),
maxWidth: '100%',
overflow: "auto",
}}
>
Expand Down
8 changes: 7 additions & 1 deletion frontend-v2/src/features/simulation/SimulationsSidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import UnitField from "../../components/UnitField";
import SimulationSliderView from "./SimulationSliderView";
import HelpButton from "../../components/HelpButton";
import { ExpandLess, ExpandMore } from "@mui/icons-material";
import { ChangeEvent, useState } from "react";
import { ChangeEvent, useEffect, useState } from "react";
import { getTableHeight } from "../../shared/calculateTableHeights";
import {
Simulation,
Expand All @@ -28,6 +28,8 @@ import {
UnitRead,
} from "../../app/backendApi";
import { Control } from "react-hook-form";
import { useCollapsibleSidebar } from "../../shared/contexts/CollapsibleSidebarContext";
import '../../App.css'

type SimulationsSidePanelType = {
portalId: string;
Expand Down Expand Up @@ -143,17 +145,21 @@ export const SimulationsSidePanel = ({
const [collapseParameters, setCollapseParameters] = useState(true);
const [collapseReference, setCollapseReference] = useState(true);
const [collapseLegend, setCollapseLegend] = useState(true);
const { simulationAnimationClasses } = useCollapsibleSidebar();

if (!portalRoot) return null;

return ReactDOM.createPortal(
<Box
className={simulationAnimationClasses}
sx={{
display: "flex",
flexDirection: "column",
justifyContent: "space-between",
height: "100%",
paddingBottom: "1rem",
backgroundColor: "#FBFBFA",
borderRight: "1px solid #DBD6D1",
}}
>
<Box
Expand Down
Loading
Loading