diff --git a/src/components/data_search/DatasetExportButton.jsx b/src/components/data_search/DatasetExportButton.jsx index c39c25bd4..bf2453570 100644 --- a/src/components/data_search/DatasetExportButton.jsx +++ b/src/components/data_search/DatasetExportButton.jsx @@ -1,53 +1,22 @@ import * as React from 'react'; -import { CircularProgress, IconButton, Link } from '@mui/material'; -import { useState } from 'react'; -import IosShareIcon from '@mui/icons-material/IosShare'; -import { TerraDataRepo } from '../../libs/ajax/TerraDataRepo'; +import {useEffect, useState} from 'react'; +import {Link} from '@mui/material'; +import {Config} from '../../libs/config'; export const DatasetExportButton = (props) => { - const { snapshot, title } = props; - // The exportStatus flow is: initial -> prepping -> ready - // TODO: error handling? - const [exportStatus, setExportStatus] = useState('initial'); - const [exportResult, setExportResult] = useState(null); + const {snapshot, title} = props; - // Not a supported export location - if (!snapshot) { - return null; - } + const [terraUrl, setTerraUrl] = useState(''); - const prepExportHandler = async () => { - setExportStatus('prepping'); - const job = await TerraDataRepo.prepareExport(snapshot.id); - const result = await TerraDataRepo.waitForJob(job.id); - setExportResult(result); - setExportStatus('ready'); - }; + useEffect(() => { + (async () => { + setTerraUrl(await Config.getTerraUrl()); + })(); + }, []); - if (exportStatus === 'initial') { - return ( - - - - ); - } - - if (exportStatus === 'prepping') { - return ( - ({})} disabled> - , - - ); - } - - if (exportStatus === 'ready') { - return ( - Export - ); - } - - return null; + const link = `${terraUrl}/#import-data?snapshotId=${snapshot.id}&format=tdrexport&tdrSyncPermissions=false`; + return Export; }; export default DatasetExportButton; diff --git a/src/libs/ajax/TerraDataRepo.js b/src/libs/ajax/TerraDataRepo.js index ef27a0378..68466d304 100644 --- a/src/libs/ajax/TerraDataRepo.js +++ b/src/libs/ajax/TerraDataRepo.js @@ -1,6 +1,5 @@ import { Config } from '../config'; import axios from 'axios'; -import { sleep, reportError } from '../ajax'; export const TerraDataRepo = { @@ -10,31 +9,4 @@ export const TerraDataRepo = { const res = await axios.get(url, Config.authOpts()); return res.data; }, - - prepareExport: async (snapshotId) => { - const url = `${await Config.getTdrApiUrl()}/api/repository/v1/snapshots/${snapshotId}/export`; - const res = await axios.get(url, Config.authOpts()); - return res.data; - }, - - waitForJob: async (jobId) => { - const url = `${await Config.getTdrApiUrl()}/api/repository/v1/jobs/${jobId}`; - const resultsUrl = `${await Config.getTdrApiUrl()}/api/repository/v1/jobs/${jobId}/result`; - - // eslint-disable-next-line no-constant-condition - while (true) { - const res = await axios.get(url, Config.authOpts()); - if (res.data.job_status === 'running') { - await sleep(1000); - } else if (res.data.job_status === 'succeeded') { - const finalResult = await axios.get(resultsUrl, Config.authOpts()); - // Add the URL to link to - finalResult.data.terraImportLink = - `${await Config.getTerraUrl()}/#import-data?url=${window.location.origin}&snapshotId=${finalResult.data.snapshot.id}&format=tdrexport&snapshotName=${finalResult.data.snapshot.name}&tdrmanifest=${encodeURIComponent(finalResult.data.format.parquet.manifest)}&tdrSyncPermissions=false`; - return finalResult.data; - } else if (res.data.job_status === 'failed') { - return reportError(url, res.data.status_code); - } - } - }, };