mindmap-drawer.tsx
Overview
mindmap-drawer.tsx defines a React functional component named MindMapDrawer that provides a user interface element for displaying a mind map inside a sliding drawer panel. It leverages Ant Design's Drawer component to present content conditionally based on loading state: either a circular progress indicator showing the loading percentage of a pending mind map or a fully rendered indented tree structure representing the mind map data.
This file mainly serves as a UI wrapper component that integrates translation support, loading progress visualization, and hierarchical data presentation for mind maps. It is intended to be used in contexts where a user needs to view or interact with a mind map in a collapsible side panel.
Detailed Explanations
interface IProps
Defines the props accepted by the MindMapDrawer component.
Property | Type | Description |
|---|---|---|
| The mind map data to be rendered by | |
| Function to close or hide the drawer/modal. (Inherited from | |
|
| Controls visibility of the drawer/modal. (Inherited from |
|
| Indicates if the mind map data is in a loading state, triggering the display of a progress indicator. |
MindMapDrawer Component
const MindMapDrawer = ({ data, hideModal, visible, loading }: IProps) => { ... }
Purpose
Renders a drawer UI that either displays a circular loading progress indicator or a mind map tree visualization, depending on the loading state.
Parameters
data: Mind map data for visualization.hideModal: Callback to close the drawer.visible: Boolean controlling drawer visibility.loading: Boolean controlling loading state UI.
Returns
A React element representing the drawer with conditional content.
Internal Details and Usage
Uses the
useTranslationhook fromreact-i18nextto support internationalization; the drawer title is localized using the key'chunk.mind'.Uses a custom hook
usePendingMindMap()to retrieve the current loading progress percentage for the mind map data.When
loadingistrue, displays an Ant DesignProgresscomponent in a circular format centered inside aFlexcontainer.When
loadingisfalse, renders anIndentedTreecomponent with the provideddata.The drawer width is set to 40% of the viewport width (
'40vw').
Example Usage
<MindMapDrawer
data={mindMapData}
visible={isDrawerVisible}
hideModal={() => setDrawerVisible(false)}
loading={isDataLoading}
/>
This would show the drawer with either the loading progress or the mind map depending on isDataLoading. The drawer visibility is controlled by isDrawerVisible, and closing it triggers setDrawerVisible(false).
Important Implementation Details
Loading State Management:
Thepercentvalue comes fromusePendingMindMap(), a custom hook which likely connects to some async state or global store tracking mind map loading progress. This decouples loading state logic from the UI component, allowing reuse and separation of concerns.Internationalization:
Usingreact-i18nextensures the drawer's title can be localized, improving accessibility and user experience in multiple languages.Modular Component Composition:
The drawer content is composed of two reusable components:Progressfromantdfor visual loading feedback.IndentedTreefor hierarchical mind map rendering, which is imported from a separate component directory, suggesting it abstracts tree rendering logic internally.
Responsive Styling:
The drawer width is specified in viewport relative units (vw), enabling responsive design on various screen sizes.
Interaction with Other Parts of the System
IndentedTreeComponent:
This component is responsible for rendering the mind map data visually as an indented hierarchical tree. It expects the data prop to be formatted accordingly and manages its own internal rendering logic.usePendingMindMapHook:
Likely interfaces with a state management system (React Context, Redux, or other) or asynchronous data fetching mechanisms to provide real-time loading progress updates.Ant Design UI Library:
Utilizes Ant Design components likeDrawer,Flex, andProgressto maintain consistent styling and behavior aligned with the application's UI framework.Internationalization via
react-i18next:
Ensures translated UI strings are served based on the user's locale settings.Parent Components:
TheMindMapDraweris designed to be embedded in higher-level UI components or pages where mind map data is passed down, and visibility/loading states are managed.
Visual Diagram
componentDiagram
MindMapDrawer <|-- AntD_Drawer : uses
MindMapDrawer <|-- IndentedTree : renders when !loading
MindMapDrawer <|-- Progress : renders when loading
MindMapDrawer o-- usePendingMindMap : calls hook for loading %
MindMapDrawer o-- useTranslation : calls hook for localization
Summary
The mindmap-drawer.tsx file implements a specialized React component that provides a user-friendly, internationalized drawer interface for displaying and interacting with mind maps. It cleanly separates concerns between loading state visualization and data rendering, uses standardized UI components for consistency, and is designed to integrate seamlessly within a larger React application that manages mind map data and UI state externally.