dataset-table.tsx


Overview

dataset-table.tsx defines the DatasetTable React component, a feature-rich, interactive table designed to display and manage a list of documents within a dataset. It supports advanced functionalities such as sorting, filtering, pagination, column visibility toggling, and row selection. Integrated dialogs enable users to rename documents, change document parsers, and set metadata for documents directly from the table interface.

This component leverages the @tanstack/react-table library for table state management and rendering, alongside several custom hooks and UI components tailored to the application's domain. The table operates with server-side pagination, fetching and displaying document data based on the current page and page size.


Detailed Explanation

DatasetTable Component

function DatasetTable({
  documents,
  pagination,
  setPagination,
  rowSelection,
  setRowSelection,
}: DatasetTableProps)

Purpose

Renders an interactive, paginated table of documents with capabilities to:

Props

DatasetTableProps combines properties from document fetching and row selection hooks:

Prop Name

Type

Description

documents

Document[]

Array of document data objects to display in the table.

pagination

{ current: number; pageSize: number; total?: number }

Pagination state including current page, page size, and total number of documents.

setPagination

(pagination: { page: number; pageSize: number }) => void

Callback to update pagination state, typically triggering data fetch.

rowSelection

Record<string, boolean>

Object mapping row IDs to their selected state.

setRowSelection

(selection: Record<string, boolean>) => void

Callback to update row selection state.

Internal State

Custom Hooks Used

Table Configuration

Uses useReactTable with:

Render Output


Classes, Functions, and Methods

DatasetTable

import { useFetchDocumentList } from '@/hooks/use-document-request';
import { useRowSelection } from '@/hooks/logic-hooks/use-row-selection';

function ParentComponent() {
  const { documents, pagination, setPagination, loading } = useFetchDocumentList();
  const { rowSelection, setRowSelection } = useRowSelection();

  return (
    <DatasetTable
      documents={documents}
      pagination={pagination}
      setPagination={setPagination}
      rowSelection={rowSelection}
      setRowSelection={setRowSelection}
    />
  );
}

Important Implementation Details and Algorithms


Interaction with Other System Components


Visual Diagram

componentDiagram
    component DatasetTable {
        +documents: Document[]
        +pagination: Pagination
        +setPagination(page, pageSize)
        +rowSelection: Record<string, boolean>
        +setRowSelection(selection)
        -- Internal State --
        +sorting
        +columnFilters
        +columnVisibility
    }

    component useReactTable
    component useDatasetTableColumns
    component ChunkMethodDialog
    component RenameDialog
    component SetMetaDialog
    component RAGFlowPagination

    DatasetTable --> useReactTable : uses for table state & rendering
    DatasetTable --> useDatasetTableColumns : gets column defs with callbacks
    DatasetTable --> ChunkMethodDialog : renders on changeParserVisible
    DatasetTable --> RenameDialog : renders on renameVisible
    DatasetTable --> SetMetaDialog : renders on setMetaVisible
    DatasetTable --> RAGFlowPagination : renders pagination controls

Summary

The dataset-table.tsx file implements a powerful, modular React component for displaying and managing a list of dataset documents with extensive user interaction capabilities. It is tightly integrated with the application's data-fetching hooks and UI components to provide a seamless experience for viewing, selecting, sorting, filtering, paginating, and performing document operations such as renaming, changing parsers, and editing metadata.

By leveraging @tanstack/react-table for robust table state management and separating concerns through specialized hooks and dialogs, the component remains maintainable and extensible for future feature enhancements.