From e7bbbc29532c8024a872ee9456382098407c71b4 Mon Sep 17 00:00:00 2001 From: Flavien David Date: Mon, 12 Aug 2024 18:35:45 +0200 Subject: [PATCH] Unfold ancestor items --- front/components/vaults/VaultSideBarMenu.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/front/components/vaults/VaultSideBarMenu.tsx b/front/components/vaults/VaultSideBarMenu.tsx index 34154d3c225d..43489c6aaa1c 100644 --- a/front/components/vaults/VaultSideBarMenu.tsx +++ b/front/components/vaults/VaultSideBarMenu.tsx @@ -87,7 +87,11 @@ const VaultMenuItem = ({ }) => { const router = useRouter(); - const [isExpanded, setIsExpanded] = useState(false); + const vaultPath = `/w/${owner.sId}/data-sources/vaults/${vault.sId}`; + const isAncestorToCurrentPage = router.asPath.includes(vaultPath); + + // Unfold the vault if it's an ancestor of the current page. + const [isExpanded, setIsExpanded] = useState(isAncestorToCurrentPage); const { vaultInfo, isVaultInfoLoading } = useVaultInfo({ workspaceId: owner.sId, @@ -95,8 +99,6 @@ const VaultMenuItem = ({ disabled: !isExpanded, }); - const vaultPath = `/w/${owner.sId}/data-sources/vaults/${vault.sId}`; - return ( { const router = useRouter(); - const [isExpanded, setIsExpanded] = useState(false); + + const vaultCategoryPath = `/w/${owner.sId}/data-sources/vaults/${vault.sId}/categories/${category}`; + const isAncestorToCurrentPage = router.asPath.includes(vaultCategoryPath); + + // Unfold the vault's category if it's an ancestor of the current page. + const [isExpanded, setIsExpanded] = useState(isAncestorToCurrentPage); const categoryDetails = DATA_SOURCE_OR_VIEW_SUB_ITEMS[category]; const { isVaultDataSourceOrViewsLoading, vaultDataSourceOrViews } = @@ -217,8 +224,6 @@ const VaultCategoryItem = ({ disabled: !isExpanded, }); - const vaultCategoryPath = `/w/${owner.sId}/data-sources/vaults/${vault.sId}/categories/${category}`; - return (