Skip to content

Commit

Permalink
feat: added pagination to servizio cards in UO (#678)
Browse files Browse the repository at this point in the history
* feat: added pagination to servizio cards in UO

* fix: better syntaxis + lodash range function

* fix: code rework for optimization

* chore: fixed release.md

* chore: removed unused import
  • Loading branch information
sabrina-bongiovanni authored May 20, 2024
1 parent a223f33 commit 4abefd5
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 3 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

### Migliorie

- Se il CT UO è collegato a più di 4 servizi, le card dei servizi collegati verranno divise in diverse pagine navigabili da uno strumento di paginazione per rendere lo scorrimento della pagina più semplice.
- Cambiato il layout delle immagini all'interno del blocco Griglia.
- Migliorata la visualizzazione delle parole evidenziate nella pagina di Ricerca.

Expand Down
5 changes: 5 additions & 0 deletions src/components/ItaliaTheme/Pagination/Pagination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class Pagination extends Component {
totalPages,
});

const inactivePrevButton = activePage === 1;
const inactiveForwButton = activePage === this.props.totalPages;

return (
<Pager
className="justify-content-center mt-5"
Expand All @@ -96,6 +99,8 @@ class Pagination extends Component {
onClick={this.handleItemClick}
type={type}
ellipsisItem={ellipsisItem}
isPrevButtonInactive={inactivePrevButton}
isForwButtonInactive={inactiveForwButton}
>
{value}
</PaginationItem>
Expand Down
16 changes: 15 additions & 1 deletion src/components/ItaliaTheme/Pagination/PaginationItem.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import cx from 'classnames';
import _ from 'lodash';
import keyboardKey from 'keyboard-key';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -50,6 +51,9 @@ class PaginationItem extends Component {
'nextItem',
'lastItem',
]),

isPrevButtonInactive: PropTypes.bool,
isForwButtonInactive: PropTypes.bool,
};

handleClick = (e) => {
Expand All @@ -63,7 +67,15 @@ class PaginationItem extends Component {
};

render() {
const { active, type, children, intl, ellipsisItem } = this.props;
const {
active,
type,
children,
intl,
ellipsisItem,
isPrevButtonInactive,
isForwButtonInactive,
} = this.props;
const disabled = this.props.disabled || type === 'ellipsisItem';
return (
<PagerItem disabled={disabled}>
Expand All @@ -79,6 +91,7 @@ class PaginationItem extends Component {
icon="it-chevron-left"
style={{ ariaHidden: true }}
color="primary"
className={cx({ disabled: isPrevButtonInactive })}
title={intl.formatMessage(messages.prevPage)}
/>

Expand All @@ -93,6 +106,7 @@ class PaginationItem extends Component {
icon="it-chevron-right"
style={{ ariaHidden: true }}
color="primary"
className={cx({ disabled: isForwButtonInactive })}
title={intl.formatMessage(messages.nextPage)}
/>
<span className="visually-hidden">
Expand Down
40 changes: 38 additions & 2 deletions src/components/ItaliaTheme/View/UOView/UOServices.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import { defineMessages, useIntl } from 'react-intl';
import {
Row,
Expand All @@ -9,6 +9,7 @@ import {
CardTitle,
CardText,
} from 'design-react-kit';
import { Pagination } from 'design-comuni-plone-theme/components/ItaliaTheme';
import { UniversalLink } from '@plone/volto/components';

const messages = defineMessages({
Expand All @@ -18,9 +19,35 @@ const messages = defineMessages({
},
});

//* Pagination **/
const divideServicesIntoBatches = (arr, batchSize) => {
const batches = [];
for (let i = 0; i < arr.length; i += batchSize) {
batches.push(arr.slice(i, i + batchSize));
}
return batches;
};

const UOServices = ({ content }) => {
const intl = useIntl();

const [currentPage, setCurrentPage] = useState(1);
const bSize = 4;

//* Calcolo numero pagine

const servizi_offerti =
content.servizi_offerti === undefined || content.servizi_offerti === null
? []
: content.servizi_offerti;

const pageNumbers = Math.ceil(servizi_offerti.length / bSize);

const onPaginationChange = (activePage) => {
const current = activePage?.children ?? 1;
setCurrentPage(current);
};

return content?.servizi_offerti?.length > 0 ? (
<section
id={'servizi_offerti'}
Expand All @@ -30,7 +57,9 @@ const UOServices = ({ content }) => {
{intl.formatMessage(messages.servizi_offerti)}
</h2>
<Row className="card-wrapper card-teaser-wrapper align-items-stretch">
{content?.servizi_offerti?.map((servizio, i) => (
{divideServicesIntoBatches(content?.servizi_offerti, bSize)[
currentPage - 1
]?.map((servizio, i) => (
<Col xs="12" lg="6">
<Card className="shadow rounded card-big-io-comune p-3 my-3">
<CardBody>
Expand All @@ -46,6 +75,13 @@ const UOServices = ({ content }) => {
</Col>
))}
</Row>
<div className="pagination-wrapper">
<Pagination
activePage={currentPage}
totalPages={pageNumbers}
onPageChange={(e, { activePage }) => onPaginationChange(activePage)}
/>
</div>
</section>
) : null;
};
Expand Down
10 changes: 10 additions & 0 deletions src/theme/ItaliaTheme/Components/_pager.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@
}
}
}

.pagination-wrapper {
li.page-item {
button.page-link {
.icon.icon-primary.disabled {
fill: $gray-600 !important;
}
}
}
}

0 comments on commit 4abefd5

Please sign in to comment.