Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor: update the navbar to match the new designs #15964

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

Merged
merged 15 commits into from
Dec 30, 2024

Conversation

BrunoQuaresma
Copy link
Collaborator

@BrunoQuaresma BrunoQuaresma commented Dec 27, 2024

Update the navbar to match the designs in this Figma file. Related to #15617.

Desktop preview:

Screen.Recording.2024-12-27.at.12.13.38.mov

Mobile preview:

Screen.Recording.2024-12-27.at.12.12.42.mov

For a closer look, you can check Chromatic snapshots or test the changes locally.

A few considerations:

  • I made some adjustments to improve the design, such as removing the chevron from the profile menu and reducing the size of the chevrons in the dropdowns. I’ve documented these changes in the Figma file so @chrifro can review them after returning from vacation.
  • Some of the design questions involve how the proxy and account dropdown menus should look on desktop and mobile. For desktop, I decided to retain the current styles, and for mobile, I tried to infer how they should look based on the existing design.
  • There is some duplicated logic between the regular/desktop navbar menus and the mobile menus, which could lead to inconsistencies and make maintenance harder in the future. I plan to address this in a follow-up PR to keep this review manageable.
  • I’ve added tests to minimize inconsistencies and potential bugs while working on this refactor.

@BrunoQuaresma BrunoQuaresma self-assigned this Dec 27, 2024
@BrunoQuaresma BrunoQuaresma requested review from a team, code-asher, jaaydenh and Parkreiner and removed request for a team and code-asher December 27, 2024 15:11
Copy link
Member

@Parkreiner Parkreiner 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 so far!
Close to approving this – I left a few comments, but nothing blocking. I just want to take the UI for a test drive to make sure I didn't miss anything

@@ -70,4 +70,10 @@
* {
@apply border-border;
}

/** Related to https://github.com/radix-ui/primitives/issues/3251 */
Copy link
Member

Choose a reason for hiding this comment

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

Could the comment also be updated to list what components rely on this patch?

/>
);
});
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
Copy link
Member

Choose a reason for hiding this comment

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

I'm just now realizing: do we want the ref type to always be HTMLButtonElement? I'm thinking about cases like this:

<Button asChild>
  <a href="#">Not actually a button in the output</a>
</Button>

Where TypeScript will think it's a button, but the actual HTML node will be for an anchor. I'm not sure what properties are on one but not the other, but calling a button method that doesn't exist could blow up the app

Copy link
Member

Choose a reason for hiding this comment

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

Only thing is, I'm not actually sure how you would add a generic ref type to forwardRef, since it's just a function call, and not a full function signature

I don't think this is worth blocking over, but I'll try to figure out a fix next week

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think your concern is totally valid, but this is the default implementation from the shadcn/ui Button. I’d be open to changing it only if necessary, as I’d prefer not to add complexity without bringing justifiable value to us.

);
},
);
Button.displayName = "Button";
Copy link
Member

Choose a reason for hiding this comment

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

I know there were some conversations about getting rid of displayName, but we weren't sure if it was necessary for forwarded anonymous components. Does the component not get a name in the dev tools if the name isn't set here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, okay, I wasn’t aware of that. Thanks for letting me know! I’ve just been copying and pasting the default implementation and making changes only when necessary.

proxies: Proxies,
latencies: ProxyLatencies,
) {
return [...proxies].sort((a, b) => {
Copy link
Member

Choose a reason for hiding this comment

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

Could we get away with replacing this with a call to .toSorted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

close={open}
/>
</div>
<button
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 a reason why we're still using the default HTML button here, instead of adding a new variant to the Button component?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This button style isn’t used anywhere else, so I’d avoid creating a new variant (essentially an abstraction) for just a single use case. If we encounter more use cases like this in the future, I think that would be the right time to turn it into a variant.

@@ -26,7 +25,7 @@ describe("Navbar", () => {
await userEvent.click(deploymentMenu);
await waitFor(
() => {
const link = screen.getByText(Language.audit);
const link = screen.getByText("Audit Logs");
expect(link).toBeDefined();
Copy link
Member

Choose a reason for hiding this comment

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

Is this check needed since getByText will throw if a node can't be found?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You’re right, it’s not needed.

@@ -26,7 +25,7 @@ describe("Navbar", () => {
await userEvent.click(deploymentMenu);
await waitFor(
() => {
const link = screen.getByText(Language.audit);
const link = screen.getByText("Audit Logs");
Copy link
Member

Choose a reason for hiding this comment

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

Could we update these to be role selectors, too?

open: "text-content-primary",
};

type MobileMenuProps = MobileMenuPermissions & {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: could this be moved below MobileMenuPermissions? When I was reading this top to bottom, I had to do a double take to see where the permissions were defined

export interface DropdownMenuButtonProps
extends ComponentPropsWithoutRef<typeof Button> {}

export const DropdownMenuButton = forwardRef<
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if it's a little confusing to have a file export both a trigger and a button, especially since the button doesn't use the trigger internally

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm... I hadn’t thought of that 🤔. Honestly—maybe it’s just personal—I don’t see any confusion since a trigger is a behavioral component and a button is a visual component. To me, it feels okay to have both. What would you suggest?

Copy link
Contributor

Choose a reason for hiding this comment

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

@BrunoQuaresma It looks like you are adding DropdownMenuButton to the shadcn DropdownMenu component? Im curious why it is necessary to add this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The purpose of this component is to make dropdown button styling consistent. For example, instead of composing a Button + Icon + styling in every component or page where you want to add a dropdown, you could use a consistent component to reduce boilerplate. While I don’t mind boilerplate in general, in this case, since we already have a consistent design, it could help avoid inconsistencies.

Before:

<Button ref={ref} variant="outline">
	Admin settings
	<DropdownMenuChevronDown />
</Button>

After:

<DropdownMenuButton>Admin settings</DropdownMenuButton>

However, while writing this, I thought of another approach that might be better—creating a new dropdown variant in the Button component:

<Button ref={ref} variant="dropdown">
	Admin settings
</Button>

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

If every DropdownMenu component will always use the DropdownMenuButton with this styling then it could make sense. However. that may not always be the case. I personally like having a dropdown variant for the button component more than altering the DropdownMenu component.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I decided to remove the DropdownMenuButton component for now until we actually need it.

}}
>
Workspace proxy settings:
<span className="leading-[0px] flex items-center gap-1">
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we want to set the line height to 0. It'll cause a lot of text rendering issues the moment the text has to wrap around

99% sure we want to set this to leading-none to set the text solid (line height of 1)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Noted! I’m not sure why, but when I used a line height of 1, it was misaligned, and I only managed to fix it by setting it to 0. I’ll double-check that.

Copy link
Member

@Parkreiner Parkreiner left a comment

Choose a reason for hiding this comment

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

Quick notes from testing things out:

  • Do we want to add overflow-x: auto to NavItems? That way if the viewport shrinks enough on mobile, the user can still scroll to the page link that they want
  • I also feel like the new navbar feels a little off with the rest of the site. The navbar and the sub-navigation below it are just different enough to be noticeable, while still similar enough to make it feel like it wasn't intentional
Screenshot 2024-12-27 at 12 13 03 PM

I posted a comment on the Figma design, but I really can't help but feel like the blurred background is a mistake. The comment goes into more detail, but I think a solid background is way less disorienting

Screen.Recording.2024-12-27.at.12.37.22.PM.mov

Still, I'm going to approve. We can always update the design in a second pass once Christin is back

@BrunoQuaresma
Copy link
Collaborator Author

BrunoQuaresma commented Dec 27, 2024

Do we want to add overflow-x: auto to NavItems? That way if the viewport shrinks enough on mobile, the user can still scroll to the page link that they want

I don’t think so—or at least, I wouldn’t expect that. What viewport did you use? If it’s something under 360px, I think we can safely skip it since that’s not very common these days.

Reference: Common Screen Resolutions

I also feel like the new navbar feels a little off with the rest of the site. The navbar and the sub-navigation below it are just different enough to be noticeable, while still similar enough to make it feel like it wasn't intentional

Good catch, I’ll fix that 👍.

I posted a comment on the Figma design, but I really can't help but feel like the blurred background is a mistake. The comment goes into more detail, but I think a solid background is way less disorienting

Ahhh, you’re right. I definitely prefer the solid background over the blurry one, but let’s let @chrifro make the final decision on it.

cc.: @Parkreiner

@BrunoQuaresma BrunoQuaresma merged commit 49fadb8 into main Dec 30, 2024
29 checks passed
@BrunoQuaresma BrunoQuaresma deleted the bq/improve-navbar branch December 30, 2024 17:25
@github-actions github-actions bot locked and limited conversation to collaborators Dec 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants