From 975b7dfe935f646b9833f8a555b9676e5281cadb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B0=8F=E6=96=90?= Date: Mon, 15 May 2023 09:34:14 +0800 Subject: [PATCH] fix: action error when field deleted (#1849) * fix: action error when field deleted * fix: delete field cannot set dynamic value --- .../collection-manager/CollectionField.tsx | 2 +- .../CollectionFieldProvider.tsx | 2 +- packages/core/client/src/locale/en_US.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/tr_TR.ts | 2 +- packages/core/client/src/locale/zh_CN.ts | 2 +- .../buttons/TableActionColumnInitializers.tsx | 2 +- .../components/BulkEditField.tsx | 5 +-- .../components/DeletedField.tsx | 7 ++++ .../assigned-field/AssignedField.tsx | 35 ++++++++++++------- 12 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 packages/core/client/src/schema-initializer/components/DeletedField.tsx diff --git a/packages/core/client/src/collection-manager/CollectionField.tsx b/packages/core/client/src/collection-manager/CollectionField.tsx index d1a56a93b..fe38e601b 100644 --- a/packages/core/client/src/collection-manager/CollectionField.tsx +++ b/packages/core/client/src/collection-manager/CollectionField.tsx @@ -101,7 +101,7 @@ export const InternalFallbackField = () => { // 当字段被删除时,显示一个提示占位符 const DeletedField = () => { const { t } = useTranslation(); - return
{t('The field has bee deleted')}
; + return
{t('The field has been deleted')}
; }; export const CollectionField = connect((props) => { diff --git a/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx b/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx index d5e800331..aec1f6496 100644 --- a/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx +++ b/packages/core/client/src/collection-manager/CollectionFieldProvider.tsx @@ -9,7 +9,7 @@ export const CollectionFieldProvider: React.FC<{ field?: CollectionFieldOptions; fallback?: React.ReactElement; }> = (props) => { - const { name, field, children, fallback } = props; + const { name, field, children, fallback = null } = props; const fieldSchema = useFieldSchema(); const { getField } = useCollection(); const { getCollectionJoinField } = useCollectionManager(); diff --git a/packages/core/client/src/locale/en_US.ts b/packages/core/client/src/locale/en_US.ts index 9091fefaf..304d51901 100644 --- a/packages/core/client/src/locale/en_US.ts +++ b/packages/core/client/src/locale/en_US.ts @@ -504,7 +504,7 @@ export default { "Skip required validation": "Skip required validation", "Form values": "Form values", "Fields values": "Fields values", - 'The field has bee deleted': 'The field has bee deleted', + 'The field has been deleted': 'The field has been deleted', "When submitting the following fields, the saved values are": "When submitting the following fields, the saved values are", "After successful submission": "After successful submission", "Then": "Then", diff --git a/packages/core/client/src/locale/ja_JP.ts b/packages/core/client/src/locale/ja_JP.ts index 81aec0762..28ed1653d 100644 --- a/packages/core/client/src/locale/ja_JP.ts +++ b/packages/core/client/src/locale/ja_JP.ts @@ -421,7 +421,7 @@ export default { "Skip required validation": "必須のバリデーションをスキップ", "Form values": "フォームの値", "Fields values": "フィールドの値", - 'The field has bee deleted': 'フィールドが削除されました', + 'The field has been deleted': 'フィールドが削除されました', "When submitting the following fields, the saved values are": "次のフィールドを送信すると、保存された値は", "After successful submission": "送信が成功した後", "Then": "その後", diff --git a/packages/core/client/src/locale/pt_BR.ts b/packages/core/client/src/locale/pt_BR.ts index 31b4ee4f9..af92d9458 100644 --- a/packages/core/client/src/locale/pt_BR.ts +++ b/packages/core/client/src/locale/pt_BR.ts @@ -461,7 +461,7 @@ export default { "Skip required validation": "Ignorar validação obrigatória", "Form values": "Valores do formulário", "Fields values": "campo removido", - 'The field has bee deleted': 'O campo foi excluído', + 'The field has been deleted': 'O campo foi excluído', "When submitting the following fields, the saved values are": "Ao enviar os seguintes campos, os valores salvos são", "After successful submission": "Depois do envio bem-sucedido", "Then": "Então", diff --git a/packages/core/client/src/locale/ru_RU.ts b/packages/core/client/src/locale/ru_RU.ts index a267f5bba..e1ed4b6e8 100644 --- a/packages/core/client/src/locale/ru_RU.ts +++ b/packages/core/client/src/locale/ru_RU.ts @@ -363,7 +363,7 @@ export default { "Skip required validation": "Пропустить обязатеьную проверку", "Form values": "Значения формы", "Fields values": "Значения полей", - 'The field has bee deleted': 'Поле было удалено', + 'The field has been deleted': 'Поле было удалено', "When submitting the following fields, the saved values are": "При отправке следующих полей, сохраненные значения такие", "After successful submission": "После удачной отправки", "Then": "Затем", diff --git a/packages/core/client/src/locale/tr_TR.ts b/packages/core/client/src/locale/tr_TR.ts index 918af306c..c5a9c41f6 100644 --- a/packages/core/client/src/locale/tr_TR.ts +++ b/packages/core/client/src/locale/tr_TR.ts @@ -362,7 +362,7 @@ export default { "Skip required validation": "Zorunlu alan kontrollerini atla", "Form values": "Form değerleri", "Fields values": "Alanların değerleri", - 'The field has bee deleted': 'Alan silindi', + 'The field has been deleted': 'Alan silindi', "When submitting the following fields, the saved values are": "Aşağıdaki alanlar gönderilirken kaydedilen değerler", "After successful submission": "Başarılı gönderimden sonra", "Then": "Then", diff --git a/packages/core/client/src/locale/zh_CN.ts b/packages/core/client/src/locale/zh_CN.ts index a59fbd4fb..8a606af13 100644 --- a/packages/core/client/src/locale/zh_CN.ts +++ b/packages/core/client/src/locale/zh_CN.ts @@ -543,7 +543,7 @@ export default { 'Skip required validation': '跳过必填校验', 'Form values': '表单值', 'Fields values': '字段值', - 'The field has bee deleted': '字段已删除', + 'The field has been deleted': '字段已删除', 'When submitting the following fields, the saved values are': '提交以下字段时,保存的值为', 'After successful submission': '提交成功后', 'Then': '然后', diff --git a/packages/core/client/src/schema-initializer/buttons/TableActionColumnInitializers.tsx b/packages/core/client/src/schema-initializer/buttons/TableActionColumnInitializers.tsx index 78c121f53..bc52bdf9c 100644 --- a/packages/core/client/src/schema-initializer/buttons/TableActionColumnInitializers.tsx +++ b/packages/core/client/src/schema-initializer/buttons/TableActionColumnInitializers.tsx @@ -191,7 +191,7 @@ export const TableActionColumnInitializers = (props: any) => { title: '{{t("Update record")}}', component: 'CustomizeActionInitializer', schema: { - title: '{{ t("Update record") }}', + title: '{{t("Update record")}}', 'x-component': 'Action.Link', 'x-action': 'customize:update', 'x-decorator': 'ACLActionProvider', diff --git a/packages/core/client/src/schema-initializer/components/BulkEditField.tsx b/packages/core/client/src/schema-initializer/components/BulkEditField.tsx index f860d8ea9..855197637 100644 --- a/packages/core/client/src/schema-initializer/components/BulkEditField.tsx +++ b/packages/core/client/src/schema-initializer/components/BulkEditField.tsx @@ -8,6 +8,7 @@ import { useTranslation } from 'react-i18next'; import { useFormBlockContext } from '../../block-provider'; import { CollectionFieldProvider, useCollection, useCollectionField } from '../../collection-manager'; import { useCompile, useComponent } from '../../schema-component'; +import { DeletedField } from './DeletedField'; const InternalField: React.FC = (props) => { const field = useField(); @@ -65,7 +66,7 @@ const InternalField: React.FC = (props) => { const CollectionField = connect((props) => { const fieldSchema = useFieldSchema(); return ( - + }> ); @@ -85,7 +86,7 @@ export const BulkEditField = (props: any) => { const [type, setType] = useState(BulkEditFormItemValueType.RemainsTheSame); const [value, setValue] = useState(null); const { getField } = useCollection(); - const collectionField = getField(fieldSchema.name); + const collectionField = getField(fieldSchema.name) || {}; useEffect(() => { field.value = { [type]: value }; diff --git a/packages/core/client/src/schema-initializer/components/DeletedField.tsx b/packages/core/client/src/schema-initializer/components/DeletedField.tsx new file mode 100644 index 000000000..ba341eb15 --- /dev/null +++ b/packages/core/client/src/schema-initializer/components/DeletedField.tsx @@ -0,0 +1,7 @@ +import React from 'react'; +import { useTranslation } from 'react-i18next'; + +export const DeletedField = () => { + const { t } = useTranslation(); + return
{t('The field has bee deleted')}
; +}; diff --git a/packages/core/client/src/schema-initializer/components/assigned-field/AssignedField.tsx b/packages/core/client/src/schema-initializer/components/assigned-field/AssignedField.tsx index 190a3b585..ad23191c7 100644 --- a/packages/core/client/src/schema-initializer/components/assigned-field/AssignedField.tsx +++ b/packages/core/client/src/schema-initializer/components/assigned-field/AssignedField.tsx @@ -2,7 +2,7 @@ import { Field } from '@formily/core'; import { connect, useField, useFieldSchema } from '@formily/react'; import { merge } from '@formily/shared'; import { Cascader, Select, Space } from 'antd'; -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useFormBlockContext } from '../../../block-provider'; import { @@ -12,6 +12,7 @@ import { useCollectionFilterOptions, } from '../../../collection-manager'; import { useCompile, useComponent } from '../../../schema-component'; +import { DeletedField } from '../DeletedField'; const DYNAMIC_RECORD_REG = /\{\{\s*currentRecord\.(.*)\s*\}\}/; const DYNAMIC_USER_REG = /\{\{\s*currentUser\.(.*)\s*\}\}/; @@ -134,7 +135,6 @@ export const AssignedField = (props: any) => { name: 'currentTime', title: t('Current time'), }); - } else { } setOptions(compile(opt)); }, []); @@ -178,16 +178,15 @@ export const AssignedField = (props: any) => { const userChangeHandler = (val) => { setUserValue(val); }; - return ( - - - {type === AssignedFieldValueType.ConstantValue ? ( - - ) : ( + const useFieldMemo = useMemo(() => { + if (!collectionField) { + return ; + } + if (type === AssignedFieldValueType.ConstantValue) { + return ; + } else { + return ( - )} + ); + } + }, [collectionField, type, value, fieldType]); + + return ( + + + + {useFieldMemo} + {fieldType === 'currentRecord' && (