Skip to content

Commit

Permalink
pagination component - add new property and extend config
Browse files Browse the repository at this point in the history
  • Loading branch information
SKarolFolio committed Oct 23, 2024
1 parent f9eb350 commit fc76f8f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/components/ItemSearch/ItemSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ export const ItemSearch = () => {

useLoadSearchResults(fetchData);

const isVisiblePaginationCount = isVisibleSegments
? !!navigationSegment?.value && primarySegments?.[navigationSegment?.value]?.isVisiblePaginationCount
: true;
const segmentConfig = isVisibleSegments
? !!navigationSegment?.value && primarySegments?.[navigationSegment?.value]
: undefined;
const isVisiblePaginationCount = segmentConfig ? segmentConfig.isVisiblePaginationCount : true;
const isLoopedPagination = segmentConfig ? segmentConfig.isLoopedPagination : false;

return (
<div data-testid="id-search" className="item-search">
Expand All @@ -72,6 +74,7 @@ export const ItemSearch = () => {
showCount={isVisiblePaginationCount}
onPrevPageClick={onPrevPageClick}
onNextPageClick={onNextPageClick}
isLooped={isLoopedPagination}
/>
)}
</>
Expand Down
6 changes: 4 additions & 2 deletions src/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type Props = {
showCount?: boolean;
onPrevPageClick: VoidFunction;
onNextPageClick: VoidFunction;
isLooped?: boolean;
};

export const Pagination: FC<Props> = memo(
Expand All @@ -25,6 +26,7 @@ export const Pagination: FC<Props> = memo(
showCount = true,
onPrevPageClick,
onNextPageClick,
isLooped = false,
}) => {
const isFirstPage = currentPage === 0;
const isDisabledNext = totalPages ? currentPage === totalPages - 1 : false;
Expand All @@ -45,7 +47,7 @@ export const Pagination: FC<Props> = memo(
<Button
type={ButtonType.Text}
onClick={onPrevPageClick}
disabled={isFirstPage}
disabled={!isLooped && isFirstPage}
className="pagination-button"
data-testid="backward-button"
>
Expand All @@ -67,7 +69,7 @@ export const Pagination: FC<Props> = memo(
<Button
type={ButtonType.Text}
onClick={onNextPageClick}
disabled={isDisabledNext}
disabled={!isLooped && isDisabledNext}
className="pagination-button"
data-testid="forward-button"
>
Expand Down
2 changes: 2 additions & 0 deletions src/configs/complexLookup/complexLookup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ export const COMPLEX_LOOKUPS_CONFIG: ComplexLookupsConfig = {
labelId: 'ld.search',
isVisiblePaginationCount: true,
isVisibleSubLabel: true,
isLoopedPagination: false,
},
[SearchSegment.Browse]: {
type: SearchSegment.Browse,
labelId: 'ld.browse',
isVisiblePaginationCount: false,
isVisibleSubLabel: false,
isLoopedPagination: true,
},
},
defaultValues: {
Expand Down
1 change: 1 addition & 0 deletions src/types/complexLookup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type SearchSegmentConfig = {
labelId: string;
isVisiblePaginationCount?: boolean;
isVisibleSubLabel?: boolean;
isLoopedPagination?: boolean;
};

type PrimarySegmentsConfig = { [key in SearchSegment]: SearchSegmentConfig };
Expand Down

0 comments on commit fc76f8f

Please sign in to comment.