web/satellite: fix errant pagination

This change fixes an issue where changing the size of a page will also
change the current page. It uses a more accurate calculation to
determine if the new size and current page will result in a page index
error.

Issue: https://github.com/storj/storj/issues/6094

Change-Id: Ie62f79191eb34ccd75ccd42b923b8866fe4e4d7f
This commit is contained in:
Wilfred Asomani 2023-07-28 10:31:17 +00:00 committed by Storj Robot
parent ceef4b8362
commit af69e20cc8

View File

@ -159,14 +159,12 @@ const isLastPage = computed((): boolean => {
return currentPageNumber.value === props.totalPageCount;
});
async function sizeChanged(size: number) {
function sizeChanged(size: number) {
// if the new size is large enough to cause the page index to be out of range
// we calculate an appropriate new page index.
let page = currentPageNumber.value;
if (size * props.totalPageCount > props.totalItemsCount) {
page = Math.ceil(props.totalItemsCount / size);
}
await withLoading(async () => {
const maxPage = Math.ceil(Math.ceil(props.totalItemsCount / size));
const page = currentPageNumber.value > maxPage ? maxPage : currentPageNumber.value;
withLoading(async () => {
if (!props.onPageChange) {
return;
}