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

[DashboardLayout] Show nested navigation in mini-drawer #4276

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

apedroferreira
Copy link
Member

@apedroferreira apedroferreira commented Oct 18, 2024

Initially was just trying to refactor the sidebar navigation in DashboardLayout to use the same navigation cache and utilities as the PageContainer component.

But this required adding nested navigation to the sidebar for consistency with the warnings we show when there are duplicated navigation items, because the navigation links should match in all variants of the sidebar:

Screen.Recording.2025-01-16.at.13.56.19.mov

Also improved selected navigation item tests to cover an extra case.

Inspiration:

@apedroferreira apedroferreira added the enhancement This is not a bug, nor a new feature label Oct 18, 2024
@apedroferreira apedroferreira self-assigned this Oct 18, 2024
@apedroferreira apedroferreira changed the title Use navigation utils for sidebar selected item [DashboardLayout] Refactor sidebar selected item logic Oct 18, 2024
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 18, 2024
@apedroferreira apedroferreira changed the title [DashboardLayout] Refactor sidebar selected item logic [DashboardLayout] Show nested navigation in mini-drawer Oct 28, 2024
@oliviertassinari oliviertassinari added component: DashboardLayout component: layout This is the name of the generic UI component, not the React module! labels Nov 8, 2024
@douglaszaltron
Copy link

Nice!

@apedroferreira

This comment was marked as resolved.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 16, 2025
@mui-bot
Copy link

mui-bot commented Jan 16, 2025

Netlify deploy preview

https://deploy-preview-4276--mui-toolpad-docs.netlify.app/

Generated by 🚫 dangerJS against 98e83dc

@apedroferreira apedroferreira marked this pull request as ready for review January 16, 2025 14:03
@apedroferreira apedroferreira requested a review from a team January 16, 2025 14:03
Copy link
Member

@bharatkashyap bharatkashyap left a comment

Choose a reason for hiding this comment

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

Looks really good! Great addition to the feature-set. Some small comments on code.

sx={{
py: 0,
px: 1,
overflowX: 'hidden',
}}
>
<NavigationListItemButton
selected={isSelected && (!navigationItem.children || isMini)}
selected={
Copy link
Member

Choose a reason for hiding this comment

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

Might be helpful to add some comments to explain the thinking behind the really long ternaries


if (isSelected && !selectedItemId) {
selectedItemId = navigationItemId;
let nestedNavigationCollapseSx: SxProps<Theme> = { display: 'none' };
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this could be a useMemo to prevent having to recalculate on every render

@@ -67,7 +25,9 @@ function buildItemToPathMap(navigation: Navigation): Map<NavigationPageItem, str

const visit = (item: NavigationItem, base: string) => {
if (isPageItem(item)) {
const path = `${base}${item.segment ? `/${item.segment}` : ''}` || '/';
const path =
`${base.startsWith('/') ? base : `/${base}`}${base && base !== '/' && item.segment ? '/' : ''}${item.segment || ''}` ||
Copy link
Member

Choose a reason for hiding this comment

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

Similar comment about comments being helpful on really long ternaries. Even though this one seems relatively straightforward, a comment helps bolt down the original intent instead of having to guess/derive

return hasSelectedNavigationChildren(navigation, nestedItem, activePagePath);
}

return activePagePath === getItemPath(navigation, nestedItem);
Copy link
Member

Choose a reason for hiding this comment

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

To be sure, does this function work in cases where the nested navigation items are supplied via regex patterns? I might be missing something, but seems like the earlier function was checking for a navigationItem.pattern case and testing the path against the regex pattern in case it existed but I can't seem to find an analogous case here

<Box
sx={{
position: 'fixed',
left: 62,
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 no avoidable way to hard code the left and pl values here? I could be wrong but this might create a future bug if we make the size of the mini sidebar configurable - perhaps we can link these values to that constant (if indeed they derive from it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: layout This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

6 participants