mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-02 12:18:15 +08:00
Merge branch 'main' into next
This commit is contained in:
commit
f58013ee06
@ -146,4 +146,52 @@ describe('list action', () => {
|
||||
expect(response.status).toEqual(200);
|
||||
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.
|
||||
*/
|
||||
|
||||
import { assign, isValidFilter } from '@nocobase/utils';
|
||||
import { Context } from '..';
|
||||
import { getRepositoryFromParams, pageArgsToLimitArgs } from '../utils';
|
||||
import { DEFAULT_PAGE, DEFAULT_PER_PAGE } from '../constants';
|
||||
@ -49,9 +48,13 @@ async function listWithPagination(ctx: Context) {
|
||||
});
|
||||
|
||||
if (simplePaginate) {
|
||||
options.limit = options.limit + 1;
|
||||
|
||||
const rows = await repository.find(options);
|
||||
|
||||
ctx.body = {
|
||||
rows,
|
||||
rows: rows.slice(0, pageSize),
|
||||
hasNext: rows.length > pageSize,
|
||||
page: Number(page),
|
||||
pageSize: Number(pageSize),
|
||||
};
|
||||
|
@ -81,8 +81,7 @@ const usePaginationProps = () => {
|
||||
const field = useField<ArrayField>();
|
||||
const { service, columnCount: _columnCount = defaultColumnCount } = useGridCardBlockContext();
|
||||
const meta = service?.data?.meta;
|
||||
const { count, pageSize, page } = meta || {};
|
||||
|
||||
const { count, pageSize, page, hasNext } = meta || {};
|
||||
if (count) {
|
||||
return {
|
||||
total: count || 0,
|
||||
@ -100,7 +99,7 @@ const usePaginationProps = () => {
|
||||
showTitle: false,
|
||||
showSizeChanger: true,
|
||||
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`
|
||||
.ant-pagination-simple-pager {
|
||||
display: none !important;
|
||||
|
@ -42,6 +42,7 @@ import { useToken } from '../__builtins__';
|
||||
import { SubFormProvider } from '../association-field/hooks';
|
||||
import { ColumnFieldProvider } from './components/ColumnFieldProvider';
|
||||
import { extractIndex, isCollectionFieldComponent, isColumnComponent } from './utils';
|
||||
import { useDataBlockRequest } from '../../../';
|
||||
const MemoizedAntdTable = React.memo(AntdTable);
|
||||
|
||||
const useArrayField = (props) => {
|
||||
@ -267,6 +268,9 @@ const usePaginationProps = (pagination1, pagination2) => {
|
||||
const { t } = useTranslation();
|
||||
const field: any = useField();
|
||||
const { token } = useToken();
|
||||
const { data } = useDataBlockRequest() || ({} as any);
|
||||
const { meta } = data || {};
|
||||
const { hasNext } = meta || {};
|
||||
const pagination = useMemo(
|
||||
() => ({ ...pagination1, ...pagination2 }),
|
||||
[JSON.stringify({ ...pagination1, ...pagination2 })],
|
||||
@ -295,7 +299,7 @@ const usePaginationProps = (pagination1, pagination2) => {
|
||||
showSizeChanger: true,
|
||||
hideOnSinglePage: false,
|
||||
...pagination,
|
||||
total: field.value?.length < pageSize ? pageSize * current : pageSize * current + 1,
|
||||
total: field.value?.length < pageSize || !hasNext ? pageSize * current : pageSize * current + 1,
|
||||
className: css`
|
||||
.ant-pagination-simple-pager {
|
||||
display: none !important;
|
||||
|
@ -57,9 +57,12 @@ async function listWithPagination(ctx: Context) {
|
||||
});
|
||||
|
||||
if (simplePaginate) {
|
||||
options.limit = options.limit + 1;
|
||||
|
||||
const rows = await repository.find(options);
|
||||
ctx.body = {
|
||||
rows,
|
||||
rows: rows.slice(0, pageSize),
|
||||
hasNext: rows.length > pageSize,
|
||||
page: Number(page),
|
||||
pageSize: Number(pageSize),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user