index.tsx


Overview

The index.tsx file defines a React component module centered around a file upload modal dialog, primarily designed for uploading files and directories locally with optional parsing on creation. It utilizes Ant Design components for UI elements and custom hooks for internationalization. The core functionality allows users to drag-and-drop or select files/directories to upload, track upload progress visually, and manage upload state within a modal interface.

This file exports a single default component FileUploadModal, which encapsulates the entire modal dialog functionality. Within it, a reusable FileUpload subcomponent handles the drag-and-drop upload UI and file list management for either single files or directories.


Components and Functions

1. FileUpload Component

A functional component that provides a drag-and-drop file uploader interface using Ant Design's Upload.Dragger. It supports both single file and directory uploads.

Props

Name

Type

Description

directory

boolean

Whether to allow uploading directories (folder upload).

fileList

UploadFile[]

The current list of files selected for upload.

setFileList

Dispatch<SetStateAction<UploadFile[]>>

State setter function to update the file list.

uploadProgress

number (optional)

Represents the current upload progress percentage (0-100).

Behavior

Usage Example

<FileUpload
  directory={false}
  fileList={fileList}
  setFileList={setFileList}
  uploadProgress={uploadProgress}
/>

2. FileUploadModal Component (Default Export)

A modal dialog component wrapping the upload UI, managing modal visibility, upload states, and file selection between files and directories. It supports toggling between local and (future) S3 uploads.

Props (IFileUploadModalProps)

Extends a generic modal props interface IModalProps with additional fields:

Name

Type

Description

visible

boolean (from IModalProps)

Controls modal visibility.

hideModal

() => void (from IModalProps)

Callback to close the modal.

loading

boolean (from IModalProps)

Shows loading state during upload confirmation.

onOk

function (from IModalProps)

Callback on modal confirmation, handles upload logic.

uploadFileList

UploadFile[] (optional)

External file list controlled from parent component.

setUploadFileList

Dispatch<SetStateAction<UploadFile[]>> (optional)

Setter for external file list.

uploadProgress

number (optional)

Upload progress percentage (0-100).

setUploadProgress

Dispatch<SetStateAction<number>> (optional)

Setter for upload progress.

Internal State

Key Methods

UI Structure

Usage Example

<FileUploadModal
  visible={isModalVisible}
  hideModal={() => setModalVisible(false)}
  loading={isUploading}
  onOk={handleUpload}
  uploadFileList={uploadFileList}
  setUploadFileList={setUploadFileList}
  uploadProgress={uploadProgress}
  setUploadProgress={setUploadProgress}
/>

Important Implementation Details


Interaction with Other Parts of the System


Mermaid Diagram: Component Structure and Interactions

componentDiagram
    direction TB
    FileUploadModal --> FileUpload : uses twice for 'file' and 'directory'
    FileUploadModal o-- Modal : renders modal dialog
    FileUpload o-- Upload.Dragger : uses AntD Dragger for upload UI
    FileUpload o-- Progress : shows upload progress
    FileUploadModal o-- Segmented : for local/S3 toggle
    FileUploadModal o-- Checkbox : for parseOnCreation option
    FileUploadModal o-- Tabs : to switch between file/directory uploads
    FileUploadModal --> useTranslate : localization hook
    FileUpload --> useTranslate : localization hook

Summary

The index.tsx file provides a modular, localized, and extensible file upload modal component primarily for local file and directory uploads. It cleanly separates UI concerns between the modal container (FileUploadModal) and the drag-and-drop upload area (FileUpload). It supports controlled and uncontrolled file lists, upload progress feedback, and toggling between local and planned S3 uploads. This component is designed to integrate seamlessly with external upload handling logic and overall application state management.