When using the `admin.hidden: true` property on a collection, it rightfully removes all navigation and routing for that particular collection. However, this also affects the expected behavior of hidden entities when they are rendered within a drawer, such as the document drawer or list drawer. For example, when creating a new _admin.hidden_ document through the relationship or join field, the drawer should still render the view, despite the underlying route for that view being disabled. This change was a result of the introduction of on-demand server components in #8364, where we now make a server roundtrip to render the view in its entirety, which include the logic that redirects these hidden entities. Now, we pass a new `overrideEntityVisibility` argument through the server function that, when true, skips this step. This way documents can continue to respect `admin.hidden` while also having the ability to override on a case-by-case basis throughout the UI.
104 lines
2.0 KiB
TypeScript
104 lines
2.0 KiB
TypeScript
import type { Payload } from 'payload'
|
|
|
|
import path from 'path'
|
|
import { getFileByPath } from 'payload'
|
|
import { fileURLToPath } from 'url'
|
|
|
|
import { devUser } from '../credentials.js'
|
|
import { seedDB } from '../helpers/seed.js'
|
|
import {
|
|
categoriesSlug,
|
|
collectionSlugs,
|
|
hiddenPostsSlug,
|
|
postsSlug,
|
|
uploadsSlug,
|
|
} from './shared.js'
|
|
|
|
const filename = fileURLToPath(import.meta.url)
|
|
const dirname = path.dirname(filename)
|
|
|
|
export const seed = async (_payload) => {
|
|
await _payload.create({
|
|
collection: 'users',
|
|
data: {
|
|
email: devUser.email,
|
|
password: devUser.password,
|
|
},
|
|
})
|
|
|
|
const category = await _payload.create({
|
|
collection: categoriesSlug,
|
|
data: {
|
|
name: 'example',
|
|
group: {},
|
|
},
|
|
})
|
|
|
|
await _payload.create({
|
|
collection: hiddenPostsSlug,
|
|
data: {
|
|
category: category.id,
|
|
title: 'Test Post 1',
|
|
},
|
|
})
|
|
|
|
await _payload.create({
|
|
collection: postsSlug,
|
|
data: {
|
|
category: category.id,
|
|
group: {
|
|
category: category.id,
|
|
},
|
|
title: 'Test Post 1',
|
|
},
|
|
})
|
|
|
|
await _payload.create({
|
|
collection: postsSlug,
|
|
data: {
|
|
category: category.id,
|
|
group: {
|
|
category: category.id,
|
|
},
|
|
title: 'Test Post 2',
|
|
},
|
|
})
|
|
|
|
await _payload.create({
|
|
collection: postsSlug,
|
|
data: {
|
|
category: category.id,
|
|
group: {
|
|
category: category.id,
|
|
},
|
|
title: 'Test Post 3',
|
|
},
|
|
})
|
|
|
|
// create an upload with image.png
|
|
const imageFilePath = path.resolve(dirname, './image.png')
|
|
const imageFile = await getFileByPath(imageFilePath)
|
|
const { id: uploadedImage } = await _payload.create({
|
|
collection: uploadsSlug,
|
|
data: {},
|
|
file: imageFile,
|
|
})
|
|
|
|
// create a post that uses the upload
|
|
await _payload.create({
|
|
collection: postsSlug,
|
|
data: {
|
|
upload: uploadedImage.id,
|
|
},
|
|
})
|
|
}
|
|
|
|
export async function clearAndSeedEverything(_payload: Payload) {
|
|
return await seedDB({
|
|
_payload,
|
|
collectionSlugs,
|
|
seedFunction: seed,
|
|
snapshotKey: 'adminTest',
|
|
})
|
|
}
|