use-dataset-table-columns.tsx


Overview

The use-dataset-table-columns.tsx file defines a custom React hook, useDatasetTableColumns, which returns a collection of column definitions for rendering a dataset table using the @tanstack/table-core library. These columns represent metadata and controls related to documents within a dataset, enabling features such as row selection, sorting, status toggling, parsing controls, and action management.

This hook integrates UI components (checkboxes, buttons, switches, tooltips) and leverages translation hooks, navigation logic, and document status management hooks to provide a rich interactive table experience. It is meant to be used within a React component rendering a dataset table, providing columns configured with cell renderers and headers tailored for document-related data.


Detailed Explanations

Main Export: useDatasetTableColumns

function useDatasetTableColumns({
  showChangeParserModal,
  showRenameModal,
  showSetMetaModal,
}: UseDatasetTableColumnsType): ColumnDef<IDocumentInfo>[]

Purpose

Provides an array of column definitions (ColumnDef<IDocumentInfo>[]) to be consumed by a table component rendering documents' dataset information.

Parameters

These callbacks are passed down to specific cells to control modals.

Returns


Columns Description

Each column is a configuration object compatible with @tanstack/table-core's ColumnDef interface, tailored for the IDocumentInfo type.

Column ID / Key

Header

Cell Content

Sorting

Special Features

select

Checkbox to select all rows or individual rows

Checkbox for row selection

Disabled

Manages bulk and per-row selection

name

Sortable button labeled "Name" (localized)

Displays file icon and truncated document name with tooltip. Clicking navigates to parsed chunk results

Enabled

Uses navigateToChunkParsedResult hook for navigation

create_time

Sortable button labeled "Upload Date" (localized)

Displays formatted creation timestamp in lowercase

Enabled

Uses formatDate utility

status

Label "Enabled" (localized)

Switch toggle controlling the document's active status

Disabled

Calls setDocumentStatus hook on toggle

chunk_num

Label "Chunk Number" (localized)

Displays the number of chunks (capitalized)

Disabled

Static display

run

Label "Parse" (localized)

Custom <ParsingStatusCell> component rendering parsing status and controls

Disabled

Passes modals for changing parser and setting metadata

actions

Label "Action" (localized)

Custom <DatasetActionCell> component for row-specific actions (e.g., rename)

Disabled

Passes modal for renaming


Supporting Types and Interfaces

UseDatasetTableColumnsType

A composite type combining modal control types:

type UseDatasetTableColumnsType = UseChangeDocumentParserShowType &
  UseRenameDocumentShowType &
  UseSaveMetaShowType;

These types ensure the hook receives all modal control functions.


Imported Components and Hooks


Important Implementation Details


Interaction with Other System Components


Usage Example

import React from 'react';
import { useTable } from '@tanstack/react-table';
import { useDatasetTableColumns } from './use-dataset-table-columns';

function DatasetTable() {
  const columns = useDatasetTableColumns({
    showChangeParserModal: () => { /* open parser modal */ },
    showRenameModal: () => { /* open rename modal */ },
    showSetMetaModal: () => { /* open set meta modal */ },
  });

  const data = [ /* array of IDocumentInfo objects */ ];

  const table = useTable({ columns, data });

  return (
    <table>
      {/* render table headers and rows using table instance */}
    </table>
  );
}

Mermaid Component Diagram

componentDiagram
    component useDatasetTableColumns {
      +showChangeParserModal()
      +showRenameModal()
      +showSetMetaModal()
      +returns ColumnDef<IDocumentInfo>[]
    }
    component DatasetActionCell
    component ParsingStatusCell
    component useNavigatePage
    component useSetDocumentStatus
    component UI_Components {
      Button
      Checkbox
      Switch
      Tooltip
    }
    useDatasetTableColumns --> DatasetActionCell : uses
    useDatasetTableColumns --> ParsingStatusCell : uses
    useDatasetTableColumns --> useNavigatePage : navigates
    useDatasetTableColumns --> useSetDocumentStatus : updates status
    useDatasetTableColumns --> UI_Components : renders UI

Summary

The use-dataset-table-columns.tsx file provides a modular, reusable hook for defining dataset table columns tailored for document management. It combines UI controls, status management, navigation, and localization to deliver an interactive dataset table experience in a React application. The file's integration with modals and custom cells encapsulates complex logic while keeping the column definitions clean and declarative.