From 81948f4f2ccb73a48343ce933e93f8c4720ef930 Mon Sep 17 00:00:00 2001 From: chenos Date: Tue, 21 Mar 2023 18:09:09 +0800 Subject: [PATCH] fix(tree-collection): cannot read properties of undefined (reading 'addChild') --- .../core/client/src/block-provider/FormBlockProvider.tsx | 5 ++--- packages/core/client/src/block-provider/hooks/index.ts | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/client/src/block-provider/FormBlockProvider.tsx b/packages/core/client/src/block-provider/FormBlockProvider.tsx index 35b336048..c9ac36994 100644 --- a/packages/core/client/src/block-provider/FormBlockProvider.tsx +++ b/packages/core/client/src/block-provider/FormBlockProvider.tsx @@ -5,9 +5,8 @@ import isEmpty from 'lodash/isEmpty'; import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react'; import { useCollection } from '../collection-manager'; import { RecordProvider, useRecord } from '../record-provider'; -import { useDesignable } from '../schema-component'; +import { useActionContext, useDesignable } from '../schema-component'; import { BlockProvider, useBlockRequestContext } from './BlockProvider'; -import { useActionContext } from '../schema-component'; export const FormBlockContext = createContext({}); @@ -91,7 +90,7 @@ export const useFormBlockProps = () => { const ctx = useFormBlockContext(); const record = useRecord(); const { fieldSchema } = useActionContext(); - const { addChild } = fieldSchema?.['x-component-props']||{}; + const addChild = fieldSchema?.['x-component-props']?.addChild; useEffect(() => { if (addChild) { ctx.form.query('parent').take((field) => { diff --git a/packages/core/client/src/block-provider/hooks/index.ts b/packages/core/client/src/block-provider/hooks/index.ts index fd8a848c1..edfd3361e 100644 --- a/packages/core/client/src/block-provider/hooks/index.ts +++ b/packages/core/client/src/block-provider/hooks/index.ts @@ -84,6 +84,7 @@ function getFormValues(filterByTk, field, form, fieldNames, getField, resource) return omit({ ...form.values }, keys); } } + console.log('form.values', form.values); return form.values; let values = {}; for (const key in form.values) { @@ -151,7 +152,7 @@ export const useCreateActionProps = () => { overwriteValues, skipValidator, } = actionSchema?.['x-action-settings'] ?? {}; - const { addChild } = fieldSchema?.['x-component-props']; + const addChild = fieldSchema?.['x-component-props']?.addChild; const assignedValues = parse(originalAssignedValues)({ currentTime: new Date(), currentRecord, currentUser }); if (!skipValidator) { await form.submit();