Browse Source

fix: handle pagination offset in gui

pull/8295/head
Pranav C 8 months ago
parent
commit
0cbc56464e
  1. 4
      packages/nc-gui/components/smartsheet/Pagination.vue
  2. 5
      packages/nc-gui/composables/useViewData.ts
  3. 9
      packages/nocodb/src/helpers/PagedResponse.ts

4
packages/nc-gui/components/smartsheet/Pagination.vue

@ -66,6 +66,8 @@ const isRTLLanguage = computed(() => isRtlLang(locale.value as keyof typeof Lang
const renderAltOrOptlKey = () => { const renderAltOrOptlKey = () => {
return isMac() ? '⌥' : 'ALT' return isMac() ? '⌥' : 'ALT'
} }
const tempPageVal = ref(page.value)
</script> </script>
<template> <template>
@ -118,7 +120,7 @@ const renderAltOrOptlKey = () => {
/> />
<div v-else class="mx-auto flex items-center mt-n1" style="max-width: 250px"> <div v-else class="mx-auto flex items-center mt-n1" style="max-width: 250px">
<span class="text-xs" style="white-space: nowrap"> Change page:</span> <span class="text-xs" style="white-space: nowrap"> Change page:</span>
<a-input size="small" class="ml-1 !text-xs" type="number" @keydown.enter="changePage(page)"> <a-input v-model:value="tempPageVal" size="small" class="ml-1 !text-xs" type="number" @keydown.enter="changePage(tempPageVal)" @blur="tempPageVal = page">
<template #suffix> <template #suffix>
<component :is="iconMap.returnKey" class="mt-1" @click="changePage(page)" /> <component :is="iconMap.returnKey" class="mt-1" @click="changePage(page)" />
</template> </template>

5
packages/nc-gui/composables/useViewData.ts

@ -215,16 +215,17 @@ export function useViewData(
return message.error(await extractSdkResponseErrorMsg(error)) return message.error(await extractSdkResponseErrorMsg(error))
} }
formattedData.value = formatData(response.list) formattedData.value = formatData(response.list)
paginationData.value = response.pageInfo || {} paginationData.value = response.pageInfo || paginationData.value || {}
isPaginationLoading.value = false isPaginationLoading.value = false
// to cater the case like when querying with a non-zero offset // to cater the case like when querying with a non-zero offset
// the result page may point to the target page where the actual returned data don't display on // the result page may point to the target page where the actual returned data don't display on
if (paginationData.value.totalRows !== undefined && paginationData.value.totalRows !== null) {
const expectedPage = Math.max(1, Math.ceil(paginationData.value.totalRows! / paginationData.value.pageSize!)) const expectedPage = Math.max(1, Math.ceil(paginationData.value.totalRows! / paginationData.value.pageSize!))
if (expectedPage < paginationData.value.page!) { if (expectedPage < paginationData.value.page!) {
await changePage(expectedPage) await changePage(expectedPage)
} }
}
if (viewMeta.value?.type === ViewTypes.GRID) { if (viewMeta.value?.type === ViewTypes.GRID) {
loadAggCommentsCount() loadAggCommentsCount()
} }

9
packages/nocodb/src/helpers/PagedResponse.ts

@ -23,7 +23,7 @@ export class PagedResponseImpl<T> {
this.list = list; this.list = list;
if (count !== null) { if (count !== null && count !== undefined) {
this.pageInfo = { totalRows: +count }; this.pageInfo = { totalRows: +count };
this.pageInfo.page = offset ? offset / limit + 1 : 1; this.pageInfo.page = offset ? offset / limit + 1 : 1;
this.pageInfo.pageSize = limit; this.pageInfo.pageSize = limit;
@ -37,15 +37,16 @@ export class PagedResponseImpl<T> {
this.pageInfo.offset = offset; this.pageInfo.offset = offset;
delete this.pageInfo.page; delete this.pageInfo.page;
} }
}
if (additionalProps) Object.assign(this, additionalProps);
if (offset && offset >= +count) { if (offset && offset >= +count) {
NcError.invalidOffsetValue(offset); NcError.invalidOffsetValue(offset);
} }
} }
if (additionalProps) Object.assign(this, additionalProps);
}
list: Array<T>; list: Array<T>;
pageInfo: PaginatedType; pageInfo: PaginatedType;
errors?: any[]; errors?: any[];

Loading…
Cancel
Save