Skip to content

Commit

Permalink
[DUOS-2907, DUOS-2917][risk=no] Bug fix: Update use effect handler (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rushtong authored Feb 8, 2024
1 parent b767f84 commit a932086
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/pages/DatasetSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?
Expand Down

0 comments on commit a932086

Please sign in to comment.