From 05508b5adf8cb517f31c3d2a11c43b715fabb3d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne=20L=27H=C3=B4te?= Date: Thu, 9 Nov 2023 14:12:00 +0100 Subject: [PATCH] fix(ui): Validate datasets via affiliations --- client/src/pages/home/actions.jsx | 4 ++-- client/src/pages/home/index.jsx | 23 +++++++++++--------- client/src/pages/home/views/affiliations.jsx | 14 ++++++------ client/src/utils/works.js | 6 ++--- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/client/src/pages/home/actions.jsx b/client/src/pages/home/actions.jsx index 62edfc78..7bcb8149 100644 --- a/client/src/pages/home/actions.jsx +++ b/client/src/pages/home/actions.jsx @@ -110,8 +110,8 @@ Actions.propTypes = { name: PropTypes.string.isRequired, nameHtml: PropTypes.string.isRequired, status: PropTypes.string.isRequired, - publications: PropTypes.arrayOf(PropTypes.string).isRequired, - publicationsNumber: PropTypes.number.isRequired, + works: PropTypes.arrayOf(PropTypes.string).isRequired, + worksNumber: PropTypes.number.isRequired, })).isRequired, allPublications: PropTypes.arrayOf(PropTypes.shape({ affiliations: PropTypes.arrayOf(PropTypes.object).isRequired, diff --git a/client/src/pages/home/index.jsx b/client/src/pages/home/index.jsx index 829f85ae..0fffe5a2 100644 --- a/client/src/pages/home/index.jsx +++ b/client/src/pages/home/index.jsx @@ -114,14 +114,14 @@ export default function Home() { .normalize('NFD') .replace(/[^a-zA-Z0-9]/g, ''); - const groupByAffiliations = (publications) => { + const groupByAffiliations = () => { setIsLoading(true); // Save already decided affiliations const decidedAffiliations = Object.values(allAffiliations).filter((affiliation) => affiliation.status !== status.tobedecided.id); // Compute distinct affiliations of the undecided works let allAffiliationsTmp = {}; - publications.filter((publication) => publication.status === status.tobedecided.id).forEach((publication) => { - (publication?.affiliations ?? []) + [...allDatasets, ...allPublications].filter((work) => work.status === status.tobedecided.id).forEach((work) => { + (work?.affiliations ?? []) .filter((affiliation) => Object.keys(affiliation).length && affiliation?.name) .forEach((affiliation) => { const ror = getAffiliationRor(affiliation); @@ -131,7 +131,7 @@ export default function Home() { let matches = `${affiliation?.name}`?.match(regexp) ?? []; // Normalize matched strings matches = matches.map((name) => normalizedName(name)); - // Filter matches as uniq + // Filter matches as unique matches = [...new Set(matches)]; allAffiliationsTmp[normalizedAffiliationName] = { matches: matches.length, @@ -140,10 +140,10 @@ export default function Home() { ror, rorHtml: ror?.replace(regexp, '$&'), status: status.tobedecided.id, - publications: [], + works: [], }; } - allAffiliationsTmp[normalizedAffiliationName].publications.push(publication.id); + allAffiliationsTmp[normalizedAffiliationName].works.push(work.id); }); }); @@ -157,7 +157,7 @@ export default function Home() { }); allAffiliationsTmp = Object.values(allAffiliationsTmp) - .map((affiliation, index) => ({ ...affiliation, publications: [...new Set(affiliation.publications)], id: index.toString(), publicationsNumber: [...new Set(affiliation.publications)].length })); + .map((affiliation, index) => ({ ...affiliation, works: [...new Set(affiliation.works)], id: index.toString(), worksNumber: [...new Set(affiliation.works)].length })); setAllAffiliations(allAffiliationsTmp); setIsLoading(false); }; @@ -221,7 +221,7 @@ export default function Home() { }, [allPublications, filteredDatasources, filteredFosmIdentifiers, filteredTypes, filteredYears]); useEffect(() => { - groupByAffiliations(allPublications, regexp); + groupByAffiliations(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [allPublications, regexp]); @@ -243,10 +243,13 @@ export default function Home() { const tagAffiliations = (affiliations, action) => { if (action !== status.excluded.id) { + const worksIds = affiliations.map((affiliation) => affiliation.works).flat(); const allPublicationsTmp = [...allPublications]; - const publicationsIds = affiliations.map((affiliation) => affiliation.publications).flat(); - allPublicationsTmp.filter((publication) => publicationsIds.includes(publication.id)).map((publication) => publication.status = action); + allPublicationsTmp.filter((publication) => worksIds.includes(publication.id)).map((publication) => publication.status = action); setAllPublications(allPublicationsTmp); + const allDatasetsTmp = [...allDatasets]; + allDatasetsTmp.filter((dataset) => worksIds.includes(dataset.id)).map((dataset) => dataset.status = action); + setAllDatasets(allDatasetsTmp); } const allAffiliationsTmp = [...allAffiliations]; const affiliationIds = affiliations.map((affiliation) => affiliation.id); diff --git a/client/src/pages/home/views/affiliations.jsx b/client/src/pages/home/views/affiliations.jsx index 2ec26acd..1bce21e8 100644 --- a/client/src/pages/home/views/affiliations.jsx +++ b/client/src/pages/home/views/affiliations.jsx @@ -29,7 +29,7 @@ export default function AffiliationsView({ selection={selectedAffiliations} selectionPageOnly size="small" - sortField="publicationsNumber" + sortField="worksNumber" sortOrder={-1} stripedRows style={{ fontSize: '11px', lineHeight: '10px' }} @@ -39,8 +39,8 @@ export default function AffiliationsView({ - - + + ); } @@ -51,18 +51,18 @@ AffiliationsView.propTypes = { matches: PropTypes.number.isRequired, name: PropTypes.string.isRequired, nameHtml: PropTypes.string.isRequired, - publications: PropTypes.arrayOf(PropTypes.string).isRequired, - publicationsNumber: PropTypes.number.isRequired, status: PropTypes.string.isRequired, + works: PropTypes.arrayOf(PropTypes.string).isRequired, + worksNumber: PropTypes.number.isRequired, })).isRequired, selectedAffiliations: PropTypes.arrayOf(PropTypes.shape({ id: PropTypes.string.isRequired, matches: PropTypes.number.isRequired, name: PropTypes.string.isRequired, nameHtml: PropTypes.string.isRequired, - publications: PropTypes.arrayOf(PropTypes.string).isRequired, - publicationsNumber: PropTypes.number.isRequired, status: PropTypes.string.isRequired, + works: PropTypes.arrayOf(PropTypes.string).isRequired, + worksNumber: PropTypes.number.isRequired, })).isRequired, setSelectedAffiliations: PropTypes.func.isRequired, }; diff --git a/client/src/utils/works.js b/client/src/utils/works.js index 5a3dca78..27390915 100644 --- a/client/src/utils/works.js +++ b/client/src/utils/works.js @@ -82,7 +82,7 @@ const getBsoWorks = async ({ allResults = [], index = VITE_BSO_PUBLICATIONS_INDE // eslint-disable-next-line no-param-reassign allResults = allResults.concat(hits.map((result) => ({ ...result._source, - // Filter ids on uniq values + // Filter ids on unique values allIds: Object.values((result?._source?.external_ids ?? []).reduce((acc, obj) => ({ ...acc, [obj.id_value]: obj }), {})), authors: result._source?.authors ?? [], datasource: 'bso', @@ -248,9 +248,9 @@ const mergePublications = (publi1, publi2) => { return ({ ...priorityPublication, affiliations: [...publi1.affiliations, ...publi2.affiliations], - // Filter allIds by uniq values + // Filter allIds by unique values allIds: Object.values([...publi1.allIds, ...publi2.allIds].reduce((acc, obj) => ({ ...acc, [obj.id_value]: obj }), {})), - // Filter authors by uniq full_name + // Filter authors by unique full_name authors: Object.values([...publi1.authors, ...publi2.authors].reduce((acc, obj) => ({ ...acc, [obj.full_name]: obj }), {})), datasource: 'bso, openalex', });