Skip to content

Commit d52dfb7

Browse files
committed
fix
1 parent 8ca6282 commit d52dfb7

5 files changed

Lines changed: 94 additions & 2 deletions

File tree

packages/plugin-multi-tenant/src/components/TenantField/index.client.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export const TenantField = ({ debug, unique, ...fieldArgs }: Props) => {
3434
const { isValid: isFormValid, setModified } = useForm()
3535
const { id: docID, collectionSlug } = useDocumentInfo()
3636
const { isModalOpen, openModal } = useModal()
37-
const isEditManyModalOpen = collectionSlug ? isModalOpen(`edit-${collectionSlug}`) : false
37+
const isEditManyModalOpen = collectionSlug
38+
? isModalOpen(`edit-${collectionSlug}`) || isModalOpen(`edit-${collectionSlug}-bulk-uploads`)
39+
: false
3840
const isConfirmingRef = React.useRef<boolean>(false)
3941
const prevModified = React.useRef(modified)
4042
const prevValue = React.useRef<typeof value>(value)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { CollectionConfig } from 'payload'
2+
3+
import { mediaSlug } from '../shared.js'
4+
5+
export const Media: CollectionConfig = {
6+
slug: mediaSlug,
7+
admin: {
8+
useAsTitle: 'filename',
9+
},
10+
fields: [
11+
{
12+
name: 'alt',
13+
type: 'text',
14+
},
15+
],
16+
upload: true,
17+
}

test/plugin-multi-tenant/config.base.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const dirname = path.dirname(filename)
1010
import type { Config as ConfigType } from './payload-types.js'
1111

1212
import { AutosaveGlobal } from './collections/AutosaveGlobal.js'
13+
import { Media } from './collections/Media.js'
1314
import { Menu } from './collections/Menu.js'
1415
import { MenuItems } from './collections/MenuItems.js'
1516
import { MultiTenantPosts } from './collections/MultiTenantPosts.js'
@@ -19,6 +20,7 @@ import { Users } from './collections/Users/index.js'
1920
import { seed } from './seed/index.js'
2021
import {
2122
autosaveGlobalSlug,
23+
mediaSlug,
2224
menuItemsSlug,
2325
menuSlug,
2426
multiTenantPostsSlug,
@@ -34,6 +36,7 @@ export const baseConfig: Partial<Config> = {
3436
AutosaveGlobal,
3537
Relationships,
3638
MultiTenantPosts,
39+
Media,
3740
{
3841
slug: notTenantedSlug,
3942
admin: {
@@ -110,6 +113,7 @@ export const baseConfig: Partial<Config> = {
110113
hasMany: true,
111114
},
112115
},
116+
[mediaSlug]: {},
113117
},
114118
i18n: {
115119
translations: {

test/plugin-multi-tenant/e2e.spec.ts

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ import { reInitializeDB } from '../__helpers/shared/clearAndSeed/reInitializeDB.
3030
import { initPayloadE2ENoConfig } from '../__helpers/shared/initPayloadE2ENoConfig.js'
3131
import { TEST_TIMEOUT_LONG } from '../playwright.config.js'
3232
import { credentials } from './credentials.js'
33-
import { autosaveGlobalSlug, menuItemsSlug, menuSlug, tenantsSlug, usersSlug } from './shared.js'
33+
import {
34+
autosaveGlobalSlug,
35+
mediaSlug,
36+
menuItemsSlug,
37+
menuSlug,
38+
tenantsSlug,
39+
usersSlug,
40+
} from './shared.js'
3441

3542
const filename = fileURLToPath(import.meta.url)
3643
const dirname = path.dirname(filename)
@@ -40,6 +47,7 @@ test.describe('Multi Tenant', () => {
4047
let serverURL: string
4148
let globalMenuURL: AdminUrlUtil
4249
let autosaveGlobalURL: AdminUrlUtil
50+
let mediaURL: AdminUrlUtil
4351
let menuItemsURL: AdminUrlUtil
4452
let usersURL: AdminUrlUtil
4553
let tenantsURL: AdminUrlUtil
@@ -53,6 +61,7 @@ test.describe('Multi Tenant', () => {
5361
await initPayloadE2ENoConfig<Config>({ dirname })
5462
serverURL = serverFromInit
5563
globalMenuURL = new AdminUrlUtil(serverURL, menuSlug)
64+
mediaURL = new AdminUrlUtil(serverURL, mediaSlug)
5665
menuItemsURL = new AdminUrlUtil(serverURL, menuItemsSlug)
5766
usersURL = new AdminUrlUtil(serverURL, usersSlug)
5867
tenantsURL = new AdminUrlUtil(serverURL, tenantsSlug)
@@ -461,6 +470,64 @@ test.describe('Multi Tenant', () => {
461470
})
462471
})
463472

473+
test.describe('Bulk Upload', () => {
474+
test('should render the tenant field inline in the Edit all drawer for bulk uploads', async () => {
475+
await loginClientSide({
476+
data: credentials.admin,
477+
page,
478+
serverURL,
479+
})
480+
481+
await page.goto(mediaURL.list)
482+
await clearTenantFilter({ page })
483+
484+
await page.locator('.list-header__title-actions button', { hasText: 'Bulk Upload' }).click()
485+
486+
await page
487+
.locator('.dropzone input[type="file"]')
488+
.setInputFiles([
489+
path.resolve(dirname, '../uploads/image.png'),
490+
path.resolve(dirname, '../uploads/test-image.png'),
491+
])
492+
493+
// The per-file form opens an AssignTenantFieldModal automatically; cancel it
494+
// so we can drive the bulk-edit flow ourselves.
495+
const perFileAssignModal = page
496+
.locator('dialog#assign-tenant-field-modal')
497+
.filter({ hasText: 'Assign' })
498+
await expect(perFileAssignModal).toBeVisible()
499+
await perFileAssignModal.locator('button', { hasText: 'Cancel' }).click()
500+
await expect(perFileAssignModal).toBeHidden()
501+
502+
// Open the bulk-upload "Edit all" drawer and pick the Site (tenant) field.
503+
await page.locator('.edit-many-bulk-uploads__toggle').click()
504+
const editManyDrawer = page.locator('dialog#edit-media-bulk-uploads')
505+
await expect(editManyDrawer).toBeVisible()
506+
507+
await selectInput({
508+
multiSelect: true,
509+
options: ['Site'],
510+
selectLocator: editManyDrawer.locator('.edit-many-bulk-uploads__form .react-select'),
511+
})
512+
513+
// The Site field should render inline inside the bulk-edit drawer (like Alt does).
514+
// The bug: TenantField doesn't recognize 'edit-${slug}-bulk-uploads' as an
515+
// edit-many context, so it wraps itself in a non-interactive AssignTenantFieldModal.
516+
const inlineTenantField = editManyDrawer.locator('.tenantField .field-type.relationship')
517+
await expect(inlineTenantField).toBeVisible()
518+
519+
await selectInput({
520+
multiSelect: false,
521+
option: 'Blue Dog',
522+
selectLocator: inlineTenantField,
523+
selectType: 'relationship',
524+
})
525+
await expect(
526+
inlineTenantField.locator('.relationship--single-value__text', { hasText: 'Blue Dog' }),
527+
).toBeVisible()
528+
})
529+
})
530+
464531
test.describe('Globals', () => {
465532
test('should redirect list view to edit view', async () => {
466533
await loginClientSide({

test/plugin-multi-tenant/shared.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ export const relationshipsSlug = 'relationships'
1313
export const notTenantedSlug = 'notTenanted'
1414

1515
export const multiTenantPostsSlug = 'multi-tenant-posts'
16+
17+
export const mediaSlug = 'media'

0 commit comments

Comments
 (0)