From 0ca85637bfb15c6ca9dbf6024cdbb2201060f1dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne=20L=27H=C3=B4te?= Date: Thu, 6 Jun 2024 17:02:47 +0200 Subject: [PATCH] fix(search): Restore feature to delete RoR affiliation --- client/src/pages/filters.jsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/client/src/pages/filters.jsx b/client/src/pages/filters.jsx index e3d73075..74d31e7f 100644 --- a/client/src/pages/filters.jsx +++ b/client/src/pages/filters.jsx @@ -106,7 +106,9 @@ export default function Filters({ useEffect(() => { const getData = async () => { setIsLoading(true); - const queries = searchedAffiliations.map((affiliation) => getRorData(affiliation, getRoRChildren)); + const filteredSearchedAffiliation = searchedAffiliations + .filter((affiliation) => !deletedAffiliations.includes(affiliation)); + const queries = filteredSearchedAffiliation.map((affiliation) => getRorData(affiliation, getRoRChildren)); let rorNames = await Promise.all(queries); rorNames = rorNames.filter( (rorName) => !deletedAffiliations.includes(rorName), @@ -115,7 +117,7 @@ export default function Filters({ const allTags = []; const knownTags = {}; - searchedAffiliations.forEach((affiliation) => { + filteredSearchedAffiliation.forEach((affiliation) => { const label = affiliation .replace('https://ror.org/', '') .replace('ror.org/', ''); @@ -176,18 +178,17 @@ export default function Filters({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [deletedAffiliations, getRoRChildren, searchedAffiliations]); - // eslint-disable-next-line no-shadow - const onTagsChange = async (affiliations, deletedAffiliations) => { + const onTagsChange = async (affiliations, _deletedAffiliations) => { const previousDeleted = currentSearchParams.deletedAffiliations || []; + const nextDeleted = [...new Set(_deletedAffiliations + .map((affiliation) => affiliation.label) + .concat(previousDeleted))]; setSearchParams({ ...currentSearchParams, affiliations: affiliations .filter((affiliation) => affiliation.source === 'user') .map((affiliation) => affiliation.label), - deletedAffiliations: deletedAffiliations - .filter((affiliation) => affiliation.source !== 'user') - .map((affiliation) => affiliation.label) - .concat(previousDeleted), + deletedAffiliations: nextDeleted, }); };