Skip to content

Commit

Permalink
fix: loader keeps showing when opening export in new page
Browse files Browse the repository at this point in the history
we were assigning setting the state to an event in the new window. That reference doesn't work one outside the React app in the new window, so the loader never hides. Not sure if this pattern worked at some point, but even if it did, it was propbably disabled as a security issue
  • Loading branch information
kabaros committed Feb 23, 2024
1 parent 8de27e2 commit 021c83d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/pages/DataExport/form-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const onExport = (baseUrl, setExportEnabled) => async (values) => {
const filename = `${endpoint}.${fileExtension}`
const downloadUrlParams = valuesToParams(values, filename)
const url = `${apiBaseUrl}${endpoint}?${downloadUrlParams}`
locationAssign(url, setExportEnabled)
locationAssign(url)
setExportEnabled(true)

// log for debugging purposes
console.log('data-export:', { url, params: downloadUrlParams })
Expand Down
3 changes: 2 additions & 1 deletion src/pages/EventExport/form-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ const onExport = (baseUrl, setExportEnabled) => (values) => {
.filter((s) => s != '')
.join('&')
const url = `${apiBaseUrl}${endpoint}.${endpointExtension}?${downloadUrlParams}`
locationAssign(url, setExportEnabled)
locationAssign(url)
setExportEnabled(true)

// log for debugging purposes
console.log('event-export:', { url, params: downloadUrlParams })
Expand Down
3 changes: 2 additions & 1 deletion src/pages/MetadataDependencyExport/form-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const onExport = (baseUrl, setExportEnabled) => (values) => {
const endpointExtension = compression ? `${format}.${compression}` : format
const downloadUrlParams = `skipSharing=${skipSharing}&download=true`
const url = `${apiBaseUrl}${endpoint}.${endpointExtension}?${downloadUrlParams}`
locationAssign(url, setExportEnabled)
locationAssign(url)
setExportEnabled(true)

// log for debugging purposes
console.log('metadata-dependency-export:', {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/MetadataExport/form-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const onExport = (baseUrl, setExportEnabled) => (values) => {
const schemaParams = checkedSchemas.map((name) => `${name}=true`).join('&')
const downloadUrlParams = `skipSharing=${skipSharing}&download=true&${schemaParams}`
const url = `${apiBaseUrl}${endpoint}.${endpointExtension}?${downloadUrlParams}`
locationAssign(url, setExportEnabled)
locationAssign(url)
setExportEnabled(true)

// log for debugging purposes
console.log('metadata-export:', { url, params: downloadUrlParams })
Expand Down
3 changes: 2 additions & 1 deletion src/pages/TEIExport/form-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ const onExport = (baseUrl, setExportEnabled) => async (values) => {
const filename = `${endpoint}.${format}`
const downloadUrlParams = valuesToParams(values, filename)
const url = `${apiBaseUrl}${endpoint}.${format}?${downloadUrlParams}`
locationAssign(url, setExportEnabled)
locationAssign(url)
setExportEnabled(true)

// log for debugging purposes
console.log('tei-export:', { url, params: downloadUrlParams })
Expand Down
7 changes: 1 addition & 6 deletions src/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,14 @@ const downloadWindowHtml = `
`

// call stub function if available
const locationAssign = (url, setExportEnabled) => {
const locationAssign = (url) => {
if (window.locationAssign) {
window.locationAssign(url)
} else {
const downloadWindow = window.open(url, '_blank')

downloadWindow.document.title = downloadWindowTitle
downloadWindow.document.body.innerHTML = downloadWindowHtml // does not work in Chrome

const enableExport = () => setExportEnabled(true)
downloadWindow.onbeforeunload = enableExport
downloadWindow.onabort = enableExport
downloadWindow.onerror = enableExport
}
}

Expand Down

0 comments on commit 021c83d

Please sign in to comment.