Skip to content

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

Merged
apedroferreira merged 16 commits intomui:masterfrom
apedroferreira:refactor-nav-selected-item
Mar 19, 2025
Merged

[DashboardLayout] Show nested navigation in mini-drawer#4276
apedroferreira merged 16 commits intomui:masterfrom
apedroferreira:refactor-nav-selected-item

Conversation

@apedroferreira
Copy link
Collaborator

@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-03-13.at.18.08.48.mov

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

Inspiration:

@apedroferreira apedroferreira added the type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or 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
@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 145f76b

@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
Collaborator

@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.

>
<NavigationListItemButton
selected={isSelected && (!navigationItem.children || isMini)}
selected={
Copy link
Collaborator

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
Collaborator

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

if (isPageItem(item)) {
const path = `${base}${item.segment ? `/${item.segment}` : ''}` || '/';
const path =
`${base.startsWith('/') ? base : `/${base}`}${base && base !== '/' && item.segment ? '/' : ''}${item.segment || ''}` ||
Copy link
Collaborator

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
Collaborator

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

Copy link
Collaborator Author

@apedroferreira apedroferreira Mar 12, 2025

Choose a reason for hiding this comment

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

I believe the activePagePath that goes here as a parameter already accounts for pattern matching with the logic in the useActivePage hook. I'll check again just to be sure.

So the behavior should be that pattern matching in children items works, but only under the segments in the parent items. If the parent also has a pattern, that pattern in the parent will probably be ignored in these cases and I think that's probably the way it should work.

<Box
sx={{
position: 'fixed',
left: 62,
Copy link
Collaborator

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)

@royhuntley
Copy link

Related a little to this item...

If you have a navigation structure that a PAGE item also has children, when the navigation drawer is open (Wide), you cant actually navigate to the page, because clicking on it expands to make the children visible. However, when the navigation drawer is closed (Narrow), you get taken to the page when you click on the item.

{
segment: 'test',
title: 'Test',
children: [ {
segment: 'orders',
title: 'Orders',
icon: ,
},
{
kind: 'divider'
},
{
segment: 'orders',
title: 'Orders',
icon: ,
},

@apedroferreira
Copy link
Collaborator Author

Related a little to this item...

If you have a navigation structure that a PAGE item also has children, when the navigation drawer is open (Wide), you cant actually navigate to the page, because clicking on it expands to make the children visible. However, when the navigation drawer is closed (Narrow), you get taken to the page when you click on the item.

{ segment: 'test', title: 'Test', children: [ { segment: 'orders', title: 'Orders', icon: , }, { kind: 'divider' }, { segment: 'orders', title: 'Orders', icon: , },

Hey, I know, that behavior will change once this PR is merged.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 13, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 13, 2025
@apedroferreira
Copy link
Collaborator Author

apedroferreira commented Mar 13, 2025

Didn't want to abandon this old PR so addressed review suggestions + improved mini bar design as the previous one here wasn't great.
Updated the video above with the new mini bar design.

@apedroferreira apedroferreira requested a review from a team March 13, 2025 18:41
@royhuntley
Copy link

royhuntley commented Mar 13, 2025 via email

@apedroferreira apedroferreira moved this from Backlog to In progress in Toolpad public roadmap Mar 17, 2025
@apedroferreira
Copy link
Collaborator Author

I'll merge this one soon if it's good with everyone!

Copy link
Collaborator

@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 good!

@DaliborHomola
Copy link

I'll merge this one soon if it's good with everyone!

Yes, great

@apedroferreira apedroferreira merged commit 2bf6a0b into mui:master Mar 19, 2025
15 checks passed
@apedroferreira apedroferreira deleted the refactor-nav-selected-item branch March 19, 2025 13:45
@github-project-automation github-project-automation bot moved this from In progress to Completed in Toolpad public roadmap Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

8 participants