index.tsx
Overview
index.tsx defines the React functional component FileMovingModal, a modal dialog used within a file management user interface to move files or folders to a different destination folder. The component leverages the Ant Design (antd) UI library for form and modal elements, and incorporates an asynchronous tree-select control for selecting the destination folder.
The modal includes form validation to ensure the user selects a destination before submitting, and provides a loading state while the move operation is in progress. It also supports internationalization through a custom translation hook.
Component: FileMovingModal
Description
FileMovingModal is a controlled modal component that allows users to pick a destination folder from a hierarchical tree and confirm the move operation. It uses an asynchronous tree select component (AsyncTreeSelect) to dynamically load folder options.
Props
The component expects the following props, extending from IModalManagerChildrenProps (except for showModal which is omitted):
Prop | Type | Description |
|---|---|---|
|
| Controls whether the modal is visible or hidden. |
| Callback function to hide/close the modal. | |
|
| Indicates if the modal is in a loading state, e.g., while waiting for the move operation. |
| Callback invoked when the form is successfully submitted, providing the selected folder ID. |
Internal Types
FieldType- Defines the shape of the form fields used in this component.
type FieldType = {
name?: string;
};
Methods
handleOk: () => Promise<void>
Description:
Triggered when the user clicks the modal's OK button. It validates the form fields and, on successful validation, calls theonOkcallback with the selected folder ID.Return value:
Returns a Promise that resolves after form validation and callback execution.Details:
Uses Ant Design's form validation (form.validateFields()) to ensure the destination folder is selected before proceeding.
Usage Example
<FileMovingModal
visible={isModalVisible}
hideModal={() => setModalVisible(false)}
loading={isMoving}
onOk={(folderId) => handleMoveFile(folderId)}
/>
Implementation Details
The modal title is internationalized via the
useTranslatehook with the key'move'under the'common'namespace.The form consists of a single field labeled "Destination Folder", which uses the
AsyncTreeSelectcomponent to display folders in a tree structure asynchronously.The form layout uses a label column span of 6 and a wrapper column span of 18 for balanced spacing.
The modal width is fixed at 600 pixels for a consistent UI experience.
The modal's confirm button shows a loading spinner when the
loadingprop istrue.
Interactions with Other Parts of the System
IModalManagerChildrenProps: The component receives modal visibility and hiding controls from a modal manager system, integrating into a larger modal management context.useTranslateHook: Used for internationalization to support multiple languages.AsyncTreeSelect: A custom or third-party component that asynchronously loads and displays a tree of folders for user selection.antdComponents: Uses Ant Design'sModalandFormcomponents for UI and form management.Parent Component: The parent component controls
visible,hideModal, andloadingstates and handles the actual file move operation via theonOkcallback.
Diagram: Component Structure and Workflow
componentDiagram
component FileMovingModal {
+visible: boolean
+hideModal(): void
+loading: boolean
+onOk(folderId: string): void
-handleOk(): Promise<void>
-form: FormInstance
}
component Modal {
+title: string
+open: boolean
+onOk(): void
+onCancel(): void
+okButtonProps: object
+confirmLoading: boolean
}
component Form {
+formInstance: FormInstance
+validateFields(): Promise<object>
}
component AsyncTreeSelect {
// Asynchronously loads tree nodes for folder selection
}
FileMovingModal --> Modal : renders
FileMovingModal --> Form : uses for data entry
Form --> AsyncTreeSelect : form field component
Modal --> Form : contains
Summary
Purpose: Provide a modal dialog for moving files/folders by selecting a destination folder.
Key Functionality: Form validation, asynchronous folder selection, internationalized UI, loading state handling.
Usage Context: Part of a file management UI, integrated with modal management and localization systems.
Extensibility: Easily extendable to include more fields or validation rules if needed.
This documentation should enable developers to understand, integrate, and extend the FileMovingModal component effectively within the file management system.