diff --git a/packages/core/client/src/block-provider/hooks/index.ts b/packages/core/client/src/block-provider/hooks/index.ts index 6bceb259d..6fe470086 100644 --- a/packages/core/client/src/block-provider/hooks/index.ts +++ b/packages/core/client/src/block-provider/hooks/index.ts @@ -1,7 +1,7 @@ import { Schema, SchemaExpressionScopeContext, useField, useFieldSchema, useForm } from '@formily/react'; import { parse } from '@nocobase/utils/client'; import { Modal, message } from 'antd'; -import { cloneDeep, uniq } from 'lodash'; +import { cloneDeep, isEqual, uniq, omitBy } from 'lodash'; import get from 'lodash/get'; import omit from 'lodash/omit'; import { ChangeEvent, useContext, useEffect } from 'react'; @@ -158,7 +158,8 @@ export const useCreateActionProps = () => { if (!skipValidator) { await form.submit(); } - const values = getFormValues(filterByTk, field, form, fieldNames, getField, resource); + const formValues = getFormValues(filterByTk, field, form, fieldNames, getField, resource); + const values = omitBy(formValues, (value) => isEqual(JSON.stringify(value), '[{}]')); if (addChild) { const treeParentField = getTreeParentField(); values[treeParentField?.name ?? 'parent'] = currentRecord; @@ -255,6 +256,7 @@ export const useAssociationCreateActionProps = () => { } message.success(compile(onSuccess?.successMessage)); } catch (error) { + actionField.data.data = null; actionField.data.loading = false; } }, diff --git a/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx b/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx index 69a3dea88..e13aee2de 100644 --- a/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx +++ b/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx @@ -53,6 +53,7 @@ export const ActionDesigner = (props) => { const isChildCollectionAction = getChildrenCollections(name).length > 0 && fieldSchema['x-action'] === 'create'; const isLink = fieldSchema['x-component'] === 'Action.Link'; const isDelete = fieldSchema?.parent['x-component'] === 'CollectionField'; + const isDraggable=fieldSchema?.parent['x-component'] !== 'CollectionField'; useEffect(() => { const schemaUid = uid(); const schema: ISchema = { @@ -73,7 +74,7 @@ export const ActionDesigner = (props) => { ), }; return ( - + { async onClick() { await onClick(); const { data } = actionField.data?.data?.data || {}; - if (['m2m', 'o2m'].includes(collectionField?.interface) && multiple !== false) { - const values = JSON.parse(JSON.stringify(form.values[fieldSchema.name] || [])); - values.push({ - ...data, - }); - setTimeout(() => { - form.setValuesIn(field.props.name, values); - }, 100); - } else { - const value = { - ...data, - }; - setTimeout(() => { - form.setValuesIn(field.props.name, value); - }, 100); + if (data) { + if (['m2m', 'o2m'].includes(collectionField?.interface) && multiple !== false) { + const values = JSON.parse(JSON.stringify(form.values[fieldSchema.name] || [])); + values.push({ + ...data, + }); + setTimeout(() => { + form.setValuesIn(field.props.name, values); + }, 100); + } else { + const value = { + ...data, + }; + setTimeout(() => { + form.setValuesIn(field.props.name, value); + }, 100); + } } }, }; diff --git a/packages/core/client/src/schema-component/antd/association-field/Nester.tsx b/packages/core/client/src/schema-component/antd/association-field/Nester.tsx index d9a788953..e2b3e61fa 100644 --- a/packages/core/client/src/schema-component/antd/association-field/Nester.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/Nester.tsx @@ -2,11 +2,10 @@ import { CloseCircleOutlined } from '@ant-design/icons'; import { ArrayField } from '@formily/core'; import { RecursionField, observer, useFieldSchema } from '@formily/react'; import { Button, Card, Divider } from 'antd'; -import React, { useContext } from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { AssociationFieldContext } from './context'; import { useAssociationFieldContext } from './hooks'; -// import { useRemoveActionProps } from '../../../block-provider/hooks'; export const Nester = (props) => { const { options } = useContext(AssociationFieldContext); @@ -36,9 +35,12 @@ const toArr = (value, isReadpretty) => { const ToManyNester = observer((props) => { const fieldSchema = useFieldSchema(); const { field } = useAssociationFieldContext(); - const values = toArr(field.value, field.readPretty); + const [values, setValues] = useState([]); + useEffect(() => { + const values = toArr(field.value, field.readPretty); + setValues(values); + }, []); const { t } = useTranslation(); - // const { onClick } = useRemoveActionProps(`${collectionField.collectionName}.${collectionField.target}`); return ( {values.map((value, index) => { @@ -49,7 +51,9 @@ const ToManyNester = observer((props) => { { - field.value.splice(index, 1); + const data = values.concat(); + data.splice(index, 1); + setValues(data); }} /> @@ -64,13 +68,9 @@ const ToManyNester = observer((props) => { type={'dashed'} block onClick={() => { - const v = field.value || []; - if (values.length > v.length) { - field.value = values; - } else { - field.value = v; - } - field.value.push({}); + const data = values.concat(); + data.push({}); + setValues(data); }} > {t('Add new')} diff --git a/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx b/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx index 7f071acba..f7b534250 100644 --- a/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx +++ b/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx @@ -125,7 +125,6 @@ export const CreateAction = observer((props: any) => { const allowAddToCurrent = fieldSchema?.['x-allow-add-to-current']; const field: any = useField(); const componentType = field.componentProps.type || 'primary'; - console.log(componentType) const { getChildrenCollections } = useCollectionManager(); const totalChildCollections = getChildrenCollections(collection.name); const inheritsCollections = enableChildren