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
This commit is contained in:
katherinehhh 2023-06-25 14:01:52 +08:00 committed by GitHub
parent 2bbba7b7fa
commit 7c5df477f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 56 additions and 13 deletions

View File

@ -294,7 +294,7 @@ export default {
"Quick upload": "Quick upload", "Quick upload": "Quick upload",
"Select file": "Select file", "Select file": "Select file",
"Subtable": "Sub-table", "Subtable": "Sub-table",
"Subform": "Sub-form", "Sub-form": "Sub-form",
"Field mode":"Field mode", "Field mode":"Field mode",
"Allow add new data":"Allow add new data", "Allow add new data":"Allow add new data",
"Record picker": "Record picker", "Record picker": "Record picker",

View File

@ -280,7 +280,7 @@ export default {
"Display field title": "Mostrar título de campo", "Display field title": "Mostrar título de campo",
"Field component": "Componente del campo", "Field component": "Componente del campo",
"Subtable": "Subtabla", "Subtable": "Subtabla",
"Subform": "Subformulario", "Sub-form": "Subformulario",
"Record picker": "Selector de registros", "Record picker": "Selector de registros",
"Toggles the subfield mode": "Alterna el modo de subcampo", "Toggles the subfield mode": "Alterna el modo de subcampo",
"Selector mode": "Modo selector", "Selector mode": "Modo selector",

View File

@ -540,7 +540,7 @@ export default {
"Quick upload": "クイックアップロード", "Quick upload": "クイックアップロード",
"Select file": "ファイルを選択", "Select file": "ファイルを選択",
"Subtable": "サブテーブル", "Subtable": "サブテーブル",
"Subform": "サブフォーム", "Sub-form": "サブフォーム",
"Sub-details":"サブリスト", "Sub-details":"サブリスト",
"Field mode":"フィールドコンポーネント", "Field mode":"フィールドコンポーネント",
"Allow add new data":"データの追加を許可", "Allow add new data":"データの追加を許可",

View File

@ -244,7 +244,7 @@ export default {
"Select file": "Selecionar arquivo", "Select file": "Selecionar arquivo",
"Allow multiple": "Permitir múltiplos", "Allow multiple": "Permitir múltiplos",
"Subtable": "Subtabela", "Subtable": "Subtabela",
"Subform": "Subformulário", "Sub-form": "Subformulário",
"Record picker": "Selecionador de registros", "Record picker": "Selecionador de registros",
"Toggles the subfield mode": "Alterna o modo de subcampo", "Toggles the subfield mode": "Alterna o modo de subcampo",
"Selector mode": "Modo de seleção", "Selector mode": "Modo de seleção",

View File

@ -478,7 +478,7 @@ export default {
"Quick upload": "Быстрая загрузка", "Quick upload": "Быстрая загрузка",
"Select file": "Выбрать файл", "Select file": "Выбрать файл",
"Subtable": "Подтаблица", "Subtable": "Подтаблица",
"Subform": "Подформа", "Sub-form": "Подформа",
"Regular expression": "Образец", "Regular expression": "Образец",
"Enabled languages": "Включенные языки", "Enabled languages": "Включенные языки",
"View all plugins": "Посмотреть все плагины", "View all plugins": "Посмотреть все плагины",

View File

@ -316,7 +316,7 @@ export default {
"Quick upload": "快速上传", "Quick upload": "快速上传",
"Select file": "选择文件", "Select file": "选择文件",
"Subtable": "子表格", "Subtable": "子表格",
"Subform": "子表单", "Sub-form": "子表单",
"Sub-details":"子详情", "Sub-details":"子详情",
"Record picker": "数据选择器", "Record picker": "数据选择器",
"Toggles the subfield mode": "切换子字段模式", "Toggles the subfield mode": "切换子字段模式",

View File

@ -75,7 +75,7 @@ export const SubTable: any = observer(
.ant-table table { .ant-table table {
} }
td:not(.ant-table-selection-column) { td:not(.ant-table-selection-column) {
padding: 0 !important; padding: 5px !important;
} }
`} `}
bordered bordered

View File

@ -1,10 +1,13 @@
import { ISchema, useField, useFieldSchema } from '@formily/react'; import { ISchema, useField, useFieldSchema } from '@formily/react';
import React from 'react'; import React from 'react';
import { set } from 'lodash';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useCollectionManager } from '../../../collection-manager'; import { useCollectionManager, useCollectionFilterOptions } from '../../../collection-manager';
import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled } from '../../../schema-settings'; import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled } from '../../../schema-settings';
import { useCompile, useDesignable } from '../../hooks'; import { useCompile, useDesignable } from '../../hooks';
import { useAssociationFieldContext } from '../association-field/hooks'; import { useAssociationFieldContext } from '../association-field/hooks';
import { FilterDynamicComponent } from './FilterDynamicComponent';
import { removeNullCondition } from '../filter';
const useLabelFields = (collectionName?: any) => { const useLabelFields = (collectionName?: any) => {
// 需要在组件顶层调用 // 需要在组件顶层调用
@ -39,6 +42,8 @@ export const TableColumnDesigner = (props) => {
const isFileField = isFileCollection(targetCollection); const isFileField = isFileCollection(targetCollection);
const isSubTableColumn = ['QuickEdit', 'FormItem'].includes(fieldSchema['x-decorator']); const isSubTableColumn = ['QuickEdit', 'FormItem'].includes(fieldSchema['x-decorator']);
const { currentMode, field: tableField } = useAssociationFieldContext(); const { currentMode, field: tableField } = useAssociationFieldContext();
const defaultFilter = fieldSchema?.['x-component-props']?.service?.params?.filter || {};
const dataSource = useCollectionFilterOptions(collectionField?.target);
let readOnlyMode = 'editable'; let readOnlyMode = 'editable';
if (fieldSchema['x-disabled'] === true) { if (fieldSchema['x-disabled'] === true) {
readOnlyMode = 'readonly'; readOnlyMode = 'readonly';
@ -80,6 +85,44 @@ export const TableColumnDesigner = (props) => {
dn.refresh(); dn.refresh();
}} }}
/> />
{currentMode && !field.readPretty && (
<SchemaSettings.ModalItem
title={t('Set the data scope')}
schema={
{
type: 'object',
title: t('Set the data scope'),
properties: {
filter: {
default: defaultFilter,
enum: dataSource,
'x-component': 'Filter',
'x-component-props': {
dynamicComponent: (props) => 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,
},
});
}}
/>
)}
<SchemaSettings.ModalItem <SchemaSettings.ModalItem
title={t('Column width')} title={t('Column width')}
schema={ schema={
@ -282,7 +325,7 @@ export const TableColumnDesigner = (props) => {
)} )}
<SchemaSettings.Divider /> <SchemaSettings.Divider />
<SchemaSettings.Remove <SchemaSettings.Remove
removeParentsIfNoChildren removeParentsIfNoChildren={!isSubTableColumn}
breakRemoveOn={{ breakRemoveOn={{
'x-component': 'Grid', 'x-component': 'Grid',
}} }}

View File

@ -234,7 +234,7 @@
"Quick upload": "Quick upload", "Quick upload": "Quick upload",
"Select file": "Select file", "Select file": "Select file",
"Subtable": "Subtable", "Subtable": "Subtable",
"Subform": "Sub-form", "Sub-form": "Sub-form",
"Record picker": "Record picker", "Record picker": "Record picker",
"Toggles the subfield mode": "Toggles the subfield mode", "Toggles the subfield mode": "Toggles the subfield mode",
"Selector mode": "Selector mode", "Selector mode": "Selector mode",

View File

@ -284,7 +284,7 @@
"Display field title": "Mostrar título de campo", "Display field title": "Mostrar título de campo",
"Field component": "Componente del campo", "Field component": "Componente del campo",
"Subtable": "Subtabla", "Subtable": "Subtabla",
"Subform": "Subformulario", "Sub-form": "Subformulario",
"Record picker": "Selector de registros", "Record picker": "Selector de registros",
"Toggles the subfield mode": "Alterna el modo de subcampo", "Toggles the subfield mode": "Alterna el modo de subcampo",
"Selector mode": "Modo selector", "Selector mode": "Modo selector",

View File

@ -218,7 +218,7 @@
"Select file": "Selecionar arquivo", "Select file": "Selecionar arquivo",
"Allow multiple": "Permitir múltiplos", "Allow multiple": "Permitir múltiplos",
"Subtable": "Subtabela", "Subtable": "Subtabela",
"Subform": "Subformulário", "Sub-form": "Subformulário",
"Record picker": "Selecionador de registro", "Record picker": "Selecionador de registro",
"Toggles the subfield mode": "Alterna o modo de subcampo", "Toggles the subfield mode": "Alterna o modo de subcampo",
"Selector mode": "Modo de seleção", "Selector mode": "Modo de seleção",

View File

@ -234,7 +234,7 @@
"Quick upload": "快速上传", "Quick upload": "快速上传",
"Select file": "选择文件", "Select file": "选择文件",
"Subtable": "子表格", "Subtable": "子表格",
"Subform": "子表单", "Sub-form": "子表单",
"Record picker": "数据选择器", "Record picker": "数据选择器",
"Toggles the subfield mode": "切换子字段模式", "Toggles the subfield mode": "切换子字段模式",
"Selector mode": "选择器模式", "Selector mode": "选择器模式",