Skip to content

Commit

Permalink
jobname defaults to result record name if left blank
Browse files Browse the repository at this point in the history
  • Loading branch information
prabh-t committed Oct 1, 2024
1 parent cc23e17 commit a3d335d
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/ui/modal/DownloadModal.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import {useCallback, useRef, useState} from 'react';
import {useCallback, useEffect, useRef, useState} from 'react';
import Button from '../elements/form/Button';
import Modal from './Modal';
import useOnClickOutside from '../../hooks/useOnClickOutside';
import {emailValidate} from '../../utills/Validator';
import {DownloadRecord, recordFromResponse} from "../../types/DownloadRecord";
import {LOCAL_DOWNLOADS} from "../../constants/const";
import {LOCAL_DOWNLOADS, LOCAL_RESULTS} from "../../constants/const";
import Notify from "../elements/Notify";
import {downloadResult} from "../../services/ProtVarService";
import useLocalStorage from "../../hooks/useLocalStorage";
import {useLocation, useSearchParams} from "react-router-dom";
import {InputType} from "../../types/PagedMappingResponse";
import {Assembly} from "../../constants/CommonTypes";
import Spaces from "../elements/Spaces";
import {ResultRecord} from "../../types/ResultRecord";

interface DownloadForm {
email: string
Expand All @@ -36,6 +38,7 @@ function DownloadModal(props: DownloadModalProps) {
useOnClickOutside(downloadModelDiv, useCallback(() => setShowModel(false), []));
const { getItem, setItem } = useLocalStorage();
const [errorMsg, setErrorMsg] = useState("")
const [jobNamePlaceholder, setJobNamePlaceholder] = useState<string>('')

const location = useLocation();
const [searchParams] = useSearchParams();
Expand All @@ -50,6 +53,17 @@ function DownloadModal(props: DownloadModalProps) {
const [annotations, setAnnotations] = useState<boolean>(true)
const [currPage, setCurrPage] = useState<boolean>(true)

useEffect(() => {
if (props.id) {
// Retrieve result records from local storage
const localResults = getItem<ResultRecord[]>(LOCAL_RESULTS) || []
const savedRecord = localResults.find((r) => r.id === props.id);
if (savedRecord && savedRecord.name) {
setJobNamePlaceholder(savedRecord.name)
}
}
}, [getItem]);

const updateForm = (key: string, value: any) => {
setForm({
...form,
Expand All @@ -74,7 +88,7 @@ function DownloadModal(props: DownloadModalProps) {
}

const handleErr = () => {
Notify.err(`Job ${form.jobName} failed. Please try again.`)
Notify.err(`Job ${form.jobName ? form.jobName : jobNamePlaceholder} failed. Please try again.`)
}

const handleSubmit = () => {
Expand All @@ -96,14 +110,15 @@ function DownloadModal(props: DownloadModalProps) {
const assembly = searchParams.get('assembly')

let promise;
let jname = form.jobName ? form.jobName : jobNamePlaceholder
if (props.inputType === InputType.SINGLE_VARIANT && props.query) {
promise = downloadResult(props.query, InputType[props.inputType], null, null,
assembly === Assembly.GRCh37 ? Assembly.GRCh37 : Assembly.GRCh38, // default is 38 (overriding auto)
form.email, form.jobName, form.fun, form.pop, form.str)
form.email, jname, form.fun, form.pop, form.str)
} else if ((props.inputType === InputType.ID || props.inputType === InputType.PROTEIN_ACCESSION)
&& props.id){
promise = downloadResult(props.id, InputType[props.inputType], page, pageSize, assembly,
form.email, form.jobName, form.fun, form.pop, form.str)
form.email, jname, form.fun, form.pop, form.str)
}

if (promise) {
Expand Down Expand Up @@ -274,6 +289,7 @@ function DownloadModal(props: DownloadModalProps) {
value={form.jobName}
name="jobName"
onChange={(e) => updateForm(e.target.name, e.target.value)}
placeholder={jobNamePlaceholder}
/>
</label>
</div>
Expand Down

0 comments on commit a3d335d

Please sign in to comment.