-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add system vault navigation #6750
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { | |
Tree, | ||
} from "@dust-tt/sparkle"; | ||
import type { | ||
DataSourceOrView, | ||
DataSourceOrViewInfo, | ||
LightWorkspaceType, | ||
VaultType, | ||
|
@@ -73,7 +74,7 @@ const renderVaultItems = (vaults: VaultType[], owner: LightWorkspaceType) => | |
vaults.map((vault) => ( | ||
<Fragment key={`vault-${vault.sId}`}> | ||
{vault.kind === "system" ? ( | ||
<SystemVaultMenu /> | ||
<SystemVaultMenu owner={owner} vault={vault} /> | ||
) : ( | ||
<VaultMenuItem owner={owner} vault={vault} /> | ||
)} | ||
|
@@ -110,9 +111,102 @@ const SubItemIconItemWrapper = ( | |
|
||
// System vault. | ||
|
||
const SystemVaultMenu = () => { | ||
// TODO(Groups UI) Implement system vault menu. | ||
return <></>; | ||
const SYSTEM_VAULTS_ITEMS = [ | ||
{ | ||
label: "Connection Management", | ||
visual: RootItemIconWrapper(CloudArrowLeftRightIcon), | ||
category: "managed", | ||
}, | ||
{ | ||
label: "Files", | ||
visual: RootItemIconWrapper(FolderIcon), | ||
category: "files", | ||
}, | ||
// TODO(GROUPS_UI) Add support for Dust apps. | ||
]; | ||
|
||
const SystemVaultMenu = ({ | ||
owner, | ||
vault, | ||
}: { | ||
owner: LightWorkspaceType; | ||
vault: VaultType; | ||
}) => { | ||
return ( | ||
<> | ||
{SYSTEM_VAULTS_ITEMS.map((item) => ( | ||
<SystemVaultItem | ||
category={item.category} | ||
key={item.label} | ||
label={item.label} | ||
owner={owner} | ||
vault={vault} | ||
visual={item.visual} | ||
/> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
const SystemVaultItem = ({ | ||
category, | ||
label, | ||
owner, | ||
vault, | ||
visual, | ||
}: { | ||
category: string; | ||
label: string; | ||
owner: LightWorkspaceType; | ||
vault: VaultType; | ||
visual: ReactElement; | ||
}) => { | ||
const router = useRouter(); | ||
|
||
const itemPath = `/w/${owner.sId}/data-sources/vaults/${vault.sId}/categories/${category}/data_sources`; | ||
const isAncestorToCurrentPage = router.asPath.includes(itemPath); | ||
|
||
// Unfold the item if it's an ancestor of the current page. | ||
const [isExpanded, setIsExpanded] = useState(isAncestorToCurrentPage); | ||
|
||
const { isVaultDataSourceOrViewsLoading, vaultDataSourceOrViews } = | ||
useVaultDataSourceOrViews({ | ||
workspaceId: owner.sId, | ||
vaultId: vault.sId, | ||
category, | ||
// System vault only has data sources. | ||
type: "data_sources", | ||
disabled: !isExpanded, | ||
}); | ||
|
||
return ( | ||
<Tree.Item | ||
label={label} | ||
collapsed={!isExpanded} | ||
onItemClick={() => router.push(itemPath)} | ||
isSelected={router.asPath === itemPath} | ||
onChevronClick={() => setIsExpanded(!isExpanded)} | ||
visual={visual} | ||
size="md" | ||
areActionsFading={false} | ||
> | ||
{isExpanded && ( | ||
<Tree isLoading={isVaultDataSourceOrViewsLoading}> | ||
{vaultDataSourceOrViews && | ||
vaultDataSourceOrViews.map((ds) => ( | ||
<VaultDataSourceOrViewItem | ||
item={ds} | ||
key={ds.sId} | ||
owner={owner} | ||
vault={vault} | ||
// System vault only has data sources. | ||
viewType="data_sources" | ||
/> | ||
))} | ||
</Tree> | ||
)} | ||
</Tree.Item> | ||
); | ||
}; | ||
|
||
// Global + regular vaults. | ||
|
@@ -179,7 +273,7 @@ const DATA_SOURCE_OR_VIEW_SUB_ITEMS: { | |
icon: ReactElement<{ | ||
className?: string; | ||
}>; | ||
dataSourceOrView: "data_sources" | "data_source_views"; | ||
dataSourceOrView: DataSourceOrView; | ||
}; | ||
} = { | ||
managed: { | ||
|
@@ -205,13 +299,15 @@ const DATA_SOURCE_OR_VIEW_SUB_ITEMS: { | |
}; | ||
|
||
const VaultDataSourceOrViewItem = ({ | ||
item, | ||
owner, | ||
vault, | ||
item, | ||
viewType, | ||
}: { | ||
item: DataSourceOrViewInfo; | ||
owner: LightWorkspaceType; | ||
vault: VaultType; | ||
item: DataSourceOrViewInfo; | ||
viewType: "data_sources" | "data_source_views"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we move the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed this one could live in |
||
}): ReactElement => { | ||
const router = useRouter(); | ||
const configuration = item.connectorProvider | ||
|
@@ -220,8 +316,6 @@ const VaultDataSourceOrViewItem = ({ | |
|
||
const LogoComponent = configuration?.logoComponent ?? FolderIcon; | ||
const label = configuration?.name ?? item.name; | ||
const viewType = | ||
DATA_SOURCE_OR_VIEW_SUB_ITEMS[item.category].dataSourceOrView; | ||
const dataSourceOrViewPath = `/w/${owner.sId}/data-sources/vaults/${vault.sId}/categories/${item.category}/${viewType}/${item.sId}`; | ||
|
||
return ( | ||
|
@@ -278,10 +372,11 @@ const VaultCategoryItem = ({ | |
{vaultDataSourceOrViews && | ||
vaultDataSourceOrViews.map((ds) => ( | ||
<VaultDataSourceOrViewItem | ||
item={ds} | ||
key={ds.sId} | ||
owner={owner} | ||
vault={vault} | ||
item={ds} | ||
viewType={categoryDetails.dataSourceOrView} | ||
/> | ||
))} | ||
</Tree> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
.../pages/w/[wId]/data-sources/vaults/[vaultId]/categories/[category]/data_sources/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import type { | ||
DataSourceOrViewCategory, | ||
UserType, | ||
VaultType, | ||
} from "@dust-tt/types"; | ||
import { isDataSourceOrViewCategory } from "@dust-tt/types"; | ||
import type { InferGetServerSidePropsType } from "next"; | ||
import type { ReactElement } from "react"; | ||
|
||
import type { VaultLayoutProps } from "@app/components/vaults/VaultLayout"; | ||
import { VaultLayout } from "@app/components/vaults/VaultLayout"; | ||
import config from "@app/lib/api/config"; | ||
import { withDefaultUserAuthRequirements } from "@app/lib/iam/session"; | ||
import { VaultResource } from "@app/lib/resources/vault_resource"; | ||
|
||
export const getServerSideProps = withDefaultUserAuthRequirements< | ||
VaultLayoutProps & { | ||
category: DataSourceOrViewCategory; | ||
user: UserType; | ||
vault: VaultType; | ||
} | ||
>(async (context, auth) => { | ||
const owner = auth.getNonNullableWorkspace(); | ||
const user = auth.getNonNullableUser(); | ||
const subscription = auth.subscription(); | ||
|
||
if (!subscription) { | ||
return { | ||
notFound: true, | ||
}; | ||
} | ||
|
||
const vault = await VaultResource.fetchById( | ||
auth, | ||
context.query.vaultId as string | ||
); | ||
if (!vault) { | ||
return { | ||
notFound: true, | ||
}; | ||
} | ||
|
||
const dataSourceOrViewCategory = context.query.category; | ||
if ( | ||
typeof dataSourceOrViewCategory !== "string" || | ||
!isDataSourceOrViewCategory(dataSourceOrViewCategory) | ||
) { | ||
return { | ||
notFound: true, | ||
}; | ||
} | ||
|
||
return { | ||
props: { | ||
category: dataSourceOrViewCategory, | ||
gaTrackingId: config.getGaTrackingId(), | ||
owner, | ||
subscription, | ||
user, | ||
vault: vault.toJSON(), | ||
}, | ||
}; | ||
}); | ||
|
||
export default function Vault({ | ||
category, | ||
vault, | ||
}: InferGetServerSidePropsType<typeof getServerSideProps>) { | ||
return ( | ||
<> | ||
Manage {category} connections in vault {vault.name} | ||
</> | ||
); | ||
} | ||
|
||
Vault.getLayout = (page: ReactElement, pageProps: any) => { | ||
return <VaultLayout pageProps={pageProps}>{page}</VaultLayout>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move this to types? Feel like we are gonna need this in other places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is specifically for menu rendering so I'd keep it close to the implementation. What other places do you have in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The company data screen?