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:
Connect the file to a knowledge base
Move the file to another folder
Rename the file
Download the file
Preview supported document types
Delete the file
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
UI Components:
Button,ConfirmDeleteDialog,NewDocumentLinkIcons: Lucide-react icons for visual representation of actions (e.g.,
Trash2,ArrowDownToLine)Hooks:
useDownloadFile,useHandleDeleteFilefor file operationsUtilities: Helpers like
getExtension,isSupportedPreviewDocumentType,isFolderType,isKnowledgeBaseTypeTypes:
IFileinterface for file data shape,CellContextfrom@tanstack/react-table
Type Definitions
type IProps = Pick<CellContext<IFile, unknown>, 'row'> &
Pick<UseHandleConnectToKnowledgeReturnType, 'showConnectToKnowledgeModal'> &
Pick<UseRenameCurrentFileReturnType, 'showFileRenameModal'> &
UseMoveDocumentShowType;
row: Context object representing the current table row, with access to the underlying file record.showConnectToKnowledgeModal: Function to open a modal for connecting the file to a knowledge base.showFileRenameModal: Function to open a modal for renaming the current file.showMoveFileModal: Function to open a modal for moving the file(s).
Component: ActionCell
export function ActionCell({
row,
showConnectToKnowledgeModal,
showFileRenameModal,
showMoveFileModal,
}: IProps)
Parameters
row(CellContext<IFile, unknown>): Provides access to the file/folder record for this table row.showConnectToKnowledgeModal((file: IFile) => void): Callback to display modal for connecting file to knowledge base.showFileRenameModal((file: IFile) => void): Callback to display modal for renaming file.showMoveFileModal((fileIds: string[]) => void): Callback to display modal for moving files.
Returns
JSX element rendering action buttons tailored to the type and properties of the file record.
Usage Example
<ActionCell
row={tableRowContext}
showConnectToKnowledgeModal={openConnectModal}
showFileRenameModal={openRenameModal}
showMoveFileModal={openMoveModal}
/>
Internal Logic and Handlers
record: Extracted file/folder fromrow.original.documentId: File/folder unique ID.isFolder: Boolean indicating if the record is a folder.extension: File extension extracted from the filename.isKnowledgeBase: Boolean indicating if the record is a knowledge base type.
Callbacks
handleShowConnectToKnowledgeModal: Opens connect modal for the record.onDownloadDocument: Initiates file download viauseDownloadFilehook.handleShowFileRenameModal: Opens rename modal for the record.handleShowMoveFileModal: Opens move modal with current record ID.onRemoveFile: Deletes the file usinguseHandleDeleteFilehook.
Rendered Buttons and Conditions
Button | Icon | Condition | Action |
|---|---|---|---|
Connect to Knowledge |
| Shown if not a knowledge base | Opens connect modal |
Move File |
| Shown if not a knowledge base | Opens move modal |
Rename File |
| Shown if not a knowledge base | Opens rename modal |
Download File |
| Shown if record is not a folder | Triggers file download |
Preview Document |
| Shown if file extension is supported for preview | Links to document preview |
Delete File |
| 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
Uses React's
useCallbackto memoize event handlers for performance.Uses utility functions (
isFolderType,isKnowledgeBaseType) to determine record type.Uses a compositional approach, passing file actions as props rather than managing state internally.
Integrates with external hooks (
useDownloadFile,useHandleDeleteFile) that manage side effects and API calls.Uses the
NewDocumentLinkcomponent to wrap the preview button, enabling navigation to a document preview view.UI buttons use a transparent variant with hover effects for clean design.
The action buttons container uses CSS classes to only appear on row hover (
opacity-0 group-hover:opacity-100).
Interaction with Other Parts of the System
Table Component:
ActionCellis used as a custom cell renderer within a table displaying file/folder records.File Management Hooks: Depends on hooks managing file download and deletion.
Modals: Relies on parent components or contexts to provide modal display functions for connecting, renaming, and moving files.
Utilities: Uses file type utilities to determine rendering logic.
UI Components: Composes UI elements such as buttons and dialogs shared across the app.
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.