diff --git a/src/components/UIUC-Components/ProjectFilesTable.tsx b/src/components/UIUC-Components/ProjectFilesTable.tsx index 548d485cb..067f3c1ef 100644 --- a/src/components/UIUC-Components/ProjectFilesTable.tsx +++ b/src/components/UIUC-Components/ProjectFilesTable.tsx @@ -24,6 +24,7 @@ import { IconCheck, IconCopy, IconEye, + IconFileExport, IconTrash, IconX, } from '@tabler/icons-react' @@ -44,6 +45,16 @@ import { import { LoadingSpinner } from './LoadingSpinner' import { montserrat_heading } from 'fonts' import { useMediaQuery } from '@mantine/hooks' +import { IconInfoCircleFilled } from '@tabler/icons-react' +import { handleExport } from '~/pages/api/UIUC-api/exportAllDocuments' +import { showToastOnUpdate } from './MakeQueryAnalysisPage' +import { useRouter } from 'next/router' + + +// export const getCurrentPageName = () => { +// const router = useRouter() +// return router.asPath.slice(1).split('/')[0] as string +// } const useStyles = createStyles((theme) => ({})) @@ -64,7 +75,7 @@ const PAGE_SIZE = 100 export function ProjectFilesTable({ course_name, - setFailedCount = (count: number) => {}, + setFailedCount = (count: number) => { }, tabValue, }: { course_name: string @@ -86,7 +97,12 @@ export function ProjectFilesTable({ const [currentError, setCurrentError] = useState('') const isSmallScreen = useMediaQuery('(max-width: 768px)') const isBetweenSmallAndMediumScreen = useMediaQuery('(max-width: 878px)') + const [exportModalOpened, setExportModalOpened] = useState(false) + const router = useRouter() + const getCurrentPageName = () => { + return router.asPath.slice(1).split('/')[0] as string + } const openModel = (open: boolean, error = '') => { setErrorModalOpened(open) setCurrentError(error) @@ -587,155 +603,155 @@ export function ProjectFilesTable({ }, ...(tabValue === 'failed' ? [ - { - accessor: 'error', - title: 'Error', - width: 200, - render: ({ error }: { error: string }, index: number) => { - // Ensure a ref exists for this row - if (!textRefs.current[index]) { - textRefs.current[index] = createRef() - } + { + accessor: 'error', + title: 'Error', + width: 200, + render: ({ error }: { error: string }, index: number) => { + // Ensure a ref exists for this row + if (!textRefs.current[index]) { + textRefs.current[index] = createRef() + } - return ( -
+ return ( +
+ + {error} + + {overflowStates[index] && ( openModel(true, error)} + className="rounded-md hover:underline" style={{ - display: '-webkit-box', - WebkitLineClamp: 3, - WebkitBoxOrient: 'vertical', - overflow: 'hidden', - maxWidth: '100%', + cursor: 'pointer', + bottom: 0, + textAlign: 'right', }} > - {error} + Read more - {overflowStates[index] && ( - openModel(true, error)} - className="rounded-md hover:underline" - style={{ - cursor: 'pointer', - bottom: 0, - textAlign: 'right', - }} - > - Read more - - )} -
- ) - }, + )} +
+ ) }, - ] + }, + ] : [ - { - accessor: 'doc_group', - title: 'Document Groups', - width: 200, // Increase this value to make the column wider - render: (record: CourseDocument) => ( - - ({ - value: doc_group.name || '', - label: doc_group.name || '', - })) - : [] - } - value={record.doc_groups ? record.doc_groups : []} - placeholder={ - isLoadingDocumentGroups - ? 'Loading...' - : 'Select Group' - } - searchable={!isLoadingDocumentGroups} - nothingFound={ - isLoadingDocumentGroups ? 'Loading...' : 'No Options' - } - creatable - getCreateLabel={(query) => `+ Create "${query}"`} - onCreate={(doc_group_name) => { - // createDocumentGroup.mutate({ record, doc_group_name }) - return { - value: doc_group_name, - label: doc_group_name, - } - }} - onChange={(newSelectedGroups) => - handleDocumentGroupsChange(record, newSelectedGroups) + { + accessor: 'doc_group', + title: 'Document Groups', + width: 200, // Increase this value to make the column wider + render: (record: CourseDocument) => ( + + ({ + value: doc_group.name || '', + label: doc_group.name || '', + })) + : [] + } + value={record.doc_groups ? record.doc_groups : []} + placeholder={ + isLoadingDocumentGroups + ? 'Loading...' + : 'Select Group' + } + searchable={!isLoadingDocumentGroups} + nothingFound={ + isLoadingDocumentGroups ? 'Loading...' : 'No Options' + } + creatable + getCreateLabel={(query) => `+ Create "${query}"`} + onCreate={(doc_group_name) => { + // createDocumentGroup.mutate({ record, doc_group_name }) + return { + value: doc_group_name, + label: doc_group_name, } - disabled={isLoadingDocumentGroups} - sx={{ flex: 1, width: '100%' }} - classNames={{ - value: 'tag-item self-center', - }} - styles={{ - input: { - paddingTop: '12px', - paddingBottom: '12px', - }, - value: { - marginTop: '2px', - }, - }} - /> - - ), - }, - ]), + }} + onChange={(newSelectedGroups) => + handleDocumentGroupsChange(record, newSelectedGroups) + } + disabled={isLoadingDocumentGroups} + sx={{ flex: 1, width: '100%' }} + classNames={{ + value: 'tag-item self-center', + }} + styles={{ + input: { + paddingTop: '12px', + paddingBottom: '12px', + }, + value: { + marginTop: '2px', + }, + }} + /> + + ), + }, + ]), ...(tabValue === 'failed' ? [] : [ - { - accessor: 'actions', - title: Actions, - width: 75, - render: (materials: any, index: number) => { - const openModal = async (action: string) => { - let urlToOpen = materials.url - if (!materials.url && materials.s3_path) { - const presignedUrl = await fetchPresignedUrl( - materials.s3_path, - ) - urlToOpen = presignedUrl - } - if (action === 'view' && urlToOpen) { - window.open(urlToOpen, '_blank') - } else if (action === 'delete') { - setRecordsToDelete([materials]) - setModalOpened(true) - } + { + accessor: 'actions', + title: Actions, + width: 75, + render: (materials: any, index: number) => { + const openModal = async (action: string) => { + let urlToOpen = materials.url + if (!materials.url && materials.s3_path) { + const presignedUrl = await fetchPresignedUrl( + materials.s3_path, + ) + urlToOpen = presignedUrl + } + if (action === 'view' && urlToOpen) { + window.open(urlToOpen, '_blank') + } else if (action === 'delete') { + setRecordsToDelete([materials]) + setModalOpened(true) } + } - return ( - - openModal('view')} - > - - - openModal('delete')} - > - - - - ) - }, + return ( + + openModal('view')} + > + + + openModal('delete')} + > + + + + ) }, - ]), + }, + ]), ]} selectedRecords={selectedRecords} onSelectedRecordsChange={(newSelectedRecords) => { @@ -746,8 +762,8 @@ export function ProjectFilesTable({ setSelectedRecords([]) } }} - // Accessor not necessary when documents have an `id` property - // idAccessor={(row: any) => (row.url ? row.url : row.s3_path)} + // Accessor not necessary when documents have an `id` property + // idAccessor={(row: any) => (row.url ? row.url : row.s3_path)} />{' '} {/* End DataTable */} {selectedRecords.length - ? `Delete ${ - selectedRecords.length === 1 - ? '1 selected record' - : `${selectedRecords.length} selected records` - }` + ? `Delete ${selectedRecords.length === 1 + ? '1 selected record' + : `${selectedRecords.length} selected records` + }` : 'Select records to delete'} +
+ + + + +
+ setExportModalOpened(false)} // Update the state variable when the modal is closed + title="Please confirm your action" + > + + {`Are you sure you want to export all the documents and embeddings?`} + +
+ + +
+
) } @@ -909,7 +1001,7 @@ function errorStateForProjectFilesTable() { radius="lg" src="https://assets.kastan.ai/this-is-fine.jpg" alt="No data found" - // style={{ filter: 'grayscale(1)' }} + // style={{ filter: 'grayscale(1)' }} /> So.. please try again later.