Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DUOS-2907, DUOS-2917][risk=no] Bug fix: Update use effect handler #2457

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/pages/DatasetSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const DatasetSearch = (props) => {
const { match: { params: { query } } } = props;
const [datasets, setDatasets] = useState([]);
const [loading, setLoading] = useState(true);
const [loaded, setLoaded] = useState(false);
const user = Storage.getCurrentUser();

const isSigningOfficial = user.isSigningOfficial;
Expand Down Expand Up @@ -194,26 +195,30 @@ 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 institutionSet = 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 (!loaded) {
if (institutionSet) {
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' });
}
setLoaded(true);
}
};
init();
}, [institutionId, isInstitutionQuery, isSigningOfficial, props.history, version.query]);

}, [loaded, institutionSet, fullQuery, props.history]);
fboulnois marked this conversation as resolved.
Show resolved Hide resolved
return (
loading ?
<Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '50vh' }}>
Expand Down
Loading