Skip to content

Commit ef863e6

Browse files
SpreizuElmo EgersElmo Egersjacobsfletch
authored
feat: add support for custom Status component in document controls (#11154)
### What? This PR adds the ability to replace the Status section of the document or global edit view, without the need to replace the whole Edit view. ### Why? In certain cases there may be a need to add custom elements before or after the original Status component. In our case, we need to replace the whole Status component to support custom locale publishing logic and also for additional status indicators for the users. ### How? **In the `docs` package:** - Added a description of the Status component to the components section within both the collections and globals sections. **In the `next` package:** - Enabled rendering of the custom Status component. - Modified the Live Preview components to include the Status component prop. **In the `payload` package:** - Introduced type definitions for the Status component. - Implemented importMap generation for the Status component. **In the `ui` package:** - Modified the Edit view to pass the Status component to DocumentControls. - Updated the DocumentControls component to accept and render a custom Status component if defined. Now supports the following Status component in admin ```ts admin: { components: { edit: { Status: '/components/Status/index.tsx#Status', }, }, }, ``` --------- Co-authored-by: Elmo Egers <elmo.egers@smit.ee> Co-authored-by: Elmo Egers <uplaymedia@gmail.com> Co-authored-by: Jacob Fletcher <jacobsfletch@gmail.com>
1 parent 35fe09d commit ef863e6

20 files changed

Lines changed: 226 additions & 2 deletions

File tree

docs/configuration/collections.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ The following options are available:
212212
| `editMenuItems` | Inject custom components within the 3-dot menu dropdown located in the document controls bar. [More details](../custom-components/edit-view#editmenuitems). |
213213
| `SaveButton` | Replace the default Save Button within the Edit View. [Drafts](../versions/drafts) must be disabled. [More details](../custom-components/edit-view#savebutton). |
214214
| `SaveDraftButton` | Replace the default Save Draft Button within the Edit View. [Drafts](../versions/drafts) must be enabled and autosave must be disabled. [More details](../custom-components/edit-view#savedraftbutton). |
215+
| `Status` | Replace the default Status component within the Edit View. [Drafts](../versions/drafts) must be enabled. [More details](../custom-components/edit-view#status). |
215216
| `PublishButton` | Replace the default Publish Button within the Edit View. [Drafts](../versions/drafts) must be enabled. [More details](../custom-components/edit-view#publishbutton). |
216217
| `PreviewButton` | Replace the default Preview Button within the Edit View. [Preview](../admin/preview) must be enabled. [More details](../custom-components/edit-view#previewbutton). |
217218
| `Upload` | Replace the default Upload component within the Edit View. [Upload](../upload/overview) must be enabled. [More details](../custom-components/edit-view#upload). |

docs/configuration/globals.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ The following options are available:
187187
| `SaveDraftButton` | Replace the default Save Draft Button with a Custom Component. [Drafts](../versions/drafts) must be enabled and autosave must be disabled. [More details](../custom-components/edit-view#savedraftbutton). |
188188
| `PublishButton` | Replace the default Publish Button with a Custom Component. [Drafts](../versions/drafts) must be enabled. [More details](../custom-components/edit-view#publishbutton). |
189189
| `PreviewButton` | Replace the default Preview Button with a Custom Component. [Preview](../admin/preview) must be enabled. [More details](../custom-components/edit-view#previewbutton). |
190+
| `Status` | Replace the default Status component with a Custom Component. [Drafts](../versions/drafts) must be enabled. [More details](../custom-components/edit-view#status). |
190191

191192
<Banner type="success">
192193
**Note:** For details on how to build Custom Components, see [Building Custom

docs/custom-components/edit-view.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ The following options are available:
110110
| `PublishButton` | A button that publishes the current document. [More details](#publishbutton). |
111111
| `PreviewButton` | A button that previews the current document. [More details](#previewbutton). |
112112
| `Description` | A description of the Collection. [More details](#description). |
113+
| `Status` | A component that represents the status of the current document. [More details](#status). |
113114
| `Upload` | A file upload component. [More details](#upload). |
114115

115116
#### Globals
@@ -144,6 +145,7 @@ The following options are available:
144145
| `PublishButton` | A button that publishes the current document. [More details](#publishbutton). |
145146
| `PreviewButton` | A button that previews the current document. [More details](#previewbutton). |
146147
| `Description` | A description of the Global. [More details](#description). |
148+
| `Status` | A component that represents the status of the global. [More details](#status). |
147149

148150
### SaveButton
149151

@@ -548,6 +550,29 @@ export function MyDescriptionComponent(props: ViewDescriptionClientProps) {
548550
}
549551
```
550552

553+
### Status
554+
555+
The `Status` property allows you to render a component that represents the collection or global status in the Edit View.
556+
557+
To add an `Status` component, use the `components.edit.Status` property in your [Collection Config](../configuration/collections):
558+
559+
```ts
560+
import type { CollectionConfig } from 'payload'
561+
562+
export const MyCollection: CollectionConfig = {
563+
// ...
564+
admin: {
565+
components: {
566+
edit: {
567+
// highlight-start
568+
Status: '/path/to/MyStatusComponent',
569+
// highlight-end
570+
},
571+
},
572+
},
573+
}
574+
```
575+
551576
### Upload
552577

553578
The `Upload` property allows you to render a custom file upload component in the Edit View. This is only available for upload-enabled Collections.

packages/next/src/views/Document/renderDocumentSlots.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,20 @@ export const renderDocumentSlots: (args: {
120120
})
121121
}
122122

123+
if (collectionConfig?.versions?.drafts || globalConfig?.versions?.drafts) {
124+
const CustomStatus =
125+
collectionConfig?.admin?.components?.edit?.Status ||
126+
globalConfig?.admin?.components?.elements?.Status
127+
128+
if (CustomStatus) {
129+
components.Status = RenderServerComponent({
130+
Component: CustomStatus,
131+
importMap: req.payload.importMap,
132+
serverProps,
133+
})
134+
}
135+
}
136+
123137
if (hasSavePermission) {
124138
if (hasDraftsEnabled(collectionConfig || globalConfig)) {
125139
const CustomPublishButton =
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { CustomComponent } from '../../config/types.js'
2+
3+
export type CustomStatus = CustomComponent

packages/payload/src/admin/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export type {
8181
SaveDraftButtonServerPropsOnly,
8282
} from './elements/SaveDraftButton.js'
8383

84+
export type { CustomStatus } from './elements/Status.js'
85+
8486
export type { Column } from './elements/Table.js'
8587

8688
export type { CustomUpload } from './elements/Upload.js'
@@ -567,6 +569,7 @@ export type DocumentSlots = {
567569
PublishButton?: React.ReactNode
568570
SaveButton?: React.ReactNode
569571
SaveDraftButton?: React.ReactNode
572+
Status?: React.ReactNode
570573
Upload?: React.ReactNode
571574
UploadControls?: React.ReactNode
572575
}

packages/payload/src/bin/generateImportMap/iterateCollections.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function iterateCollections({
4242
addToImportMap(collection.admin?.components?.edit?.PublishButton)
4343
addToImportMap(collection.admin?.components?.edit?.SaveButton)
4444
addToImportMap(collection.admin?.components?.edit?.SaveDraftButton)
45+
addToImportMap(collection.admin?.components?.edit?.Status)
4546
addToImportMap(collection.admin?.components?.edit?.Upload)
4647

4748
if (collection.upload?.admin?.components?.controls) {

packages/payload/src/bin/generateImportMap/iterateGlobals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function iterateGlobals({
3535
addToImportMap(global.admin?.components?.elements?.PublishButton)
3636
addToImportMap(global.admin?.components?.elements?.SaveButton)
3737
addToImportMap(global.admin?.components?.elements?.SaveDraftButton)
38+
addToImportMap(global.admin?.components?.elements?.Status)
3839

3940
if (global.admin?.components?.views?.edit) {
4041
for (const editViewConfig of Object.values(global.admin?.components?.views?.edit)) {

packages/payload/src/collections/config/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { GraphQLInputObjectType, GraphQLNonNull, GraphQLObjectType } from 'graphql'
33
import type { DeepRequired, IsAny, MarkOptional } from 'ts-essentials'
44

5-
import type { CustomUpload, ViewTypes } from '../../admin/types.js'
5+
import type { CustomStatus, CustomUpload, ViewTypes } from '../../admin/types.js'
66
import type { Arguments as MeArguments } from '../../auth/operations/me.js'
77
import type {
88
Arguments as RefreshArguments,
@@ -370,6 +370,10 @@ export type CollectionAdminOptions = {
370370
* + autosave must be disabled
371371
*/
372372
SaveDraftButton?: CustomComponent
373+
/**
374+
* Replaces the "Status" section
375+
*/
376+
Status?: CustomStatus
373377
/**
374378
* Replaces the "Upload" section
375379
* + upload must be enabled

packages/payload/src/globals/config/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
CustomPublishButton,
88
CustomSaveButton,
99
CustomSaveDraftButton,
10+
CustomStatus,
1011
} from '../../admin/types.js'
1112
import type {
1213
Access,
@@ -131,6 +132,10 @@ export type GlobalAdminOptions = {
131132
* + autosave must be disabled
132133
*/
133134
SaveDraftButton?: CustomSaveDraftButton
135+
/**
136+
* Replaces the "Status" section
137+
*/
138+
Status?: CustomStatus
134139
}
135140
views?: {
136141
/**

0 commit comments

Comments
 (0)