chore: live preview tests pass

This commit is contained in:
James
2023-10-08 16:47:42 -04:00
parent 18da607f5b
commit 999f2fba04
8 changed files with 49 additions and 35 deletions

View File

@@ -30,6 +30,7 @@ type Args = {
disableUnique: boolean
fields: Field[]
rootRelationsToBuild?: Map<string, string>
rootRelationships?: Set<string>
rootTableIDColType?: string
rootTableName?: string
tableName: string
@@ -48,6 +49,7 @@ export const buildTable = ({
disableUnique = false,
fields,
rootRelationsToBuild,
rootRelationships,
rootTableIDColType,
rootTableName,
tableName,
@@ -66,9 +68,12 @@ export const buildTable = ({
let localesTable: GenericTable
let numbersTable: GenericTable
const relationships: Set<string> = new Set()
// Relationships to the base collection
const relationships: Set<string> = rootRelationships || new Set()
let relationshipsTable: GenericTable
// Drizzle relations
const relationsToBuild: Map<string, string> = new Map()
const idField = fields.find((field) => fieldAffectsData(field) && field.name === 'id')

View File

@@ -277,6 +277,7 @@ export const traverseFields = ({
disableUnique,
fields: field.fields,
rootRelationsToBuild,
rootRelationships: relationships,
rootTableIDColType,
rootTableName,
tableName: arrayTableName,
@@ -341,6 +342,7 @@ export const traverseFields = ({
disableUnique,
fields: block.fields,
rootRelationsToBuild,
rootRelationships: relationships,
rootTableIDColType,
rootTableName,
tableName: blockTableName,

View File

@@ -260,17 +260,21 @@ const validateFilterOptions: Validate = async (
}
})
const result = await payload.find({
collection,
depth: 0,
limit: 0,
pagination: false,
where: {
and: [{ id: { in: valueIDs } }, optionFilter],
},
})
if (valueIDs.length > 0) {
const result = await payload.find({
collection,
depth: 0,
limit: 0,
pagination: false,
where: {
and: [{ id: { in: valueIDs } }, optionFilter],
},
})
options[collection] = result.docs.map((doc) => doc.id)
options[collection] = result.docs.map((doc) => doc.id)
} else {
options[collection] = []
}
}),
)

View File

@@ -72,41 +72,55 @@ export default buildConfigWithDefaults({
},
})
const mediaID = payload.db.defaultIDType === 'number' ? media.id : `"${media.id}"`
const [post1Doc, post2Doc, post3Doc] = await Promise.all([
await payload.create({
collection: postsSlug,
data: JSON.parse(JSON.stringify(post1).replace(/\{\{IMAGE\}\}/g, media.id)),
data: JSON.parse(JSON.stringify(post1).replace(/"\{\{IMAGE\}\}"/g, mediaID)),
}),
await payload.create({
collection: postsSlug,
data: JSON.parse(JSON.stringify(post2).replace(/\{\{IMAGE\}\}/g, media.id)),
data: JSON.parse(JSON.stringify(post2).replace(/"\{\{IMAGE\}\}"/g, mediaID)),
}),
await payload.create({
collection: postsSlug,
data: JSON.parse(JSON.stringify(post3).replace(/\{\{IMAGE\}\}/g, media.id)),
data: JSON.parse(JSON.stringify(post3).replace(/"\{\{IMAGE\}\}"/g, mediaID)),
}),
])
const postsPageDoc = await payload.create({
collection: pagesSlug,
data: JSON.parse(JSON.stringify(postsPage).replace(/\{\{IMAGE\}\}/g, media.id)),
data: JSON.parse(JSON.stringify(postsPage).replace(/"\{\{IMAGE\}\}"/g, mediaID)),
})
let postsPageDocID = postsPageDoc.id
let post1DocID = post1Doc.id
let post2DocID = post2Doc.id
let post3DocID = post3Doc.id
if (payload.db.defaultIDType !== 'number') {
postsPageDocID = `"${postsPageDoc.id}"`
post1DocID = `"${post1Doc.id}"`
post2DocID = `"${post2Doc.id}"`
post3DocID = `"${post3Doc.id}"`
}
await payload.create({
collection: pagesSlug,
data: JSON.parse(
JSON.stringify(home)
.replace(/\{\{MEDIA_ID\}\}/g, media.id)
.replace(/\{\{POSTS_PAGE_ID\}\}/g, postsPageDoc.id)
.replace(/\{\{POST_1_ID\}\}/g, post1Doc.id)
.replace(/\{\{POST_2_ID\}\}/g, post2Doc.id)
.replace(/\{\{POST_3_ID\}\}/g, post3Doc.id),
.replace(/"\{\{MEDIA_ID\}\}"/g, mediaID)
.replace(/"\{\{POSTS_PAGE_ID\}\}"/g, postsPageDocID)
.replace(/"\{\{POST_1_ID\}\}"/g, post1DocID)
.replace(/"\{\{POST_2_ID\}\}"/g, post2DocID)
.replace(/"\{\{POST_3_ID\}\}"/g, post3DocID),
),
})
await payload.updateGlobal({
slug: 'header',
data: JSON.parse(JSON.stringify(header).replace(/\{\{POSTS_PAGE_ID\}\}/g, postsPageDoc.id)),
data: JSON.parse(JSON.stringify(header).replace(/"\{\{POSTS_PAGE_ID\}\}"/g, postsPageDocID)),
})
await payload.updateGlobal({

View File

@@ -4,8 +4,6 @@ export const home: Page = {
slug: 'home',
title: 'Home',
id: '',
updatedAt: '',
createdAt: '',
meta: {
description: 'This is an example of live preview on a page.',
},

View File

@@ -37,10 +37,7 @@ export const post1: Partial<Post> = {
},
],
link: {
reference: {
relationTo: 'pages',
value: '',
},
type: 'custom',
url: '',
label: '',
},

View File

@@ -38,10 +38,7 @@ export const post2: Partial<Post> = {
},
],
link: {
reference: {
relationTo: 'pages',
value: '',
},
type: 'custom',
url: '',
label: '',
},

View File

@@ -38,10 +38,7 @@ export const post3: Partial<Post> = {
},
],
link: {
reference: {
relationTo: 'pages',
value: '',
},
type: 'custom',
url: '',
label: '',
},