From 46b2192d5ef166a95183afba92fd66dd7505282c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne=20L=27H=C3=B4te?= Date: Sun, 24 Sep 2023 12:11:17 +0200 Subject: [PATCH] feat(affiliations): Add RoR column --- client/src/pages/home/index.jsx | 28 ++++++++++---------- client/src/pages/home/views/affiliations.jsx | 1 + client/src/utils/templates.jsx | 21 +++++---------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/client/src/pages/home/index.jsx b/client/src/pages/home/index.jsx index 263970e8..a0b30771 100644 --- a/client/src/pages/home/index.jsx +++ b/client/src/pages/home/index.jsx @@ -15,8 +15,8 @@ import Gauge from '../../components/gauge'; import { PageSpinner } from '../../components/spinner'; import { getAllIdsHtmlField, + getAffiliationRor, getAffiliationsHtmlField, - getAffiliationName, getAuthorsHtmlField, getAuthorsTooltipField, } from '../../utils/templates'; @@ -138,31 +138,31 @@ export default function Home() { const groupByAffiliations = (works) => { setIsLoading(true); + // Save already decided affiliations + const decidedAffiliations = Object.values(allAffiliations).filter((affiliation) => affiliation.status !== TO_BE_DECIDED_STATUS); + // Compute distinct affiliations of the undecided works let allAffiliationsTmp = {}; - - // save already tagged affiliations - const taggedAffiliations = Object.values(allAffiliations).filter((affiliation) => affiliation.status !== TO_BE_DECIDED_STATUS); - works.filter((work) => work.status === TO_BE_DECIDED_STATUS).forEach((work) => { (work?.affiliations ?? []) .filter((affiliation) => Object.keys(affiliation).length) .forEach((affiliation) => { - const name = getAffiliationName(affiliation); - const affiliationName = normalizedName(name); - if (!allAffiliationsTmp?.[affiliationName]) { - allAffiliationsTmp[affiliationName] = { - matches: [...new Set(name.match(regexp))].length, - name, - nameHtml: name.replace(regexp, '$&'), + const ror = getAffiliationRor(affiliation); + const normalizedAffiliationName = normalizedName(affiliation.name); + if (!allAffiliationsTmp?.[normalizedAffiliationName]) { + allAffiliationsTmp[normalizedAffiliationName] = { + matches: [...new Set(affiliation.name.match(regexp))].length, + name: affiliation.name, + nameHtml: affiliation.name.replace(regexp, '$&'), + ror, status: TO_BE_DECIDED_STATUS, works: [], }; } - allAffiliationsTmp[affiliationName].works.push(work.id); + allAffiliationsTmp[normalizedAffiliationName].works.push(work.id); }); }); - taggedAffiliations.forEach((affiliation) => { + decidedAffiliations.forEach((affiliation) => { const affiliationName = normalizedName(affiliation.name); if (!allAffiliationsTmp?.[affiliationName]) { diff --git a/client/src/pages/home/views/affiliations.jsx b/client/src/pages/home/views/affiliations.jsx index fd44dd2f..5ef51376 100644 --- a/client/src/pages/home/views/affiliations.jsx +++ b/client/src/pages/home/views/affiliations.jsx @@ -39,6 +39,7 @@ export default function AffiliationsView({ + diff --git a/client/src/utils/templates.jsx b/client/src/utils/templates.jsx index 7a8493c2..7e073828 100644 --- a/client/src/utils/templates.jsx +++ b/client/src/utils/templates.jsx @@ -19,24 +19,17 @@ const authorsTemplate = (rowData) => ( ); -const getAffiliationName = (affiliation) => { - let affiliationName = affiliation.name; - if (affiliation?.ror) { - let ror = ''; - if (Array.isArray(affiliation.ror)) { - ror = affiliation.ror.map((_ror) => _ror.replace('https://ror.org/', '')).join(' '); - } else { - ror = affiliation.ror.replace('https://ror.org/', ''); - } - affiliationName += ` ${ror}`; - } - return affiliationName; +const getAffiliationRor = (affiliation) => { + if (!affiliation?.ror) return undefined; + if (Array.isArray(affiliation.ror)) return affiliation.ror.map((ror) => (ror.startsWith('https') ? ror : `https://ror.org/${ror}`)).join(' '); + if (!affiliation.ror.startsWith('https')) return `https://ror.org/${affiliation.ror}`; + return affiliation.ror; }; const getAffiliationsHtmlField = (rowData, regexp) => { let affiliations = (rowData?.affiliations ?? []) .filter((affiliation) => Object.keys(affiliation).length) - .map((affiliation) => getAffiliationName(affiliation).replace(regexp, '$&')) + .map((affiliation) => affiliation.name.replace(regexp, '$&')) .filter((affiliation) => affiliation.length) .flat(); affiliations = [...new Set(affiliations)]; @@ -136,8 +129,8 @@ export { affiliationsTemplate, allIdsTemplate, authorsTemplate, + getAffiliationRor, getAffiliationsHtmlField, - getAffiliationName, getAllIdsHtmlField, getAuthorsHtmlField, getAuthorsTooltipField,