Skip to content

Commit a9ad7c7

Browse files
fix(ui): bulk upload redirecting to relationship documents when added (#13001)
Fixes #12786
1 parent 7a40a9f commit a9ad7c7

File tree

7 files changed

+142
-1
lines changed

7 files changed

+142
-1
lines changed

packages/ui/src/elements/BulkUpload/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React from 'react'
88
import { toast } from 'sonner'
99

1010
import { useConfig } from '../../providers/Config/index.js'
11+
import { EditDepthProvider } from '../../providers/EditDepth/index.js'
1112
import { useTranslation } from '../../providers/Translation/index.js'
1213
import { UploadControlsProvider } from '../../providers/UploadControls/index.js'
1314
import { Drawer, useDrawerDepth } from '../Drawer/index.js'
@@ -77,7 +78,9 @@ export function BulkUploadDrawer() {
7778
<Drawer gutter={false} Header={null} slug={drawerSlug}>
7879
<FormsManagerProvider>
7980
<UploadControlsProvider>
80-
<DrawerContent />
81+
<EditDepthProvider>
82+
<DrawerContent />
83+
</EditDepthProvider>
8184
</UploadControlsProvider>
8285
</FormsManagerProvider>
8386
</Drawer>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { CollectionConfig } from 'payload'
2+
3+
import { bulkUploadsSlug } from '../../shared.js'
4+
5+
export const BulkUploadsCollection: CollectionConfig = {
6+
slug: bulkUploadsSlug,
7+
upload: true,
8+
admin: {
9+
useAsTitle: 'title',
10+
},
11+
fields: [
12+
{
13+
type: 'text',
14+
name: 'title',
15+
required: true,
16+
},
17+
{
18+
name: 'relationship',
19+
type: 'relationship',
20+
relationTo: ['simple-relationship'],
21+
},
22+
],
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { CollectionConfig } from 'payload'
2+
3+
export const SimpleRelationshipCollection: CollectionConfig = {
4+
slug: 'simple-relationship',
5+
admin: {
6+
useAsTitle: 'title',
7+
},
8+
fields: [
9+
{
10+
type: 'text',
11+
name: 'title',
12+
},
13+
],
14+
}

test/uploads/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { AdminThumbnailFunction } from './collections/AdminThumbnailFunction/ind
1111
import { AdminThumbnailSize } from './collections/AdminThumbnailSize/index.js'
1212
import { AdminThumbnailWithSearchQueries } from './collections/AdminThumbnailWithSearchQueries/index.js'
1313
import { AdminUploadControl } from './collections/AdminUploadControl/index.js'
14+
import { BulkUploadsCollection } from './collections/BulkUploads/index.js'
1415
import { CustomUploadFieldCollection } from './collections/CustomUploadField/index.js'
16+
import { SimpleRelationshipCollection } from './collections/SimpleRelationship/index.js'
1517
import { Uploads1 } from './collections/Upload1/index.js'
1618
import { Uploads2 } from './collections/Upload2/index.js'
1719
import {
@@ -880,6 +882,8 @@ export default buildConfigWithDefaults({
880882
staticDir: path.resolve(dirname, './media'),
881883
},
882884
},
885+
BulkUploadsCollection,
886+
SimpleRelationshipCollection,
883887
],
884888
onInit: async (payload) => {
885889
const uploadsDir = path.resolve(dirname, './media')

test/uploads/e2e.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
adminUploadControlSlug,
2929
animatedTypeMedia,
3030
audioSlug,
31+
bulkUploadsSlug,
3132
constructorOptionsSlug,
3233
customFileNameMediaSlug,
3334
customUploadFieldSlug,
@@ -82,6 +83,7 @@ let constructorOptionsURL: AdminUrlUtil
8283
let consoleErrorsFromPage: string[] = []
8384
let collectErrorsFromPage: () => boolean
8485
let stopCollectingErrorsFromPage: () => boolean
86+
let bulkUploadsURL: AdminUrlUtil
8587

8688
describe('Uploads', () => {
8789
let page: Page
@@ -119,6 +121,7 @@ describe('Uploads', () => {
119121
withoutEnlargementResizeOptionsURL = new AdminUrlUtil(serverURL, withoutEnlargeSlug)
120122
threeDimensionalURL = new AdminUrlUtil(serverURL, threeDimensionalSlug)
121123
constructorOptionsURL = new AdminUrlUtil(serverURL, constructorOptionsSlug)
124+
bulkUploadsURL = new AdminUrlUtil(serverURL, bulkUploadsSlug)
122125

123126
const context = await browser.newContext()
124127
page = await context.newPage()
@@ -1193,6 +1196,26 @@ describe('Uploads', () => {
11931196
// ensure the prefix field is still filled with the original value
11941197
await expect(page.locator('#field-prefix')).toHaveValue('should-preserve')
11951198
})
1199+
1200+
test('should not redirect to created relationship document inside the bulk upload drawer', async () => {
1201+
await page.goto(bulkUploadsURL.list)
1202+
await page.locator('.list-header__title-actions button', { hasText: 'Bulk Upload' }).click()
1203+
await page.setInputFiles('.dropzone input[type="file"]', path.resolve(dirname, './image.png'))
1204+
1205+
await page.locator('#field-title').fill('Upload title 1')
1206+
const bulkUploadForm = page.locator('.bulk-upload--file-manager')
1207+
const relationshipField = bulkUploadForm.locator('#field-relationship')
1208+
await relationshipField.locator('.relationship-add-new__add-button').click()
1209+
1210+
const collectionForm = page.locator('.collection-edit')
1211+
await collectionForm.locator('#field-title').fill('Related Document Title')
1212+
await saveDocAndAssert(page)
1213+
await collectionForm.locator('.doc-drawer__header-close').click()
1214+
1215+
await expect(bulkUploadForm.locator('.relationship--single-value__text')).toHaveText(
1216+
'Related Document Title',
1217+
)
1218+
})
11961219
})
11971220

11981221
describe('remote url fetching', () => {

test/uploads/payload-types.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export interface Config {
111111
'list-view-preview': ListViewPreview;
112112
'three-dimensional': ThreeDimensional;
113113
'constructor-options': ConstructorOption;
114+
'bulk-uploads': BulkUpload;
115+
'simple-relationship': SimpleRelationship;
114116
users: User;
115117
'payload-locked-documents': PayloadLockedDocument;
116118
'payload-preferences': PayloadPreference;
@@ -162,6 +164,8 @@ export interface Config {
162164
'list-view-preview': ListViewPreviewSelect<false> | ListViewPreviewSelect<true>;
163165
'three-dimensional': ThreeDimensionalSelect<false> | ThreeDimensionalSelect<true>;
164166
'constructor-options': ConstructorOptionsSelect<false> | ConstructorOptionsSelect<true>;
167+
'bulk-uploads': BulkUploadsSelect<false> | BulkUploadsSelect<true>;
168+
'simple-relationship': SimpleRelationshipSelect<false> | SimpleRelationshipSelect<true>;
165169
users: UsersSelect<false> | UsersSelect<true>;
166170
'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>;
167171
'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>;
@@ -1465,6 +1469,39 @@ export interface ConstructorOption {
14651469
focalX?: number | null;
14661470
focalY?: number | null;
14671471
}
1472+
/**
1473+
* This interface was referenced by `Config`'s JSON-Schema
1474+
* via the `definition` "bulk-uploads".
1475+
*/
1476+
export interface BulkUpload {
1477+
id: string;
1478+
title: string;
1479+
relationship?: {
1480+
relationTo: 'simple-relationship';
1481+
value: string | SimpleRelationship;
1482+
} | null;
1483+
updatedAt: string;
1484+
createdAt: string;
1485+
url?: string | null;
1486+
thumbnailURL?: string | null;
1487+
filename?: string | null;
1488+
mimeType?: string | null;
1489+
filesize?: number | null;
1490+
width?: number | null;
1491+
height?: number | null;
1492+
focalX?: number | null;
1493+
focalY?: number | null;
1494+
}
1495+
/**
1496+
* This interface was referenced by `Config`'s JSON-Schema
1497+
* via the `definition` "simple-relationship".
1498+
*/
1499+
export interface SimpleRelationship {
1500+
id: string;
1501+
title?: string | null;
1502+
updatedAt: string;
1503+
createdAt: string;
1504+
}
14681505
/**
14691506
* This interface was referenced by `Config`'s JSON-Schema
14701507
* via the `definition` "users".
@@ -1672,6 +1709,14 @@ export interface PayloadLockedDocument {
16721709
relationTo: 'constructor-options';
16731710
value: string | ConstructorOption;
16741711
} | null)
1712+
| ({
1713+
relationTo: 'bulk-uploads';
1714+
value: string | BulkUpload;
1715+
} | null)
1716+
| ({
1717+
relationTo: 'simple-relationship';
1718+
value: string | SimpleRelationship;
1719+
} | null)
16751720
| ({
16761721
relationTo: 'users';
16771722
value: string | User;
@@ -3065,6 +3110,34 @@ export interface ConstructorOptionsSelect<T extends boolean = true> {
30653110
focalX?: T;
30663111
focalY?: T;
30673112
}
3113+
/**
3114+
* This interface was referenced by `Config`'s JSON-Schema
3115+
* via the `definition` "bulk-uploads_select".
3116+
*/
3117+
export interface BulkUploadsSelect<T extends boolean = true> {
3118+
title?: T;
3119+
relationship?: T;
3120+
updatedAt?: T;
3121+
createdAt?: T;
3122+
url?: T;
3123+
thumbnailURL?: T;
3124+
filename?: T;
3125+
mimeType?: T;
3126+
filesize?: T;
3127+
width?: T;
3128+
height?: T;
3129+
focalX?: T;
3130+
focalY?: T;
3131+
}
3132+
/**
3133+
* This interface was referenced by `Config`'s JSON-Schema
3134+
* via the `definition` "simple-relationship_select".
3135+
*/
3136+
export interface SimpleRelationshipSelect<T extends boolean = true> {
3137+
title?: T;
3138+
updatedAt?: T;
3139+
createdAt?: T;
3140+
}
30683141
/**
30693142
* This interface was referenced by `Config`'s JSON-Schema
30703143
* via the `definition` "users_select".

test/uploads/shared.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ export const skipAllowListSafeFetchMediaSlug = 'skip-allow-list-safe-fetch-media
3131
export const listViewPreviewSlug = 'list-view-preview'
3232
export const threeDimensionalSlug = 'three-dimensional'
3333
export const constructorOptionsSlug = 'constructor-options'
34+
export const bulkUploadsSlug = 'bulk-uploads'

0 commit comments

Comments
 (0)