From 39c63e8e29723a9615129abff27727b5ed8f7126 Mon Sep 17 00:00:00 2001 From: Yannick Brosseau Date: Wed, 18 Dec 2024 11:47:52 -0500 Subject: [PATCH] Clean up FileUploader We remove the unused ImporterValidator. Comment out unused Error section and remove non-necessaru onChange handler --- .../services/importers/ImporterValidator.ts | 19 -------------- .../src/components/input/FileUploaderHOC.tsx | 26 +++---------------- .../AccessibilityMapBatchForm.tsx | 2 +- .../stepForms/ConfigureDemandFromCsvForm.tsx | 2 +- .../src/components/parts/FileImportForm.tsx | 16 +++++------- 5 files changed, 12 insertions(+), 53 deletions(-) delete mode 100644 packages/chaire-lib-common/src/services/importers/ImporterValidator.ts diff --git a/packages/chaire-lib-common/src/services/importers/ImporterValidator.ts b/packages/chaire-lib-common/src/services/importers/ImporterValidator.ts deleted file mode 100644 index f1910bab..00000000 --- a/packages/chaire-lib-common/src/services/importers/ImporterValidator.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2022, Polytechnique Montreal and contributors - * - * This file is licensed under the MIT License. - * License text available at https://opensource.org/licenses/MIT - */ -import { ObjectWithHistory } from '../../utils/objects/ObjectWithHistory'; -import { GenericAttributes } from '../../utils/objects/GenericObject'; - -export type ImporterValidatorAttributes = GenericAttributes; - -// TODO: This seems very useless, but it is used for the FileUploaderHOC. Do we need it? -class ImporterValidator extends ObjectWithHistory { - constructor(attributes: Partial) { - super(attributes, false); - } -} - -export default ImporterValidator; diff --git a/packages/chaire-lib-frontend/src/components/input/FileUploaderHOC.tsx b/packages/chaire-lib-frontend/src/components/input/FileUploaderHOC.tsx index 01ad8a5b..473a665b 100644 --- a/packages/chaire-lib-frontend/src/components/input/FileUploaderHOC.tsx +++ b/packages/chaire-lib-frontend/src/components/input/FileUploaderHOC.tsx @@ -8,7 +8,6 @@ import React from 'react'; import SocketIOFileClient from 'socket.io-file-client'; import serviceLocator from 'chaire-lib-common/lib/utils/ServiceLocator'; -import ImportValidator from 'chaire-lib-common/lib/services/importers/ImporterValidator'; export type FileUploadStatus = | { @@ -32,21 +31,14 @@ export type FileUploadStatus = export type FileUploaderHOCProps = { fileImportRef: React.RefObject; fileUploader: SocketIOFileClient; - onChange: React.ChangeEventHandler; - validator?: ImportValidator; uploadStatus: FileUploadStatus; }; -type FileUploaderHOCState = { - validator?: ImportValidator; +interface FileUploaderHOCState { uploadStatus: FileUploadStatus; -}; +} -const fileUploaderHOC = ( - WrappedComponent: React.ComponentType

, - importerValidator?: typeof ImportValidator, - autoImport = true -) => { +const fileUploaderHOC = (WrappedComponent: React.ComponentType

, autoImport = true) => { class FileUploaderHOC extends React.Component

{ private fileImportRef: React.RefObject; private fileUploader: SocketIOFileClient; @@ -55,7 +47,6 @@ const fileUploaderHOC = ( super(props); this.state = { - validator: importerValidator ? new importerValidator({}) : undefined, uploadStatus: { status: 'notUploaded' } }; @@ -67,7 +58,6 @@ const fileUploaderHOC = ( this.onFileUploadComplete = this.onFileUploadComplete.bind(this); this.onFileUploadError = this.onFileUploadError.bind(this); this.onFileUploadAbort = this.onFileUploadAbort.bind(this); - this.onChange = this.onChange.bind(this); } componentDidMount() { @@ -86,14 +76,6 @@ const fileUploaderHOC = ( this.fileUploader.off('abort', this.onFileUploadAbort); } - onChange() { - this.setState((state) => { - return { - validator: state.validator - }; - }); - } - onFileUploadStart(_fileInfo) { this.setState({ uploadStatus: { status: 'uploading', progress: 0 } }); serviceLocator.eventManager.emit('progress', { name: 'UploadingFile', progress: 0.0 }); @@ -129,8 +111,6 @@ const fileUploaderHOC = ( {...this.props} fileImportRef={this.fileImportRef} fileUploader={this.fileUploader} - onChange={this.onChange} - validator={this.state.validator} uploadStatus={this.state.uploadStatus} /> ); diff --git a/packages/transition-frontend/src/components/forms/accessibilityMap/AccessibilityMapBatchForm.tsx b/packages/transition-frontend/src/components/forms/accessibilityMap/AccessibilityMapBatchForm.tsx index 8820a206..889d3109 100644 --- a/packages/transition-frontend/src/components/forms/accessibilityMap/AccessibilityMapBatchForm.tsx +++ b/packages/transition-frontend/src/components/forms/accessibilityMap/AccessibilityMapBatchForm.tsx @@ -331,4 +331,4 @@ class AccessibilityMapBatchForm extends ChangeEventsForm< // ** File upload //export default FileUploaderHOC(TransitRoutingForm, null, false); -export default FileUploaderHOC(withTranslation(['transit', 'main'])(AccessibilityMapBatchForm), undefined, false); +export default FileUploaderHOC(withTranslation(['transit', 'main'])(AccessibilityMapBatchForm), false); diff --git a/packages/transition-frontend/src/components/forms/batchCalculation/stepForms/ConfigureDemandFromCsvForm.tsx b/packages/transition-frontend/src/components/forms/batchCalculation/stepForms/ConfigureDemandFromCsvForm.tsx index fbd1331d..abbb845d 100644 --- a/packages/transition-frontend/src/components/forms/batchCalculation/stepForms/ConfigureDemandFromCsvForm.tsx +++ b/packages/transition-frontend/src/components/forms/batchCalculation/stepForms/ConfigureDemandFromCsvForm.tsx @@ -142,4 +142,4 @@ const ConfigureDemandFromCsvForm: React.FunctionComponent< ); }; -export default FileUploaderHOC(withTranslation(['transit', 'main'])(ConfigureDemandFromCsvForm), undefined, false); +export default FileUploaderHOC(withTranslation(['transit', 'main'])(ConfigureDemandFromCsvForm), false); diff --git a/packages/transition-frontend/src/components/parts/FileImportForm.tsx b/packages/transition-frontend/src/components/parts/FileImportForm.tsx index 8e2b0999..e0adf9a6 100644 --- a/packages/transition-frontend/src/components/parts/FileImportForm.tsx +++ b/packages/transition-frontend/src/components/parts/FileImportForm.tsx @@ -13,7 +13,6 @@ import { faUpload } from '@fortawesome/free-solid-svg-icons/faUpload'; import InputFile from 'chaire-lib-frontend/lib/components/input/InputFile'; import Button from 'chaire-lib-frontend/lib/components/input/Button'; import FormErrors from 'chaire-lib-frontend/lib/components/pageParts/FormErrors'; -import ImporterValidator from 'chaire-lib-common/lib/services/importers/ImporterValidator'; import FileUploaderHOC, { FileUploaderHOCProps } from 'chaire-lib-frontend/lib/components/input/FileUploaderHOC'; interface FileImportFormProps extends FileUploaderHOCProps { @@ -27,26 +26,25 @@ interface FileImportFormProps extends FileUploaderHOCProps { const FileImportForm: React.FunctionComponent = ( props: FileImportFormProps & WithTranslation ) => { - const validator = props.validator as ImporterValidator; + const [fileSelected, setFileSelected] = React.useState(false); + return (

{props.t('main:Import')}

-
setFileSelected(true)} />
-
- - + {/* TODO Add actual upload error information when we have it + */} ); }; -export default FileUploaderHOC(withTranslation('main')(FileImportForm), ImporterValidator); +export default FileUploaderHOC(withTranslation('main')(FileImportForm));