Skip to content

Commit

Permalink
fix: table: add page sizes prop to table pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
dkilgore-eightfold committed Sep 27, 2022
1 parent bd4cfac commit ca2ed59
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 34 deletions.
6 changes: 0 additions & 6 deletions src/components/Table/Hooks/usePagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ export default function usePagination(
if (pages) {
for (let i: number = 0; i < pages.length; ++i) {
if (mergedPagination.pageSize === pages[i]) {
console.log('usePagination pages: ' + pages[i]);
maxPage = Math.ceil((paginationTotal || total) / pages[i]!);
console.log('usePagination maxPage: ' + maxPage);
}
}
} else {
Expand Down Expand Up @@ -145,10 +143,6 @@ export default function usePagination(
mergedPagination.onSizeChange?.(
mergedPagination?.pageSizes[i]
);
console.log(
'onInternalSizeChange pageSize: ' +
mergedPagination?.pageSizes[i]
);
refreshPagination(
mergedPagination?.currentPage,
size,
Expand Down
1 change: 1 addition & 0 deletions src/components/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,7 @@ const Page_Sizes_Story: ComponentStory<typeof Table> = (args) => {
PaginationLayoutOptions.Pager,
],
pageSizes: [5, 10, 20],
selfControlled: false,
total: r?.length,
}}
scroll={{
Expand Down
31 changes: 3 additions & 28 deletions src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ function InternalTable<RecordType extends object = any>(
const pages: number[] = changeInfo.pagination!.pageSizes!;

if (pages) {
console.log('triggerOnChange pages: ' + pages);
for (let i: number = 0; i < pages.length; ++i) {
pagination.onSizeChange?.(
changeInfo.pagination!.pageSizes[i]
Expand Down Expand Up @@ -333,13 +332,6 @@ function InternalTable<RecordType extends object = any>(
pageSize: number,
pageSizes: number[]
) => {
console.log(
'onPaginationChange pageSize: ' +
pageSize +
' ' +
'onPaginationChange pageSizes: ' +
pageSizes
);
triggerOnChange(
{
pagination: {
Expand Down Expand Up @@ -376,7 +368,9 @@ function InternalTable<RecordType extends object = any>(
}

const {
currentPage = 1,
currentPage = mergedPagination.pageSizes
? mergedPagination.currentPage || 1
: 1,
total,
pageSize = mergedPagination.pageSizes
? mergedPagination.pageSizes[0]
Expand All @@ -386,16 +380,9 @@ function InternalTable<RecordType extends object = any>(

// Dynamic table data
if (pageSizes) {
console.log('Dynamic table data pageSizes: ' + pageSizes);
for (let i: number = 0; i < pageSizes.length; ++i) {
if (pageSize === pageSizes[i]) {
mergedPagination.pageSize = pageSizes[i];
console.log(
'Dynamic table data pageSizes[' +
i +
'] value: ' +
pageSizes[i]
);
if (mergedData.length < total!) {
if (mergedData.length > pageSizes[i]) {
return mergedData.slice(
Expand All @@ -406,23 +393,13 @@ function InternalTable<RecordType extends object = any>(
return mergedData;
}

// This is not getting logged unless the page size is updated twice
// after changing page size then paging to a new page.
console.log(
mergedData.slice(
(currentPage - 1) * pageSizes[i],
currentPage * pageSizes[i]
)
);

return mergedData.slice(
(currentPage - 1) * pageSizes[i],
currentPage * pageSizes[i]
);
}
}
} else {
console.log('Dynamic table data pageSize: ' + pageSize);
if (mergedData.length < total!) {
if (mergedData.length > pageSize) {
return mergedData.slice(
Expand Down Expand Up @@ -525,13 +502,11 @@ function InternalTable<RecordType extends object = any>(
let paginationSizes: TablePaginationConfig['pageSizes'];

if (mergedPagination.pageSize) {
console.log('Table pageSize: ' + mergedPagination.pageSize);
paginationSize = mergedPagination.pageSize;
} else {
paginationSize = undefined;
}
if (mergedPagination.pageSizes) {
console.log('Table pageSizes: ' + mergedPagination.pageSizes);
paginationSizes = mergedPagination.pageSizes;
} else {
paginationSizes = undefined;
Expand Down

0 comments on commit ca2ed59

Please sign in to comment.