Browse Source

Merge pull request #3622 from nocodb/fix/default-limit

fix(nc-gui): use default limit from app info if specified
pull/3798/head
աɨռɢӄաօռɢ 2 years ago committed by GitHub
parent
commit
6c4e29ed24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      packages/nc-gui/composables/useSharedView.ts
  2. 15
      packages/nc-gui/composables/useViewData.ts

8
packages/nc-gui/composables/useSharedView.ts

@ -1,13 +1,15 @@
import type { ExportTypes, FilterType, PaginatedType, RequestParams, SortType, TableType, ViewType } from 'nocodb-sdk' import type { ExportTypes, FilterType, PaginatedType, RequestParams, SortType, TableType, ViewType } from 'nocodb-sdk'
import { UITypes } from 'nocodb-sdk' import { UITypes } from 'nocodb-sdk'
import { useNuxtApp } from '#app' import { useGlobal, useNuxtApp } from '#imports'
export function useSharedView() { export function useSharedView() {
const nestedFilters = useState<(FilterType & { status?: 'update' | 'delete' | 'create'; parentId?: string })[]>( const nestedFilters = useState<(FilterType & { status?: 'update' | 'delete' | 'create'; parentId?: string })[]>(
'nestedFilters', 'nestedFilters',
() => [], () => [],
) )
const paginationData = useState<PaginatedType>('paginationData', () => ({ page: 1, pageSize: 25 })) const { appInfo } = $(useGlobal())
const appInfoDefaultLimit = appInfo.defaultLimit || 25
const paginationData = useState<PaginatedType>('paginationData', () => ({ page: 1, pageSize: appInfoDefaultLimit }))
const sharedView = useState<ViewType | undefined>('sharedView', () => undefined) const sharedView = useState<ViewType | undefined>('sharedView', () => undefined)
const sorts = useState<SortType[]>('sorts', () => []) const sorts = useState<SortType[]>('sorts', () => [])
const password = useState<string | undefined>('password', () => undefined) const password = useState<string | undefined>('password', () => undefined)
@ -57,7 +59,7 @@ export function useSharedView() {
if (!sharedView.value) return if (!sharedView.value) return
const page = paginationData.value.page || 1 const page = paginationData.value.page || 1
const pageSize = paginationData.value.pageSize || 25 const pageSize = paginationData.value.pageSize || appInfoDefaultLimit
const { data } = await $api.public.dataList( const { data } = await $api.public.dataList(
sharedView.value.uuid!, sharedView.value.uuid!,

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

@ -9,6 +9,7 @@ import {
extractSdkResponseErrorMsg, extractSdkResponseErrorMsg,
getHTMLEncodedText, getHTMLEncodedText,
useApi, useApi,
useGlobal,
useI18n, useI18n,
useNuxtApp, useNuxtApp,
useProject, useProject,
@ -44,7 +45,9 @@ export function useViewData(
const { t } = useI18n() const { t } = useI18n()
const { api, isLoading, error } = useApi() const { api, isLoading, error } = useApi()
const _paginationData = ref<PaginatedType>({ page: 1, pageSize: 25 }) const { appInfo } = $(useGlobal())
const appInfoDefaultLimit = appInfo.defaultLimit || 25
const _paginationData = ref<PaginatedType>({ page: 1, pageSize: appInfoDefaultLimit })
const aggCommentCount = ref<{ row_id: string; count: number }[]>([]) const aggCommentCount = ref<{ row_id: string; count: number }[]>([])
const galleryData = ref<GalleryType>() const galleryData = ref<GalleryType>()
const formColumnData = ref<FormType>() const formColumnData = ref<FormType>()
@ -79,8 +82,8 @@ export function useViewData(
}) })
const queryParams = computed(() => ({ const queryParams = computed(() => ({
offset: ((paginationData.value?.page ?? 0) - 1) * (paginationData.value?.pageSize ?? 25), offset: ((paginationData.value.page ?? 0) - 1) * (paginationData.value.pageSize ?? appInfoDefaultLimit),
limit: paginationData.value?.pageSize ?? 25, limit: paginationData.value.pageSize ?? appInfoDefaultLimit,
where: where?.value ?? '', where: where?.value ?? '',
})) }))
@ -116,9 +119,9 @@ export function useViewData(
// total records in the current table // total records in the current table
const count = paginationData.value?.totalRows ?? Infinity const count = paginationData.value?.totalRows ?? Infinity
// the number of rows in a page // the number of rows in a page
const size = paginationData.value?.pageSize ?? 25 const size = paginationData.value.pageSize ?? appInfoDefaultLimit
// the current page number // the current page number
const currentPage = paginationData.value?.page ?? 1 const currentPage = paginationData.value.page ?? 1
// the maximum possible page given the current count and the size // the maximum possible page given the current count and the size
const mxPage = Math.ceil(count / size) const mxPage = Math.ceil(count / size)
// calculate targetPage where 1 <= targetPage <= mxPage // calculate targetPage where 1 <= targetPage <= mxPage
@ -263,7 +266,7 @@ export function useViewData(
async function changePage(page: number) { async function changePage(page: number) {
paginationData.value.page = page paginationData.value.page = page
await loadData({ offset: (page - 1) * (paginationData.value.pageSize || 25), where: where?.value } as any) await loadData({ offset: (page - 1) * (paginationData.value.pageSize || appInfoDefaultLimit), where: where?.value } as any)
$e('a:grid:pagination') $e('a:grid:pagination')
} }

Loading…
Cancel
Save