Skip to content

Commit

Permalink
feat(publications): Use publication ids to apply action
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Jul 26, 2023
1 parent 13d1488 commit 332d9c4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 42 deletions.
45 changes: 22 additions & 23 deletions client/src/pages/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ const getData = async (options) => {
export default function Home() {
const [formOptions, setFormOptions] = useState({});
const [selectedAffiliations, setSelectedAffiliations] = useState([]);
const [selectedPublications1, setSelectedPublications1] = useState([]);
const [selectedPublications2, setSelectedPublications2] = useState([]);
const [selectedPublications3, setSelectedPublications3] = useState([]);
const [selectedPublicationIds1, setSelectedPublicationIds1] = useState([]);
const [selectedPublicationIds2, setSelectedPublicationIds2] = useState([]);
const [selectedPublicationIds3, setSelectedPublicationIds3] = useState([]);
const [sortedPublications, setSortedPublications] = useState([]);
const [viewAllAffiliations, setViewAllAffiliations] = useState(false);
const [viewAllPublications, setViewAllPublications] = useState(false);
Expand Down Expand Up @@ -187,9 +187,8 @@ export default function Home() {
setAffiliationsDataTable(affiliationsDataTableTmp);
}, [data]);

const tagPublications = (publications, action, setSelectedPublications) => {
const tagPublications = (publicationIds, action, setSelectedPublications) => {
const publicationsDataTableTmp = [...publicationsDataTable];
const publicationIds = publications.map((publication) => publication.id);
publicationsDataTableTmp.filter((publication) => publicationIds.includes(publication.id)).map((publication) => publication.status = action);
setPublicationsDataTable(publicationsDataTableTmp);
setSelectedPublications([]);
Expand Down Expand Up @@ -298,18 +297,18 @@ export default function Home() {
<Col className="text-right">
<Button
className="fr-mr-1w"
disabled={selectedPublications1.length === 0}
disabled={selectedPublicationIds1.length === 0}
icon="ri-check-fill"
onClick={() => { tagPublications(selectedPublications1, 'keep', setSelectedPublications1); }}
onClick={() => { tagPublications(selectedPublicationIds1, 'keep', setSelectedPublicationIds1); }}
size="sm"
>
Keep
</Button>
<Button
className="fr-mb-1w"
disabled={selectedPublications1.length === 0}
disabled={selectedPublicationIds1.length === 0}
icon="ri-close-fill"
onClick={() => { tagPublications(selectedPublications1, 'exclude', setSelectedPublications1); }}
onClick={() => { tagPublications(selectedPublicationIds1, 'exclude', setSelectedPublicationIds1); }}
size="sm"
>
Exclude
Expand All @@ -320,8 +319,8 @@ export default function Home() {
<Col>
<PublicationsView
publicationsDataTable={viewAllPublications ? publicationsDataTable : publicationsDataTable.filter((item) => item.status === 'sort')}
selectedPublications={selectedPublications1}
setSelectedPublications={setSelectedPublications1}
selectedPublicationIds={selectedPublicationIds1}
setSelectedPublicationIds={setSelectedPublicationIds1}
/>
</Col>
</Row>
Expand All @@ -339,18 +338,18 @@ export default function Home() {
<Col className="text-right">
<Button
className="fr-mr-1w"
disabled={selectedPublications2.length === 0}
disabled={selectedPublicationIds2.length === 0}
icon="ri-check-fill"
onClick={() => { tagPublications(selectedPublications2, 'sort', setSelectedPublications2); }}
onClick={() => { tagPublications(selectedPublicationIds2, 'sort', setSelectedPublicationIds2); }}
size="sm"
>
Sort
</Button>
<Button
className="fr-mb-1w"
disabled={selectedPublications2.length === 0}
disabled={selectedPublicationIds2.length === 0}
icon="ri-close-fill"
onClick={() => { tagPublications(selectedPublications2, 'exclude', setSelectedPublications2); }}
onClick={() => { tagPublications(selectedPublicationIds2, 'exclude', setSelectedPublicationIds2); }}
size="sm"
>
Exclude
Expand All @@ -361,8 +360,8 @@ export default function Home() {
<Col>
<PublicationsView
publicationsDataTable={viewAllPublications ? publicationsDataTable : publicationsDataTable.filter((item) => item.status === 'keep')}
selectedPublications={selectedPublications2}
setSelectedPublications={setSelectedPublications2}
selectedPublicationIds={selectedPublicationIds2}
setSelectedPublicationIds={setSelectedPublicationIds2}
/>
</Col>
</Row>
Expand All @@ -380,18 +379,18 @@ export default function Home() {
<Col className="text-right">
<Button
className="fr-mr-1w"
disabled={selectedPublications3.length === 0}
disabled={selectedPublicationIds3.length === 0}
icon="ri-check-fill"
onClick={() => { tagPublications(selectedPublications3, 'sort', setSelectedPublications3); }}
onClick={() => { tagPublications(selectedPublicationIds3, 'sort', setSelectedPublicationIds3); }}
size="sm"
>
Sort
</Button>
<Button
className="fr-mb-1w"
disabled={selectedPublications3.length === 0}
disabled={selectedPublicationIds3.length === 0}
icon="ri-close-fill"
onClick={() => { tagPublications(selectedPublications3, 'keep', setSelectedPublications3); }}
onClick={() => { tagPublications(selectedPublicationIds3, 'keep', setSelectedPublicationIds3); }}
size="sm"
>
Keep
Expand All @@ -402,8 +401,8 @@ export default function Home() {
<Col>
<PublicationsView
publicationsDataTable={viewAllPublications ? publicationsDataTable : publicationsDataTable.filter((item) => item.status === 'exclude')}
selectedPublications={selectedPublications3}
setSelectedPublications={setSelectedPublications3}
selectedPublicationIds={selectedPublicationIds3}
setSelectedPublicationIds={setSelectedPublicationIds3}
/>
</Col>
</Row>
Expand Down
25 changes: 6 additions & 19 deletions client/src/pages/home/views/publications.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import {

export default function PublicationsView({
publicationsDataTable,
selectedPublications,
setSelectedPublications,
selectedPublicationIds,
setSelectedPublicationIds,
}) {
return (
<DataTable
currentPageReportTemplate="{first} to {last} of {totalRecords}"
dataKey="id"
filterDisplay="row"
metaKeySelection={false}
onSelectionChange={(e) => setSelectedPublications(e.value)}
onSelectionChange={(e) => setSelectedPublicationIds(e.value.map((item) => item.id))}
paginator
paginatorTemplate="RowsPerPageDropdown FirstPageLink PrevPageLink CurrentPageReport NextPageLink LastPageLink"
rows={25}
rowsPerPageOptions={[25, 50, 100, 200]}
scrollable
selection={selectedPublications}
selection={selectedPublicationIds}
size="small"
stripedRows
style={{ fontSize: '11px', lineHeight: '15px' }}
Expand Down Expand Up @@ -53,19 +53,6 @@ PublicationsView.propTypes = {
status: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
})).isRequired,
setSelectedPublications: PropTypes.func,
selectedPublications: PropTypes.arrayOf(PropTypes.shape({
affiliations: PropTypes.arrayOf(PropTypes.object).isRequired,
allIds: PropTypes.arrayOf(PropTypes.object).isRequired,
authors: PropTypes.arrayOf(PropTypes.object).isRequired,
datasource: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
status: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
})),
};

PublicationsView.defaultProps = {
setSelectedPublications: () => {},
selectedPublications: [],
setSelectedPublicationIds: PropTypes.func.isRequired,
selectedPublicationIds: PropTypes.arrayOf(PropTypes.string).isRequired,
};

0 comments on commit 332d9c4

Please sign in to comment.