From 021c83d726b3e3660b59f8bbe2a7c5365488aeed Mon Sep 17 00:00:00 2001 From: Mozafar Haider Date: Fri, 23 Feb 2024 09:58:21 +0000 Subject: [PATCH] fix: loader keeps showing when opening export in new page 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 --- src/pages/DataExport/form-helper.js | 3 ++- src/pages/EventExport/form-helper.js | 3 ++- src/pages/MetadataDependencyExport/form-helper.js | 3 ++- src/pages/MetadataExport/form-helper.js | 3 ++- src/pages/TEIExport/form-helper.js | 3 ++- src/utils/helper.js | 7 +------ 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/pages/DataExport/form-helper.js b/src/pages/DataExport/form-helper.js index 03c350735..216b7793d 100644 --- a/src/pages/DataExport/form-helper.js +++ b/src/pages/DataExport/form-helper.js @@ -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 }) diff --git a/src/pages/EventExport/form-helper.js b/src/pages/EventExport/form-helper.js index bdecb8ff4..9bdacba82 100644 --- a/src/pages/EventExport/form-helper.js +++ b/src/pages/EventExport/form-helper.js @@ -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 }) diff --git a/src/pages/MetadataDependencyExport/form-helper.js b/src/pages/MetadataDependencyExport/form-helper.js index ee5e77dca..ca7dc2526 100644 --- a/src/pages/MetadataDependencyExport/form-helper.js +++ b/src/pages/MetadataDependencyExport/form-helper.js @@ -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:', { diff --git a/src/pages/MetadataExport/form-helper.js b/src/pages/MetadataExport/form-helper.js index 879f3889a..63a1cbe0b 100644 --- a/src/pages/MetadataExport/form-helper.js +++ b/src/pages/MetadataExport/form-helper.js @@ -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 }) diff --git a/src/pages/TEIExport/form-helper.js b/src/pages/TEIExport/form-helper.js index 5f19cb647..bebe7f652 100644 --- a/src/pages/TEIExport/form-helper.js +++ b/src/pages/TEIExport/form-helper.js @@ -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 }) diff --git a/src/utils/helper.js b/src/utils/helper.js index 5db84c3f2..ff6078504 100644 --- a/src/utils/helper.js +++ b/src/utils/helper.js @@ -193,7 +193,7 @@ const downloadWindowHtml = ` ` // call stub function if available -const locationAssign = (url, setExportEnabled) => { +const locationAssign = (url) => { if (window.locationAssign) { window.locationAssign(url) } else { @@ -201,11 +201,6 @@ const locationAssign = (url, setExportEnabled) => { 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 } }