From 673ea808b01008b4eb7225575d5df501b2cb0e2f Mon Sep 17 00:00:00 2001
From: katherinehhh <shunai.tang@hand-china.com>
Date: Wed, 26 Jul 2023 10:18:02 +0800
Subject: [PATCH] fix: collectionField undefined (#2320)

---
 .../client/src/schema-component/antd/form-item/FormItem.tsx | 4 ++--
 packages/core/client/src/schema-settings/SchemaSettings.tsx | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx
index 3607e887b..05cf804f8 100644
--- a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx
+++ b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx
@@ -69,7 +69,7 @@ export const FormItem: any = observer(
         } else if (
           isVariable(schema?.default) &&
           schema?.default?.includes('$context') &&
-          collectionField.interface === 'm2m'
+          collectionField?.interface === 'm2m'
         ) {
           // 直接对多
           const contextData = parseVariables('{{$context}}', variablesCtx);
@@ -212,7 +212,7 @@ FormItem.Designer = function Designer() {
   const isPickerMode = fieldSchema['x-component-props']?.mode === 'Picker';
   const showFieldMode = isAssociationField && fieldModeOptions && !isTableField;
   const showModeSelect = showFieldMode && isPickerMode;
-  const isDateField = ['datetime', 'createdAt', 'updatedAt'].includes(collectionField.interface);
+  const isDateField = ['datetime', 'createdAt', 'updatedAt'].includes(collectionField?.interface);
 
   return (
     <GeneralSchemaDesigner>
diff --git a/packages/core/client/src/schema-settings/SchemaSettings.tsx b/packages/core/client/src/schema-settings/SchemaSettings.tsx
index 441bc4bf4..ab98a5bc1 100644
--- a/packages/core/client/src/schema-settings/SchemaSettings.tsx
+++ b/packages/core/client/src/schema-settings/SchemaSettings.tsx
@@ -1462,12 +1462,12 @@ SchemaSettings.DefaultValue = function DefaultvalueConfigure(props) {
       `${collectionField.target}.${fieldSchema['x-component-props']?.fieldNames?.label || 'id'}`,
     );
   }
-  const parentFieldSchema = collectionField.interface === 'm2o' && findParentFieldSchema(fieldSchema);
+  const parentFieldSchema = collectionField?.interface === 'm2o' && findParentFieldSchema(fieldSchema);
   const parentCollectionField = parentFieldSchema && getCollectionJoinField(parentFieldSchema?.['x-collection-field']);
   const tableCtx = useTableBlockContext();
   const isAllowContexVariable =
-    collectionField.interface === 'm2m' ||
-    (parentCollectionField?.type === 'hasMany' && collectionField.interface === 'm2o');
+    collectionField?.interface === 'm2m' ||
+    (parentCollectionField?.type === 'hasMany' && collectionField?.interface === 'm2o');
   return (
     <SchemaSettings.ModalItem
       title={t('Set default value')}