## 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
171 lines
3.2 KiB
TypeScript
171 lines
3.2 KiB
TypeScript
import type { CollectionConfig } from 'payload'
|
|
|
|
import { defaultText, textFieldsSlug } from './shared.js'
|
|
|
|
const TextFields: CollectionConfig = {
|
|
slug: textFieldsSlug,
|
|
admin: {
|
|
useAsTitle: 'text',
|
|
},
|
|
defaultSort: 'id',
|
|
fields: [
|
|
{
|
|
name: 'text',
|
|
type: 'text',
|
|
required: true,
|
|
hooks: {
|
|
beforeDuplicate: [({ value }) => `${value} - duplicate`],
|
|
},
|
|
},
|
|
{
|
|
name: 'localizedText',
|
|
type: 'text',
|
|
localized: true,
|
|
},
|
|
{
|
|
name: 'i18nText',
|
|
type: 'text',
|
|
admin: {
|
|
description: {
|
|
en: 'en description',
|
|
es: 'es description',
|
|
},
|
|
placeholder: {
|
|
en: 'en placeholder',
|
|
es: 'es placeholder',
|
|
},
|
|
},
|
|
label: {
|
|
en: 'Text en',
|
|
es: 'Text es',
|
|
},
|
|
},
|
|
{
|
|
name: 'defaultString',
|
|
type: 'text',
|
|
defaultValue: defaultText,
|
|
},
|
|
{
|
|
name: 'defaultEmptyString',
|
|
type: 'text',
|
|
defaultValue: '',
|
|
},
|
|
{
|
|
name: 'defaultFunction',
|
|
type: 'text',
|
|
defaultValue: () => defaultText,
|
|
},
|
|
{
|
|
name: 'defaultAsync',
|
|
type: 'text',
|
|
defaultValue: async (): Promise<string> => {
|
|
return new Promise((resolve) =>
|
|
setTimeout(() => {
|
|
resolve(defaultText)
|
|
}, 1),
|
|
)
|
|
},
|
|
},
|
|
{
|
|
name: 'overrideLength',
|
|
type: 'text',
|
|
label: 'Override the 40k text length default',
|
|
maxLength: 50000,
|
|
},
|
|
{
|
|
name: 'fieldWithDefaultValue',
|
|
type: 'text',
|
|
defaultValue: async () => {
|
|
const defaultValue = new Promise((resolve) => setTimeout(() => resolve('some-value'), 1000))
|
|
|
|
return defaultValue
|
|
},
|
|
},
|
|
{
|
|
name: 'dependentOnFieldWithDefaultValue',
|
|
type: 'text',
|
|
hooks: {
|
|
beforeChange: [
|
|
({ data }) => {
|
|
return data?.fieldWithDefaultValue || ''
|
|
},
|
|
],
|
|
},
|
|
},
|
|
{
|
|
name: 'hasMany',
|
|
type: 'text',
|
|
hasMany: true,
|
|
},
|
|
{
|
|
name: 'validatesHasMany',
|
|
type: 'text',
|
|
hasMany: true,
|
|
minLength: 3,
|
|
},
|
|
{
|
|
name: 'localizedHasMany',
|
|
type: 'text',
|
|
hasMany: true,
|
|
localized: true,
|
|
},
|
|
{
|
|
name: 'withMinRows',
|
|
type: 'text',
|
|
hasMany: true,
|
|
minRows: 2,
|
|
},
|
|
{
|
|
name: 'withMaxRows',
|
|
type: 'text',
|
|
hasMany: true,
|
|
maxRows: 4,
|
|
},
|
|
{
|
|
name: 'disableListColumnText',
|
|
type: 'text',
|
|
admin: {
|
|
disableListColumn: true,
|
|
disableListFilter: false,
|
|
},
|
|
},
|
|
{
|
|
name: 'disableListFilterText',
|
|
type: 'text',
|
|
admin: {
|
|
disableListColumn: false,
|
|
disableListFilter: true,
|
|
},
|
|
},
|
|
{
|
|
name: 'array',
|
|
type: 'array',
|
|
fields: [
|
|
{
|
|
name: 'texts',
|
|
type: 'text',
|
|
hasMany: true,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'blocks',
|
|
type: 'blocks',
|
|
blocks: [
|
|
{
|
|
slug: 'block',
|
|
fields: [
|
|
{
|
|
name: 'texts',
|
|
type: 'text',
|
|
hasMany: true,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
}
|
|
|
|
export default TextFields
|