From 29398e74848c6cfc7fb0912830ae26e6a4f80381 Mon Sep 17 00:00:00 2001 From: David Crespo Date: Wed, 14 Aug 2024 16:55:19 -0500 Subject: [PATCH] Use real links in dropdown menus (#2343) add DropdownMenu.LinkItem so we can use real links when possible --- app/components/TopBar.tsx | 6 +----- app/ui/lib/DropdownMenu.tsx | 10 ++++++++++ app/ui/styles/components/menu-button.css | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/components/TopBar.tsx b/app/components/TopBar.tsx index dc1d3287f..708662be3 100644 --- a/app/components/TopBar.tsx +++ b/app/components/TopBar.tsx @@ -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' @@ -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 }), }) @@ -63,9 +61,7 @@ export function TopBar({ children }: { children: React.ReactNode }) { - navigate(pb.profile())}> - Settings - + Settings {loggedIn ? ( logout.mutate({})}> Sign out diff --git a/app/ui/lib/DropdownMenu.tsx b/app/ui/lib/DropdownMenu.tsx index ddebab55a..929296262 100644 --- a/app/ui/lib/DropdownMenu.tsx +++ b/app/ui/lib/DropdownMenu.tsx @@ -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 +// 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 & { to: string } + export const DropdownMenu = { Root, Trigger, @@ -38,4 +43,9 @@ export const DropdownMenu = { Item: forwardRef(({ className, ...props }: DropdownMenuItemProps, ref: DivRef) => ( )), + LinkItem: ({ className, children, to, ...props }: LinkitemProps) => ( + + {children} + + ), } diff --git a/app/ui/styles/components/menu-button.css b/app/ui/styles/components/menu-button.css index 386fd7e67..526a881ca 100644 --- a/app/ui/styles/components/menu-button.css +++ b/app/ui/styles/components/menu-button.css @@ -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; &.destructive { @apply text-destructive;