Skip to content

Commit

Permalink
web/satellite: fix object browser pagination for the folders
Browse files Browse the repository at this point in the history
Fix pagination for the folders which are not on the first page.
Also, fixed object count calculation inside folders.

Issue:
storj/customer-issues#1055

Change-Id: I1d0fbb8856f13be6fb20698315a7e4d20b4affd9
  • Loading branch information
VitaliiShpital authored and Storj Robot committed Sep 27, 2023
1 parent e1215d5 commit 6364520
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
14 changes: 13 additions & 1 deletion web/satellite/src/components/browser/FileBrowser.vue
Expand Up @@ -114,6 +114,7 @@
:loading="isLoading"
class="file-browser-table"
:on-page-change="isPaginationEnabled ? changePageAndLimit : null"
:page-number="cursor.page"
@selectAllClicked="toggleSelectAllFiles"
>
<template #head>
Expand Down Expand Up @@ -272,6 +273,7 @@ const isOver = ref<boolean>(false);
const routePath = ref(calculateRoutePath());
const NUMBER_OF_DISPLAYED_OBJECTS = 1000;
const routePageCache = new Map<string, number>();
/**
* Calculates page count depending on object count and page limit.
Expand Down Expand Up @@ -440,7 +442,8 @@ const bucket = computed((): string => {
/**
* Changes table page and limit.
*/
async function changePageAndLimit(page: number, limit: number): void {
async function changePageAndLimit(page: number, limit: number): Promise<void> {
routePageCache.set(routePath.value, page);
obStore.setCursor({ limit, page });
const lastObjectOnPage = page * limit;
Expand Down Expand Up @@ -501,6 +504,15 @@ async function onRouteChange(): Promise<void> {
await list(routePath.value);
}
});
if (isPaginationEnabled.value) {
const cachedPage = routePageCache.get(routePath.value);
if (cachedPage !== undefined) {
obStore.setCursor({ limit: cursor.value.limit, page: cachedPage });
} else {
obStore.setCursor({ limit: cursor.value.limit, page: 1 });
}
}
}
/**
Expand Down
8 changes: 7 additions & 1 deletion web/satellite/src/components/common/TablePagination.vue
Expand Up @@ -87,7 +87,7 @@
</template>

<script setup lang="ts">
import { computed, ref } from 'vue';
import { computed, ref, watch } from 'vue';
import { PageChangeCallback } from '@/types/pagination';
import { useLoading } from '@/composables/useLoading';
Expand All @@ -114,6 +114,7 @@ const props = withDefaults(defineProps<{
onNextClicked?: (() => Promise<void>) | null;
onPreviousClicked?: (() => Promise<void>) | null;
onPageSizeChanged?: ((size: number) => Promise<void> | void) | null;
pageNumber?: number;
}>(), {
itemsLabel: 'items',
totalPageCount: 0,
Expand All @@ -124,6 +125,7 @@ const props = withDefaults(defineProps<{
onNextClicked: null,
onPreviousClicked: null,
onPageSizeChanged: null,
pageNumber: 1,
});
const currentPageNumber = ref<number>(1);
Expand Down Expand Up @@ -260,6 +262,10 @@ async function prevPage(): Promise<void> {
currentPageNumber.value--;
});
}
watch(() => props.pageNumber, () => {
goToPage(props.pageNumber);
});
</script>

<style scoped lang="scss">
Expand Down
3 changes: 3 additions & 0 deletions web/satellite/src/components/common/VTable.vue
Expand Up @@ -31,6 +31,7 @@
:on-page-change="onPageChange"
:on-next-clicked="onNextClicked"
:on-previous-clicked="onPreviousClicked"
:page-number="pageNumber"
/>
</div>
</div>
Expand All @@ -57,6 +58,7 @@ const props = withDefaults(defineProps<{
showSelect?: boolean,
simplePagination?: boolean,
loading?: boolean,
pageNumber?: number,
}>(), {
selectable: false,
selected: false,
Expand All @@ -71,6 +73,7 @@ const props = withDefaults(defineProps<{
onPreviousClicked: null,
onPageSizeChanged: null,
loading: false,
pageNumber: 1,
});
const emit = defineEmits(['selectAllClicked']);
Expand Down
6 changes: 6 additions & 0 deletions web/satellite/src/store/modules/objectBrowserStore.ts
Expand Up @@ -297,6 +297,12 @@ export const useObjectBrowserStore = defineStore('objectBrowser', () => {
}

keyCount += response.KeyCount ?? 0;
// We decrement key count if we're inside a folder to exclude .file_placeholder object
// which was auto created for this folder because it's not visible by the user
// and it shouldn't be included in pagination process.
if (path) {
keyCount -= 1;
}

if (!response.NextContinuationToken) break;

Expand Down

0 comments on commit 6364520

Please sign in to comment.