Skip to content

Commit

Permalink
fix duplicated affiliations when excluded
Browse files Browse the repository at this point in the history
  • Loading branch information
jerem1508 committed Sep 21, 2023
1 parent 9009054 commit 5306922
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions client/src/pages/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,17 @@ export default function Home() {
const groupByAffiliations = (works) => {
setIsLoading(true);
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 affiliationName = normalizedName(affiliation.name);
const name = getAffiliationName(affiliation);
const affiliationName = normalizedName(name);
if (!allAffiliationsTmp?.[affiliationName]) {
const name = getAffiliationName(affiliation);
allAffiliationsTmp[affiliationName] = {
matches: [...new Set(name.match(regexp))].length,
name,
Expand All @@ -158,14 +161,17 @@ export default function Home() {
allAffiliationsTmp[affiliationName].works.push(work.id);
});
});

taggedAffiliations.forEach((affiliation) => {
const affiliationName = normalizedName(affiliation.name);

if (!allAffiliationsTmp?.[affiliationName]) {
allAffiliationsTmp[affiliationName] = affiliation;
} else {
allAffiliationsTmp[affiliationName].status = affiliation.status;
}
});

allAffiliationsTmp = Object.values(allAffiliationsTmp)
.map((affiliation, index) => ({ ...affiliation, works: [...new Set(affiliation.works)], id: index.toString(), worksNumber: [...new Set(affiliation.works)].length }));
setAllAffiliations(allAffiliationsTmp);
Expand Down

0 comments on commit 5306922

Please sign in to comment.