dataset-action-cell.tsx


Overview

dataset-action-cell.tsx defines a React functional component named DatasetActionCell that provides a set of interactive action buttons related to a document (dataset) record. These actions include renaming the document, previewing its metadata, downloading the file, and deleting the document. The component is designed to be used as part of a UI table or list where each row represents a document, enabling users to conveniently manage documents inline.

Key features:


Detailed Explanation

Imports and Constants


Component: DatasetActionCell

export function DatasetActionCell({
  record,
  showRenameModal,
}: { record: IDocumentInfo } & UseRenameDocumentShowType)

Props

Prop

Type

Description

record

IDocumentInfo

The document record object containing metadata and state.

showRenameModal

(record: IDocumentInfo) => void

Callback to display the rename dialog/modal for a document.

Internal variables

Callback functions

All callbacks are memoized with useCallback to optimize rendering.

JSX Rendered


Usage Example

import { DatasetActionCell } from './dataset-action-cell';

// Example document record
const exampleRecord = {
  id: 'doc123',
  name: 'Sample Dataset',
  size: 1048576,
  type: DocumentType.Normal,
  create_time: '2024-05-10T12:00:00Z',
  update_time: '2024-06-01T15:30:00Z',
  run: { status: 'idle' },
};

function showRenameModal(record) {
  console.log('Rename modal shown for', record.name);
}

<DatasetActionCell record={exampleRecord} showRenameModal={showRenameModal} />;

Important Implementation Details


Interaction with Other Parts of the System

This component is designed to be embedded in a data table or list where documents are presented, providing inline controls for document management.


Mermaid Component Diagram

componentDiagram
    component DatasetActionCell {
      +record: IDocumentInfo
      +showRenameModal(record: IDocumentInfo): void

      +onDownloadDocument(): void
      +handleRemove(): void
      +handleRename(): void
    }

    DatasetActionCell --> Button : Rename
    DatasetActionCell --> Button : Preview (HoverCard)
    DatasetActionCell --> Button : Download (conditional)
    DatasetActionCell --> ConfirmDeleteDialog --> Button : Delete

    DatasetActionCell ..> useRemoveDocument : hook
    DatasetActionCell ..> downloadDocument : util function
    DatasetActionCell ..> formatFileSize : util function
    DatasetActionCell ..> formatDate : util function
    DatasetActionCell ..> isParserRunning : util function

Summary

dataset-action-cell.tsx provides an interactive, user-friendly component to manage dataset documents via inline action buttons. It balances UX considerations such as disabling buttons during processing, previewing metadata on hover, and confirming deletions. The component integrates tightly with the app's hooks, utilities, and design system, making it a reusable and maintainable part of the dataset management UI.