From 16772d11fb8e1ac8a55ce766959d833d966247bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne=20L=27H=C3=B4te?= Date: Tue, 28 Nov 2023 13:20:06 +0100 Subject: [PATCH] fix a few stuff --- client/src/pages/index.jsx | 1 + server/src/routes/works.routes.js | 4 ++-- server/src/utils/utils.js | 4 ++-- server/src/utils/works.js | 19 ++++++++++++++----- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/client/src/pages/index.jsx b/client/src/pages/index.jsx index 29a35217..57def566 100644 --- a/client/src/pages/index.jsx +++ b/client/src/pages/index.jsx @@ -122,6 +122,7 @@ export default function Home() { const affiliationIds = affiliations.map((affiliation) => affiliation.id); allAffiliationsTmp.filter((affiliation) => affiliationIds.includes(affiliation.id)).map((affiliation) => affiliation.status = action); setAllAffiliations(allAffiliationsTmp); + // setSelectedAffiliations([]); }; return ( diff --git a/server/src/routes/works.routes.js b/server/src/routes/works.routes.js index b935ee5a..22b64a2b 100644 --- a/server/src/routes/works.routes.js +++ b/server/src/routes/works.routes.js @@ -41,12 +41,12 @@ router.route('/works') const datasets = []; deduplicatedWorks.forEach((deduplicatedWork) => { if ( - (deduplicatedWork.datasource.includes('fosm') && deduplicatedWork.genre_raw !== 'dataset') + (deduplicatedWork.datasource.includes('fosm') && deduplicatedWork.type !== 'dataset') || (deduplicatedWork.datasource.includes('openalex') && deduplicatedWork.type !== 'dataset') ) { publications.push(deduplicatedWork); } else if ( - (deduplicatedWork.datasource.includes('fosm') && deduplicatedWork.genre_raw === 'dataset') + (deduplicatedWork.datasource.includes('fosm') && deduplicatedWork.type === 'dataset') || (deduplicatedWork.datasource.includes('openalex') && deduplicatedWork.type === 'dataset') ) { datasets.push(deduplicatedWork); diff --git a/server/src/utils/utils.js b/server/src/utils/utils.js index f7827e95..e2671d4e 100644 --- a/server/src/utils/utils.js +++ b/server/src/utils/utils.js @@ -32,7 +32,7 @@ const getRegexpFromOptions = (options) => { return regex; }; -const normalizedName = (name) => name +const normalizeName = (name) => name .toLowerCase() .normalize('NFD') .replace(/[^a-zA-Z0-9]/g, ' ') @@ -42,6 +42,6 @@ const normalizedName = (name) => name export { cleanId, getRegexpFromOptions, - normalizedName, + normalizeName, range, }; diff --git a/server/src/utils/works.js b/server/src/utils/works.js index d22031fd..314884ed 100644 --- a/server/src/utils/works.js +++ b/server/src/utils/works.js @@ -1,4 +1,4 @@ -import { cleanId, getRegexpFromOptions, normalizedName, range } from './utils'; +import { cleanId, getRegexpFromOptions, normalizeName, range } from './utils'; const VITE_OPENALEX_MAX_PAGE = Math.floor(process.env.VITE_OPENALEX_SIZE / process.env.VITE_OPENALEX_PER_PAGE); @@ -157,6 +157,8 @@ const getTypeFromOpenAlex = (type) => { case 'posted-content': newType = 'preprint'; break; + default: + newType = type; } return newType; }; @@ -217,12 +219,12 @@ const groupByAffiliations = ({ options, works }) => { works.forEach((work) => { (work?.affiliations ?? []) .forEach((affiliation) => { - const normalizedAffiliationName = normalizedName(affiliation); + const normalizedAffiliationName = normalizeName(affiliation); if (!allAffiliationsTmp?.[normalizedAffiliationName]) { // Check matches in affiliation name let matches = affiliation?.match(regexp) ?? []; // Normalize matched strings - matches = matches.map((match) => normalizedName(match)); + matches = matches.map((match) => normalizeName(match)); // Filter matches as unique matches = [...new Set(matches)]; allAffiliationsTmp[normalizedAffiliationName] = { @@ -235,9 +237,16 @@ const groupByAffiliations = ({ options, works }) => { allAffiliationsTmp[normalizedAffiliationName].works.push(work.id); }); }); - allAffiliationsTmp = Object.values(allAffiliationsTmp) - .map((affiliation, index) => ({ ...affiliation, id: index.toString(), works: [...new Set(affiliation.works)], worksNumber: [...new Set(affiliation.works)].length })); + .map((affiliation, index) => { + const uniqueWorks = [...new Set(affiliation.works)]; + return ({ + ...affiliation, + id: index.toString(), + works: uniqueWorks, + worksNumber: uniqueWorks.length, + }); + }); return allAffiliationsTmp; };