From 947cdff93c7f2b03b3f7a51d9b952c175438fa77 Mon Sep 17 00:00:00 2001 From: Denise Li Date: Thu, 29 Aug 2024 19:17:33 -0400 Subject: [PATCH] feat: make the module tree scrollable + scroll to selected module (#2557) Final part of https://github.com/TBD54566975/ftl/issues/2487 https://github.com/user-attachments/assets/eb7ed1eb-d8ae-4a92-b56e-7bde8aed3a6b --- frontend/src/components/ResizableHorizontalPanels.tsx | 2 +- frontend/src/features/modules/ModulesTree.tsx | 11 +++++++++-- frontend/src/layout/Layout.tsx | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/ResizableHorizontalPanels.tsx b/frontend/src/components/ResizableHorizontalPanels.tsx index 7338e10f04..b5009af45c 100644 --- a/frontend/src/components/ResizableHorizontalPanels.tsx +++ b/frontend/src/components/ResizableHorizontalPanels.tsx @@ -48,7 +48,7 @@ export const ResizableHorizontalPanels: React.FC
{rightPanelContent}
diff --git a/frontend/src/features/modules/ModulesTree.tsx b/frontend/src/features/modules/ModulesTree.tsx index b408b6e74c..e2a9c048e0 100644 --- a/frontend/src/features/modules/ModulesTree.tsx +++ b/frontend/src/features/modules/ModulesTree.tsx @@ -16,7 +16,7 @@ import { TableCellsIcon, } from '@heroicons/react/24/outline' import type { ForwardRefExoticComponent, SVGProps } from 'react' -import { useEffect, useMemo } from 'react' +import { useEffect, useMemo, useRef } from 'react' import { useNavigate, useParams } from 'react-router-dom' import type { Decl } from '../../protos/xyz/block/ftl/v1/schema/schema_pb' import { classNames } from '../../utils' @@ -70,12 +70,19 @@ const DeclNode = ({ decl, href, isSelected }: { decl: Decl; href: string; isSele const ModuleSection = ({ module, isExpanded, toggleExpansion }: { module: ModuleTreeItem; isExpanded: boolean; toggleExpansion: (m: string) => void }) => { const { moduleName, declName } = useParams() - const isSelected = useMemo(() => moduleName === module.name, [moduleName, module.name]) const navigate = useNavigate() + const isSelected = useMemo(() => moduleName === module.name, [moduleName, module.name]) + const selectedRef = useRef(null) + const refProp = isSelected ? { ref: selectedRef } : {} + + // Scroll to the selected module on the first page load + useEffect(() => selectedRef.current?.scrollIntoView(), []) + return (
  • { const version = status.data?.controllers?.[0]?.version return ( -
    +
    -
    +