Skip to content

Commit

Permalink
Unfold ancestor items
Browse files Browse the repository at this point in the history
  • Loading branch information
flvndvd committed Aug 12, 2024
1 parent 9436d77 commit e7bbbc2
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions front/components/vaults/VaultSideBarMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,18 @@ 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,
vaultId: vault.sId,
disabled: !isExpanded,
});

const vaultPath = `/w/${owner.sId}/data-sources/vaults/${vault.sId}`;

return (
<Tree.Item
label={vault.kind === "global" ? "Company Data" : vault.name}
Expand Down Expand Up @@ -205,7 +207,12 @@ const VaultCategoryItem = ({
category: string;
}) => {
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 } =
Expand All @@ -217,8 +224,6 @@ const VaultCategoryItem = ({
disabled: !isExpanded,
});

const vaultCategoryPath = `/w/${owner.sId}/data-sources/vaults/${vault.sId}/categories/${category}`;

return (
<Tree.Item
label={categoryDetails.label}
Expand Down

0 comments on commit e7bbbc2

Please sign in to comment.