From 336ddbd1fecb8566dab81fdf9ffb67dfd7345733 Mon Sep 17 00:00:00 2001 From: pablodanswer Date: Tue, 27 Aug 2024 14:01:04 -0700 Subject: [PATCH] Filter by user for docset display (#2245) * filter by user for docset display * spacing --- .../sets/DocumentSetCreationForm.tsx | 270 +++++++++++------- web/src/components/IsPublicGroupSelector.tsx | 2 +- 2 files changed, 173 insertions(+), 99 deletions(-) diff --git a/web/src/app/admin/documents/sets/DocumentSetCreationForm.tsx b/web/src/app/admin/documents/sets/DocumentSetCreationForm.tsx index c934af61e..814af4e28 100644 --- a/web/src/app/admin/documents/sets/DocumentSetCreationForm.tsx +++ b/web/src/app/admin/documents/sets/DocumentSetCreationForm.tsx @@ -8,13 +8,19 @@ import { updateDocumentSet, DocumentSetCreationRequest, } from "./lib"; -import { ConnectorIndexingStatus, DocumentSet, UserGroup } from "@/lib/types"; +import { + ConnectorIndexingStatus, + DocumentSet, + UserGroup, + UserRole, +} from "@/lib/types"; import { TextFormField } from "@/components/admin/connectors/Field"; import { ConnectorTitle } from "@/components/admin/connectors/ConnectorTitle"; import { Button, Divider } from "@tremor/react"; import { usePaidEnterpriseFeaturesEnabled } from "@/components/settings/usePaidEnterpriseFeaturesEnabled"; import { IsPublicGroupSelector } from "@/components/IsPublicGroupSelector"; import React, { useEffect, useState } from "react"; +import { useUser } from "@/components/user/UserProvider"; interface SetCreationPopupProps { ccPairs: ConnectorIndexingStatus[]; @@ -34,6 +40,7 @@ export const DocumentSetCreationForm = ({ const isPaidEnterpriseFeaturesEnabled = usePaidEnterpriseFeaturesEnabled(); const isUpdate = existingDocumentSet !== undefined; const [localCcPairs, setLocalCcPairs] = useState(ccPairs); + const { user } = useUser(); useEffect(() => { if (existingDocumentSet?.is_public) { @@ -128,42 +135,161 @@ export const DocumentSetCreationForm = ({ )} -
-

- These are the connectors available to{" "} - {userGroups && userGroups.length > 1 - ? "the selected group" - : "the group you curate"} - : -

-

- All documents indexed by these selected connectors will be a - part of this document set. -

- { - // Filter visible cc pairs - const visibleCcPairs = localCcPairs.filter( - (ccPair) => - ccPair.public_doc || - (ccPair.groups.length > 0 && - props.values.groups.every((group) => - ccPair.groups.includes(group) - )) - ); - // Deselect filtered out cc pairs - const visibleCcPairIds = visibleCcPairs.map( - (ccPair) => ccPair.cc_pair_id - ); - props.values.cc_pair_ids = props.values.cc_pair_ids.filter( - (id) => visibleCcPairIds.includes(id) - ); + {user?.role === UserRole.CURATOR ? ( + <> +
+

+ These are the connectors available to{" "} + {userGroups && userGroups.length > 1 + ? "the selected group" + : "the group you curate"} + : +

- return ( +

+ All documents indexed by these selected connectors will be + a part of this document set. +

+ { + // Filter visible cc pairs + const visibleCcPairs = localCcPairs.filter( + (ccPair) => + ccPair.public_doc || + (ccPair.groups.length > 0 && + props.values.groups.every((group) => + ccPair.groups.includes(group) + )) + ); + + // Deselect filtered out cc pairs + const visibleCcPairIds = visibleCcPairs.map( + (ccPair) => ccPair.cc_pair_id + ); + props.values.cc_pair_ids = + props.values.cc_pair_ids.filter((id) => + visibleCcPairIds.includes(id) + ); + + return ( +
+ {visibleCcPairs.map((ccPair) => { + const ind = props.values.cc_pair_ids.indexOf( + ccPair.cc_pair_id + ); + let isSelected = ind !== -1; + return ( +
{ + if (isSelected) { + arrayHelpers.remove(ind); + } else { + arrayHelpers.push(ccPair.cc_pair_id); + } + }} + > +
+ +
+
+ ); + })} +
+ ); + }} + /> +
+ +
+ { + // Filter non-visible cc pairs + const nonVisibleCcPairs = localCcPairs.filter( + (ccPair) => + !ccPair.public_doc && + (ccPair.groups.length === 0 || + !props.values.groups.every((group) => + ccPair.groups.includes(group) + )) + ); + + return nonVisibleCcPairs.length > 0 ? ( + <> + +

+ These connectors are not available to the{" "} + {userGroups && userGroups.length > 1 + ? `group${props.values.groups.length > 1 ? "s" : ""} you have selected` + : "group you curate"} + : +

+

+ Only connectors that are directly assigned to the + group you are trying to add the document set to + will be available. +

+
+ {nonVisibleCcPairs.map((ccPair) => ( +
+
+ +
+
+ ))} +
+ + ) : null; + }} + /> +
+ + ) : ( +
+

+ Pick your connectors: +

+

+ All documents indexed by the selected connectors will be a + part of this document set. +

+ (
- {visibleCcPairs.map((ccPair) => { + {ccPairs.map((ccPair) => { const ind = props.values.cc_pair_ids.indexOf( ccPair.cc_pair_id ); @@ -173,14 +299,14 @@ export const DocumentSetCreationForm = ({ key={`${ccPair.connector.id}-${ccPair.credential.id}`} className={ ` - px-3 - py-1 - rounded-lg - border - border-border - w-fit - flex - cursor-pointer ` + + px-3 + py-1 + rounded-lg + border + border-border + w-fit + flex + cursor-pointer ` + (isSelected ? " bg-background-strong" : " hover:bg-hover") @@ -206,62 +332,10 @@ export const DocumentSetCreationForm = ({ ); })}
- ); - }} - /> -
-
- { - // Filter non-visible cc pairs - const nonVisibleCcPairs = localCcPairs.filter( - (ccPair) => - !ccPair.public_doc && - (ccPair.groups.length === 0 || - !props.values.groups.every((group) => - ccPair.groups.includes(group) - )) - ); - - return nonVisibleCcPairs.length > 0 ? ( - <> - -

- These connectors are not available to the{" "} - {userGroups && userGroups.length > 1 - ? `group${props.values.groups.length > 1 ? "s" : ""} you have selected` - : "group you curate"} - : -

-

- Only connectors that are directly assigned to the - group you are trying to add the document set to will - be available. -

-
- {nonVisibleCcPairs.map((ccPair) => ( -
-
- -
-
- ))} -
- - ) : null; - }} - /> -
+ )} + /> +
+ )}