Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a settings per projects and per tables for the pagination and number of rows shown #8360

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,4 @@ test_noco.db
httpbin
.run/test-debug.run.xml

venv
1 change: 1 addition & 0 deletions packages/nc-gui/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ declare module 'vue' {
ARadio: typeof import('ant-design-vue/es')['Radio']
ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup']
ARate: typeof import('ant-design-vue/es')['Rate']
AResult: typeof import('ant-design-vue/es')['Result']
ARow: typeof import('ant-design-vue/es')['Row']
ASelect: typeof import('ant-design-vue/es')['Select']
ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
Expand Down
155 changes: 155 additions & 0 deletions packages/nc-gui/components/dlg/PaginationLimit.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<script setup lang="ts">
import {
Form,
TabType,
computed,
nextTick,
onMounted,
ref,
useBase,
useTableNew,
useTablesStore,
useTabs,
useVModel,
validateTableName,
} from '#imports'

import NcTooltip from '~/components/nc/Tooltip.vue'
import { useGlobal } from '#imports'

const props = defineProps<{
modelValue: boolean
sourceId: string
baseId: string
current: number
total: number
pageSize: number
mode?: 'simple' | 'full'
prevPageTooltip?: string
nextPageTooltip?: string
firstPageTooltip?: string
lastPageTooltip?: string
showSizeChanger?: boolean
}>()

// const emit = defineEmits(['update:modelValue', 'create'])
const emits = defineEmits(['update:current', 'update:pageSize'])

const dialogShow = useVModel(props, 'modelValue', emits)

const { total, showSizeChanger } = toRefs(props)

const current = useVModel(props, 'current', emits)

const pageSize = useVModel(props, 'pageSize', emits)

const { gridViewPageSize, setGridViewPageSize } = useGlobal()



const localPageSize = computed({
get: () => {
return gridViewPageSize.value
},
set: (val) => {
// reset to default value if user input is empty
if (!val) {
val = 25
Comment on lines +56 to +57
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a constant for the default page size instead of hardcoding '25' in multiple places. This would make the code cleaner and easier to maintain if the default size needs to be changed in the future.

}
setGridViewPageSize(val)
pageSize.value = val
},
})

const pageSizeOptions = [
{
value: 25,
label: '25 / page',
},
{
value: 50,
label: '50 / page',
},
{
value: 75,
label: '75 / page',
},
{
value: 100,
label: '100 / page',
},
]

const pageSizeDefaults = pageSizeOptions.map((item) => item.value)


const customPageValue = computed({
get: () => {
return ""
},
set: (val) => {
localPageSize.value = val
},
})

const customPageOption = computed({
get: () => {
if (pageSizeDefaults.includes(localPageSize.value)) {
return localPageSize.value
}
return localPageSize.value.toString().concat(" / page")
},
set: (val) => {
localPageSize.value = val
}
})

const pageSizeRef = ref()

const pageSizeDropdownVisibleChange = (value: boolean) => {
if (!value && pageSizeRef.value) {
pageSizeRef.value?.blur()
}
}

</script>

<template>
<NcModal v-model:visible="dialogShow" :header="$t('labels.modifyPaginationLimit')" size="small" @keydown.esc="dialogShow = false">
<template #header>
<div class="flex flex-row items-center gap-x-2">
{{ $t('labels.modifyPaginationLimit') }}
</div>
</template>
<div class="nc-pagination flex flex-row items-center gap-x-2">
<a-select ref="pageSizeRef" v-model:value="customPageOption" class="!min-w-[110px]" :options="pageSizeOptions"
size="small" dropdown-class-name="nc-pagination-dropdown"
@dropdown-visible-change="pageSizeDropdownVisibleChange">
<template #suffixIcon>
<GeneralIcon icon="arrowDown" class="text-gray-500 nc-select-page-size-expand-btn" />
</template>
</a-select>
<!-- Input and Button for entering a value -->
<input v-model.lazy="customPageValue" type="number" placeholder="Set custom page size" size="small" />

</div>
</NcModal>
</template>

<style lang="scss" scoped>
:deep(.ant-select-selector) {
@apply !border-gray-200 !rounded-lg !h-[25px];
}

:deep(.nc-button:not(:disabled)) {
.nc-pagination-icon {
@apply !text-gray-500;
}
}
</style>

<style lang="scss">
.nc-pagination-dropdown {
@apply !rounded-lg;
}
</style>
100 changes: 48 additions & 52 deletions packages/nc-gui/components/nc/Pagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const { gridViewPageSize, setGridViewPageSize } = useGlobal()
const localPageSize = computed({
get: () => {
if (!showSizeChanger.value) return pageSize.value

const storedPageSize = gridViewPageSize.value || 25

if (pageSize.value !== storedPageSize) {
Expand All @@ -38,8 +37,11 @@ const localPageSize = computed({
return pageSize.value
},
set: (val) => {
// reset to default value if user input is empty
if (!val) {
val = 25
}
Comment on lines +40 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a constant for the default page size instead of hardcoding '25' in multiple places. This would make the code cleaner and easier to maintain if the default size needs to be changed in the future.

setGridViewPageSize(val)

pageSize.value = val
},
})
Expand Down Expand Up @@ -96,6 +98,32 @@ const pageSizeOptions = [
},
]

const pageSizeDefaults = pageSizeOptions.map((item) => item.value)

const customPageValue = computed({
get: () => {
if (pageSizeDefaults.includes(localPageSize.value)) {
return ""
}
return localPageSize.value
},
set: (val) => {
localPageSize.value = val
},
})

const customPageOption = computed({
get: () => {
if (pageSizeDefaults.includes(localPageSize.value)) {
return localPageSize.value
}
return localPageSize.value.toString().concat(" / page")
},
set: (val) => {
localPageSize.value = val
}
})

const pageListRef = ref()
const pageSizeRef = ref()

Expand All @@ -109,6 +137,7 @@ const pageSizeDropdownVisibleChange = (value: boolean) => {
pageSizeRef.value?.blur()
}
}

</script>

<template>
Expand All @@ -118,14 +147,8 @@ const pageSizeDropdownVisibleChange = (value: boolean) => {
<template v-if="props.firstPageTooltip" #title>
{{ props.firstPageTooltip }}
</template>
<NcButton
v-e="[`a:pagination:${entityName}:first-page`]"
class="first-page"
type="secondary"
size="xsmall"
:disabled="current === 1"
@click="goToFirstPage"
>
<NcButton v-e="[`a:pagination:${entityName}:first-page`]" class="first-page" type="secondary" size="xsmall"
:disabled="current === 1" @click="goToFirstPage">
<GeneralIcon icon="doubleLeftArrow" class="nc-pagination-icon" />
</NcButton>
</component>
Expand All @@ -134,28 +157,15 @@ const pageSizeDropdownVisibleChange = (value: boolean) => {
<template v-if="props.prevPageTooltip" #title>
{{ props.prevPageTooltip }}
</template>
<NcButton
v-e="[`a:pagination:${entityName}:prev-page`]"
class="prev-page"
type="secondary"
size="xsmall"
:disabled="current === 1"
@click="changePage({ increase: false })"
>
<NcButton v-e="[`a:pagination:${entityName}:prev-page`]" class="prev-page" type="secondary" size="xsmall"
:disabled="current === 1" @click="changePage({ increase: false })">
<GeneralIcon icon="arrowLeft" class="nc-pagination-icon" />
</NcButton>
</component>

<div v-if="!isMobileMode" class="text-gray-500">
<a-select
ref="pageListRef"
v-model:value="current"
class="!mr-[2px]"
:options="pagesList"
size="small"
dropdown-class-name="nc-pagination-dropdown"
@dropdown-visible-change="pageListDropdownVisibleChange"
>
<a-select ref="pageListRef" v-model:value="current" class="!mr-[2px]" :options="pagesList" size="small"
dropdown-class-name="nc-pagination-dropdown" @dropdown-visible-change="pageListDropdownVisibleChange">
<template #suffixIcon>
<GeneralIcon icon="arrowDown" class="text-gray-500 nc-select-expand-btn" />
</template>
Expand All @@ -170,14 +180,8 @@ const pageSizeDropdownVisibleChange = (value: boolean) => {
<template v-if="props.nextPageTooltip" #title>
{{ props.nextPageTooltip }}
</template>
<NcButton
v-e="[`a:pagination:${entityName}:next-page`]"
class="next-page"
type="secondary"
size="xsmall"
:disabled="current === totalPages"
@click="changePage({ increase: true })"
>
<NcButton v-e="[`a:pagination:${entityName}:next-page`]" class="next-page" type="secondary" size="xsmall"
:disabled="current === totalPages" @click="changePage({ increase: true })">
<GeneralIcon icon="arrowRight" class="nc-pagination-icon" />
</NcButton>
</component>
Expand All @@ -186,33 +190,25 @@ const pageSizeDropdownVisibleChange = (value: boolean) => {
<template v-if="props.lastPageTooltip" #title>
{{ props.lastPageTooltip }}
</template>
<NcButton
v-e="[`a:pagination:${entityName}:last-page`]"
class="last-page"
type="secondary"
size="xsmall"
:disabled="current === totalPages"
@click="goToLastPage"
>
<NcButton v-e="[`a:pagination:${entityName}:last-page`]" class="last-page" type="secondary" size="xsmall"
:disabled="current === totalPages" @click="goToLastPage">
<GeneralIcon icon="doubleRightArrow" class="nc-pagination-icon" />
</NcButton>
</component>
</template>
<div v-if="showSizeChanger && !isMobileMode" class="text-gray-500">
<a-select
ref="pageSizeRef"
v-model:value="localPageSize"
class="!min-w-[110px]"
:options="pageSizeOptions"
size="small"
dropdown-class-name="nc-pagination-dropdown"
@dropdown-visible-change="pageSizeDropdownVisibleChange"
>
<a-select ref="pageSizeRef" v-model:value="customPageOption" class="!min-w-[110px]" :options="pageSizeOptions"
size="small" dropdown-class-name="nc-pagination-dropdown"
@dropdown-visible-change="pageSizeDropdownVisibleChange">
<template #suffixIcon>
<GeneralIcon icon="arrowDown" class="text-gray-500 nc-select-page-size-expand-btn" />
</template>
</a-select>
</div>
<div v-if="showSizeChanger && !isMobileMode" class="text-gray-500">
<!-- Input and Button for entering a value -->
<input v-model.lazy="customPageValue" type="number" placeholder="Set custom page size" size="small" />
</div>
</div>
</template>

Expand Down