From a9320867f5397209928ff8d002ba0809c303fec8 Mon Sep 17 00:00:00 2001 From: Gregory Rushton Date: Thu, 8 Feb 2024 14:01:24 -0500 Subject: [PATCH] [DUOS-2907, DUOS-2917][risk=no] Bug fix: Update use effect handler (#2457) --- src/pages/DatasetSearch.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/pages/DatasetSearch.js b/src/pages/DatasetSearch.js index 29b42cbe8..9550910a5 100644 --- a/src/pages/DatasetSearch.js +++ b/src/pages/DatasetSearch.js @@ -194,25 +194,29 @@ export const DatasetSearch = (props) => { const version = versions[key] === undefined ? versions['/custom'] : versions[key]; const isInstitutionQuery = key === 'myinstitution'; + const fullQuery = assembleFullQuery(isSigningOfficial, isInstitutionQuery, version.query); + const isInstitutionSet = institutionId === undefined && isInstitutionQuery; + useEffect(() => { const init = async () => { - if (institutionId === undefined && isInstitutionQuery) { - Notifications.showError({ text: 'You must set an institution in your profile to view the `myinstitution` data library' }); - props.history.push('/profile'); - return; - } - try { - const query = assembleFullQuery(isSigningOfficial, isInstitutionQuery, version.query); - await DataSet.searchDatasetIndex(query).then((datasets) => { - setDatasets(datasets); - setLoading(false); - }); - } catch (error) { - Notifications.showError({ text: 'Failed to load Elasticsearch index' }); + if (loading) { + if (isInstitutionSet) { + Notifications.showError({ text: 'You must set an institution in your profile to view the `myinstitution` data library' }); + props.history.push('/profile'); + return; + } + try { + await DataSet.searchDatasetIndex(fullQuery).then((datasets) => { + setDatasets(datasets); + setLoading(false); + }); + } catch (error) { + Notifications.showError({ text: 'Failed to load Elasticsearch index' }); + } } }; init(); - }, [institutionId, isInstitutionQuery, isSigningOfficial, props.history, version.query]); + }, [loading, isInstitutionSet, fullQuery, props.history]); return ( loading ?