Skip to content

Commit

Permalink
Address comments from review
Browse files Browse the repository at this point in the history
  • Loading branch information
flvndvd committed Aug 12, 2024
1 parent e7bbbc2 commit b35d21f
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions front/components/vaults/VaultSideBarMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
VaultType,
} from "@dust-tt/types";
import { DATA_SOURCE_OR_VIEW_CATEGORIES } from "@dust-tt/types";
import { groupBy } from "lodash";
import { useRouter } from "next/router";
import type { ReactElement } from "react";
import { Fragment, useState } from "react";
Expand All @@ -29,27 +30,39 @@ interface VaultSideBarMenuProps {
owner: LightWorkspaceType;
}

const VAULTS_SORT_ORDER = ["system", "global", "regular"];

export default function VaultSideBarMenu({ owner }: VaultSideBarMenuProps) {
const { vaults, isVaultsLoading } = useVaults({ workspaceId: owner.sId });

if (!vaults || isVaultsLoading) {
return <></>;
}

// Group by kind and sort.
const groupedVaults = groupBy(vaults, (vault) => vault.kind);
const sortedGroupedVaults = VAULTS_SORT_ORDER.map(
(kind) => groupedVaults[kind] || []
);

return (
<div className="flex flex-col px-3">
<Item.List>
{vaults.map((vault) => (
<Fragment key={`vault-${vault.sId}`}>
<Item.SectionHeader
label={vault.kind === "global" ? "SHARED" : vault.name}
key={vault.sId}
/>
{vault.kind === "system" ? (
<SystemVaultMenu />
) : (
<VaultMenuItem owner={owner} vault={vault} />
)}
{sortedGroupedVaults.map((vaults, index) => (
<Fragment key={`vault-section-${index}`}>
{vaults.map((vault) => (
<Fragment key={`vault-${vault.sId}`}>
<Item.SectionHeader
label={vault.kind === "global" ? "SHARED" : vault.name}
key={vault.sId}
/>
{vault.kind === "system" ? (
<SystemVaultMenu />
) : (
<VaultMenuItem owner={owner} vault={vault} />
)}
</Fragment>
))}
</Fragment>
))}
</Item.List>
Expand Down

0 comments on commit b35d21f

Please sign in to comment.