changed page to get connector type as url

This commit is contained in:
Lucas Oliveira 2025-10-03 18:06:52 -03:00
parent 5654620989
commit ae4925cd56

View file

@ -2,7 +2,15 @@
import type { ColDef } from "ag-grid-community";
import { AgGridReact, type CustomCellRendererProps } from "ag-grid-react";
import { Building2, Cloud, Globe, HardDrive, Search, Trash2, X } from "lucide-react";
import {
Building2,
Cloud,
Globe,
HardDrive,
Search,
Trash2,
X,
} from "lucide-react";
import { useRouter } from "next/navigation";
import { type ChangeEvent, useCallback, useRef, useState } from "react";
import { SiGoogledrive } from "react-icons/si";
@ -17,18 +25,21 @@ import "@/components/AgGrid/registerAgGridModules";
import "@/components/AgGrid/agGridStyles.css";
import { toast } from "sonner";
import { KnowledgeActionsDropdown } from "@/components/knowledge-actions-dropdown";
import { filterAccentClasses } from "@/components/knowledge-filter-panel";
import { StatusBadge } from "@/components/ui/status-badge";
import { DeleteConfirmationDialog } from "../../../components/confirmation-dialog";
import { useDeleteDocument } from "../api/mutations/useDeleteDocument";
import { filterAccentClasses } from "@/components/knowledge-filter-panel";
// Function to get the appropriate icon for a connector type or mimetype
function getSourceIcon(connectorType?: string, mimetype?: string) {
// If the document is HTML, show a web globe icon regardless of connector
if (typeof mimetype === "string" && mimetype.startsWith("text/html")) {
return <Globe className="h-4 w-4 text-muted-foreground flex-shrink-0" strokeWidth={1.25} />;
}
function getSourceIcon(connectorType?: string) {
switch (connectorType) {
case "url":
return (
<Globe
className="h-4 w-4 text-muted-foreground flex-shrink-0"
/>
);
case "google_drive":
return (
<SiGoogledrive className="h-4 w-4 text-foreground flex-shrink-0" />
@ -60,7 +71,7 @@ function SearchPage() {
const { data = [], isFetching } = useGetSearchQuery(
parsedFilterData?.query || "*",
parsedFilterData
parsedFilterData,
);
const handleTableSearch = (e: ChangeEvent<HTMLInputElement>) => {
@ -85,7 +96,7 @@ function SearchPage() {
return (
taskFile.status !== "active" &&
!backendFiles.some(
(backendFile) => backendFile.filename === taskFile.filename
(backendFile) => backendFile.filename === taskFile.filename,
)
);
});
@ -111,12 +122,12 @@ function SearchPage() {
onClick={() => {
router.push(
`/knowledge/chunks?filename=${encodeURIComponent(
data?.filename ?? ""
)}`
data?.filename ?? "",
)}`,
);
}}
>
{getSourceIcon(data?.connector_type, data?.mimetype)}
{getSourceIcon(data?.connector_type)}
<span className="font-medium text-foreground truncate">
{value}
</span>
@ -206,7 +217,7 @@ function SearchPage() {
try {
// Delete each file individually since the API expects one filename at a time
const deletePromises = selectedRows.map((row) =>
deleteDocumentMutation.mutateAsync({ filename: row.filename })
deleteDocumentMutation.mutateAsync({ filename: row.filename }),
);
await Promise.all(deletePromises);
@ -214,7 +225,7 @@ function SearchPage() {
toast.success(
`Successfully deleted ${selectedRows.length} document${
selectedRows.length > 1 ? "s" : ""
}`
}`,
);
setSelectedRows([]);
setShowBulkDeleteDialog(false);
@ -227,7 +238,7 @@ function SearchPage() {
toast.error(
error instanceof Error
? error.message
: "Failed to delete some documents"
: "Failed to delete some documents",
);
}
};