Merge branch 'main' into next

This commit is contained in:
katherinehhh 2024-08-22 16:57:20 +08:00
commit c66cf82d9f
14 changed files with 33 additions and 131 deletions

View File

@ -30,10 +30,12 @@ function findArgs(ctx: Context) {
}
async function listWithPagination(ctx: Context) {
const { page = DEFAULT_PAGE, pageSize = DEFAULT_PER_PAGE, simplePaginate } = ctx.action.params;
const { page = DEFAULT_PAGE, pageSize = DEFAULT_PER_PAGE } = ctx.action.params;
const repository = getRepositoryFromParams(ctx);
const { simplePaginate } = repository.collection?.options || {};
const options = {
context: ctx,
...findArgs(ctx),

View File

@ -166,11 +166,6 @@ 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

@ -24,6 +24,7 @@ export class GeneralCollectionTemplate extends CollectionTemplate {
'inherits',
'category',
'description',
'simplePaginate',
'presetFields',
);
}

View File

@ -60,6 +60,13 @@ export const defaultConfigurableProperties = {
'x-decorator': 'FormItem',
'x-component': 'Input.TextArea',
},
simplePaginate: {
'x-content': '{{t("Use simple pagination mode")}}',
type: 'string',
name: 'simplePaginate',
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
},
presetFields: {
title: '{{t("Preset fields")}}',
type: 'void',
@ -92,6 +99,7 @@ export type DefaultConfigurableKeys =
| 'updatedAt'
| 'sortable'
| 'description'
| 'simplePaginate'
| 'presetFields';
export const getConfigurableProperties = (...keys: DefaultConfigurableKeys[]) => {

View File

@ -968,8 +968,7 @@
"Open in new window": "新窗口打开",
"is none of": "不包含任何一个",
"is any of": "包含任何一个",
"Paging mode": "分页模式",
"Simple Paginate": "简单分页",
"Use simple pagination mode": "使用简单分页模式",
"Sorry, the page you visited does not exist.": "抱歉,你访问的页面不存在。",
"Set Template Engine": "设置模板引擎"
}

View File

@ -25,7 +25,6 @@ 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',
@ -187,10 +186,6 @@ export const tableBlockSettings = new SchemaSettings({
};
},
},
{
name: 'pagingMode',
Component: SchemaSettingsPagingMode,
},
{
name: 'ConnectDataBlocks',
Component: SchemaSettingsConnectDataBlocks,

View File

@ -30,7 +30,6 @@ 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,7 +302,6 @@ export const TableBlockDesigner = () => {
});
}}
/>
<SchemaSettingsPagingMode />
<SchemaSettingsConnectDataBlocks type={FilterBlockType.TABLE} emptyDescription={t('No blocks to connect')} />
{supportTemplate && <SchemaSettingsDivider />}
{supportTemplate && (

View File

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

View File

@ -26,51 +26,7 @@ export const isPdf = (file) => {
return match(file.mimetype || file.type, 'application/pdf');
};
export const toMap = (fileList: any) => {
if (!fileList) {
return [];
}
if (typeof fileList !== 'object') {
return [];
}
let list = fileList;
if (!Array.isArray(fileList)) {
if (Object.keys({ ...fileList }).length === 0) {
return [];
}
list = [fileList];
}
return list.map((item) => {
return [item.id || item.uid, toItem(item)];
});
};
export const toImages = (fileList) => {
if (!fileList) {
return [];
}
if (typeof fileList !== 'object') {
return [];
}
if (Object.keys(fileList).length === 0) {
return [];
}
let list = fileList;
if (!Array.isArray(fileList) && typeof fileList === 'object') {
list = [fileList];
}
return list.map((item) => {
return {
...item,
title: item.title || item.name,
imageUrl: getImageByUrl(item.url, {
exclude: ['.png', '.jpg', '.jpeg', '.gif'],
}),
};
});
};
export const toArr = (value) => {
const toArr = (value) => {
if (!isValid(value)) {
return [];
}
@ -210,9 +166,11 @@ export const toItem = (file) => {
...file,
id: file.id || file.uid,
title: file.title || file.name,
imageUrl: getImageByUrl(file.url, {
exclude: ['.png', '.jpg', '.jpeg', '.gif'],
}),
imageUrl: isImage(file)
? file.url
: getImageByUrl(file.url, {
exclude: ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp', '.bmp', '.ico'],
}),
};
};

View File

@ -653,7 +653,15 @@ export const SchemaSettingsActionModalItem: FC<SchemaSettingsActionModalItemProp
const submitHandler = useCallback(async () => {
await form.submit();
try {
await onSubmit?.(cloneDeep(form.values));
const allValues = form.values;
// 过滤掉那些在表单 Schema 中未定义的字段
const visibleValues = Object.keys(allValues).reduce((result, key) => {
if (form.query(key).take()) {
result[key] = allValues[key];
}
return result;
}, {});
await onSubmit?.(cloneDeep(visibleValues));
setVisible(false);
} catch (err) {
console.error(err);

View File

@ -1,61 +0,0 @@
/**
* 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,7 +21,6 @@ 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,10 +38,12 @@ function findArgs(ctx: Context) {
}
async function listWithPagination(ctx: Context) {
const { page = 1, pageSize = 50, simplePaginate } = ctx.action.params;
const { page = 1, pageSize = 50 } = ctx.action.params;
const repository = ctx.getCurrentRepository();
const { simplePaginate } = repository.collection?.options || {};
const options = {
context: ctx,
...findArgs(ctx),

View File

@ -114,6 +114,8 @@ export interface CollectionOptions extends Omit<ModelOptions, 'name' | 'hooks'>
tree?: string;
template?: string;
simplePaginate?: boolean;
/**
* where is the collection from
*