index.tsx
Overview
index.tsx defines a React functional component named ChunkToolBar, which serves as a toolbar interface for managing "chunks" within a knowledge base document. This toolbar provides users with controls to:
Navigate back to the dataset view.
View the current document's name.
Toggle chunk text display modes.
Perform bulk operations on chunks (select all, enable, disable, delete).
Search within chunks.
Filter chunks by availability status (all, enabled, disabled).
Create new chunks.
The component integrates various UI elements from the Ant Design library, custom hooks for data and state management, and localized text support. It is designed for use in a knowledge management system where users interact with segmented document data ("chunks").
Detailed Explanation
Component: ChunkToolBar
Purpose
ChunkToolBar provides a user-friendly interface to manage chunks related to a knowledge base document. It combines search, filtering, bulk actions, and chunk display mode toggling in a single toolbar.
Props (IProps)
Prop Name | Type | Description |
|---|---|---|
|
| Current search query text input by the user. |
| Callback to handle changes in the search input box. | |
| [number \ | undefined](/projects/311/74002) |
| [(available: number \ | undefined) => void](/projects/311/72209) |
|
| Indicates if all chunks are currently selected. |
| Function to select or deselect all chunks. | |
| Function to create a new chunk. | |
| Function to remove selected chunks. | |
| Function to switch the availability status of selected chunks. | |
| Function to change how chunk text is displayed (full or ellipsis). |
Usage Example
import ChunkToolBar from './index';
import { ChunkTextMode } from '../../constant';
function Example() {
const [search, setSearch] = useState('');
const [available, setAvailable] = useState<number | undefined>(undefined);
const [checked, setChecked] = useState(false);
const selectAllChunk = (checked: boolean) => {
setChecked(checked);
// Additional logic to select chunks
};
const createChunk = () => {
// Logic to create a new chunk
};
const removeChunk = () => {
// Logic to delete selected chunks
};
const switchChunk = (status: number) => {
// Logic to enable/disable chunks
};
const changeChunkTextMode = (mode: ChunkTextMode) => {
// Logic to update text display mode
};
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setSearch(e.target.value);
};
const handleSetAvailable = (value: number | undefined) => {
setAvailable(value);
};
return (
<ChunkToolBar
searchString={search}
handleInputChange={handleInputChange}
available={available}
handleSetAvailable={handleSetAvailable}
checked={checked}
selectAllChunk={selectAllChunk}
createChunk={createChunk}
removeChunk={removeChunk}
switchChunk={switchChunk}
changeChunkTextMode={changeChunkTextMode}
/>
);
}
Internal Implementation Details
Data Hooks Used:
useSelectChunkList: Fetches chunk list data and document info.useKnowledgeBaseId: Retrieves the current knowledge base ID.useTranslate: Provides localized strings scoped to 'chunk'.
State:
isShowSearchBox: boolean— Controls visibility of the search input box.
Handlers:
handleSelectAllCheck: Toggles selection of all chunks.handleSearchIconClick: Shows the search box.handleSearchBlur: Hides search box if input is empty.handleDelete: Triggers chunk removal.handleEnabledClick/handleDisabledClick: Changes chunk status to enabled/disabled.handleFilterChange: Changes chunk availability filter.
UI Components:
Navigation link back to dataset using
KnowledgeRouteKey.Dataset.Document name display with ellipsis tooltip.
Segmentedcontrol toggling chunk text display mode (FullvsEllipse).Popovermenus for bulk actions and filtering.Search input with clear and blur behavior.
Buttons with icons for various toolbar actions.
Bulk Actions Menu:
Select All checkbox.
Enable selected.
Disable selected.
Delete selected.
Filter Popover:
Radio buttons for filtering chunks by status (all/enabled/disabled).
Interaction with Other System Components
Data Flow:
Uses hooks (
useSelectChunkList,useKnowledgeBaseId) to pull data from global or contextual stores.Calls callback props to notify parent components or state managers of user actions (e.g., chunk selection, creation, deletion).
Routing:
Uses
Linkfromumito navigate back to the knowledge base dataset view, passing the current knowledge base ID as a route parameter.
Localization:
Uses
useTranslatehook for multi-language support on UI text, scoped to the "chunk" namespace.
Constants:
ChunkTextModedefines chunk text display modes, likely imported from a shared constants file.
Assets:
Custom SVG icon imported as React component (
FilterIcon).
UI Framework:
Built on Ant Design components and icons, ensuring consistent styling and behavior.
Mermaid Diagram: Component Interaction Diagram
componentDiagram
component ChunkToolBar {
+selectAllChunk(checked: boolean)
+createChunk()
+removeChunk()
+switchChunk(available: number)
+changeChunkTextMode(mode: ChunkTextMode)
}
component useSelectChunkList
component useKnowledgeBaseId
component useTranslate
component AntdComponents
component umi_Link
ChunkToolBar --> useSelectChunkList : fetch chunk data, document info
ChunkToolBar --> useKnowledgeBaseId : get knowledgeBaseId
ChunkToolBar --> useTranslate : get localized text
ChunkToolBar --> AntdComponents : Button, Popover, Menu, Input, Checkbox, Radio, Segmented, Typography
ChunkToolBar --> umi_Link : navigation to dataset page
ChunkToolBar --calls--> selectAllChunk
ChunkToolBar --calls--> createChunk
ChunkToolBar --calls--> removeChunk
ChunkToolBar --calls--> switchChunk
ChunkToolBar --calls--> changeChunkTextMode
Summary
The ChunkToolBar component is a critical UI element for managing chunks within a knowledge base document. It provides:
Navigation and document context.
Text display mode toggling.
Bulk chunk selection and actions.
Search and filter capabilities.
Chunk creation.
It leverages React hooks for data and localization, Ant Design for UI, and integrates closely with knowledge base data structures and routing.
This modular, reusable toolbar enhances user productivity by consolidating chunk management controls into a single coherent interface.