file-toolbar.tsx


Overview

file-toolbar.tsx defines a React functional component named FileToolbar which acts as a control panel toolbar for managing files and folders within a file manager interface. It provides features such as breadcrumb navigation, search input, bulk operations (delete, move), and actions to upload files or create new folders. The toolbar is designed to integrate into a larger file management system, supporting localization, selection management, and contextual UI behaviors based on the folder type (e.g., knowledge base folders).


Component: FileToolbar

Purpose

The FileToolbar component serves as the user interface for:

It adapts its UI dynamically based on the context (e.g., disables bulk actions when no items are selected, hides certain controls in knowledge base folders).


Props (IProps)

Prop Name

Type

Description

selectedRowKeys

string[]

Array of currently selected file/folder IDs for bulk operations.

showFolderCreateModal

() => void

Callback to open the modal dialog for creating a new folder.

showFileUploadModal

() => void

Callback to open the modal dialog for uploading new files.

setSelectedRowKeys

(keys: string[]) => void

Setter function to update the selected rows outside this component.

searchString

string

Current value of the search input field.

handleInputChange

(e: React.ChangeEvent) => void

Handler for changes in the search input field.

showMoveFileModal

(ids: string[]) => void

Callback to open the modal dialog for moving selected files/folders.


Internal Hooks and State


Rendered UI Elements

  1. Breadcrumb Navigation

    • Displays the folder path.

    • Non-last breadcrumb items are clickable to navigate folders.

    • Last breadcrumb item is displayed as plain text.

  2. Bulk Actions Dropdown (hidden if isKnowledgeBase is true)

    • Delete selected files/folders.

    • Move selected files/folders.

  3. Search Input

    • Allows filtering files/folders by name.

    • Includes a search icon prefix and clear capability.

  4. Add File Dropdown (hidden if isKnowledgeBase is true)

    • Upload new files.

    • Create new folders.


Methods and Handlers

itemRender

Custom renderer for breadcrumb items.


handleShowMoveFileModal


Usage Example

<FileToolbar
  selectedRowKeys={selectedIds}
  setSelectedRowKeys={setSelectedIds}
  searchString={searchValue}
  handleInputChange={handleSearchChange}
  showFolderCreateModal={() => openFolderModal()}
  showFileUploadModal={() => openUploadModal()}
  showMoveFileModal={(ids) => openMoveModal(ids)}
/>

Implementation Details


Interaction with Other Parts of the System


Mermaid Component Diagram

componentDiagram
    component FileToolbar {
        +selectedRowKeys: string[]
        +showFolderCreateModal(): void
        +showFileUploadModal(): void
        +setSelectedRowKeys(keys: string[]): void
        +searchString: string
        +handleInputChange(e): void
        +showMoveFileModal(ids: string[]): void
        ---
        +render()
    }
    component Breadcrumb {
        +items: []
        +itemRender()
    }
    component Dropdown {
        +menu: {items: []}
        +Button
    }
    component Input {
        +value: string
        +onChange()
    }
    FileToolbar --> Breadcrumb : renders
    FileToolbar --> Dropdown : bulk actions menu
    FileToolbar --> Dropdown : add file menu
    FileToolbar --> Input : search input

Summary

The file-toolbar.tsx component provides an interactive, localized toolbar for file management operations including navigation, searching, and bulk editing. It smartly adapts UI elements based on the current folder context and selection state. It interacts closely with custom hooks and parent components to manage state and trigger modal dialogs, fitting cleanly into a modular file management application architecture.