-
Notifications
You must be signed in to change notification settings - Fork 363
Issue 7552. Sidebar Navigation in Admin Section #8391
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
Open
RomanGolchuk
wants to merge
8
commits into
develop
Choose a base branch
from
rgolchuk/otr-2518-sidebar-navigation-in-admin-section
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7119068
feat(ehr): replace admin tabs with sidebar navigation
RomanGolchuk a3fdcc2
Merge branch 'develop' into rgolchuk/otr-2518-sidebar-navigation-in-a…
RomanGolchuk 327a441
fix(ehr): keep admin sidebar item selected on legacy detail routes
RomanGolchuk 962e8bd
test(ehr): update admin billing e2e specs for sidebar nav
RomanGolchuk e6ea718
fix(ehr): resolve MUI console warnings in admin pages
RomanGolchuk 5df6d84
test(ehr): update admin e2e specs for sidebar nav and heading changes
RomanGolchuk b429a42
test(ehr): fix AdminCustomFoldersPage component test and trim stale c…
RomanGolchuk 7d2accb
test: add adminSidebarItem e2e helper for admin nav selectors
RomanGolchuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { createContext, FC, PropsWithChildren, useContext } from 'react'; | ||
| import { createPortal } from 'react-dom'; | ||
|
|
||
| /** | ||
| * Holds the DOM node of the shared admin page header's action area. Admin pages render their | ||
| * primary CTA into it via {@link AdminHeaderActionSlot}, so every page shares one title+action row. | ||
| */ | ||
| const AdminHeaderSlotContext = createContext<HTMLElement | null>(null); | ||
|
|
||
| export const AdminHeaderSlotProvider = AdminHeaderSlotContext.Provider; | ||
|
|
||
| /** | ||
| * Renders its children into the shared admin page header, on the same row as the page title and | ||
| * aligned to the right. Place it anywhere inside an admin page to lift that page's primary action | ||
| * (e.g. an "Add"/"New" button) into the common header while keeping its handler and state local. | ||
| */ | ||
| export const AdminHeaderActionSlot: FC<PropsWithChildren> = ({ children }) => { | ||
| const container = useContext(AdminHeaderSlotContext); | ||
| if (!container) { | ||
| return null; | ||
| } | ||
| return createPortal(children, container); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,208 @@ | ||
| import { otherColors } from '@ehrTheme/colors'; | ||
| import ArrowDropDownCircleOutlinedIcon from '@mui/icons-material/ArrowDropDownCircleOutlined'; | ||
| import { | ||
| Box, | ||
| Collapse, | ||
| Drawer, | ||
| IconButton, | ||
| List, | ||
| ListItem, | ||
| ListItemButton, | ||
| ListItemIcon, | ||
| ListItemText, | ||
| Tooltip, | ||
| Typography, | ||
| useTheme, | ||
| } from '@mui/material'; | ||
| import { FC, Fragment, ReactElement, ReactNode, useState } from 'react'; | ||
| import { Link, Outlet, useLocation } from 'react-router-dom'; | ||
| import { adjustTopForBannerHeight } from 'src/helpers/misc.helper'; | ||
| import { ArrowIcon } from '../visits/shared/components/Sidebar'; | ||
| import { adminNavGroups } from './adminNav'; | ||
| import { isItemActive } from './adminRoutes'; | ||
|
|
||
| const CLOSED_DRAWER_WIDTH = 56; | ||
| const OPEN_DRAWER_WIDTH = 250; | ||
| // The sticky Navbar occupies this height; the sidebar starts just below it. In non-production the | ||
| // environment banner sits above the Navbar, so we offset by the banner height too (matching Navbar's | ||
| // own `top`) — otherwise the fixed sidebar slides up underneath the banner and Navbar. | ||
| const NAVBAR_OFFSET = adjustTopForBannerHeight(81); | ||
|
|
||
| interface AdminSidebarProps { | ||
| children: ReactNode; | ||
| } | ||
|
|
||
| export const AdminSidebar: FC<AdminSidebarProps> = ({ children }) => { | ||
| const theme = useTheme(); | ||
| const { pathname } = useLocation(); | ||
| const [open, setOpen] = useState(true); | ||
| const [collapsedGroups, setCollapsedGroups] = useState<Set<string>>(new Set()); | ||
|
|
||
| const drawerWidth = open ? OPEN_DRAWER_WIDTH : CLOSED_DRAWER_WIDTH; | ||
| const sidebarToggleLabel = `${open ? 'Collapse' : 'Expand'} sidebar`; | ||
|
|
||
| const toggleGroup = (groupLabel: string): void => { | ||
| setCollapsedGroups((prev) => { | ||
| const next = new Set(prev); | ||
| if (next.has(groupLabel)) { | ||
| next.delete(groupLabel); | ||
| } else { | ||
| next.add(groupLabel); | ||
| } | ||
| return next; | ||
| }); | ||
| }; | ||
|
|
||
| const renderItem = (itemPath: string, label: string, icon: ReactNode): ReactNode => { | ||
| const active = isItemActive(pathname, itemPath); | ||
| return ( | ||
| <ListItem key={itemPath} disablePadding sx={{ display: 'block' }}> | ||
| <Link to={itemPath} style={{ textDecoration: 'none', color: 'inherit' }}> | ||
| <Tooltip title={open ? '' : label} placement="right"> | ||
| <ListItemButton | ||
| selected={active} | ||
| sx={{ | ||
| minHeight: 44, | ||
| justifyContent: open ? 'initial' : 'center', | ||
| px: 2, | ||
| '&.Mui-selected': { | ||
| backgroundColor: theme.palette.action.hover, | ||
| borderRight: `2px solid ${theme.palette.primary.main}`, | ||
| }, | ||
| }} | ||
| > | ||
| <ListItemIcon | ||
| sx={{ | ||
| minWidth: 0, | ||
| mr: open ? 2 : 'auto', | ||
| justifyContent: 'center', | ||
| color: active ? theme.palette.primary.main : theme.palette.text.secondary, | ||
| }} | ||
| > | ||
| {icon} | ||
| </ListItemIcon> | ||
| <ListItemText | ||
| primary={label} | ||
| sx={{ opacity: open ? 1 : 0, m: 0 }} | ||
| primaryTypographyProps={{ | ||
| fontSize: 14, | ||
| fontWeight: active ? 700 : 500, | ||
| color: active ? theme.palette.primary.main : theme.palette.text.primary, | ||
| noWrap: true, | ||
| }} | ||
| /> | ||
| </ListItemButton> | ||
| </Tooltip> | ||
| </Link> | ||
| </ListItem> | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <Box sx={{ display: 'flex' }}> | ||
| <Drawer | ||
| variant="permanent" | ||
| sx={{ | ||
| width: drawerWidth, | ||
| flexShrink: 0, | ||
| '& .MuiDrawer-paper': { | ||
| position: 'fixed', | ||
| top: `${NAVBAR_OFFSET}px`, | ||
| height: `calc(100% - ${NAVBAR_OFFSET}px)`, | ||
| width: drawerWidth, | ||
| boxSizing: 'border-box', | ||
| overflowX: 'hidden', | ||
| borderRight: `1px solid ${theme.palette.divider}`, | ||
| transition: theme.transitions.create('width', { | ||
| easing: theme.transitions.easing.sharp, | ||
| duration: open ? theme.transitions.duration.enteringScreen : theme.transitions.duration.leavingScreen, | ||
| }), | ||
| }, | ||
| }} | ||
| > | ||
| <Box | ||
| sx={{ | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| minHeight: 48, | ||
| px: open ? '10px' : 0, | ||
| justifyContent: open ? 'flex-end' : 'center', | ||
| }} | ||
| > | ||
| <Tooltip title={sidebarToggleLabel} placement="right"> | ||
| <IconButton | ||
| onClick={() => setOpen((prev) => !prev)} | ||
| aria-label={sidebarToggleLabel} | ||
| sx={{ | ||
| width: 40, | ||
| height: 40, | ||
| padding: 0, | ||
| '&:hover': { | ||
| backgroundColor: otherColors.sidebarItemHover, | ||
| }, | ||
| }} | ||
| > | ||
| <ArrowIcon direction={open ? 'left' : 'right'} /> | ||
| </IconButton> | ||
| </Tooltip> | ||
| </Box> | ||
|
|
||
| <List sx={{ py: 0 }}> | ||
| {adminNavGroups.map((group) => { | ||
| const groupCollapsed = collapsedGroups.has(group.label); | ||
| return ( | ||
| <Fragment key={group.label}> | ||
| <Tooltip title={open ? '' : group.label} placement="right"> | ||
| <ListItemButton | ||
| onClick={() => toggleGroup(group.label)} | ||
| sx={{ | ||
| padding: open ? '8px 16px 6px 16px' : '8px 0', | ||
| justifyContent: open ? 'space-between' : 'center', | ||
| }} | ||
| aria-label={`Toggle ${group.label} section`} | ||
| > | ||
| {open && ( | ||
| <Typography | ||
| sx={{ | ||
| flexGrow: 1, | ||
| fontSize: '14px', | ||
| fontWeight: 500, | ||
| letterSpacing: '0px', | ||
| textTransform: 'uppercase', | ||
| color: theme.palette.primary.dark, | ||
| }} | ||
| > | ||
| {group.label} | ||
| </Typography> | ||
| )} | ||
| <ArrowDropDownCircleOutlinedIcon | ||
| fontSize="small" | ||
| sx={{ color: theme.palette.primary.main, rotate: groupCollapsed ? '' : '180deg' }} | ||
| /> | ||
| </ListItemButton> | ||
| </Tooltip> | ||
| <Collapse in={!groupCollapsed} timeout="auto" unmountOnExit> | ||
| {group.items.map((item) => renderItem(item.path, item.label, item.icon))} | ||
| </Collapse> | ||
| </Fragment> | ||
| ); | ||
| })} | ||
| </List> | ||
| </Drawer> | ||
| <Box component="main" sx={{ flexGrow: 1, minWidth: 0 }}> | ||
| {children} | ||
| </Box> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * Route layout that keeps the admin sidebar mounted across every `/admin/*` route — including the | ||
| * detail/add pages (e.g. `/admin/employees/add`) that render their own components rather than going | ||
| * through {@link AdminPage}. Nest admin routes under a `<Route element={<AdminLayout />}>`. | ||
| */ | ||
| export const AdminLayout: FC = (): ReactElement => ( | ||
| <AdminSidebar> | ||
| <Outlet /> | ||
| </AdminSidebar> | ||
| ); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.