Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions app/components/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Copyright Oxide Computer Company
*/
import React from 'react'
import { useNavigate } from 'react-router-dom'

import { navToLogin, useApiMutation } from '@oxide/api'
import { DirectionDownIcon, Profile16Icon } from '@oxide/design-system/icons/react'
Expand All @@ -17,7 +16,6 @@ import { DropdownMenu } from '~/ui/lib/DropdownMenu'
import { pb } from '~/util/path-builder'

export function TopBar({ children }: { children: React.ReactNode }) {
const navigate = useNavigate()
const logout = useApiMutation('logout', {
onSuccess: () => navToLogin({ includeCurrent: false }),
})
Expand Down Expand Up @@ -63,9 +61,7 @@ export function TopBar({ children }: { children: React.ReactNode }) {
</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content align="end" sideOffset={8}>
<DropdownMenu.Item onSelect={() => navigate(pb.profile())}>
Settings
</DropdownMenu.Item>
<DropdownMenu.LinkItem to={pb.profile()}>Settings</DropdownMenu.LinkItem>
{loggedIn ? (
<DropdownMenu.Item onSelect={() => logout.mutate({})}>
Sign out
Expand Down
10 changes: 10 additions & 0 deletions app/ui/lib/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ import {
} from '@radix-ui/react-dropdown-menu'
import cn from 'classnames'
import { forwardRef, type ForwardedRef } from 'react'
import { Link } from 'react-router-dom'

type DivRef = ForwardedRef<HTMLDivElement>

// remove possibility of disabling links for now. if we put it back, make sure
// to forwardRef on LinkItem so the disabled tooltip can work
type LinkitemProps = Omit<DropdownMenuItemProps, 'disabled'> & { to: string }

export const DropdownMenu = {
Root,
Trigger,
Expand All @@ -38,4 +43,9 @@ export const DropdownMenu = {
Item: forwardRef(({ className, ...props }: DropdownMenuItemProps, ref: DivRef) => (
<Item {...props} className={cn('DropdownMenuItem ox-menu-item', className)} ref={ref} />
)),
LinkItem: ({ className, children, to, ...props }: LinkitemProps) => (
<Item {...props} className={cn('DropdownMenuItem ox-menu-item', className)} asChild>
<Link to={to}>{children}</Link>
</Item>
),
}
2 changes: 1 addition & 1 deletion app/ui/styles/components/menu-button.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@apply z-30 min-w-36 rounded border p-0 bg-raise border-secondary;

& .DropdownMenuItem {
@apply block cursor-pointer select-none border-b py-2 pl-3 pr-6 text-left text-sans-md text-secondary border-secondary last-of-type:border-b-0;
@apply block cursor-pointer select-none border-b py-2 pl-3 pr-6 text-left text-sans-md text-secondary border-secondary last:border-b-0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

last-of-type was getting thrown off by the mix of Item and LinkItem.


&.destructive {
@apply text-destructive;
Expand Down