From ce5715e45add6bbf22912708b5bdcf04be068f30 Mon Sep 17 00:00:00 2001 From: Denise Li Date: Fri, 25 Oct 2024 13:43:29 +1100 Subject: [PATCH] feat: support cmd+click to open module + decl links in new tab (#3187) Fixes https://github.com/TBD54566975/ftl/issues/3021 --- frontend/console/e2e/helpers.ts | 2 +- frontend/console/src/components/List.tsx | 28 +++++++----- .../src/features/modules/ModulesPanel.tsx | 8 +--- .../src/features/modules/ModulesTree.tsx | 45 +++++++------------ .../src/features/modules/decls/DeclLink.tsx | 9 ++-- 5 files changed, 40 insertions(+), 52 deletions(-) diff --git a/frontend/console/e2e/helpers.ts b/frontend/console/e2e/helpers.ts index 8c383d3cd5..d4de948707 100644 --- a/frontend/console/e2e/helpers.ts +++ b/frontend/console/e2e/helpers.ts @@ -16,6 +16,6 @@ export async function navigateToDecl(page: Page, moduleName: string, declName: s await navigateToModule(page, moduleName) // Navigate to the decl page - await page.locator(`div#decl-${declName}`).click() + await page.locator(`a#decl-${declName}`).click() await expect(page).toHaveURL(new RegExp(`/modules/${moduleName}/verb/${declName}`)) } diff --git a/frontend/console/src/components/List.tsx b/frontend/console/src/components/List.tsx index 52246b0440..3003e98552 100644 --- a/frontend/console/src/components/List.tsx +++ b/frontend/console/src/components/List.tsx @@ -1,26 +1,30 @@ import { ArrowRight01Icon } from 'hugeicons-react' +import { Link } from 'react-router-dom' import { classNames } from '../utils' type ListProps = { items: T[] renderItem: (item: T) => React.ReactNode - onClick?: (item: T) => void + href?: (item: T) => string className?: string } -export const List = ({ items, renderItem, onClick, className }: ListProps) => { +export const List = ({ items, renderItem, href, className }: ListProps) => { + const baseClasses = 'relative flex justify-between items-center gap-x-4 p-4' return (
    - {items.map((item, index) => ( -
  • onClick(item) : undefined} - > - {renderItem(item)} - {onClick && } -
  • - ))} + {items.map((item, index) => + href ? ( + + {renderItem(item)} + + + ) : ( +
  • + {renderItem(item)} +
  • + ), + )}
) } diff --git a/frontend/console/src/features/modules/ModulesPanel.tsx b/frontend/console/src/features/modules/ModulesPanel.tsx index 45f36354de..47455bf9cf 100644 --- a/frontend/console/src/features/modules/ModulesPanel.tsx +++ b/frontend/console/src/features/modules/ModulesPanel.tsx @@ -1,4 +1,3 @@ -import { useNavigate } from 'react-router-dom' import { useModules } from '../../api/modules/use-modules' import { AttributeBadge } from '../../components' import { List } from '../../components/List' @@ -8,17 +7,14 @@ import { deploymentTextColor } from '../deployments/deployment.utils' export const ModulesPanel = () => { const modules = useModules() - const navigate = useNavigate() - const handleModuleClick = (module: Module) => { - navigate(`/modules/${module.name}`) - } + const moduleHref = (module: Module) => `/modules/${module.name}` return (
(
diff --git a/frontend/console/src/features/modules/ModulesTree.tsx b/frontend/console/src/features/modules/ModulesTree.tsx index f470ad1ac9..192b50b6e8 100644 --- a/frontend/console/src/features/modules/ModulesTree.tsx +++ b/frontend/console/src/features/modules/ModulesTree.tsx @@ -1,6 +1,6 @@ import { ArrowRight01Icon, ArrowShrink02Icon, CircleArrowRight02Icon, FileExportIcon, PackageIcon } from 'hugeicons-react' import { useEffect, useMemo, useRef, useState } from 'react' -import { useNavigate, useParams, useSearchParams } from 'react-router-dom' +import { Link, useParams, useSearchParams } from 'react-router-dom' import { Multiselect, sortMultiselectOpts } from '../../components/Multiselect' import type { MultiselectOpt } from '../../components/Multiselect' import { classNames } from '../../utils' @@ -24,7 +24,6 @@ const ExportedIcon = () => ( ) const DeclNode = ({ decl, href, isSelected }: { decl: DeclInfo; href: string; isSelected: boolean }) => { - const navigate = useNavigate() const declRef = useRef(null) // Scroll to the selected decl on page load @@ -41,22 +40,19 @@ const DeclNode = ({ decl, href, isSelected }: { decl: DeclInfo; href: string; is const Icon = useMemo(() => declIcon(decl.declType), [decl.declType]) return (
  • -
    { - e.preventDefault() - navigate(href) - }} - > -
    + +
    +
    +
  • ) } @@ -68,7 +64,6 @@ const ModuleSection = ({ selectedDeclTypes, }: { module: ModuleTreeItem; isExpanded: boolean; toggleExpansion: (m: string) => void; selectedDeclTypes: MultiselectOpt[] }) => { const { moduleName, declName } = useParams() - const navigate = useNavigate() const isSelected = useMemo(() => moduleName === module.name, [moduleName, module.name]) const moduleRef = useRef(null) @@ -98,15 +93,9 @@ const ModuleSection = ({ >