Merge branch 'main' into next
Some checks are pending
Build Docker Image / build-and-push (push) Waiting to run
Build Pro Image / build-and-push (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

This commit is contained in:
katherinehhh 2024-08-21 12:23:23 +08:00
commit e1c45a5edf
10 changed files with 137 additions and 21 deletions

View File

@ -38,7 +38,7 @@ function findArgs(ctx: Context) {
}
async function listWithPagination(ctx: Context) {
const { page = DEFAULT_PAGE, pageSize = DEFAULT_PER_PAGE } = ctx.action.params;
const { page = DEFAULT_PAGE, pageSize = DEFAULT_PER_PAGE, simplePaginate } = ctx.action.params;
const repository = getRepositoryFromParams(ctx);
@ -54,15 +54,24 @@ async function listWithPagination(ctx: Context) {
}
});
const [rows, count] = await repository.findAndCount(options);
if (simplePaginate) {
const rows = await repository.find(options);
ctx.body = {
rows,
page: Number(page),
pageSize: Number(pageSize),
};
} else {
const [rows, count] = await repository.findAndCount(options);
ctx.body = {
count,
rows,
page: Number(page),
pageSize: Number(pageSize),
totalPage: totalPage(count, pageSize),
};
ctx.body = {
count,
rows,
page: Number(page),
pageSize: Number(pageSize),
totalPage: totalPage(count, pageSize),
};
}
}
async function listWithNonPaged(ctx: Context) {

View File

@ -147,7 +147,7 @@ export const TableBlockProvider = withDynamicSchemaProps((props) => {
const fieldSchema = useFieldSchema();
const { getCollection, getCollectionField } = useCollectionManager_deprecated(props.dataSource);
const collection = getCollection(props.collection, props.dataSource);
const { treeTable } = fieldSchema?.['x-decorator-props'] || {};
const { treeTable, pagingMode } = fieldSchema?.['x-decorator-props'] || {};
const { params, parseVariableLoading } = useTableBlockParamsCompat(props);
let childrenColumnName = 'children';
@ -166,6 +166,11 @@ export const TableBlockProvider = withDynamicSchemaProps((props) => {
params['tree'] = true;
}
}
if (pagingMode === 'simplePaginate') {
params['simplePaginate'] = true;
} else {
delete params?.['simplePaginate'];
}
const form = useMemo(() => createForm(), [treeTable]);
// 在解析变量的时候不渲染,避免因为重复请求数据导致的资源浪费

View File

@ -966,6 +966,8 @@
"Search": "搜索",
"Clear default value": "清除默认值",
"Open in new window": "新窗口打开",
"Paging mode": "分页模式",
"Simple Paginate": "简单分页",
"Sorry, the page you visited does not exist.": "抱歉,你访问的页面不存在。",
"Set Template Engine": "设置模板引擎"
}

View File

@ -25,6 +25,7 @@ import { setDefaultSortingRulesSchemaSettingsItem } from '../../../../schema-set
import { setTheDataScopeSchemaSettingsItem } from '../../../../schema-settings/setTheDataScopeSchemaSettingsItem';
import { useBlockTemplateContext } from '../../../../schema-templates/BlockTemplateProvider';
import { setDataLoadingModeSettingsItem } from '../details-multi/setDataLoadingModeSettingsItem';
import { SchemaSettingsPagingMode } from '../../../../schema-settings/SchemaSettingsPagingMode';
export const tableBlockSettings = new SchemaSettings({
name: 'blockSettings:table',
@ -186,6 +187,10 @@ export const tableBlockSettings = new SchemaSettings({
};
},
},
{
name: 'pagingMode',
Component: SchemaSettingsPagingMode,
},
{
name: 'ConnectDataBlocks',
Component: SchemaSettingsConnectDataBlocks,

View File

@ -264,6 +264,7 @@ const TableIndex = (props) => {
const usePaginationProps = (pagination1, pagination2) => {
const { t } = useTranslation();
const field: any = useField();
const { token } = useToken();
const pagination = useMemo(
() => ({ ...pagination1, ...pagination2 }),
[JSON.stringify({ ...pagination1, ...pagination2 })],
@ -285,7 +286,7 @@ const usePaginationProps = (pagination1, pagination2) => {
} else {
return {
showTotal: false,
simple: { readOnly: true },
simple: true,
showTitle: false,
showSizeChanger: true,
hideOnSinglePage: false,
@ -296,6 +297,24 @@ const usePaginationProps = (pagination1, pagination2) => {
display: none !important;
}
`,
itemRender: (_, type, originalElement) => {
if (type === 'prev') {
return (
<div
style={{ display: 'flex' }}
className={css`
.ant-pagination-item-link {
min-width: ${token.controlHeight}px;
}
`}
>
{originalElement} <div style={{ marginLeft: '7px' }}>{current}</div>
</div>
);
} else {
return originalElement;
}
},
};
}
}, [pagination, t, showTotal]);

View File

@ -30,7 +30,7 @@ import {
} from '../../../schema-settings';
import { SchemaSettingsBlockHeightItem } from '../../../schema-settings/SchemaSettingsBlockHeightItem';
import { SchemaSettingsBlockTitleItem } from '../../../schema-settings/SchemaSettingsBlockTitleItem';
import { SchemaSettingsPagingMode } from '../../../schema-settings/SchemaSettingsPagingMode';
import { SchemaSettingsConnectDataBlocks } from '../../../schema-settings/SchemaSettingsConnectDataBlocks';
import { SchemaSettingsDataScope } from '../../../schema-settings/SchemaSettingsDataScope';
import { SchemaSettingsTemplate } from '../../../schema-settings/SchemaSettingsTemplate';
@ -303,6 +303,7 @@ export const TableBlockDesigner = () => {
});
}}
/>
<SchemaSettingsPagingMode />
<SchemaSettingsConnectDataBlocks type={FilterBlockType.TABLE} emptyDescription={t('No blocks to connect')} />
{supportTemplate && <SchemaSettingsDivider />}
{supportTemplate && (

View File

@ -219,6 +219,10 @@ describe('Table.settings', () => {
},
],
},
{
title: 'Paging mode',
type: 'select',
},
{
title: 'Save as template',
type: 'modal',

View File

@ -0,0 +1,61 @@
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { Field } from '@formily/core';
import { useField, useFieldSchema } from '@formily/react';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useTableBlockContext } from '../block-provider';
import { useDesignable } from '../schema-component/hooks/useDesignable';
import { SchemaSettingsSelectItem } from './SchemaSettings';
export function SchemaSettingsPagingMode() {
const field = useField<Field>();
const fieldSchema = useFieldSchema();
const { t } = useTranslation();
const { dn } = useDesignable();
const { service } = useTableBlockContext();
const options = [
{
value: 'default',
label: t('Default'),
},
{
value: 'simplePaginate',
label: t('Simple Paginate'),
},
];
return (
<SchemaSettingsSelectItem
key="paging-mode"
title={t('Paging mode')}
options={options}
value={field.decoratorProps.pagingMode || 'default'}
onChange={(pagingMode) => {
fieldSchema['x-decorator-props'].pagingMode = pagingMode;
const params = { ...service.params?.[0] };
if (pagingMode === 'simplePaginate') {
params['simplePaginate'] = true;
} else {
delete params['simplePaginate'];
}
service.run({ params });
field.decoratorProps.pagingMode = pagingMode;
dn.emit('patch', {
schema: {
['x-uid']: fieldSchema['x-uid'],
'x-decorator-props': fieldSchema['x-decorator-props'],
},
});
dn.refresh();
}}
/>
);
}

View File

@ -21,6 +21,7 @@ export * from './SchemaSettingsSortingRule';
export * from './SchemaSettingsTemplate';
export * from './SchemaSettingsBlockHeightItem';
export * from './setDefaultSortingRulesSchemaSettingsItem';
export * from './SchemaSettingsPagingMode';
export * from './setTheDataScopeSchemaSettingsItem';
export * from './SchemaSettingsRenderEngine';
export * from './hooks/useGetAriaLabelOfDesigner';

View File

@ -38,7 +38,7 @@ function findArgs(ctx: Context) {
}
async function listWithPagination(ctx: Context) {
const { page = 1, pageSize = 50 } = ctx.action.params;
const { page = 1, pageSize = 50, simplePaginate } = ctx.action.params;
const repository = ctx.getCurrentRepository();
@ -54,15 +54,24 @@ async function listWithPagination(ctx: Context) {
}
});
const [rows, count] = await repository.findAndCount(options);
if (simplePaginate) {
const rows = await repository.find(options);
ctx.body = {
rows,
page: Number(page),
pageSize: Number(pageSize),
};
} else {
const [rows, count] = await repository.findAndCount(options);
ctx.body = {
count,
rows,
page: Number(page),
pageSize: Number(pageSize),
totalPage: totalPage(count, pageSize),
};
ctx.body = {
count,
rows,
page: Number(page),
pageSize: Number(pageSize),
totalPage: totalPage(count, pageSize),
};
}
}
async function listWithNonPaged(ctx: Context) {