From 209b02b0699b17d060dab3cc09cdd06ad813c053 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 6 Aug 2022 13:12:25 -0400 Subject: [PATCH] fix: #898 --- src/graphql/schema/buildMutationInputType.ts | 9 ++++++--- src/graphql/schema/buildObjectType.ts | 9 ++++++--- test/fields/collections/Tabs/UIField.tsx | 7 +++++++ test/fields/collections/Tabs/index.ts | 11 +++++++++++ 4 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 test/fields/collections/Tabs/UIField.tsx diff --git a/src/graphql/schema/buildMutationInputType.ts b/src/graphql/schema/buildMutationInputType.ts index 69c594447..fb2e86e2d 100644 --- a/src/graphql/schema/buildMutationInputType.ts +++ b/src/graphql/schema/buildMutationInputType.ts @@ -178,18 +178,21 @@ function buildMutationInputType(payload: Payload, name: string, fields: Field[], }), row: (inputObjectTypeConfig: InputObjectTypeConfig, field: RowField) => field.fields.reduce((acc, subField: Field) => { const addSubField = fieldToSchemaMap[subField.type]; - return addSubField(acc, subField); + if (addSubField) return addSubField(acc, subField); + return acc; }, inputObjectTypeConfig), collapsible: (inputObjectTypeConfig: InputObjectTypeConfig, field: CollapsibleField) => field.fields.reduce((acc, subField: CollapsibleField) => { const addSubField = fieldToSchemaMap[subField.type]; - return addSubField(acc, subField); + if (addSubField) return addSubField(acc, subField); + return acc; }, inputObjectTypeConfig), tabs: (inputObjectTypeConfig: InputObjectTypeConfig, field: TabsField) => field.tabs.reduce((acc, tab) => { return { ...acc, ...tab.fields.reduce((subFieldSchema, subField) => { const addSubField = fieldToSchemaMap[subField.type]; - return addSubField(subFieldSchema, subField); + if (addSubField) return addSubField(subFieldSchema, subField); + return subFieldSchema; }, acc), }; }, inputObjectTypeConfig), diff --git a/src/graphql/schema/buildObjectType.ts b/src/graphql/schema/buildObjectType.ts index 886937f11..9b4664746 100644 --- a/src/graphql/schema/buildObjectType.ts +++ b/src/graphql/schema/buildObjectType.ts @@ -444,18 +444,21 @@ function buildObjectType({ }, row: (objectTypeConfig: ObjectTypeConfig, field: RowField) => field.fields.reduce((objectTypeConfigWithRowFields, subField) => { const addSubField = fieldToSchemaMap[subField.type]; - return addSubField(objectTypeConfigWithRowFields, subField); + if (addSubField) return addSubField(objectTypeConfigWithRowFields, subField); + return objectTypeConfigWithRowFields; }, objectTypeConfig), collapsible: (objectTypeConfig: ObjectTypeConfig, field: CollapsibleField) => field.fields.reduce((objectTypeConfigWithCollapsibleFields, subField) => { const addSubField = fieldToSchemaMap[subField.type]; - return addSubField(objectTypeConfigWithCollapsibleFields, subField); + if (addSubField) return addSubField(objectTypeConfigWithCollapsibleFields, subField); + return objectTypeConfigWithCollapsibleFields; }, objectTypeConfig), tabs: (objectTypeConfig: ObjectTypeConfig, field: TabsField) => field.tabs.reduce((tabSchema, tab) => { return { ...tabSchema, ...tab.fields.reduce((subFieldSchema, subField) => { const addSubField = fieldToSchemaMap[subField.type]; - return addSubField(subFieldSchema, subField); + if (addSubField) return addSubField(subFieldSchema, subField); + return subFieldSchema; }, tabSchema), }; }, objectTypeConfig), diff --git a/test/fields/collections/Tabs/UIField.tsx b/test/fields/collections/Tabs/UIField.tsx new file mode 100644 index 000000000..85fbc5480 --- /dev/null +++ b/test/fields/collections/Tabs/UIField.tsx @@ -0,0 +1,7 @@ +import React from 'react'; + +export const UIField: React.FC = () => { + return ( +

This is a UI field within a tab component.

+ ); +}; diff --git a/test/fields/collections/Tabs/index.ts b/test/fields/collections/Tabs/index.ts index c59f3e9c8..00899f150 100644 --- a/test/fields/collections/Tabs/index.ts +++ b/test/fields/collections/Tabs/index.ts @@ -1,5 +1,6 @@ import type { CollectionConfig } from '../../../../src/collections/config/types'; import { blocksField, blocksFieldSeedData } from '../Blocks'; +import { UIField } from './UIField'; const TabsFields: CollectionConfig = { slug: 'tabs-fields', @@ -12,6 +13,16 @@ const TabsFields: CollectionConfig = { label: 'Tab with Array', description: 'This tab has an array.', fields: [ + { + type: 'ui', + name: 'demoUIField', + label: 'Demo UI Field', + admin: { + components: { + Field: UIField, + }, + }, + }, { name: 'array', labels: {