Skip to content

Commit

Permalink
fix(openalex): Fix search by ror id
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Nov 25, 2024
1 parent 75d0b5a commit fb96d39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
41 changes: 15 additions & 26 deletions client/src/pages/openalex-ror/results/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export default function Affiliations() {
const [rorMessage, setRorMessage] = useState('');
const [rorMessageType, setRorMessageType] = useState('');
const [selectedOpenAlex, setSelectedOpenAlex] = useState([]);
const [timer, setTimer] = useState();
const [uniqueRors, setUniqueRors] = useState({});

const { data, error, isFetched, isFetching, refetch } = useQuery({
Expand Down Expand Up @@ -214,31 +213,21 @@ export default function Affiliations() {
}, [data]);

useEffect(() => {
if (timer) {
clearTimeout(timer);
const regex = new RegExp(removeDiacritics(filteredAffiliationName));
const filteredAffiliationsTmp = affiliations.filter(
(affiliation) => regex.test(
`${affiliation.key.replace('[ source: ', '').replace(' ]', '')} ${affiliation.rors.map((_ror) => _ror.rorId).join(' ')}`,
),
);
// Recompute corrections only when the array has changed
if (filteredAffiliationsTmp.length !== filteredAffiliations.length) {
setAllOpenalexCorrections([
...allOpenalexCorrections,
...getAffiliationsCorrections(filteredAffiliationsTmp),
]);
}
const timerTmp = setTimeout(() => {
const filteredAffiliationsTmp = affiliations.filter(
(affiliation) => {
const regex = new RegExp(removeDiacritics(filteredAffiliationName));
return regex.test(
affiliation.key.replace('[ source: ', '').replace(' ]', ''),
);
},
);
// Recompute corrections only when the array has changed
if (filteredAffiliationsTmp.length !== filteredAffiliations.length) {
setAllOpenalexCorrections([
...allOpenalexCorrections,
...getAffiliationsCorrections(filteredAffiliationsTmp),
]);
}
setFilteredAffiliations(filteredAffiliationsTmp);
}, 500);
setTimer(timerTmp);
// The timer should not be tracked
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [affiliations, filteredAffiliationName, filteredStatus]);
setFilteredAffiliations(filteredAffiliationsTmp);
}, [affiliations, allOpenalexCorrections, filteredAffiliationName, filteredAffiliations.length, filteredStatus]);

useEffect(() => {
if (ror === '') {
Expand Down Expand Up @@ -557,9 +546,9 @@ export default function Affiliations() {
<div
className="wm-external-actions"
style={{
alignItems: 'center',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<div className="left-content">
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/openalex-ror/results/views-selector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { isRor } from '../../../utils/ror';
import DataTableView from './datatable-view';
import ListView from './list-view';

export default function OpenalexView({
export default function ViewsSelector({
allAffiliations,
allOpenalexCorrections,
filteredAffiliationName,
Expand Down Expand Up @@ -292,7 +292,7 @@ export default function OpenalexView({
);
}

OpenalexView.propTypes = {
ViewsSelector.propTypes = {
allAffiliations: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string.isRequired,
Expand Down

0 comments on commit fb96d39

Please sign in to comment.