Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrige une régression sur le composant Pagination #3513

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,14 @@ const IndicateursListe = ({
/>
))}
</div>
<div className="flex mt-16">
<Pagination
className="mx-auto"
selectedPage={currentPage}
nbOfElements={countTotal}
maxElementsPerPage={maxNbOfCards}
onChange={(page) => setCurrentPage(page)}
/>
</div>
<Pagination
className="mx-auto mt-16"
selectedPage={currentPage}
nbOfElements={countTotal}
maxElementsPerPage={maxNbOfCards}
idToScrollTo="app-header"
onChange={setCurrentPage}
/>
</div>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,14 @@ const PlansActionListe = ({
/>
))}
</div>
<div className="flex mt-16">
<Pagination
className="mx-auto"
selectedPage={currentPage}
nbOfElements={data?.count ?? 0}
maxElementsPerPage={maxNbOfCards}
onChange={(page) => setCurrentPage(page)}
/>
</div>
<Pagination
className="mx-auto mt-16"
selectedPage={currentPage}
nbOfElements={data?.count ?? 0}
maxElementsPerPage={maxNbOfCards}
idToScrollTo="app-header"
onChange={setCurrentPage}
/>
</div>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,14 @@ const FichesActionListe = ({
/>
))}
</div>
<div className="flex mt-16">
<Pagination
className="mx-auto"
selectedPage={currentPage}
nbOfElements={countTotal}
maxElementsPerPage={maxNbOfCards}
onChange={(page) => setCurrentPage(page)}
/>
</div>
<Pagination
className="mx-auto mt-16"
selectedPage={currentPage}
nbOfElements={countTotal}
maxElementsPerPage={maxNbOfCards}
idToScrollTo="app-header"
onChange={setCurrentPage}
/>
</div>
)}

Expand Down
2 changes: 1 addition & 1 deletion packages/site/app/programme/annuaire/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const Annuaire = () => {
nbOfElements={total}
maxElementsPerPage={PAGINATION_LIMIT}
idToScrollTo="annuaire-header"
onChange={(selectedPage) => setSelectPage(selectedPage)}
onChange={setSelectPage}
/>
</Section>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/design-system/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const Pagination = ({
const [nbOfPages, setNbOfPages] = useState(
Math.ceil(nbOfElements / maxElementsPerPage)
);
const [pageButtons, setPageButtons] = useState<number[]>([]);
const [pageButtons, setPageButtons] = useState<(number | undefined)[]>([]);
const [currentPage, setCurrentPage] = useState(selectedPage);
const [windowWidth, setWindowWidth] = useState<number>(0);
const [isMobile, setIsMobile] = useState(false);
Expand Down Expand Up @@ -100,7 +100,7 @@ export const Pagination = ({
key={i}
pageNumber={pageNum}
isSelected={currentPage === pageNum}
onClick={() => handleChangePage(pageNum)}
onClick={() => !!pageNum && handleChangePage(pageNum)}
/>
))}
</div>
Expand Down
7 changes: 4 additions & 3 deletions packages/ui/src/design-system/Pagination/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ export const calculatePaginationArray = ({
: undefined;

// Construction du tableau final
const finalArray = [...leftRange];
if (!displayAllPages && leftIntersection !== undefined) {
const finalArray: (number | undefined)[] = [...leftRange];

if (!displayAllPages) {
finalArray.push(leftIntersection);
}

finalArray.push(...middleRange);

if (isMiddlePage && !displayAllPages && rightIntersection !== undefined) {
if (isMiddlePage && !displayAllPages) {
finalArray.push(rightIntersection);
}

Expand Down
Loading