From 7c5df477f31f5b8b7afbd04da229c2ff827d1df4 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Sun, 25 Jun 2023 14:01:52 +0800 Subject: [PATCH] fix: deleting the last field from sub table, the entire table will be delete (#2077) * fix: deleting the last field from sub table, the entire table will be deleted * refactor: association select support data scope in sub-table * refactor: locale improve * style: sub-table style improve --- packages/core/client/src/locale/en_US.ts | 2 +- packages/core/client/src/locale/es_ES.ts | 2 +- packages/core/client/src/locale/ja_JP.ts | 2 +- packages/core/client/src/locale/pt_BR.ts | 2 +- packages/core/client/src/locale/ru_RU.ts | 2 +- packages/core/client/src/locale/zh_CN.ts | 2 +- .../antd/association-field/SubTable.tsx | 2 +- .../antd/table-v2/Table.Column.Designer.tsx | 47 ++++++++++++++++++- packages/plugins/client/src/locale/en-US.json | 2 +- packages/plugins/client/src/locale/es-ES.json | 2 +- packages/plugins/client/src/locale/pt-BR.json | 2 +- packages/plugins/client/src/locale/zh-CN.json | 2 +- 12 files changed, 56 insertions(+), 13 deletions(-) diff --git a/packages/core/client/src/locale/en_US.ts b/packages/core/client/src/locale/en_US.ts index 742fa725d..2b233b016 100644 --- a/packages/core/client/src/locale/en_US.ts +++ b/packages/core/client/src/locale/en_US.ts @@ -294,7 +294,7 @@ export default { "Quick upload": "Quick upload", "Select file": "Select file", "Subtable": "Sub-table", - "Subform": "Sub-form", + "Sub-form": "Sub-form", "Field mode":"Field mode", "Allow add new data":"Allow add new data", "Record picker": "Record picker", diff --git a/packages/core/client/src/locale/es_ES.ts b/packages/core/client/src/locale/es_ES.ts index aa37995da..a71546584 100644 --- a/packages/core/client/src/locale/es_ES.ts +++ b/packages/core/client/src/locale/es_ES.ts @@ -280,7 +280,7 @@ export default { "Display field title": "Mostrar título de campo", "Field component": "Componente del campo", "Subtable": "Subtabla", - "Subform": "Subformulario", + "Sub-form": "Subformulario", "Record picker": "Selector de registros", "Toggles the subfield mode": "Alterna el modo de subcampo", "Selector mode": "Modo selector", diff --git a/packages/core/client/src/locale/ja_JP.ts b/packages/core/client/src/locale/ja_JP.ts index b7f5717f0..ff2d7a95c 100644 --- a/packages/core/client/src/locale/ja_JP.ts +++ b/packages/core/client/src/locale/ja_JP.ts @@ -540,7 +540,7 @@ export default { "Quick upload": "クイックアップロード", "Select file": "ファイルを選択", "Subtable": "サブテーブル", - "Subform": "サブフォーム", + "Sub-form": "サブフォーム", "Sub-details":"サブリスト", "Field mode":"フィールドコンポーネント", "Allow add new data":"データの追加を許可", diff --git a/packages/core/client/src/locale/pt_BR.ts b/packages/core/client/src/locale/pt_BR.ts index d4d733660..5d436034b 100644 --- a/packages/core/client/src/locale/pt_BR.ts +++ b/packages/core/client/src/locale/pt_BR.ts @@ -244,7 +244,7 @@ export default { "Select file": "Selecionar arquivo", "Allow multiple": "Permitir múltiplos", "Subtable": "Subtabela", - "Subform": "Subformulário", + "Sub-form": "Subformulário", "Record picker": "Selecionador de registros", "Toggles the subfield mode": "Alterna o modo de subcampo", "Selector mode": "Modo de seleção", diff --git a/packages/core/client/src/locale/ru_RU.ts b/packages/core/client/src/locale/ru_RU.ts index c5d6293a2..228eb6d6e 100644 --- a/packages/core/client/src/locale/ru_RU.ts +++ b/packages/core/client/src/locale/ru_RU.ts @@ -478,7 +478,7 @@ export default { "Quick upload": "Быстрая загрузка", "Select file": "Выбрать файл", "Subtable": "Подтаблица", - "Subform": "Подформа", + "Sub-form": "Подформа", "Regular expression": "Образец", "Enabled languages": "Включенные языки", "View all plugins": "Посмотреть все плагины", diff --git a/packages/core/client/src/locale/zh_CN.ts b/packages/core/client/src/locale/zh_CN.ts index 2d9e62a01..cad3a8143 100644 --- a/packages/core/client/src/locale/zh_CN.ts +++ b/packages/core/client/src/locale/zh_CN.ts @@ -316,7 +316,7 @@ export default { "Quick upload": "快速上传", "Select file": "选择文件", "Subtable": "子表格", - "Subform": "子表单", + "Sub-form": "子表单", "Sub-details":"子详情", "Record picker": "数据选择器", "Toggles the subfield mode": "切换子字段模式", diff --git a/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx b/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx index 5fef2a409..86af6bc56 100644 --- a/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/SubTable.tsx @@ -75,7 +75,7 @@ export const SubTable: any = observer( .ant-table table { } td:not(.ant-table-selection-column) { - padding: 0 !important; + padding: 5px !important; } `} bordered diff --git a/packages/core/client/src/schema-component/antd/table-v2/Table.Column.Designer.tsx b/packages/core/client/src/schema-component/antd/table-v2/Table.Column.Designer.tsx index 93a7f4428..6da56e6a5 100644 --- a/packages/core/client/src/schema-component/antd/table-v2/Table.Column.Designer.tsx +++ b/packages/core/client/src/schema-component/antd/table-v2/Table.Column.Designer.tsx @@ -1,10 +1,13 @@ import { ISchema, useField, useFieldSchema } from '@formily/react'; import React from 'react'; +import { set } from 'lodash'; import { useTranslation } from 'react-i18next'; -import { useCollectionManager } from '../../../collection-manager'; +import { useCollectionManager, useCollectionFilterOptions } from '../../../collection-manager'; import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled } from '../../../schema-settings'; import { useCompile, useDesignable } from '../../hooks'; import { useAssociationFieldContext } from '../association-field/hooks'; +import { FilterDynamicComponent } from './FilterDynamicComponent'; +import { removeNullCondition } from '../filter'; const useLabelFields = (collectionName?: any) => { // 需要在组件顶层调用 @@ -39,6 +42,8 @@ export const TableColumnDesigner = (props) => { const isFileField = isFileCollection(targetCollection); const isSubTableColumn = ['QuickEdit', 'FormItem'].includes(fieldSchema['x-decorator']); const { currentMode, field: tableField } = useAssociationFieldContext(); + const defaultFilter = fieldSchema?.['x-component-props']?.service?.params?.filter || {}; + const dataSource = useCollectionFilterOptions(collectionField?.target); let readOnlyMode = 'editable'; if (fieldSchema['x-disabled'] === true) { readOnlyMode = 'readonly'; @@ -80,6 +85,44 @@ export const TableColumnDesigner = (props) => { dn.refresh(); }} /> + {currentMode && !field.readPretty && ( + FilterDynamicComponent({ ...props }), + }, + }, + }, + } as ISchema + } + onSubmit={({ filter }) => { + filter = removeNullCondition(filter); + set(field.componentProps, 'service.params.filter', filter); + fieldSchema['x-component-props'] = field.componentProps; + const path = field.path?.splice(field.path?.length - 1, 1); + (tableField as any)?.value.map((_, index) => { + field.form.query(`${path.concat(`${index}.` + fieldSchema.name)}`).take((f) => { + set(f.componentProps, 'service.params.filter', filter); + }); + }); + dn.emit('patch', { + schema: { + ['x-uid']: fieldSchema['x-uid'], + 'x-component-props': field.componentProps, + }, + }); + }} + /> + )} { )}