Skip to content

Commit

Permalink
feat(affiliations): Add RoR column
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Sep 24, 2023
1 parent 5347cb4 commit 46b2192
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
28 changes: 14 additions & 14 deletions client/src/pages/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import Gauge from '../../components/gauge';
import { PageSpinner } from '../../components/spinner';
import {
getAllIdsHtmlField,
getAffiliationRor,
getAffiliationsHtmlField,
getAffiliationName,
getAuthorsHtmlField,
getAuthorsTooltipField,
} from '../../utils/templates';
Expand Down Expand Up @@ -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, '<b>$&</b>'),
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, '<b>$&</b>'),
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]) {
Expand Down
1 change: 1 addition & 0 deletions client/src/pages/home/views/affiliations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default function AffiliationsView({
<Column selectionMode="multiple" />
<Column field="status" header="Status" body={statusTemplate} filter showFilterMenu={false} filterElement={statusFilterTemplate} />
<Column field="nameHtml" header="Affiliation" body={nameTemplate} filter filterField="name" filterMatchMode="contains" filterPlaceholder="Search by affiliation" />
<Column field="ror" header="RoR" filter />
<Column field="worksNumber" header="Number of works" sortable />
<Column field="matches" header="Number of matches" sortable />
</DataTable>
Expand Down
21 changes: 7 additions & 14 deletions client/src/utils/templates.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<b>$&</b>'))
.map((affiliation) => affiliation.name.replace(regexp, '<b>$&</b>'))
.filter((affiliation) => affiliation.length)
.flat();
affiliations = [...new Set(affiliations)];
Expand Down Expand Up @@ -136,8 +129,8 @@ export {
affiliationsTemplate,
allIdsTemplate,
authorsTemplate,
getAffiliationRor,
getAffiliationsHtmlField,
getAffiliationName,
getAllIdsHtmlField,
getAuthorsHtmlField,
getAuthorsTooltipField,
Expand Down

0 comments on commit 46b2192

Please sign in to comment.