fix: properly sets tabs key in fieldSchemaToJSON (#4317)

This commit is contained in:
Jacob Fletcher
2023-11-30 09:48:37 -05:00
committed by GitHub
parent 57fc211674
commit 9cc88bb474
4 changed files with 47 additions and 6 deletions

View File

@@ -74,7 +74,7 @@ export const fieldSchemaToJSON = (fields: Field[]): FieldSchemaJSON => {
tabFields.push({
name: tab.name,
fields: fieldSchemaToJSON(tab.fields),
type: 'tab',
type: field.type,
})
return
}

View File

@@ -121,6 +121,23 @@ export const Pages: CollectionConfig = {
},
],
},
{
label: 'Named Tabs',
type: 'tabs',
tabs: [
{
name: 'tab',
label: 'Tab',
fields: [
{
name: 'relationshipInTab',
type: 'relationship',
relationTo: 'posts',
},
],
},
],
},
],
},
],

View File

@@ -307,6 +307,27 @@ describe('Collections - Live Preview', () => {
expect(merge2.relationshipPolyHasMany).toEqual([])
})
it('— relationships - populates within tabs', async () => {
const initialData: Partial<Page> = {
title: 'Test Page',
}
const merge1 = await mergeData({
depth: 1,
fieldSchema: schemaJSON,
incomingData: {
...initialData,
tab: {
relationshipInTab: testPost.id,
},
},
initialData,
serverURL,
})
expect(merge1.tab.relationshipInTab).toMatchObject(testPost)
})
it('— relationships - populates within arrays', async () => {
const initialData: Partial<Page> = {
title: 'Test Page',

View File

@@ -152,11 +152,6 @@ export interface Page {
}
)[]
| null
meta?: {
title?: string | null
description?: string | null
image?: string | Media | null
}
relationshipInRichText?:
| {
[k: string]: unknown
@@ -198,6 +193,14 @@ export interface Page {
id?: string | null
}[]
| null
tab: {
relationshipInTab?: (string | null) | Post
}
meta?: {
title?: string | null
description?: string | null
image?: string | Media | null
}
updatedAt: string
createdAt: string
}