action-cell.tsx


Overview

action-cell.tsx defines the ActionCell React functional component, which renders a set of action buttons associated with a file or folder record displayed in a table row. These actions allow users to:

The component adapts the available actions based on the type of the record (file, folder, knowledge base) and the document type. It integrates UI elements such as buttons and dialogs and hooks for handling file operations.

This component is typically used within a table UI (likely powered by @tanstack/react-table), rendering the action cell for each row corresponding to a file or folder.


Detailed Breakdown

Imports and Dependencies


Type Definitions

type IProps = Pick<CellContext<IFile, unknown>, 'row'> &
  Pick<UseHandleConnectToKnowledgeReturnType, 'showConnectToKnowledgeModal'> &
  Pick<UseRenameCurrentFileReturnType, 'showFileRenameModal'> &
  UseMoveDocumentShowType;

Component: ActionCell

export function ActionCell({
  row,
  showConnectToKnowledgeModal,
  showFileRenameModal,
  showMoveFileModal,
}: IProps)

Parameters

Returns

Usage Example

<ActionCell
  row={tableRowContext}
  showConnectToKnowledgeModal={openConnectModal}
  showFileRenameModal={openRenameModal}
  showMoveFileModal={openMoveModal}
/>

Internal Logic and Handlers

Callbacks


Rendered Buttons and Conditions

Button

Icon

Condition

Action

Connect to Knowledge

Link2

Shown if not a knowledge base

Opens connect modal

Move File

FolderInput

Shown if not a knowledge base

Opens move modal

Rename File

FolderPen

Shown if not a knowledge base

Opens rename modal

Download File

ArrowDownToLine

Shown if record is not a folder

Triggers file download

Preview Document

Eye

Shown if file extension is supported for preview

Links to document preview

Delete File

Trash2

Shown if not a knowledge base

Opens delete confirmation dialog

Note: The component hides most actions for knowledge base records, providing minimal or no action buttons.


Implementation Details


Interaction with Other Parts of the System


Mermaid Component Diagram

componentDiagram
    component ActionCell {
      +row: CellContext<IFile, unknown>
      +showConnectToKnowledgeModal(record: IFile): void
      +showFileRenameModal(record: IFile): void
      +showMoveFileModal(ids: string[]): void
      +handleShowConnectToKnowledgeModal()
      +handleShowFileRenameModal()
      +handleShowMoveFileModal()
      +onDownloadDocument()
      +onRemoveFile()
    }
    component Button
    component ConfirmDeleteDialog
    component NewDocumentLink
    component useDownloadFile
    component useHandleDeleteFile
    component Utilities {
      +getExtension()
      +isSupportedPreviewDocumentType()
      +isFolderType()
      +isKnowledgeBaseType()
    }

    ActionCell --> Button : renders multiple
    ActionCell --> ConfirmDeleteDialog : wraps delete button
    ActionCell --> NewDocumentLink : wraps preview button
    ActionCell --> useDownloadFile : calls downloadFile()
    ActionCell --> useHandleDeleteFile : calls handleRemoveFile()
    ActionCell --> Utilities : uses type & extension helpers

Summary

action-cell.tsx provides a reusable, context-aware action toolbar for file and folder records within a table UI. It encapsulates complex conditional logic to show appropriate actions and hooks into core file operations. The component cleanly separates UI concerns from business logic by relying on external hooks and props, making it easy to integrate and maintain within a larger file management or knowledge base application.


End of Documentation for action-cell.tsx