import { DeletionAttemptSnapshot, ValidStatuses } from "@/lib/types"; import { usePopup } from "@/components/admin/connectors/Popup"; import { updateConnector } from "@/lib/connector"; import { AttachCredentialButtonForTable } from "@/components/admin/connectors/buttons/AttachCredentialButtonForTable"; import { scheduleDeletionJobForConnector } from "@/lib/documentDeletion"; import { ConnectorsTableProps } from "./ConnectorsTable"; import { Table, TableHead, TableRow, TableHeaderCell, TableBody, TableCell, } from "@tremor/react"; import { DeleteButton } from "@/components/DeleteButton"; const SingleUseConnectorStatus = ({ indexingStatus, deletionAttempt, }: { indexingStatus: ValidStatuses | null; deletionAttempt: DeletionAttemptSnapshot | null; }) => { if ( deletionAttempt && (deletionAttempt.status === "PENDING" || deletionAttempt.status === "STARTED") ) { return
Deleting...
; } if (!indexingStatus || indexingStatus === "not_started") { return
Not Started
; } if (indexingStatus === "in_progress") { return
In Progress
; } if (indexingStatus === "success") { return
Success!
; } return
Failed
; }; export function SingleUseConnectorsTable< ConnectorConfigType, ConnectorCredentialType >({ connectorIndexingStatuses, liveCredential, getCredential, specialColumns, onUpdate, onCredentialLink, includeName = false, }: ConnectorsTableProps) { const { popup, setPopup } = usePopup(); const connectorIncludesCredential = getCredential !== undefined && onCredentialLink !== undefined; return (
{popup} {includeName && Name} {specialColumns?.map(({ header }) => ( {header} ))} Status {connectorIncludesCredential && ( Credential )} Remove {connectorIndexingStatuses.map((connectorIndexingStatus) => { const connector = connectorIndexingStatus.connector; // const credential = connectorIndexingStatus.credential; const hasValidCredentials = liveCredential && connector.credential_ids.includes(liveCredential.id); const credentialDisplay = connectorIncludesCredential ? ( hasValidCredentials ? (
{getCredential(liveCredential)}
) : liveCredential ? ( onCredentialLink(connector.id)} /> ) : (

N/A

) ) : ( "-" ); return ( {includeName && (

{connectorIndexingStatus.name}

)} {specialColumns?.map(({ key, getValue }) => ( {getValue(connectorIndexingStatus)} ))} {connectorIncludesCredential && ( {credentialDisplay} )}
{ // for one-time, just disable the connector at deletion time // this is required before deletion can happen await updateConnector({ ...connector, disabled: !connector.disabled, }); const deletionScheduleError = await scheduleDeletionJobForConnector( connector.id, connectorIndexingStatus.credential.id ); if (deletionScheduleError) { setPopup({ message: "Failed to schedule deletion of connector - " + deletionScheduleError, type: "error", }); } else { setPopup({ message: "Scheduled deletion of connector!", type: "success", }); } setTimeout(() => { setPopup(null); }, 4000); onUpdate(); }} >
); })}
); }