From 8740d39e7062dbc17ccf7443d89da7d370558547 Mon Sep 17 00:00:00 2001 From: Junyi Date: Thu, 22 Aug 2024 14:57:46 +0800 Subject: [PATCH 1/3] fix(client): fix upload preview image (#5102) --- .../schema-component/antd/upload/shared.ts | 54 +++---------------- 1 file changed, 6 insertions(+), 48 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/upload/shared.ts b/packages/core/client/src/schema-component/antd/upload/shared.ts index 4a04520882..c979136edc 100644 --- a/packages/core/client/src/schema-component/antd/upload/shared.ts +++ b/packages/core/client/src/schema-component/antd/upload/shared.ts @@ -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'], + }), }; }; From a0643713dbe6e87bd5cf33ba973a2ccd580616f0 Mon Sep 17 00:00:00 2001 From: Katherine Date: Thu, 22 Aug 2024 15:06:02 +0800 Subject: [PATCH 2/3] fix: button field assignment to only update visible fields (#5104) --- .../src/schema-settings/SchemaSettings.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/core/client/src/schema-settings/SchemaSettings.tsx b/packages/core/client/src/schema-settings/SchemaSettings.tsx index 980254f56e..8e45c1d316 100644 --- a/packages/core/client/src/schema-settings/SchemaSettings.tsx +++ b/packages/core/client/src/schema-settings/SchemaSettings.tsx @@ -636,8 +636,20 @@ export const SchemaSettingsActionModalItem: FC { await form.submit(); - onSubmit?.(cloneDeep(form.values)); - setVisible(false); + try { + 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); + } }, [form, onSubmit]); const openAssignedFieldValueHandler = useCallback(async () => { From 039bc76a97ca31e0a286e141a8a1e853719b19e3 Mon Sep 17 00:00:00 2001 From: Katherine Date: Thu, 22 Aug 2024 15:30:36 +0800 Subject: [PATCH 3/3] refactor: collection support simplePaginate (#5099) * refactor: collection support simplePaginate * refactor: locale improve * fix: test * chore: simple paginate option * chore: test --------- Co-authored-by: Chareice --- packages/core/actions/src/actions/list.ts | 4 +- .../src/block-provider/TableBlockProvider.tsx | 5 -- .../collection-manager/templates/general.tsx | 1 + .../templates/properties/index.ts | 8 +++ packages/core/client/src/locale/zh-CN.json | 3 +- .../data-blocks/table/tableBlockSettings.tsx | 5 -- .../antd/table-v2/TableBlockDesigner.tsx | 2 - .../__tests__/Table.settings.test.tsx | 4 -- .../SchemaSettingsPagingMode.tsx | 61 ------------------- .../core/client/src/schema-settings/index.ts | 1 - .../src/default-actions/list.ts | 4 +- packages/core/database/src/collection.ts | 2 + 12 files changed, 18 insertions(+), 82 deletions(-) delete mode 100644 packages/core/client/src/schema-settings/SchemaSettingsPagingMode.tsx diff --git a/packages/core/actions/src/actions/list.ts b/packages/core/actions/src/actions/list.ts index 5e42b26765..47a50ab55d 100644 --- a/packages/core/actions/src/actions/list.ts +++ b/packages/core/actions/src/actions/list.ts @@ -38,10 +38,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), diff --git a/packages/core/client/src/block-provider/TableBlockProvider.tsx b/packages/core/client/src/block-provider/TableBlockProvider.tsx index 241e420e00..a7ebd57ec6 100644 --- a/packages/core/client/src/block-provider/TableBlockProvider.tsx +++ b/packages/core/client/src/block-provider/TableBlockProvider.tsx @@ -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]); // 在解析变量的时候不渲染,避免因为重复请求数据导致的资源浪费 diff --git a/packages/core/client/src/collection-manager/templates/general.tsx b/packages/core/client/src/collection-manager/templates/general.tsx index 7d4c09e9cc..1043e38e32 100644 --- a/packages/core/client/src/collection-manager/templates/general.tsx +++ b/packages/core/client/src/collection-manager/templates/general.tsx @@ -24,6 +24,7 @@ export class GeneralCollectionTemplate extends CollectionTemplate { 'inherits', 'category', 'description', + 'simplePaginate', 'presetFields', ); } diff --git a/packages/core/client/src/collection-manager/templates/properties/index.ts b/packages/core/client/src/collection-manager/templates/properties/index.ts index 4902326c05..b63c21157b 100644 --- a/packages/core/client/src/collection-manager/templates/properties/index.ts +++ b/packages/core/client/src/collection-manager/templates/properties/index.ts @@ -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[]) => { diff --git a/packages/core/client/src/locale/zh-CN.json b/packages/core/client/src/locale/zh-CN.json index 8d68823ba4..1cb17ab280 100644 --- a/packages/core/client/src/locale/zh-CN.json +++ b/packages/core/client/src/locale/zh-CN.json @@ -967,6 +967,5 @@ "Open in new window": "新窗口打开", "is none of": "不包含任何一个", "is any of": "包含任何一个", - "Paging mode": "分页模式", - "Simple Paginate": "简单分页" + "Use simple pagination mode": "使用简单分页模式" } diff --git a/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx b/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx index d49d7198ab..f5c7e3b8e7 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx +++ b/packages/core/client/src/modules/blocks/data-blocks/table/tableBlockSettings.tsx @@ -24,7 +24,6 @@ import { setDataLoadingModeSettingsItem } from '../details-multi/setDataLoadingM import { setDefaultSortingRulesSchemaSettingsItem } from '../../../../schema-settings/setDefaultSortingRulesSchemaSettingsItem'; import { setTheDataScopeSchemaSettingsItem } from '../../../../schema-settings/setTheDataScopeSchemaSettingsItem'; import { createSwitchSettingsItem } from '../../../../application/schema-settings/utils'; -import { SchemaSettingsPagingMode } from '../../../../schema-settings/SchemaSettingsPagingMode'; export const tableBlockSettings = new SchemaSettings({ name: 'blockSettings:table', @@ -186,10 +185,6 @@ export const tableBlockSettings = new SchemaSettings({ }; }, }, - { - name: 'pagingMode', - Component: SchemaSettingsPagingMode, - }, { name: 'ConnectDataBlocks', Component: SchemaSettingsConnectDataBlocks, diff --git a/packages/core/client/src/schema-component/antd/table-v2/TableBlockDesigner.tsx b/packages/core/client/src/schema-component/antd/table-v2/TableBlockDesigner.tsx index c2ba2e04db..bb1225a1e4 100644 --- a/packages/core/client/src/schema-component/antd/table-v2/TableBlockDesigner.tsx +++ b/packages/core/client/src/schema-component/antd/table-v2/TableBlockDesigner.tsx @@ -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'; @@ -301,7 +300,6 @@ export const TableBlockDesigner = () => { }); }} /> - {supportTemplate && } {supportTemplate && ( diff --git a/packages/core/client/src/schema-component/antd/table-v2/__tests__/Table.settings.test.tsx b/packages/core/client/src/schema-component/antd/table-v2/__tests__/Table.settings.test.tsx index 92d16a9924..729a7cc4f8 100644 --- a/packages/core/client/src/schema-component/antd/table-v2/__tests__/Table.settings.test.tsx +++ b/packages/core/client/src/schema-component/antd/table-v2/__tests__/Table.settings.test.tsx @@ -219,10 +219,6 @@ describe('Table.settings', () => { }, ], }, - { - title: 'Paging mode', - type: 'select', - }, { title: 'Save as template', type: 'modal', diff --git a/packages/core/client/src/schema-settings/SchemaSettingsPagingMode.tsx b/packages/core/client/src/schema-settings/SchemaSettingsPagingMode.tsx deleted file mode 100644 index 35fe1b6c01..0000000000 --- a/packages/core/client/src/schema-settings/SchemaSettingsPagingMode.tsx +++ /dev/null @@ -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(); - 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 ( - { - 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(); - }} - /> - ); -} diff --git a/packages/core/client/src/schema-settings/index.ts b/packages/core/client/src/schema-settings/index.ts index dc2b29d6e9..4146bb27cb 100644 --- a/packages/core/client/src/schema-settings/index.ts +++ b/packages/core/client/src/schema-settings/index.ts @@ -21,7 +21,6 @@ export * from './SchemaSettingsSortingRule'; export * from './SchemaSettingsTemplate'; export * from './SchemaSettingsBlockHeightItem'; export * from './setDefaultSortingRulesSchemaSettingsItem'; -export * from './SchemaSettingsPagingMode'; export * from './setTheDataScopeSchemaSettingsItem'; export * from './hooks/useGetAriaLabelOfDesigner'; export * from './hooks/useIsAllowToSetDefaultValue'; diff --git a/packages/core/data-source-manager/src/default-actions/list.ts b/packages/core/data-source-manager/src/default-actions/list.ts index 310cdbef7c..a1de82d7ea 100644 --- a/packages/core/data-source-manager/src/default-actions/list.ts +++ b/packages/core/data-source-manager/src/default-actions/list.ts @@ -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), diff --git a/packages/core/database/src/collection.ts b/packages/core/database/src/collection.ts index 688b5c8a18..6addd9c385 100644 --- a/packages/core/database/src/collection.ts +++ b/packages/core/database/src/collection.ts @@ -115,6 +115,8 @@ export interface CollectionOptions extends Omit tree?: string; template?: string; + simplePaginate?: boolean; + /** * where is the collection from *