import "./DocsList.scss"; import { FC, useState } from "react"; import { GoDownload, GoSearch, GoTrash, GoTriangleDown, GoTriangleUp } from "react-icons/go"; import { SortDirectionsTooltipMap, StatusMap } from "@/shared/constants"; import Button from "@/components/generics/button/Button"; import { DocsListProps } from "./DocsList.interface"; import Input from "@/components/generics/input/Input"; import { Pagination } from "../../pagination/Pagination"; import { SortDirections } from "@/api/documents/types"; import Spinner from "@/components/generics/spinner/Spinner"; import Tag from "@/components/generics/tag/Tag"; import Tooltip from "@/components/generics/tooltip/Tooltip"; import { downloadDocument } from "@/api/documents/documentsApi"; import { useGetDataset } from "@/api/documents/hooks"; export const DocsList: FC = ({ datasetId, handleDeleteFile }) => { const [page, setPage] = useState(0); const [pageSize, setPageSize] = useState(10); const [searchInput, setSearchInput] = useState(undefined); const [search, setSearch] = useState(undefined); const [sort, setSort] = useState(undefined); const { data: datasetData, isFetching } = useGetDataset(datasetId ?? -1, { page, page_size: pageSize, search, sort }); const toggleSort = (field: string) => { setSort((prevSort) => { if (prevSort?.length && prevSort?.length > 0) { const newSort = [...prevSort]; const existingFieldIndex = prevSort?.findIndex((e) => e.field === field); const currentDirection = prevSort[existingFieldIndex]?.direction; if (existingFieldIndex != null && existingFieldIndex !== -1) { const newSort = [...prevSort]; if (currentDirection === SortDirections.asc) { newSort[existingFieldIndex] = { field, direction: SortDirections.desc }; return newSort; } else if (currentDirection === SortDirections.desc) { newSort.splice(existingFieldIndex, 1); return newSort; } } else { newSort.push({ field, direction: SortDirections.asc }); } return newSort; } else { return [{ field, direction: SortDirections.asc }]; } }); }; const handleEnterPress = (event: React.KeyboardEvent) => { if (event.key === "Enter" && searchInput) { setSearch(searchInput); setPage(0); } }; const sorting = (field: string) => { const currentDirection = sort?.find((e) => e.field === field)?.direction; return (