Skip to content

Commit e4fa171

Browse files
authored
fix(next): admin panel UI not rendering custom upload components (#9925)
### What? Currently it is not possible to override the upload component. ### Why? The ability to override the upload component is missing from `renderDocumentSlots`. ### How? Adding a check to include the custom upload component if it is available. This issue is holding me back from releasing a payload plugin. Fixes #9591
1 parent 9684d31 commit e4fa171

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

docs/admin/collections.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ The following options are available:
7676
| **`edit.SaveDraftButton`** | Replace the default Save Draft Button with a Custom Component. [Drafts](../versions/drafts) must be enabled and autosave must be disabled. |
7777
| **`edit.PublishButton`** | Replace the default Publish Button with a Custom Component. [Drafts](../versions/drafts) must be enabled. |
7878
| **`edit.PreviewButton`** | Replace the default Preview Button with a Custom Component. [Preview](#preview) must be enabled. |
79+
| **`edit.Upload`** | Replace the default Upload component with a Custom Component. [Upload](../upload/overview) must be enabled. |
7980
| **`views`** | Override or create new views within the Admin Panel. [More details](./views). |
8081

8182
<Banner type="success">

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ export const renderDocumentSlots: (args: {
115115
}
116116
}
117117

118+
if (collectionConfig?.upload && collectionConfig?.admin?.components?.edit?.Upload) {
119+
components.Upload = RenderServerComponent({
120+
Component: collectionConfig.admin.components.edit.Upload,
121+
importMap: req.payload.importMap,
122+
serverProps,
123+
})
124+
}
125+
118126
return components
119127
}
120128

test/uploads/collections/CustomUploadField/components/CustomUpload/index.client.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ const CustomDrawer = () => {
99
return (
1010
<Drawer slug={customDrawerSlug}>
1111
<h1>Custom Drawer</h1>
12-
<TextField name="alt" path="alt" />
12+
<TextField
13+
field={{
14+
name: 'alt',
15+
label: 'Alt',
16+
}}
17+
path="alt"
18+
/>
1319
</Drawer>
1420
)
1521
}

test/uploads/e2e.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
withMetadataSlug,
3636
withOnlyJPEGMetadataSlug,
3737
withoutMetadataSlug,
38+
customUploadFieldSlug,
3839
} from './shared.js'
3940
import { startMockCorsServer } from './startMockCorsServer.js'
4041
const filename = fileURLToPath(import.meta.url)
@@ -61,6 +62,7 @@ let relationPreviewURL: AdminUrlUtil
6162
let customFileNameURL: AdminUrlUtil
6263
let uploadsOne: AdminUrlUtil
6364
let uploadsTwo: AdminUrlUtil
65+
let customUploadFieldURL: AdminUrlUtil
6466

6567
describe('Uploads', () => {
6668
let page: Page
@@ -89,6 +91,7 @@ describe('Uploads', () => {
8991
customFileNameURL = new AdminUrlUtil(serverURL, customFileNameMediaSlug)
9092
uploadsOne = new AdminUrlUtil(serverURL, 'uploads-1')
9193
uploadsTwo = new AdminUrlUtil(serverURL, 'uploads-2')
94+
customUploadFieldURL = new AdminUrlUtil(serverURL, customUploadFieldSlug)
9295

9396
const context = await browser.newContext()
9497
page = await context.newPage()
@@ -672,6 +675,20 @@ describe('Uploads', () => {
672675
expect(webpMediaDoc.sizes.sizeThree.filesize).toEqual(211638)
673676
})
674677

678+
test('should show custom upload component', async () => {
679+
await page.goto(customUploadFieldURL.create)
680+
681+
const serverText = page.locator(
682+
'.collection-edit--custom-upload-field .document-fields__edit h2',
683+
)
684+
await expect(serverText).toHaveText('This text was rendered on the server')
685+
686+
const clientText = page.locator(
687+
'.collection-edit--custom-upload-field .document-fields__edit h3',
688+
)
689+
await expect(clientText).toHaveText('This text was rendered on the client')
690+
})
691+
675692
describe('remote url fetching', () => {
676693
beforeAll(async () => {
677694
mockCorsServer = startMockCorsServer()

0 commit comments

Comments
 (0)