files-table.tsx


Overview

files-table.tsx defines a React functional component called FilesTable that renders a fully-featured, interactive file listing table with support for pagination, sorting, filtering, row selection, and inline actions. It is designed as a client-side component and leverages the @tanstack/react-table library for table state and rendering logic, alongside various UI components and custom hooks.

This table primarily serves as a file manager view for displaying files and folders with metadata such as name, upload date, size, and knowledge base associations. It enables users to select files, rename them, move them, or link them to knowledge bases via modals and dialogs. The component supports server-side pagination and integrates with application-specific navigation and file management hooks.


Detailed Explanation

Component: FilesTable

function FilesTable(props: FilesTableProps): JSX.Element

Internal State & Hooks


Columns Definition (ColumnDef<IFile>[])

The table columns are defined with sorting, rendering, and interaction logic:

  1. Select Column (id: 'select'):
    Shows checkboxes for row selection with a "select all" checkbox in the header. Disabled for knowledge base files (rows where source_type is knowledge base).

  2. Name Column (accessorKey: 'name'):

    • Displays file/folder name with an icon.

    • Folder names are clickable and trigger navigation to that folder.

    • Tooltip shows full name on hover.

    • Sortable by name.

  3. Upload Date (accessorKey: 'create_time'):
    Displays formatted upload date.
    Sortable by date.

  4. Size (accessorKey: 'size'):
    Displays formatted file size.
    Sortable by size.

  5. Knowledge Base Info (accessorKey: 'kbs_info'):
    Displays associated knowledge base info using the KnowledgeCell component.

  6. Actions (id: 'actions'):
    Displays action buttons for the row such as rename, connect to knowledge, or move file using the ActionCell component.


Table Setup Using useReactTable


Rendered Output


Important Implementation Details & Algorithms


Usage Example

import { useFetchFileList } from '@/hooks/use-file-request';
import { useRowSelection } from '@/hooks/logic-hooks/use-row-selection';
import { FilesTable } from './files-table';

function FileManager() {
  const {
    files,
    total,
    loading,
    pagination,
    setPagination,
  } = useFetchFileList();

  const { rowSelection, setRowSelection } = useRowSelection();

  return (
    <FilesTable
      files={files}
      total={total}
      loading={loading}
      pagination={pagination}
      setPagination={setPagination}
      rowSelection={rowSelection}
      setRowSelection={setRowSelection}
      showMoveFileModal={() => {/* show modal logic */}}
    />
  );
}

Interaction with Other System Parts

The file is a key UI piece in the file management workflow, showing files and folders and enabling file operations integrated tightly with backend data and app navigation.


Mermaid Component Diagram

componentDiagram
    component FilesTable {
      +props: FilesTableProps
      +state: sorting, columnFilters, columnVisibility
      +useReactTable()
      +render()
    }

    component useFetchFileList
    component useRowSelection
    component useNavigateToOtherFolder
    component useHandleConnectToKnowledge
    component useRenameCurrentFile
    component Table
    component RAGFlowPagination
    component RenameDialog
    component LinkToDatasetDialog
    component ActionCell
    component KnowledgeCell

    FilesTable --> useFetchFileList : fetches files data
    FilesTable --> useRowSelection : manages row selection state
    FilesTable --> useNavigateToOtherFolder : folder navigation
    FilesTable --> useHandleConnectToKnowledge : connect to knowledge modal
    FilesTable --> useRenameCurrentFile : rename modal
    FilesTable --> Table : renders file table UI
    FilesTable --> RAGFlowPagination : pagination controls
    FilesTable --> RenameDialog : rename file modal
    FilesTable --> LinkToDatasetDialog : knowledge base link modal
    Table --> ActionCell : renders action buttons column
    Table --> KnowledgeCell : renders knowledge base info column

Summary

The FilesTable component in files-table.tsx is a highly interactive, server-side paginated React table specifically designed for a file manager UI. It provides capabilities like sorting, selection, folder navigation, and file actions (rename, move, link to knowledge bases). It integrates multiple custom hooks and UI components to form a cohesive and user-friendly file management interface within the application.