## Description Currently, you cannot create, delete, or duplicate documents within the document drawer directly. To create a document within a relationship field, for example, you must first navigate to the parent field and open the "create new" drawer. Similarly (but worse), to duplicate or delete a document, you must _navigate to the parent document to perform these actions_ which is incredibly disruptive to the content editing workflow. This becomes especially apparent within the relationship field where you can edit documents inline, but cannot duplicate or delete them. This PR supports all document-level actions within the document drawer so that these actions can be performed on-the-fly without navigating away. Inline duplication flow on a polymorphic "hasOne" relationship: https://github.com/user-attachments/assets/bb80404a-079d-44a1-b9bc-14eb2ab49a46 Inline deletion flow on a polymorphic "hasOne" relationship: https://github.com/user-attachments/assets/10f3587f-f70a-4cca-83ee-5dbcad32f063 - [x] I have read and understand the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository. ## Type of change - [x] New feature (non-breaking change which adds functionality) ## Checklist: - [x] I have added tests that prove my fix is effective or that my feature works - [x] Existing test suite passes locally with my changes
147 lines
3.5 KiB
TypeScript
147 lines
3.5 KiB
TypeScript
import type { Payload } from 'payload'
|
|
|
|
import { devUser } from '../credentials.js'
|
|
import { executePromises } from '../helpers/executePromises.js'
|
|
import { seedDB } from '../helpers/seed.js'
|
|
import {
|
|
collectionSlugs,
|
|
customIdCollectionId,
|
|
customViews1CollectionSlug,
|
|
customViews2CollectionSlug,
|
|
geoCollectionSlug,
|
|
noApiViewCollectionSlug,
|
|
postsCollectionSlug,
|
|
usersCollectionSlug,
|
|
} from './slugs.js'
|
|
|
|
export const seed = async (_payload) => {
|
|
if (_payload.db.name === 'mongoose') {
|
|
await Promise.all(
|
|
_payload.config.collections.map(async (coll) => {
|
|
await new Promise((resolve, reject) => {
|
|
_payload.db?.collections[coll.slug]?.ensureIndexes(function (err) {
|
|
if (err) {
|
|
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
reject(err)
|
|
}
|
|
resolve(true)
|
|
})
|
|
})
|
|
}),
|
|
)
|
|
}
|
|
|
|
await executePromises(
|
|
[
|
|
() =>
|
|
_payload.create({
|
|
collection: usersCollectionSlug,
|
|
data: {
|
|
email: devUser.email,
|
|
password: devUser.password,
|
|
},
|
|
depth: 0,
|
|
overrideAccess: true,
|
|
}),
|
|
...[...Array(11)].map((_, i) => async () => {
|
|
const postDoc = await _payload.create({
|
|
collection: postsCollectionSlug,
|
|
data: {
|
|
description: 'Description',
|
|
title: `Post ${i + 1}`,
|
|
},
|
|
depth: 0,
|
|
overrideAccess: true,
|
|
})
|
|
|
|
return await _payload.update({
|
|
collection: postsCollectionSlug,
|
|
where: {
|
|
id: {
|
|
equals: postDoc.id,
|
|
},
|
|
},
|
|
data: {
|
|
relationship: postDoc.id,
|
|
},
|
|
depth: 0,
|
|
overrideAccess: true,
|
|
})
|
|
}),
|
|
() =>
|
|
_payload.create({
|
|
collection: customViews1CollectionSlug,
|
|
data: {
|
|
title: 'Custom View',
|
|
},
|
|
depth: 0,
|
|
overrideAccess: true,
|
|
}),
|
|
() =>
|
|
_payload.create({
|
|
collection: customViews2CollectionSlug,
|
|
data: {
|
|
title: 'Custom View',
|
|
},
|
|
depth: 0,
|
|
overrideAccess: true,
|
|
}),
|
|
() =>
|
|
_payload.create({
|
|
collection: geoCollectionSlug,
|
|
data: {
|
|
point: [7, -7],
|
|
},
|
|
depth: 0,
|
|
overrideAccess: true,
|
|
}),
|
|
() =>
|
|
_payload.create({
|
|
collection: geoCollectionSlug,
|
|
data: {
|
|
point: [5, -5],
|
|
},
|
|
depth: 0,
|
|
overrideAccess: true,
|
|
}),
|
|
() =>
|
|
_payload.create({
|
|
collection: noApiViewCollectionSlug,
|
|
data: {},
|
|
depth: 0,
|
|
overrideAccess: true,
|
|
}),
|
|
() =>
|
|
_payload.create({
|
|
collection: 'customIdTab',
|
|
data: {
|
|
id: customIdCollectionId,
|
|
title: 'Hello world title',
|
|
},
|
|
depth: 0,
|
|
overrideAccess: true,
|
|
}),
|
|
() =>
|
|
_payload.create({
|
|
collection: 'customIdRow',
|
|
data: {
|
|
id: customIdCollectionId,
|
|
title: 'Hello world title',
|
|
},
|
|
depth: 0,
|
|
overrideAccess: true,
|
|
}),
|
|
],
|
|
false,
|
|
)
|
|
}
|
|
|
|
export async function clearAndSeedEverything(_payload: Payload) {
|
|
return await seedDB({
|
|
_payload,
|
|
collectionSlugs,
|
|
seedFunction: seed,
|
|
snapshotKey: 'adminTest',
|
|
})
|
|
}
|