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

Navigation: New NavBar designs behind feature toggle #41045

Merged
merged 19 commits into from
Nov 2, 2021

Conversation

ashharrison90
Copy link
Contributor

What this PR does / why we need it:

implements the new NavBar designs behind the newNavigation feature toggle. changes:

  • splits the NavBar into 4 sections. search, core apps, plugin apps and config/settings.
  • removes the Home link from the dashboard menu and adds it as a standalone item in the NavBar
  • removes the + button from the NavBar and adds the actions to the dashboard menu
  • moves Server Admin + Configuration to the config/settings (bottom) section
  • refactors the grafana logo to be a NavBarItem, same as everything else
  • created a new generic NavBarSection component and removed the existing TopSection/BottomSection in favour of this
    • moved the fairly specific logic of BottomSection into a util function enrichConfigItems
  • adjusted profile weight so that it appears below config and admin (in practice this was already happening because they were split into BottomSection/TopSection respectively)
with feature toggle off with feature toggle on
image image

Which issue(s) this PR fixes:

For #37961

Special notes for your reviewer:

  • i apologise in advance for my go. any pointers to make that nicer would be greatly appreciated 🙏

Comment on lines 32 to 34
if (newNavigationEnabled) {
return !item.hideFromMenu && !item.id?.startsWith('plugin-page-');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this something we can control in the backend instead?

Copy link
Contributor

@hugohaggmark hugohaggmark left a comment

Choose a reason for hiding this comment

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

Great work as always, I left some small comments.

I found the Grafana logo to become smaller on this branch when the feature toggle is off.

Before
image

After
image

I know that this is just the beginning but so much negative space when you don't have app plugins 😞

image

className?: string;
}

const NavBarSection = ({ children, className }: Props) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we prefer function({...} : Props): ReactElement over const

);
};

export default NavBarSection;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we prefer export const NavBarSection over export defaults.

@@ -9,10 +14,69 @@ export const getForcedLoginUrl = (url: string) => {
return `${getConfig().appSubUrl}${url.split('?')[0]}?${queryParams.toString()}`;
};

export const enrichConfigItems = (
Copy link
Contributor

Choose a reason for hiding this comment

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

This function seems testable?

@ashharrison90
Copy link
Contributor Author

@hugohaggmark for the logo, good eyes 👀

now that it's a NavBarItem it's the same size as everything else in the NavBar. do you think it should be bigger (as before), or just pointing out the difference? 🤔

@hugohaggmark
Copy link
Contributor

@hugohaggmark for the logo, good eyes 👀

now that it's a NavBarItem it's the same size as everything else in the NavBar. do you think it should be bigger (as before), or just pointing out the difference? 🤔

Because we use a feature toggle, things without the toggle should remain the same.

@torkelo
Copy link
Member

torkelo commented Oct 29, 2021

visually this feels very complex to me all these separate sections and borders (where the navbar is not at the edge but actually lives 8px from the left edge)

@ashharrison90
Copy link
Contributor Author

mmm that's fair feedback, fyi @lukasztyrala

i think it still needs some usability testing so it's probably not the final design. that's the beauty of the toggle, we can iterate 😄 how do you feel about the functional changes @torkelo?

@torkelo
Copy link
Member

torkelo commented Oct 29, 2021

But I think it sort of works as well (the left padding), but I am not sure separating the sections that much is helpful, we also want app plugins to feels like any other core Grafana feature

@lukasztyrala
Copy link
Member

We are putting this behind a feature flag to test with people. We want to validate some assumptions and directions. This is not final by any means/dimensions. :-)

@ashharrison90 ashharrison90 requested a review from a team as a code owner October 29, 2021 15:18
Copy link
Contributor

@hugohaggmark hugohaggmark left a comment

Choose a reason for hiding this comment

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

Frontend code looks great and thanks for adding tests. Added some comments and would be good if someone in @grafana/backend-platform could review the backend parts too.

Id: "profile",
Img: gravatarURL,
Url: hs.Cfg.AppSubURL + "/profile",
HideFromMenu: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: HideFromMenu removed here, probably ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, now we've added the Section property to the struct, this HideFromMenu becomes redundant and a little confusing (since at the top level it never hid anything from the menu, it was used to control what appeared in TopSection/BottomSection).

Copy link
Contributor

Choose a reason for hiding this comment

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

So when the feature toggle is the new "default" we need to revisit this and deprecate/remove HideFromMenu.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, we probably need to separate out NavLink and create NavLinkChild or something. for NavLinkChild it makes sense and behaves as expected. for a top level NavLink it was kinda being repurposed

@@ -23,7 +89,7 @@ export const isLinkActive = (pathname: string, link: NavModelItem) => {
// alert channel match
// TODO refactor routes such that we don't need this custom logic
return true;
} else if (linkPathname === '/' && pathname.startsWith('/d/')) {
} else if (linkPathname === dashboardLinkMatch && pathname.startsWith('/d/')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any tests that need updating?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there weren't, but that was a little concerning tbh so i've added some more tests 😄

Comment on lines 63 to 152

{!newNavigationEnabled && (
<NavBarSection>
<NavBarItem url={homeUrl} label="Home" className={styles.grafanaLogo} showMenu={false}>
<Branding.MenuLogo />
</NavBarItem>
<NavBarItem
className={styles.search}
isActive={activeItemId === 'search'}
label="Search dashboards"
onClick={onOpenSearch}
>
<Icon name="search" size="xl" />
</NavBarItem>
</NavBarSection>
)}
{newNavigationEnabled && (
<NavBarSection>
<NavBarItem url={homeUrl} label="Home" className={styles.grafanaLogo} showMenu={false}>
<Branding.MenuLogo />
</NavBarItem>
<NavBarItem
className={styles.search}
isActive={activeItemId === 'search'}
label="Search dashboards"
onClick={onOpenSearch}
>
<Icon name="search" size="xl" />
</NavBarItem>
</NavBarSection>
)}

<NavBarSection>
{coreItems.map((link, index) => (
<NavBarItem
key={`${link.id}-${index}`}
isActive={activeItemId === link.id}
label={link.text}
menuItems={link.children}
target={link.target}
url={link.url}
>
{link.icon && <Icon name={link.icon as IconName} size="xl" />}
{link.img && <img src={link.img} alt={`${link.text} logo`} />}
</NavBarItem>
))}
</NavBarSection>

{pluginItems.length > 0 && (
<NavBarSection>
{pluginItems.map((link, index) => (
<NavBarItem
key={`${link.id}-${index}`}
isActive={activeItemId === link.id}
label={link.text}
menuItems={link.children}
menuSubTitle={newNavigationEnabled ? link.subTitle : undefined}
onClick={link.onClick}
target={link.target}
url={link.url}
>
{link.icon && <Icon name={link.icon as IconName} size="xl" />}
{link.img && <img src={link.img} alt={`${link.text} logo`} />}
</NavBarItem>
))}
</NavBarSection>
)}

<div className={styles.spacer} />

<NavBarSection>
{configItems.map((link, index) => (
<NavBarItem
key={`${link.id}-${index}`}
isActive={activeItemId === link.id}
label={link.text}
menuItems={link.children}
menuSubTitle={link.subTitle}
onClick={link.onClick}
reverseMenuDirection
target={link.target}
url={link.url}
>
{link.icon && <Icon name={link.icon as IconName} size="xl" />}
{link.img && <img src={link.img} alt={`${link.text} logo`} />}
</NavBarItem>
))}
</NavBarSection>

{showSwitcherModal && <OrgSwitcher onDismiss={toggleSwitcherModal} />}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think I would create 2 separate NavBar components one for the current and one for the feature toggle. I think that makes it a lot cleaner.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with this one.

Copy link
Contributor

@mckn mckn 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 great! Exiting stuff.

Question: what is the long-term plan for the navModel? Something we can get rid of/enhance in Grafana 9?

@ashharrison90
Copy link
Contributor Author

ashharrison90 commented Nov 1, 2021

Question: what is the long-term plan for the navModel? Something we can get rid of/enhance in Grafana 9?

great question @mckn, it's part of what we're trying to tackle with the configurable nav bar proposals that are sort of bubbling in the background right now.

navModel will probably need to stay in some respect. one proposal is we move it from bootData to an api, then we can allow a user to reconfigure their navModel (what items are in the navModel, their order, etc) via UI interactions which will trigger api calls to the backend.

would love any input/suggestions you have on that. think it's fair to say it's the part we're struggling the most on right now.

@ashharrison90 ashharrison90 merged commit 727a4bd into main Nov 2, 2021
@ashharrison90 ashharrison90 deleted the ash/navbar-enhancements branch November 2, 2021 11:19
ryantxu pushed a commit that referenced this pull request Nov 2, 2021
* Navigation: Remove plus button behind feature toggle

* Navigation: Add home button behind feature toggle

* Navigation: Move settings/admin to bottom section behind feature toggle

* Navigation: Refactor grafana logo to be a NavBarItem

* Navigation: Create new PluginSection and styling changes to support new sections

* Navigation: Hack to use mobile menu as a mega menu for now

* Navigation: Only render plugin section if there are items

* Navigation: mobile menu is always 100% width if toggle is off

* Navigation: Reset width back to 48 and fix broken css property

* Navigation: Create generic NavBarSection component to reduce repetition

* Navigation: Don't show sublinks for core items

* Navigation: Comments from UX review

* Navigation: Remove mobile menu hack

* Navigation: Unit tests for enrichConfigItems and other minor review comments

* Navigation: Move section logic to backend

* Navigation: Refactor alerting links out into a separate function

* Navigation: More tests for isLinkActive

* Linting...

* Navigation: Create new NavBar component for when feature toggle is enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants