move-dialog.tsx


Overview

move-dialog.tsx defines a React functional component MoveDialog that provides a user interface dialog for moving files or folders within a file management system. The dialog presents a tree-based folder selector loaded asynchronously, allowing users to pick a destination folder to move an item to. Once a destination is selected, users can confirm the move operation.

Key functionalities include:

The component is designed to be reusable, localized via react-i18next, and integrates with custom UI components and hooks from the broader application ecosystem.


Detailed Explanation

MoveDialog Component

function MoveDialog({ hideModal, onOk, loading }: IModalProps<any>)

Purpose

MoveDialog renders a modal dialog that allows the user to select a folder to move an item into. It fetches folder data lazily and maintains the current selection state internally.

Props (IModalProps<any>)

Internal State

Hooks and Utilities Used


Internal Methods

onLoadData

const onLoadData = useCallback(
  async ({ id }: TreeNodeType) => { ... },
  [fetchList]
);

handleSubmit

const handleSubmit = useCallback(() => {
  onOk?.(treeValue);
}, [onOk, treeValue]);

JSX Structure and Usage

<Dialog open onOpenChange={hideModal}>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>{t('common.move')}</DialogTitle>
    </DialogHeader>
    <AsyncTreeSelect
      treeData={treeData}
      value={treeValue}
      onChange={setTreeValue}
      loadData={onLoadData}
    />
    <DialogFooter>
      <ButtonLoading
        type="submit"
        onClick={handleSubmit}
        disabled={isEmpty(treeValue)}
        loading={loading}
      >
        {t('common.save')}
      </ButtonLoading>
    </DialogFooter>
  </DialogContent>
</Dialog>

Important Implementation Details


Interaction with Other System Parts


Usage Example

function ParentComponent() {
  const [showMoveDialog, setShowMoveDialog] = useState(false);
  const [loading, setLoading] = useState(false);

  const handleMove = (targetFolderId: string | number) => {
    setLoading(true);
    // Perform move operation here...
    moveFileToFolder(selectedFileId, targetFolderId).then(() => {
      setLoading(false);
      setShowMoveDialog(false);
    });
  };

  return (
    <>
      <button onClick={() => setShowMoveDialog(true)}>Move File</button>
      {showMoveDialog && (
        <MoveDialog
          hideModal={() => setShowMoveDialog(false)}
          onOk={handleMove}
          loading={loading}
        />
      )}
    </>
  );
}

Mermaid Diagram

componentDiagram
    MoveDialog --> AsyncTreeSelect
    MoveDialog --> ButtonLoading
    MoveDialog --> Dialog
    MoveDialog --> useFetchPureFileList
    MoveDialog --> useTranslation

    component MoveDialog {
      +hideModal: () => void
      +onOk: (value: any) => void
      +loading: boolean
      -treeValue: string | number
      -treeData: Array<TreeNodeType>
      -onLoadData(node: TreeNodeType): Promise<void>
      -handleSubmit(): void
    }

    component AsyncTreeSelect {
      +treeData: Array<TreeNodeType>
      +value: string | number
      +onChange(value): void
      +loadData(node: TreeNodeType): Promise<void>
    }

    component ButtonLoading {
      +onClick(): void
      +disabled: boolean
      +loading: boolean
    }

    component Dialog {
      +open: boolean
      +onOpenChange: () => void
    }

Summary

The move-dialog.tsx file implements a modal dialog component for selecting a target folder to move files into. It leverages asynchronous tree loading to efficiently handle large folder structures, maintains internal state for user selection, and integrates with application-specific UI components and data-fetching hooks. This component encapsulates the move dialog's UI and logic, enabling consistent and localized user experiences across the file management system.