Skip to content

Commit

Permalink
feat(affiliations): Enable multiple selection
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Jul 26, 2023
1 parent 24e6813 commit ebbd89c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions client/src/pages/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const getData = async (options) => {

export default function Home() {
const [formOptions, setFormOptions] = useState({});
const [selectedAffiliation, setSelectedAffiliation] = useState({});
const [selectedAffiliation, setSelectedAffiliation] = useState([]);
const [selectedPublications, setSelectedPublications] = useState([]);
const [sortedPublications, setSortedPublications] = useState([]);
const [viewAllAffiliations, setViewAllAffiliations] = useState(false);
Expand Down Expand Up @@ -217,13 +217,14 @@ export default function Home() {
const tagAffiliation = (affiliation, action) => {
console.time('tagAffiliation');
const publicationsDataTableTmp = [...publicationsDataTable];
const publicationIds = affiliation.publications.map((publication) => publication.id);
const affiliationIds = affiliation.map((aff) => aff.id);
const publicationIds = affiliation.map((aff) => aff.publications.map((publication) => publication.id)).flat();
publicationsDataTableTmp.filter((publication) => publicationIds.includes(publication.id)).map((publication) => publication.status = action);
setPublicationsDataTable(publicationsDataTableTmp);
const affiliationsDataTableTmp = [...affiliationsDataTable];
affiliationsDataTableTmp.find((aff) => aff.id === affiliation.id).display = false;
affiliationsDataTableTmp.filter((aff) => affiliationIds.includes(aff.id)).map((aff) => aff.display = false);
setAffiliationsDataTable(affiliationsDataTableTmp);
setSelectedAffiliation({});
setSelectedAffiliation([]);
console.timeEnd('tagAffiliation');
};

Expand Down
6 changes: 3 additions & 3 deletions client/src/pages/home/views/affiliations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function AffiliationsView({
tableStyle={{ minWidth: '50rem' }}
value={affiliationsDataTable}
>
<Column selectionMode="single" headerStyle={{ width: '3rem' }} />
<Column selectionMode="multiple" headerStyle={{ width: '3rem' }} />
<Column field="datasource" header="Datasource" style={{ minWidth: '10px' }} />
<Column filter filterMatchMode="contains" body={nameTemplate} field="affiliation" header="Affiliation" style={{ minWidth: '10px' }} filterPlaceholder="Search by affiliation" />
<Column showFilterMenu={false} field="publications" body={(rowData) => rowData.publications.length} header="Number of publications" style={{ minWidth: '10px' }} />
Expand All @@ -43,11 +43,11 @@ AffiliationsView.propTypes = {
name: PropTypes.string.isRequired,
publications: PropTypes.arrayOf(PropTypes.object).isRequired,
})).isRequired,
selectedAffiliation: PropTypes.shape({
selectedAffiliation: PropTypes.arrayOf(PropTypes.shape({
datasource: PropTypes.string,
id: PropTypes.string,
name: PropTypes.string,
publications: PropTypes.arrayOf(PropTypes.object),
}).isRequired,
})).isRequired,
setSelectedAffiliation: PropTypes.func.isRequired,
};

0 comments on commit ebbd89c

Please sign in to comment.