mirror of
https://github.com/nocobase/nocobase
synced 2024-11-14 22:36:35 +00:00
chore: simple paginate hasNext option (#5358)
Some checks are pending
auto-merge / push-commit (push) Waiting to run
Build Docker Image / build-and-push (push) Waiting to run
Build Pro Image / build-and-push (push) Waiting to run
deploy client docs / Build (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase Backend Test / sqlite-test (20, false) (push) Waiting to run
NocoBase Backend Test / sqlite-test (20, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, nocobase, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, nocobase, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, public, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, public, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, public, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, public, true) (push) Waiting to run
NocoBase Backend Test / mysql-test (20, false) (push) Waiting to run
NocoBase Backend Test / mysql-test (20, true) (push) Waiting to run
NocoBase Backend Test / mariadb-test (20, false) (push) Waiting to run
NocoBase Backend Test / mariadb-test (20, true) (push) Waiting to run
NocoBase FrontEnd Test / frontend-test (18) (push) Waiting to run
Test on Windows / build (push) Waiting to run
Some checks are pending
auto-merge / push-commit (push) Waiting to run
Build Docker Image / build-and-push (push) Waiting to run
Build Pro Image / build-and-push (push) Waiting to run
deploy client docs / Build (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase Backend Test / sqlite-test (20, false) (push) Waiting to run
NocoBase Backend Test / sqlite-test (20, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, nocobase, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, nocobase, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, public, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, public, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, public, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, public, true) (push) Waiting to run
NocoBase Backend Test / mysql-test (20, false) (push) Waiting to run
NocoBase Backend Test / mysql-test (20, true) (push) Waiting to run
NocoBase Backend Test / mariadb-test (20, false) (push) Waiting to run
NocoBase Backend Test / mariadb-test (20, true) (push) Waiting to run
NocoBase FrontEnd Test / frontend-test (18) (push) Waiting to run
Test on Windows / build (push) Waiting to run
* chore: simple paginate hasNext option * fix: usePaginationProps * fix: usePaginationProps --------- Co-authored-by: katherinehhh <katherine_15995@163.com>
This commit is contained in:
parent
39ab5d8350
commit
ae525e0e0b
@ -146,4 +146,52 @@ describe('list action', () => {
|
|||||||
expect(response.status).toEqual(200);
|
expect(response.status).toEqual(200);
|
||||||
expect(response.body.count).toEqual(0);
|
expect(response.body.count).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should list with simple paginate', async () => {
|
||||||
|
const Item = app.collection({
|
||||||
|
name: 'items',
|
||||||
|
simplePaginate: true,
|
||||||
|
fields: [{ type: 'string', name: 'name' }],
|
||||||
|
});
|
||||||
|
|
||||||
|
await app.db.sync();
|
||||||
|
|
||||||
|
await Item.repository.create({
|
||||||
|
values: [
|
||||||
|
{
|
||||||
|
name: 'item1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'item2',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'item3',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await app
|
||||||
|
.agent()
|
||||||
|
.resource('items')
|
||||||
|
.list({
|
||||||
|
fields: ['id'],
|
||||||
|
pageSize: 1,
|
||||||
|
page: 2,
|
||||||
|
});
|
||||||
|
|
||||||
|
const body = response.body;
|
||||||
|
expect(body.hasNext).toBeTruthy();
|
||||||
|
|
||||||
|
const lastPageResponse = await app
|
||||||
|
.agent()
|
||||||
|
.resource('items')
|
||||||
|
.list({
|
||||||
|
fields: ['id'],
|
||||||
|
pageSize: 1,
|
||||||
|
page: 3,
|
||||||
|
});
|
||||||
|
|
||||||
|
const lastPageBody = lastPageResponse.body;
|
||||||
|
expect(lastPageBody.hasNext).toBeFalsy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { assign, isValidFilter } from '@nocobase/utils';
|
|
||||||
import { Context } from '..';
|
import { Context } from '..';
|
||||||
import { getRepositoryFromParams, pageArgsToLimitArgs } from '../utils';
|
import { getRepositoryFromParams, pageArgsToLimitArgs } from '../utils';
|
||||||
import { DEFAULT_PAGE, DEFAULT_PER_PAGE } from '../constants';
|
import { DEFAULT_PAGE, DEFAULT_PER_PAGE } from '../constants';
|
||||||
@ -49,9 +48,13 @@ async function listWithPagination(ctx: Context) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (simplePaginate) {
|
if (simplePaginate) {
|
||||||
|
options.limit = options.limit + 1;
|
||||||
|
|
||||||
const rows = await repository.find(options);
|
const rows = await repository.find(options);
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
rows,
|
rows: rows.slice(0, pageSize),
|
||||||
|
hasNext: rows.length > pageSize,
|
||||||
page: Number(page),
|
page: Number(page),
|
||||||
pageSize: Number(pageSize),
|
pageSize: Number(pageSize),
|
||||||
};
|
};
|
||||||
|
@ -81,8 +81,7 @@ const usePaginationProps = () => {
|
|||||||
const field = useField<ArrayField>();
|
const field = useField<ArrayField>();
|
||||||
const { service, columnCount: _columnCount = defaultColumnCount } = useGridCardBlockContext();
|
const { service, columnCount: _columnCount = defaultColumnCount } = useGridCardBlockContext();
|
||||||
const meta = service?.data?.meta;
|
const meta = service?.data?.meta;
|
||||||
const { count, pageSize, page } = meta || {};
|
const { count, pageSize, page, hasNext } = meta || {};
|
||||||
|
|
||||||
if (count) {
|
if (count) {
|
||||||
return {
|
return {
|
||||||
total: count || 0,
|
total: count || 0,
|
||||||
@ -100,7 +99,7 @@ const usePaginationProps = () => {
|
|||||||
showTitle: false,
|
showTitle: false,
|
||||||
showSizeChanger: true,
|
showSizeChanger: true,
|
||||||
hideOnSinglePage: false,
|
hideOnSinglePage: false,
|
||||||
total: field.value?.length < pageSize ? pageSize * page : pageSize * page + 1,
|
total: field.value?.length < pageSize || !hasNext ? pageSize * page : pageSize * page + 1,
|
||||||
className: css`
|
className: css`
|
||||||
.ant-pagination-simple-pager {
|
.ant-pagination-simple-pager {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
|
@ -42,6 +42,7 @@ import { useToken } from '../__builtins__';
|
|||||||
import { SubFormProvider } from '../association-field/hooks';
|
import { SubFormProvider } from '../association-field/hooks';
|
||||||
import { ColumnFieldProvider } from './components/ColumnFieldProvider';
|
import { ColumnFieldProvider } from './components/ColumnFieldProvider';
|
||||||
import { extractIndex, isCollectionFieldComponent, isColumnComponent } from './utils';
|
import { extractIndex, isCollectionFieldComponent, isColumnComponent } from './utils';
|
||||||
|
import { useDataBlockRequest } from '../../../';
|
||||||
const MemoizedAntdTable = React.memo(AntdTable);
|
const MemoizedAntdTable = React.memo(AntdTable);
|
||||||
|
|
||||||
const useArrayField = (props) => {
|
const useArrayField = (props) => {
|
||||||
@ -267,6 +268,9 @@ const usePaginationProps = (pagination1, pagination2) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const field: any = useField();
|
const field: any = useField();
|
||||||
const { token } = useToken();
|
const { token } = useToken();
|
||||||
|
const { data } = useDataBlockRequest() || ({} as any);
|
||||||
|
const { meta } = data || {};
|
||||||
|
const { hasNext } = meta || {};
|
||||||
const pagination = useMemo(
|
const pagination = useMemo(
|
||||||
() => ({ ...pagination1, ...pagination2 }),
|
() => ({ ...pagination1, ...pagination2 }),
|
||||||
[JSON.stringify({ ...pagination1, ...pagination2 })],
|
[JSON.stringify({ ...pagination1, ...pagination2 })],
|
||||||
@ -295,7 +299,7 @@ const usePaginationProps = (pagination1, pagination2) => {
|
|||||||
showSizeChanger: true,
|
showSizeChanger: true,
|
||||||
hideOnSinglePage: false,
|
hideOnSinglePage: false,
|
||||||
...pagination,
|
...pagination,
|
||||||
total: field.value?.length < pageSize ? pageSize * current : pageSize * current + 1,
|
total: field.value?.length < pageSize || !hasNext ? pageSize * current : pageSize * current + 1,
|
||||||
className: css`
|
className: css`
|
||||||
.ant-pagination-simple-pager {
|
.ant-pagination-simple-pager {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
|
@ -57,9 +57,12 @@ async function listWithPagination(ctx: Context) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (simplePaginate) {
|
if (simplePaginate) {
|
||||||
|
options.limit = options.limit + 1;
|
||||||
|
|
||||||
const rows = await repository.find(options);
|
const rows = await repository.find(options);
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
rows,
|
rows: rows.slice(0, pageSize),
|
||||||
|
hasNext: rows.length > pageSize,
|
||||||
page: Number(page),
|
page: Number(page),
|
||||||
pageSize: Number(pageSize),
|
pageSize: Number(pageSize),
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user