Skip to content

Commit

Permalink
refactor(ui): Refactor actions buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Nov 9, 2023
1 parent 59ad212 commit ff3e525
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions client/src/pages/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,30 +247,14 @@ export default function Home() {
setSelectedAffiliations([]);
};

const renderAffiliationsButtons = (selected) => (
const renderButtons = (selected, fn) => (
<>
{Object.values(status).map((st) => (
<Button
className={`fr-mb-1w fr-mr-1w ${st.buttonClassName}`}
disabled={!selected.length}
icon={st.buttonIcon}
onClick={() => tagAffiliations(selected, st.id)}
size="sm"
>
{`${st.buttonLabel} (${selected.length})`}
</Button>
))}
</>
);

const renderWorksButtons = (selected) => (
<>
{Object.values(status).map((st) => (
<Button
className={`fr-mb-1w fr-mr-1w ${st.buttonClassName}`}
disabled={!selected.length}
icon={st.buttonIcon}
onClick={() => tagWorks(selected, st.id)}
onClick={() => fn(selected, st.id)}
size="sm"
>
{`${st.buttonLabel} (${selected.length})`}
Expand Down Expand Up @@ -351,7 +335,7 @@ export default function Home() {
)}
<Row>
<Col n="4">
{renderAffiliationsButtons(selectedAffiliations)}
{renderButtons(selectedAffiliations, tagAffiliations)}
</Col>
<Col>
<Gauge
Expand All @@ -378,14 +362,14 @@ export default function Home() {
</Row>
<Row>
<Col>
{renderAffiliationsButtons(selectedAffiliations)}
{renderButtons(selectedAffiliations, tagAffiliations)}
</Col>
</Row>
</Tab>
<Tab label="List all publications">
<Row>
<Col n="4">
{renderWorksButtons(selectedPublications)}
{renderButtons(selectedPublications, tagWorks)}
</Col>
<Col>
<Gauge
Expand Down Expand Up @@ -470,14 +454,14 @@ export default function Home() {
)}
<Row>
<Col n="4">
{renderWorksButtons(selectedPublications)}
{renderButtons(selectedPublications, tagWorks)}
</Col>
</Row>
</Tab>
<Tab label="List all datasets">
<Row>
<Col>
{renderWorksButtons(selectedDatasets)}
{renderButtons(selectedDatasets, tagWorks)}
</Col>
<Col>
<Gauge
Expand All @@ -504,7 +488,7 @@ export default function Home() {
</Row>
<Row>
<Col>
{renderWorksButtons(selectedDatasets)}
{renderButtons(selectedDatasets, tagWorks)}
</Col>
</Row>
</Tab>
Expand Down

0 comments on commit ff3e525

Please sign in to comment.