From 875d0c2604e5158810a68fefe7005980f40f041f Mon Sep 17 00:00:00 2001 From: Lucia Reynoso Date: Tue, 2 Feb 2021 09:23:04 -0800 Subject: [PATCH] Remove dead code (#44) --- src/ts/src/upload/index.tsx | 178 +----------------------------------- 1 file changed, 4 insertions(+), 174 deletions(-) diff --git a/src/ts/src/upload/index.tsx b/src/ts/src/upload/index.tsx index ba8b427a24..c0325a5eb9 100644 --- a/src/ts/src/upload/index.tsx +++ b/src/ts/src/upload/index.tsx @@ -1,24 +1,11 @@ import { Step } from "./types"; import React, { useState } from "react"; -import cx from "classnames"; -import { get, without, flow, omit, set, find } from "lodash/fp"; import UploadHeader from "./UploadHeader"; -// import UploadSampleStep from "./UploadSampleStep"; -// import UploadMetadataStep from "./UploadMetadataStep"; -// import UploadReviewStep from "./UploadReviewStep"; import style from "./index.module.scss"; -// See HOST_GENOME_SYNONYMS in MetadataField -const HOST_GENOME_SYNONYMS = [ - "host_genome", - "Host Genome", - "host_organism", - "Host Organism", -]; - interface IProps { csrf?: string; hostGenomes?: Array; @@ -30,178 +17,21 @@ interface IProps { export default function Upload(_props: IProps): JSX.Element { const [currentStep, setCurrentStep] = useState(Step.UploadSamples); + // eslint-disable-next-line @typescript-eslint/no-unused-vars const [samples, setSamples] = useState>([]); - const [uploadType, setUploadType] = useState(""); + // eslint-disable-next-line @typescript-eslint/no-unused-vars const [project, setProject] = useState(undefined); - const [sampleNamesToFiles, setSampleNamesToFiles] = useState(null); - const [metadata, setMetadata] = useState(null); - const [metadataIssues, setMetadataIssues] = useState(null); + // eslint-disable-next-line @typescript-eslint/no-unused-vars const [stepsEnabled, setStepsEnabled] = useState({ uploadSamples: true, uploadMetadata: false, review: false, }); - const [hostGenomes, setHostGenomes] = useState>([]); - const [workflows, setWorkflows] = useState(new Set()); - const [wetlabProtocol, setWetlabProtocol] = useState(null); - - window.onbeforeunload = () => - "Are you sure you want to leave? All data will be lost."; - - const onUploadComplete = (): void => { - window.onbeforeunload = null; - }; - - const handleUploadSamples = ({ - samples, - project, - uploadType, - sampleNamesToFiles, - workflows, - wetlabProtocol, - }: Record): void => { - const newStepsEnabled = set("uploadMetadata", true, stepsEnabled); - - setCurrentStep(Step.UploadMetadata); - setProject(project); - setSampleNamesToFiles(sampleNamesToFiles); - setStepsEnabled(newStepsEnabled); - setUploadType(uploadType); - setWetlabProtocol(wetlabProtocol); - setWorkflows(workflows); - }; - - const handleUploadMetadata = ({ - metadata, - issues, - newHostGenomes, - }: Record): void => { - const currentHostGenomes: Array = hostGenomes ?? []; - const updatedHostGenomes = currentHostGenomes.concat(newHostGenomes); - - // Populate host_genome_id in sample using metadata. - const newSamples: Array = []; - samples.forEach((sample) => { - const metadataRow = find( - (row) => - get("sample_name", row) === sample.name || - get("Sample Name", row) === sample.name, - metadata.rows - ); - const hostGenomeName: string = HOST_GENOME_SYNONYMS.reduce( - (match, name) => metadataRow[name] || match, - "" - ); - const hostGenomeId = - find( - // Lowercase to allow for 'human' to match 'Human'. The same logic - // is replicated in MetadataHelper. - (hg) => { - return ( - hg.name.toLowerCase() === - hostGenomeName.toLowerCase() - ); - }, - updatedHostGenomes - )?.id ?? null; - - newSamples.push({ - ...sample, - // Set the host_genome_id and name so it is available in review - host_genome_id: hostGenomeId, - host_genome_name: hostGenomeName, - }); - }); - - // Remove host_genome from metadata. - const newMetadata = flow( - set("rows", metadata.rows.map(omit(HOST_GENOME_SYNONYMS))), - set("headers", without(HOST_GENOME_SYNONYMS, metadata.headers)) - )(metadata); - - setSamples(newSamples); - setMetadata(newMetadata); - setMetadataIssues(issues); - setCurrentStep(Step.Review); - // setStepsEnabled(set("review", true, this.state.stepsEnabled)); - setHostGenomes(updatedHostGenomes); - }; - - const samplesChanged = (): void => { - setStepsEnabled({ - uploadSamples: true, - uploadMetadata: false, - review: false, - }); - }; - - const metadataChanged = (): void => { - setStepsEnabled({ - uploadSamples: true, - uploadMetadata: true, - review: false, - }); - }; const handleStepSelect = (step: Step): void => { setCurrentStep(step); }; - const onUploadStatusChange = (uploadStatus: any): void => { - setStepsEnabled({ - uploadSamples: !uploadStatus, - uploadMetadata: !uploadStatus, - review: !uploadStatus, - }); - }; - - // Uncomment function when child components are converted to Typscript/functional components - // Original IDSeq comment: - // SLIGHT HACK: Keep steps mounted, so user can return to them if needed. - // The internal state of some steps is difficult to recover if they are unmounted. - // const renderSteps = (): JSX.Element => { - // return ( - //
- // - // {samples && ( - // - // )} - // {samples && metadata && ( - // - // )} - //
- // ); - // }; - return (
-
+
{"Steps go here."}