Skip to content

Commit

Permalink
fix(ui): Validate datasets via affiliations
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Nov 9, 2023
1 parent 24291ee commit 05508b5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions client/src/pages/home/actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 13 additions & 10 deletions client/src/pages/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -140,10 +140,10 @@ export default function Home() {
ror,
rorHtml: ror?.replace(regexp, '<b>$&</b>'),
status: status.tobedecided.id,
publications: [],
works: [],
};
}
allAffiliationsTmp[normalizedAffiliationName].publications.push(publication.id);
allAffiliationsTmp[normalizedAffiliationName].works.push(work.id);
});
});

Expand All @@ -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);
};
Expand Down Expand Up @@ -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]);

Expand All @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions client/src/pages/home/views/affiliations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand All @@ -39,8 +39,8 @@ 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="publicationsNumber" header="Number of publications" sortable />
<Column field="matches" header="Number of matches" sortable />
<Column field="worksNumber" header="Number of works" sortable />
<Column field="matches" header="Number of unique matches" sortable />
</DataTable>
);
}
Expand All @@ -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,
};
6 changes: 3 additions & 3 deletions client/src/utils/works.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
});
Expand Down

0 comments on commit 05508b5

Please sign in to comment.