Skip to content

Commit

Permalink
Tracker: display tree on form when selected documents (#9297)
Browse files Browse the repository at this point in the history
* Tracker: display tree on form when selected documents

* Fix display managed ds
  • Loading branch information
PopDaph authored Dec 11, 2024
1 parent 343d359 commit e0880e4
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 10 deletions.
6 changes: 5 additions & 1 deletion front/components/data_source_view/DataSourceViewSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ export function DataSourceViewsSelector({
const folders = filteredDSVs.filter((dsv) => isFolder(dsv.dataSource));
const websites = filteredDSVs.filter((dsv) => isWebsite(dsv.dataSource));

const displayManagedDsv =
managedDsv.length > 0 &&
(useCase === "assistantBuilder" || useCase === "trackerBuilder");

const defaultSpace = useMemo(() => {
const firstKey = Object.keys(selectionConfigurations)[0] ?? null;
return firstKey
Expand Down Expand Up @@ -206,7 +210,7 @@ export function DataSourceViewsSelector({
} else {
return (
<Tree isLoading={false}>
{managedDsv.length > 0 && useCase === "assistantBuilder" && (
{displayManagedDsv && (
<Tree.Item
key="connected"
label="Connected Data"
Expand Down
46 changes: 37 additions & 9 deletions front/components/trackers/TrackerBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
AppLayoutSimpleSaveCancelTitle,
} from "@app/components/sparkle/AppLayoutTitle";
import TrackerBuilderDataSourceModal from "@app/components/trackers/TrackerBuilderDataSourceModal";
import { TrackerDataSourceSelectedTree } from "@app/components/trackers/TrackerDataSourceSelectedTree";
import { isEmailValid } from "@app/lib/utils";

export const TrackerBuilder = ({
Expand Down Expand Up @@ -182,26 +183,25 @@ export const TrackerBuilder = ({
// Handle errors.
if (!res.ok) {
const resJson = await res.json();
setIsSubmitting(false);
sendNotification({
title: initialTrackerId
? "Failed to update tracker"
: "Failed to create tracker",
description: resJson.error.message,
type: "error",
});
setIsSubmitting(false);
return;
}

setIsSubmitting(false);
await router.push(`/w/${owner.sId}/assistant/labs/trackers`);
sendNotification({
title: initialTrackerId ? "Tracker updated" : "Tracker Created",
description: initialTrackerId
? "Tracker updated successfully"
: "Tracker created successfully.",
type: "success",
});
setIsSubmitting(false);
await router.push(`/w/${owner.sId}/assistant/labs/trackers`);
};

return (
Expand Down Expand Up @@ -295,7 +295,7 @@ export const TrackerBuilder = ({
</div>
</div>

<div className="flex flex-col gap-6">
<div className="flex flex-col gap-8">
<div>
<Page.SectionHeader title="Naming" />
<div className="text-sm font-normal text-element-700">
Expand Down Expand Up @@ -339,7 +339,7 @@ export const TrackerBuilder = ({
</div>
</div>

<div className="flex flex-col gap-6">
<div className="flex flex-col gap-8">
<div>
<Page.SectionHeader title="Notification Settings" />
<div className="text-sm font-normal text-element-700">
Expand Down Expand Up @@ -395,7 +395,7 @@ export const TrackerBuilder = ({
</div>
</div>
</div>
<div className="flex flex-col gap-6">
<div className="flex flex-col gap-8">
<div>
<Page.SectionHeader title="Tracker Settings" />
<div className="text-sm font-normal text-element-700">
Expand Down Expand Up @@ -433,7 +433,21 @@ export const TrackerBuilder = ({
/>
</div>
</div>
<div className="flex items-end md:col-span-2" />
<div className="flex md:col-span-2">
<div className="flex flex-col space-y-2">
<Label className="mb-1">Maintained Documents</Label>
{Object.keys(tracker.maintainedDataSources).length === 0 ? (
<div className="text-sm font-normal text-element-700">
No documents selected.
</div>
) : (
<TrackerDataSourceSelectedTree
owner={owner}
dataSourceConfigurations={tracker.maintainedDataSources}
/>
)}
</div>
</div>
</div>

<div className="grid grid-cols-1 gap-4 md:grid-cols-3">
Expand All @@ -449,7 +463,21 @@ export const TrackerBuilder = ({
/>
</div>
</div>
<div className="flex items-end md:col-span-2" />
<div className="flex md:col-span-2">
<div className="flex flex-col space-y-2">
<Label className="mb-1">Watched Documents</Label>
{Object.keys(tracker.watchedDataSources).length === 0 ? (
<div className="text-sm font-normal text-element-700">
No documents selected.
</div>
) : (
<TrackerDataSourceSelectedTree
owner={owner}
dataSourceConfigurations={tracker.watchedDataSources}
/>
)}
</div>
</div>
</div>
</div>
</div>
Expand Down
149 changes: 149 additions & 0 deletions front/components/trackers/TrackerDataSourceSelectedTree.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import {
BracesIcon,
classNames,
ExternalLinkIcon,
FolderIcon,
IconButton,
Tree,
} from "@dust-tt/sparkle";
import type {
DataSourceViewSelectionConfigurations,
DataSourceViewType,
LightWorkspaceType,
} from "@dust-tt/types";
import { useState } from "react";

import DataSourceViewDocumentModal from "@app/components/DataSourceViewDocumentModal";
import { DataSourceViewPermissionTree } from "@app/components/DataSourceViewPermissionTree";
import { getConnectorProviderLogoWithFallback } from "@app/lib/connector_providers";
import { orderDatasourceViewSelectionConfigurationByImportance } from "@app/lib/connectors";
import { getVisualForContentNode } from "@app/lib/content_nodes";
import {
canBeExpanded,
getDisplayNameForDataSource,
} from "@app/lib/data_sources";

export const TrackerDataSourceSelectedTree = ({
owner,
dataSourceConfigurations,
}: {
owner: LightWorkspaceType;
dataSourceConfigurations: DataSourceViewSelectionConfigurations;
}) => {
const [documentToDisplay, setDocumentToDisplay] = useState<string | null>(
null
);
const [dataSourceViewToDisplay, setDataSourceViewToDisplay] =
useState<DataSourceViewType | null>(null);
return (
<>
<DataSourceViewDocumentModal
owner={owner}
dataSourceView={dataSourceViewToDisplay}
documentId={documentToDisplay}
isOpen={!!documentToDisplay}
onClose={() => setDocumentToDisplay(null)}
/>
<Tree>
{orderDatasourceViewSelectionConfigurationByImportance(
Object.values(dataSourceConfigurations)
).map((dsConfig) => {
const LogoComponent = getConnectorProviderLogoWithFallback(
dsConfig.dataSourceView.dataSource.connectorProvider,
FolderIcon
);

return (
<Tree.Item
key={dsConfig.dataSourceView.sId}
type={
canBeExpanded("documents", dsConfig.dataSourceView.dataSource)
? "node"
: "leaf"
} // todo make useConnectorPermissions hook work for non managed ds (Folders)
label={getDisplayNameForDataSource(
dsConfig.dataSourceView.dataSource
)}
visual={LogoComponent}
className="whitespace-nowrap"
>
{dsConfig.isSelectAll && (
<DataSourceViewPermissionTree
owner={owner}
dataSourceView={dsConfig.dataSourceView}
parentId={null}
onDocumentViewClick={(documentId: string) => {
setDataSourceViewToDisplay(dsConfig.dataSourceView);
setDocumentToDisplay(documentId);
}}
viewType={"documents"}
/>
)}
{dsConfig.selectedResources.map((node) => {
return (
<Tree.Item
key={`${dsConfig.dataSourceView.sId}-${node.internalId}`}
label={node.titleWithParentsContext ?? node.title}
type={node.expandable ? "node" : "leaf"}
visual={getVisualForContentNode(node)}
className="whitespace-nowrap"
actions={
<div className="mr-8 flex flex-row gap-2">
<IconButton
size="xs"
icon={ExternalLinkIcon}
onClick={() => {
if (node.sourceUrl) {
window.open(node.sourceUrl, "_blank");
}
}}
className={classNames(
node.sourceUrl
? ""
: "pointer-events-none opacity-0"
)}
disabled={!node.sourceUrl}
variant="outline"
/>
<IconButton
size="xs"
icon={BracesIcon}
onClick={() => {
if (node.dustDocumentId) {
setDataSourceViewToDisplay(
dsConfig.dataSourceView
);
setDocumentToDisplay(node.dustDocumentId);
}
}}
className={classNames(
node.dustDocumentId
? ""
: "pointer-events-none opacity-0"
)}
disabled={!node.dustDocumentId}
variant="ghost"
/>
</div>
}
>
<DataSourceViewPermissionTree
owner={owner}
dataSourceView={dsConfig.dataSourceView}
parentId={node.internalId}
onDocumentViewClick={(documentId: string) => {
setDataSourceViewToDisplay(dsConfig.dataSourceView);
setDocumentToDisplay(documentId);
}}
viewType={"documents"}
/>
</Tree.Item>
);
})}
</Tree.Item>
);
})}
</Tree>
</>
);
};

0 comments on commit e0880e4

Please sign in to comment.