From cec8c72b4609f69a21bebd233c2662fa7bdd078b Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Wed, 10 Sep 2025 19:19:40 +0530 Subject: [PATCH] (refactor:uploads) YAGNI --- frontend/src/upload/Upload.tsx | 285 +++++++++----------------- frontend/src/upload/types/ingestor.ts | 175 +++------------- 2 files changed, 120 insertions(+), 340 deletions(-) diff --git a/frontend/src/upload/Upload.tsx b/frontend/src/upload/Upload.tsx index 3c42eca0..5d0d6a96 100644 --- a/frontend/src/upload/Upload.tsx +++ b/frontend/src/upload/Upload.tsx @@ -5,8 +5,7 @@ import { useDispatch, useSelector } from 'react-redux'; import userService from '../api/services/userService'; import { getSessionToken } from '../utils/providerUtils'; -import FileUpload from '../assets/file_upload.svg'; -import WebsiteCollect from '../assets/website_collect.svg'; + import Dropdown from '../components/Dropdown'; import Input from '../components/Input'; import ToggleSwitch from '../components/ToggleSwitch'; @@ -45,10 +44,9 @@ function Upload({ onSuccessfulUpload?: () => void; }) { const token = useSelector(selectToken); - const [docName, setDocName] = useState(receivedFile[0]?.name); - const [remoteName, setRemoteName] = useState(''); + const [files, setfiles] = useState(receivedFile); - const [activeTab, setActiveTab] = useState(renderTab); + const [activeTab, setActiveTab] = useState(true); const [showAdvancedOptions, setShowAdvancedOptions] = useState(false); // File picker state @@ -59,11 +57,11 @@ function Upload({ const renderFormFields = () => { - const schema = IngestorFormSchemas[ingestor.type]; - if (!schema) return null; + if (!ingestor.type) return null; + const schema: FormField[] = IngestorFormSchemas[ingestor.type as IngestorType]; - const generalFields = schema.filter((field) => !field.advanced); - const advancedFields = schema.filter((field) => field.advanced); + const generalFields = schema.filter((field: FormField) => !field.advanced); + const advancedFields = schema.filter((field: FormField) => field.advanced); return (
@@ -184,30 +182,16 @@ function Upload({ className={`mt-2 text-base`} /> ); - case 'file_picker': - return ( - { - setSelectedFiles(selectedFileIds); - setSelectedFolders(selectedFolderIds); - }} - provider={ingestor.type} - token={token} - initialSelectedFiles={selectedFiles} - initialSelectedFolders={selectedFolders} - /> - ); case 'local_file_picker': return (
-
- +
+ Choose Files
-
+

Selected Files

@@ -230,21 +214,31 @@ function Upload({
); + case 'remote_file_picker': + return ( + { + setSelectedFiles(selectedFileIds); + setSelectedFolders(selectedFolderIds); + }} + provider={ingestor.type as unknown as string} + token={token} + initialSelectedFiles={selectedFiles} + initialSelectedFolders={selectedFolders} + /> + ); default: return null; } }; // New unified ingestor state - const [ingestor, setIngestor] = useState(() => { - const defaultType: IngestorType = 'crawler'; - const defaultConfig = IngestorDefaultConfigs[defaultType]; - return { - type: defaultType, - name: defaultConfig.name, - config: defaultConfig.config, - }; - }); + const [ingestor, setIngestor] = useState(() => ({ + type: null, + name: '', + config: {}, + })); const [progress, setProgress] = useState<{ type: 'UPLOAD' | 'TRAINING'; @@ -327,7 +321,7 @@ function Upload({ (progress?.percentage === 100 ? ( - -
-
- )} + - {activeTab === 'file' && ( - <> - setDocName(e.target.value)} - borderVariant="thin" - placeholder={t('modals.uploadDoc.name')} - labelBgClassName="bg-white dark:bg-charleston-green-2" - required={true} - /> -
- - - {t('modals.uploadDoc.choose')} - -
-

- {t('modals.uploadDoc.info')} -

-
-

- {t('modals.uploadDoc.uploadedFiles')} -

-
- {files.map((file) => ( -

- {file.name} -

- ))} - {files.length === 0 && ( -

- {t('none')} -

- )} -
-
- - )} - {activeTab === 'remote' && ( + + {activeTab && ( <> { - setRemoteName(e.target.value); - // Also update the ingestor name setIngestor((prevState) => ({ ...prevState, name: e.target.value, @@ -811,8 +719,8 @@ function Upload({ labelBgClassName="bg-white dark:bg-charleston-green-2" /> {renderFormFields()} - {IngestorFormSchemas[ingestor.type].some( - (field) => field.advanced, + {ingestor.type && IngestorFormSchemas[ingestor.type as IngestorType].some( + (field: FormField) => field.advanced, ) && ( - )} {activeTab && (