import React, { useState } from 'react'; import { Modal, Form, Input, Select, Upload, Button } from 'antd'; import { UploadOutlined } from '@ant-design/icons'; import type { UploadFile, UploadProps } from 'antd/es/upload/interface'; import type { FormInstance } from 'antd/es/form'; import styles from './BulkActionStartModal.module.css'; import { max, set } from 'lodash'; import useBulkActionStore from '../../stores/BulkActionStore'; const { TextArea } = Input; const { Option } = Select; interface WorkflowOption { value: string; label: string; } interface JobFormValues { jobName: string; jobDescription: string; workflow: string; customWorkflowInput?: string; file: File; entityType: string; } interface JobUploadModalProps { visible: boolean; onCancel: () => void; onSubmit: (values: JobFormValues) => void; initialValues?: Partial; } const workflowOptions: WorkflowOption[] = [ { value: 'workflow1', label: 'Test Workflow' }, { value: 'custom', label: 'Custom Workflow' }, ]; const BulkActionStartModal: React.FC = ({ visible, onCancel, onSubmit, initialValues }) => { const [form] = Form.useForm(); const [customWorkflow, setCustomWorkflow] = useState(false); const [fileSelected, setFileSelected] = useState(null); const handleWorkflowChange = (value: string): void => { setCustomWorkflow(value === 'custom'); }; const handleSubmit = async (): Promise => { try { const values: JobFormValues = (await form.validateFields()) as JobFormValues; if (fileSelected != null) { values.file = fileSelected; } onSubmit(values as JobFormValues); form.resetFields(); setFileSelected(null); setCustomWorkflow(false); } catch (error) { console.error('Validation failed:', error); } }; const normFile = (e: any): UploadFile[] => { if (Array.isArray(e)) { return e; } return e?.fileList || []; }; // Custom validation rules const validationRules = { jobName: [ { required: true, message: 'Please enter job name' }, { max: 100, message: 'Job name cannot exceed 100 characters' }, ], jobDescription: [ { required: true, message: 'Please enter job description' }, { max: 500, message: 'Job description cannot exceed 500 characters' }, ], workflow: [{ required: true, message: 'Please select or enter workflow' }], customWorkflowInput: [ { required: true, message: 'Please enter custom workflow' }, { max: 100, message: 'Custom workflow cannot exceed 100 characters' }, ], file: [], entityType: [{ required: true, message: 'Please select entity type' }], }; // File upload configuration const uploadProps: UploadProps = { beforeUpload: (file) => { // ~10 million rows of bigint entity-ids in a CSV file would be around 250MB const isValidSize = file.size ? file.size / 1024 / 1024 / 1024 < 250 : false; // 250MB limit if (!isValidSize) { Modal.error({ title: 'File too large', content: 'File size must be less than 250MB', }); } setFileSelected(file); return false; // Prevent automatic upload }, accept: '.csv', // Restrict file types, multiple: false, showUploadList: false, type: 'drag', }; return ( { form.resetFields(); setFileSelected(null); setCustomWorkflow(false); onCancel(); }} onOk={handleSubmit} width={600} className={styles.modal} > form={form} layout="vertical" requiredMark="optional" initialValues={initialValues}>