fixed lint
This commit is contained in:
parent
fb29f72598
commit
9336aa287e
1 changed files with 71 additions and 39 deletions
|
|
@ -1,10 +1,15 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import type { ColDef } from "ag-grid-community";
|
import type { ColDef, GetRowIdParams } from "ag-grid-community";
|
||||||
import { AgGridReact, type CustomCellRendererProps } from "ag-grid-react";
|
import { AgGridReact, type CustomCellRendererProps } from "ag-grid-react";
|
||||||
import { Building2, Cloud, HardDrive, Search, Trash2, X } from "lucide-react";
|
import { Building2, Cloud, HardDrive, Search, Trash2, X } from "lucide-react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { type ChangeEvent, useCallback, useRef, useState } from "react";
|
import {
|
||||||
|
type ChangeEvent,
|
||||||
|
useCallback,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from "react";
|
||||||
import { SiGoogledrive } from "react-icons/si";
|
import { SiGoogledrive } from "react-icons/si";
|
||||||
import { TbBrandOnedrive } from "react-icons/tb";
|
import { TbBrandOnedrive } from "react-icons/tb";
|
||||||
import { KnowledgeDropdown } from "@/components/knowledge-dropdown";
|
import { KnowledgeDropdown } from "@/components/knowledge-dropdown";
|
||||||
|
|
@ -54,15 +59,10 @@ function SearchPage() {
|
||||||
|
|
||||||
const deleteDocumentMutation = useDeleteDocument();
|
const deleteDocumentMutation = useDeleteDocument();
|
||||||
|
|
||||||
const { data = [], isFetching } = useGetSearchQuery(
|
const { data: searchData = [], isFetching } = useGetSearchQuery(
|
||||||
parsedFilterData?.query || "*",
|
parsedFilterData?.query || "*",
|
||||||
parsedFilterData,
|
parsedFilterData,
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleTableSearch = (e: ChangeEvent<HTMLInputElement>) => {
|
|
||||||
gridRef.current?.api.setGridOption("quickFilterText", e.target.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Convert TaskFiles to File format and merge with backend results
|
// Convert TaskFiles to File format and merge with backend results
|
||||||
const taskFilesAsFiles: File[] = taskFiles.map((taskFile) => {
|
const taskFilesAsFiles: File[] = taskFiles.map((taskFile) => {
|
||||||
return {
|
return {
|
||||||
|
|
@ -75,60 +75,91 @@ function SearchPage() {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const backendFiles = (data as File[]).filter((file) => !taskFilesAsFiles.some((taskFile) => taskFile.filename === file.filename && taskFile.status === "processing"));
|
// Create a map of task files by filename for quick lookup
|
||||||
|
const taskFileMap = new Map(
|
||||||
|
taskFilesAsFiles.map((file) => [file.filename, file]),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Override backend files with task file status if they exist
|
||||||
|
const backendFiles = (searchData as File[])
|
||||||
|
.map((file) => {
|
||||||
|
const taskFile = taskFileMap.get(file.filename);
|
||||||
|
if (taskFile) {
|
||||||
|
// Override backend file with task file data (includes status)
|
||||||
|
return { ...file, ...taskFile };
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
})
|
||||||
|
.filter((file) => {
|
||||||
|
// Only filter out files that are currently processing AND in taskFiles
|
||||||
|
const taskFile = taskFileMap.get(file.filename);
|
||||||
|
return !taskFile || taskFile.status !== "processing";
|
||||||
|
});
|
||||||
|
|
||||||
const filteredTaskFiles = taskFilesAsFiles.filter((taskFile) => {
|
const filteredTaskFiles = taskFilesAsFiles.filter((taskFile) => {
|
||||||
return (
|
return (
|
||||||
taskFile.status !== "active" &&
|
taskFile.status !== "active" &&
|
||||||
!backendFiles.some(
|
!backendFiles.some(
|
||||||
(backendFile) => backendFile.filename === taskFile.filename,)
|
(backendFile) => backendFile.filename === taskFile.filename,
|
||||||
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Combine task files first, then backend files
|
// Combine task files first, then backend files
|
||||||
const fileResults = [...backendFiles, ...filteredTaskFiles];
|
const fileResults = [...backendFiles, ...filteredTaskFiles];
|
||||||
|
|
||||||
|
const handleTableSearch = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
gridRef.current?.api.setGridOption("quickFilterText", e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
const gridRef = useRef<AgGridReact>(null);
|
const gridRef = useRef<AgGridReact>(null);
|
||||||
|
|
||||||
const columnDefs = [
|
const columnDefs = [
|
||||||
{
|
{
|
||||||
field: "filename",
|
field: "filename",
|
||||||
headerName: "Source",
|
headerName: "Source",
|
||||||
checkboxSelection: (data) => (data?.data?.status || "active") === "active",
|
checkboxSelection: (params: CustomCellRendererProps<File>) =>
|
||||||
|
(params?.data?.status || "active") === "active",
|
||||||
headerCheckboxSelection: true,
|
headerCheckboxSelection: true,
|
||||||
initialFlex: 2,
|
initialFlex: 2,
|
||||||
minWidth: 220,
|
minWidth: 220,
|
||||||
cellRenderer: ({ data, value }: CustomCellRendererProps<File>) => {
|
cellRenderer: ({ data, value }: CustomCellRendererProps<File>) => {
|
||||||
|
// Read status directly from data on each render
|
||||||
|
const status = data?.status || "active";
|
||||||
|
const isActive = status === "active";
|
||||||
|
console.log(data?.filename, status, "a");
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center overflow-hidden w-full">{((data?.status || "active") !== "active") &&
|
<div className="flex items-center overflow-hidden w-full">
|
||||||
<div className="min-w-7"></div>
|
<div
|
||||||
}
|
className={`transition-opacity duration-200 ${isActive ? "w-0" : "w-7"}`}
|
||||||
<button
|
></div>
|
||||||
type="button"
|
<button
|
||||||
className="flex items-center gap-2 cursor-pointer hover:text-blue-600 transition-colors text-left flex-1 overflow-hidden"
|
type="button"
|
||||||
onClick={() => {
|
className="flex items-center gap-2 cursor-pointer hover:text-blue-600 transition-colors text-left flex-1 overflow-hidden"
|
||||||
if ((data?.status || "active") !== "active") {
|
onClick={() => {
|
||||||
return;
|
if (!isActive) {
|
||||||
}
|
return;
|
||||||
router.push(
|
}
|
||||||
`/knowledge/chunks?filename=${encodeURIComponent(
|
router.push(
|
||||||
data?.filename ?? "",
|
`/knowledge/chunks?filename=${encodeURIComponent(
|
||||||
)}`,
|
data?.filename ?? "",
|
||||||
);
|
)}`,
|
||||||
}}
|
);
|
||||||
>
|
}}
|
||||||
{getSourceIcon(data?.connector_type)}
|
>
|
||||||
<span className="font-medium text-foreground truncate">
|
{getSourceIcon(data?.connector_type)}
|
||||||
{value}
|
<span className="font-medium text-foreground truncate">
|
||||||
</span>
|
{value}
|
||||||
</button></div>
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: "size",
|
field: "size",
|
||||||
headerName: "Size",
|
headerName: "Size",
|
||||||
valueFormatter: (params) =>
|
valueFormatter: (params: CustomCellRendererProps<File>) =>
|
||||||
params.value ? `${Math.round(params.value / 1024)} KB` : "-",
|
params.value ? `${Math.round(params.value / 1024)} KB` : "-",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -138,13 +169,13 @@ function SearchPage() {
|
||||||
{
|
{
|
||||||
field: "owner",
|
field: "owner",
|
||||||
headerName: "Owner",
|
headerName: "Owner",
|
||||||
valueFormatter: (params) =>
|
valueFormatter: (params: CustomCellRendererProps<File>) =>
|
||||||
params.data?.owner_name || params.data?.owner_email || "—",
|
params.data?.owner_name || params.data?.owner_email || "—",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: "chunkCount",
|
field: "chunkCount",
|
||||||
headerName: "Chunks",
|
headerName: "Chunks",
|
||||||
valueFormatter: (params) => params.data?.chunkCount?.toString() || "-",
|
valueFormatter: (params: CustomCellRendererProps<File>) => params.data?.chunkCount?.toString() || "-",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: "avgScore",
|
field: "avgScore",
|
||||||
|
|
@ -162,6 +193,7 @@ function SearchPage() {
|
||||||
field: "status",
|
field: "status",
|
||||||
headerName: "Status",
|
headerName: "Status",
|
||||||
cellRenderer: ({ data }: CustomCellRendererProps<File>) => {
|
cellRenderer: ({ data }: CustomCellRendererProps<File>) => {
|
||||||
|
console.log(data?.filename, data?.status, "b");
|
||||||
// Default to 'active' status if no status is provided
|
// Default to 'active' status if no status is provided
|
||||||
const status = data?.status || "active";
|
const status = data?.status || "active";
|
||||||
return <StatusBadge status={status} />;
|
return <StatusBadge status={status} />;
|
||||||
|
|
@ -188,7 +220,7 @@ function SearchPage() {
|
||||||
resizable: false,
|
resizable: false,
|
||||||
sortable: false,
|
sortable: false,
|
||||||
initialFlex: 0,
|
initialFlex: 0,
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const defaultColDef: ColDef<File> = {
|
const defaultColDef: ColDef<File> = {
|
||||||
|
|
@ -323,7 +355,7 @@ function SearchPage() {
|
||||||
</div>
|
</div>
|
||||||
<AgGridReact
|
<AgGridReact
|
||||||
className="w-full overflow-auto"
|
className="w-full overflow-auto"
|
||||||
columnDefs={columnDefs}
|
columnDefs={columnDefs as ColDef<File>[]}
|
||||||
defaultColDef={defaultColDef}
|
defaultColDef={defaultColDef}
|
||||||
loading={isFetching}
|
loading={isFetching}
|
||||||
ref={gridRef}
|
ref={gridRef}
|
||||||
|
|
@ -331,7 +363,7 @@ function SearchPage() {
|
||||||
rowSelection="multiple"
|
rowSelection="multiple"
|
||||||
rowMultiSelectWithClick={false}
|
rowMultiSelectWithClick={false}
|
||||||
suppressRowClickSelection={true}
|
suppressRowClickSelection={true}
|
||||||
getRowId={(params) => params.data.filename}
|
getRowId={(params: GetRowIdParams<File>) => params.data?.filename}
|
||||||
domLayout="normal"
|
domLayout="normal"
|
||||||
onSelectionChanged={onSelectionChanged}
|
onSelectionChanged={onSelectionChanged}
|
||||||
noRowsOverlayComponent={() => (
|
noRowsOverlayComponent={() => (
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue