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:
Navigating folder hierarchy via breadcrumbs.
Searching files/folders.
Executing bulk operations on selected files/folders (delete, move).
Adding new files or folders.
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 |
|---|---|---|
|
| Array of currently selected file/folder IDs for bulk operations. |
| Callback to open the modal dialog for creating a new folder. | |
| Callback to open the modal dialog for uploading new files. | |
| Setter function to update the selected rows outside this component. | |
|
| Current value of the search input field. |
| Handler for changes in the search input field. | |
| Callback to open the modal dialog for moving selected files/folders. |
Internal Hooks and State
Localization: Uses useTranslate('knowledgeDetails') hook for localized strings.
Breadcrumb Data: Uses useSelectBreadcrumbItems() to retrieve breadcrumb items (likely an array of folder path objects).
Breadcrumb Click Handler: Uses useHandleBreadcrumbClick() to navigate when breadcrumb items are clicked.
Parent Folder List: Uses useFetchParentFolderList() to get data about parent folders; used to determine if the current folder is part of a knowledge base (isKnowledgeBase flag).
Delete Handler: Uses useHandleDeleteFile(selectedRowKeys, setSelectedRowKeys) to get a function that deletes selected files and updates selection.
Memoized menu items and handlers:
useMemoanduseCallbackoptimize rendering of dropdown menu items and event handlers.
Rendered UI Elements
Breadcrumb Navigation
Displays the folder path.
Non-last breadcrumb items are clickable to navigate folders.
Last breadcrumb item is displayed as plain text.
Bulk Actions Dropdown (hidden if isKnowledgeBase is true)
Delete selected files/folders.
Move selected files/folders.
Search Input
Allows filtering files/folders by name.
Includes a search icon prefix and clear capability.
Add File Dropdown (hidden if isKnowledgeBase is true)
Upload new files.
Create new folders.
Methods and Handlers
itemRender
Custom renderer for breadcrumb items.
Parameters:
currentRoute: Current breadcrumb route object.params: Additional parameters (not used here).items: Full breadcrumb items array.
Returns:
A clickable<span>for all but the last item, which is a plain<span>.Usage:
Passed to Ant Design's component asitemRender.
handleShowMoveFileModal
Purpose:
Opens the move file modal with currently selected row keys.Implementation:
Memoized withuseCallback, depends onselectedRowKeysandshowMoveFileModal.
Usage Example
<FileToolbar
selectedRowKeys={selectedIds}
setSelectedRowKeys={setSelectedIds}
searchString={searchValue}
handleInputChange={handleSearchChange}
showFolderCreateModal={() => openFolderModal()}
showFileUploadModal={() => openUploadModal()}
showMoveFileModal={(ids) => openMoveModal(ids)}
/>
Implementation Details
Localization: Utilizes a translation hook (
useTranslate) scoped to'knowledgeDetails'for all UI text, ensuring support for multiple languages.Breadcrumbs: Uses Ant Design's
Breadcrumbcomponent with a customitemRenderfunction to make path segments clickable except for the last segment.Dropdown Menus: Uses Ant Design's
DropdownandMenucomponents to provide action menus for bulk operations and adding files/folders.Iconography: Uses icons from
@ant-design/iconsandlucide-reactto visually represent actions.Conditional Rendering: Certain UI elements (bulk actions, add file dropdown) are hidden when the current folder is a "knowledge base" type, based on data from parent folder list.
State Management: The component is controlled via props for selection and search state, delegating state changes to parent components.
Interaction with Other Parts of the System
Hooks from
@/hooks/file-manager-hooks:
Fetches folder data and search results, integrates with the file manager's state and API.Custom Hooks from
./hooks:
Encapsulates logic for breadcrumb navigation, file deletion, and breadcrumb item selection, promoting separation of concerns.Modal Control:
Receives callbacks to show modals for creating folders, uploading files, and moving files, which are likely implemented in parent components or pages.Localization System:
Integrates with a translation/localization system to ensure UI text is language-aware.Styling:
Uses CSS modules (index.less) for scoped styles, including custom styles for breadcrumb items.
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.