Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

428 - Update startProcessingDataset to accept formatted data from caller Formik components #431

Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/api/interfaces/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const url = 'dataset/'
// 'details': https://github.com/AlexsLemonade/refinebio-frontend/pull/485

export default {
create: (params) => http.post(url, params),
create: (body) => http.post(url, body),
get: (id, headers) => http.get(`${url}${id}/`, { details: true }, headers),
update: (id, params) => http.put(`${url}${id}/?details=true`, params)
update: (id, body, headers) =>
http.put(`${url}${id}/?details=true`, body, headers)
}
16 changes: 3 additions & 13 deletions src/api/interfaces/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,7 @@ import http from 'helpers/http'
const url = 'token/'

export default {
create: () => {
return http.post(url)
},
get: (id) => {
const path = `${url}${id}`

return http.get(path)
},
update: (id, params) => {
const path = `${url}${id}`

return http.put(path, params || { is_activated: true })
}
create: (body) => http.post(url, body),
get: (id) => http.get(`${url}${id}/`),
update: (id, body) => http.put(`${url}${id}`, body)
}
20 changes: 12 additions & 8 deletions src/components/Compendia/DownloadBlockForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useRef, useState, memo } from 'react'
import { Box, Heading, Text } from 'grommet'
import styled, { css } from 'styled-components'
import { useCompendiaContext } from 'hooks/useCompendiaContext'
import { useRefinebio } from 'hooks/useRefinebio'
import { useResponsive } from 'hooks/useResponsive'
import { useToken } from 'hooks/useToken'
import formatBytes from 'helpers/formatBytes'
import formatString from 'helpers/formatString'
import fuzzyFilterOnKey from 'helpers/fuzzyFilterOnKey'
Expand Down Expand Up @@ -55,9 +55,8 @@ const DropdownOption = ({ label, selected, onClick }) => (

export const DownloadBlockForm = () => {
const { setResponsive } = useResponsive()
const { validateToken } = useToken()
const hasToken = validateToken()
const [acceptTerms, setAcceptTerms] = useState(hasToken)
const { acceptedTerms, setAcceptedTerms } = useRefinebio()
const [isTermsChecked, setIsTermsChecked] = useState(acceptedTerms)
const { compendia, type, goToDownloadCompendium } = useCompendiaContext()
const [compendium, setCompendium] = useState(null)
const [showOptions, setShowOptions] = useState(false)
Expand All @@ -82,6 +81,11 @@ export const DownloadBlockForm = () => {
}
}

const handleDownloadNow = () => {
setAcceptedTerms(isTermsChecked)
goToDownloadCompendium(compendium)
}

return (
<Box background="white" pad={setResponsive('medium', 'large', 'xlarge')}>
<Heading
Expand Down Expand Up @@ -176,7 +180,7 @@ export const DownloadBlockForm = () => {
/>
</Box>
)}
{!hasToken && (
{!acceptedTerms && (
<Box margin={{ vertical: 'small' }}>
<CheckBox
label={
Expand All @@ -185,7 +189,7 @@ export const DownloadBlockForm = () => {
<Anchor href={links.terms_of_use}>Terms of Use</Anchor>
</Text>
}
onClick={() => setAcceptTerms(!acceptTerms)}
onClick={() => setIsTermsChecked(!isTermsChecked)}
/>
</Box>
)}
Expand All @@ -203,10 +207,10 @@ export const DownloadBlockForm = () => {
<Column align={setResponsive('start', 'end')}>
<Button
label="Download Now"
disabled={!acceptTerms || !compendium}
disabled={!isTermsChecked || !compendium}
primary
responsive
onClick={() => goToDownloadCompendium(compendium)}
onClick={handleDownloadNow}
/>
</Column>
</Row>
Expand Down
5 changes: 4 additions & 1 deletion src/components/Dataset/DatasetPageHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import getDatasetState from 'helpers/getDatasetState'
import { FixedContainer } from 'components/shared/FixedContainer'
import { DatasetNotProcessed } from './DatasetNotProcessed'
import { DatasetProcessingError } from './DatasetProcessingError'
import { DatasetReady } from './DatasetReady'
import { DatasetRegenerate } from './DatasetRegenerate'

const DatasetProcessing = dynamic(() => import('./DatasetProcessing'), {
ssr: false
})

const DatasetReady = dynamic(() => import('./DatasetReady'), {
ssr: false
})

export const DatasetPageHeader = ({ dataset }) => {
const { setResponsive } = useResponsive()
const { polledDatasetState } = usePollDatasetStatus(dataset.id)
Expand Down
31 changes: 13 additions & 18 deletions src/components/Dataset/DatasetReady.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useEffect, useState } from 'react'
import { useState } from 'react'
import { Box, Heading, Text } from 'grommet'
import gtag from 'analytics/gtag'
import { useDatasetManager } from 'hooks/useDatasetManager'
import { useRefinebio } from 'hooks/useRefinebio'
import { useResponsive } from 'hooks/useResponsive'
import { useToken } from 'hooks/useToken'
import formatBytes from 'helpers/formatBytes'
import { Anchor } from 'components/shared/Anchor'
import { Button } from 'components/shared/Button'
Expand All @@ -14,26 +14,21 @@ import { links } from 'config'
import { DatasetExplore } from './DatasetExplore'

export const DatasetReady = ({ dataset }) => {
const { downloadDataset } = useDatasetManager()
const { setResponsive } = useResponsive()
const { validateToken } = useToken()
const [acceptedTerms, setAcceptedTerms] = useState(false)
const { downloadDataset } = useDatasetManager()
const { acceptedTerms, setAcceptedTerms } = useRefinebio()
const [isTermsChecked, setIsTermsChecked] = useState(acceptedTerms)

const handleDownloadNow = async () => {
await downloadDataset(dataset.id, dataset.download_url)
gtag.trackDatasetDownload(dataset)
const handleDownloadNow = () => {
setAcceptedTerms(isTermsChecked)
submit()
}

const getTokenStatus = async () => {
const isActivated = await validateToken()
setAcceptedTerms(isActivated)
const submit = async () => {
await downloadDataset(dataset.id, dataset.download_url)
gtag.trackDatasetDownload(dataset)
}

// sets acceptedTerms based on the token validity
useEffect(() => {
getTokenStatus()
}, [])

return (
<>
<Box align="center">
Expand Down Expand Up @@ -72,7 +67,7 @@ export const DatasetReady = ({ dataset }) => {
/>
</Text>
}
onClick={() => setAcceptedTerms(!acceptedTerms)}
onClick={() => setIsTermsChecked(!isTermsChecked)}
/>
</Column>
)}
Expand All @@ -87,7 +82,7 @@ export const DatasetReady = ({ dataset }) => {
>
<Button
label="Download Now"
disabled={!acceptedTerms}
disabled={!isTermsChecked}
primary
responsive
onClick={handleDownloadNow}
Expand Down
89 changes: 58 additions & 31 deletions src/components/Download/DownloadDatasetModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Box, Form, Heading, Paragraph } from 'grommet'
import gtag from 'analytics/gtag'
import { validationSchemas } from 'config'
import { useDatasetManager } from 'hooks/useDatasetManager'
import { useRefinebio } from 'hooks/useRefinebio'
import { useResponsive } from 'hooks/useResponsive'
import subscribeEmail from 'helpers/subscribeEmail'
import { Button } from 'components/shared/Button'
Expand All @@ -16,10 +17,45 @@ import { TermsOfUseCheckBox } from 'components/Download/StartProcessingForm/Term

export const DownloadDatasetModal = ({ dataset, id, closeModal }) => {
const { push } = useRouter()
const { email, startProcessingDataset } = useDatasetManager()
const { setResponsive } = useResponsive()
const { email, startProcessingDataset } = useDatasetManager()
const { acceptedTerms, setAcceptedTerms } = useRefinebio()
const { StartProcessingFormSchema } = validationSchemas

const handleStartProcessing = (formValues) => {
setAcceptedTerms(formValues.terms)
submit(formValues)
}

const submit = async (formValues) => {
if (formValues.email_ccdl_ok) {
const subscribeEmailResponse = await subscribeEmail(
formValues.email_address
)
if (subscribeEmailResponse.status !== 'error') {
gtag.trackEmailSubscription(DownloadDatasetModal)
}
}

const downloadOptions = {
aggregate_by: formValues.aggregate_by,
data: dataset.data,
scale_by: formValues.scale_by,
quantile_normalize: formValues.quantile_normalize,
email_address: formValues.email_address,
email_ccdl_ok: formValues.email_ccdl_ok
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const downloadOptions = {
aggregate_by: formValues.aggregate_by,
data: dataset.data,
scale_by: formValues.scale_by,
quantile_normalize: formValues.quantile_normalize,
email_address: formValues.email_address,
email_ccdl_ok: formValues.email_ccdl_ok
}
const downloadOptions = {
data: dataset.data,
...formValues
}


const response = await startProcessingDataset(
downloadOptions,
dataset.id,
null // no accession code
)
const pathname = `/dataset/${response.id}`
push({ pathname }, pathname)
closeModal(id)
}

return (
<Box
margin={{ bottom: 'medium' }}
Expand All @@ -32,29 +68,16 @@ export const DownloadDatasetModal = ({ dataset, id, closeModal }) => {
<Formik
initialValues={{
aggregate_by: dataset.aggregate_by,
data: dataset.data,
scale_by: dataset.scale_by,
quantile_normalize: dataset.quantile_normalize,
emailAddress: email || '',
receiveUpdates: true,
termsOfUse: false
email_address: email || '',
email_ccdl_ok: true,
terms: acceptedTerms
}}
validationSchema={StartProcessingFormSchema}
validateOnChange={false}
onSubmit={async (values, { setSubmitting }) => {
const { emailAddress, receiveUpdates } = values

if (receiveUpdates) {
const subscribeEmailResponse = await subscribeEmail(emailAddress)
if (subscribeEmailResponse.status !== 'error') {
gtag.trackEmailSubscription(DownloadDatasetModal)
}
}

const response = await startProcessingDataset(values, dataset.id)
const pathname = `/dataset/${response.id}`
push({ pathname }, pathname)
closeModal(id)
handleStartProcessing(values)
setSubmitting(false)
}}
>
Expand Down Expand Up @@ -99,21 +122,25 @@ export const DownloadDatasetModal = ({ dataset, id, closeModal }) => {
</Paragraph>
<Box pad={{ top: 'small' }}>
<EmailTextInput
error={errors.emailAddress}
touched={touched.emailAddress}
value={values.emailAddress}
handleChange={handleChange}
/>
<TermsOfUseCheckBox
error={errors.termsOfUse}
touched={touched.termsOfUse}
value={values.termsOfUse}
handleChange={handleChange}
/>
<ReceiveUpdatesCheckBox
value={values.receiveUpdates}
error={errors.email_address}
touched={touched.email_address}
value={values.email_address}
handleChange={handleChange}
/>
<Box pad={{ top: 'small' }}>
{!acceptedTerms && (
<TermsOfUseCheckBox
error={errors.terms}
touched={touched.terms}
value={values.terms}
handleChange={handleChange}
/>
)}
<ReceiveUpdatesCheckBox
value={values.email_ccdl_ok}
handleChange={handleChange}
/>
</Box>
</Box>
</Box>
<Box align="end">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const EmailTextInput = ({ error, touched, value, handleChange }) => {
<TextInput
error={error && touched}
errorText={error}
name="emailAddress"
name="email_address"
type="email"
value={value}
placeholder="[email protected]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const ReceiveUpdatesCheckBox = ({ value, handleChange }) => {
<CheckBox
checked={value}
label="I would like to receive occasional updates from the refine.bio team"
name="receiveUpdates"
name="email_ccdl_ok"
onChange={handleChange}
/>
)
Expand Down
40 changes: 19 additions & 21 deletions src/components/Download/StartProcessingForm/TermsOfUseCheckBox.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
import { Box, Text } from 'grommet'
import { Text } from 'grommet'
import { links } from 'config'
import { Anchor } from 'components/shared/Anchor'
import { CheckBox } from 'components/shared/CheckBox'

export const TermsOfUseCheckBox = ({ error, touched, value, handleChange }) => {
return (
<Box margin={{ top: 'small' }}>
<CheckBox
checked={value}
error={error && touched}
errorText={error}
label={
<Text>
I agree to the{' '}
<Anchor
href={links.terms_of_use}
label="Terms of Use"
rel="noopener noreferrer"
target="_blank"
/>
</Text>
}
name="termsOfUse"
onChange={handleChange}
/>
</Box>
<CheckBox
checked={value}
error={error && touched}
errorText={error}
label={
<Text>
I agree to the{' '}
<Anchor
href={links.terms_of_use}
label="Terms of Use"
rel="noopener noreferrer"
target="_blank"
/>
</Text>
}
name="terms"
onChange={handleChange}
/>
)
}

Expand Down
Loading