fix: scopes uploadEdits to documents, hoists action to doc provider (#6664)
Fixes https://github.com/payloadcms/payload/issues/6545 ### Description Correctly scopes upload edits to a single doc, previously they were stored on the top level document. - Removes formQueryParams in favor of an upload edit provider. - Hoists the document `action` up to the doc provider
This commit is contained in:
@@ -19,6 +19,13 @@ const access = {
|
||||
}
|
||||
|
||||
export default buildConfigWithDefaults({
|
||||
collections: [
|
||||
{
|
||||
slug: 'media',
|
||||
upload: true,
|
||||
fields: [],
|
||||
},
|
||||
],
|
||||
globals: [
|
||||
{
|
||||
access,
|
||||
@@ -31,6 +38,11 @@ export default buildConfigWithDefaults({
|
||||
name: 'title',
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
name: 'media',
|
||||
type: 'upload',
|
||||
relationTo: 'media',
|
||||
},
|
||||
],
|
||||
slug,
|
||||
},
|
||||
|
||||
29
test/globals/e2e.spec.ts
Normal file
29
test/globals/e2e.spec.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import type { Page } from '@playwright/test'
|
||||
|
||||
import { expect, test } from '@playwright/test'
|
||||
|
||||
import { initPageConsoleErrorCatch } from '../helpers'
|
||||
import { AdminUrlUtil } from '../helpers/adminUrlUtil'
|
||||
import { initPayloadE2E } from '../helpers/configHelpers'
|
||||
|
||||
const { beforeAll, describe } = test
|
||||
|
||||
describe('Globals', () => {
|
||||
let page: Page
|
||||
let url: AdminUrlUtil
|
||||
|
||||
beforeAll(async ({ browser }) => {
|
||||
const { serverURL } = await initPayloadE2E(__dirname)
|
||||
url = new AdminUrlUtil(serverURL, 'media')
|
||||
|
||||
const context = await browser.newContext()
|
||||
page = await context.newPage()
|
||||
initPageConsoleErrorCatch(page)
|
||||
})
|
||||
|
||||
test('can edit media from field', async () => {
|
||||
await page.goto(url.create)
|
||||
|
||||
// const textCell = page.locator('.row-1 .cell-text')
|
||||
})
|
||||
})
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
cropOnlySlug,
|
||||
enlargeSlug,
|
||||
focalOnlySlug,
|
||||
globalWithMedia,
|
||||
mediaSlug,
|
||||
reduceSlug,
|
||||
relationSlug,
|
||||
@@ -491,6 +492,18 @@ export default buildConfigWithDefaults({
|
||||
},
|
||||
},
|
||||
],
|
||||
globals: [
|
||||
{
|
||||
slug: globalWithMedia,
|
||||
fields: [
|
||||
{
|
||||
type: 'upload',
|
||||
name: 'media',
|
||||
relationTo: cropOnlySlug,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
onInit: async (payload) => {
|
||||
const uploadsDir = path.resolve(__dirname, './media')
|
||||
removeFiles(path.normalize(uploadsDir))
|
||||
|
||||
@@ -12,7 +12,7 @@ import { AdminUrlUtil } from '../helpers/adminUrlUtil'
|
||||
import { initPayloadE2E } from '../helpers/configHelpers'
|
||||
import { RESTClient } from '../helpers/rest'
|
||||
import { adminThumbnailSrc } from './collections/admin-thumbnail'
|
||||
import { adminThumbnailSlug, audioSlug, mediaSlug, relationSlug } from './shared'
|
||||
import { adminThumbnailSlug, audioSlug, globalWithMedia, mediaSlug, relationSlug } from './shared'
|
||||
|
||||
const { beforeAll, describe } = test
|
||||
|
||||
@@ -21,6 +21,7 @@ let mediaURL: AdminUrlUtil
|
||||
let audioURL: AdminUrlUtil
|
||||
let relationURL: AdminUrlUtil
|
||||
let adminThumbnailURL: AdminUrlUtil
|
||||
let globalURL: string
|
||||
|
||||
describe('uploads', () => {
|
||||
let page: Page
|
||||
@@ -36,6 +37,7 @@ describe('uploads', () => {
|
||||
audioURL = new AdminUrlUtil(serverURL, audioSlug)
|
||||
relationURL = new AdminUrlUtil(serverURL, relationSlug)
|
||||
adminThumbnailURL = new AdminUrlUtil(serverURL, adminThumbnailSlug)
|
||||
globalURL = new AdminUrlUtil(serverURL, globalWithMedia).global(globalWithMedia)
|
||||
|
||||
const context = await browser.newContext()
|
||||
page = await context.newPage()
|
||||
@@ -323,4 +325,17 @@ describe('uploads', () => {
|
||||
expect(redDoc.filesize).toEqual(1207)
|
||||
})
|
||||
})
|
||||
|
||||
describe('globals', () => {
|
||||
test('should be able to crop media from a global', async () => {
|
||||
await page.goto(globalURL)
|
||||
await page.click('.upload__toggler.doc-drawer__toggler')
|
||||
await page.setInputFiles('input[type="file"]', path.resolve(__dirname, './image.png'))
|
||||
await page.click('.file-field__edit')
|
||||
await page.click('.btn.edit-upload__save')
|
||||
await saveDocAndAssert(page, '.drawer__content #action-save')
|
||||
await saveDocAndAssert(page)
|
||||
await expect(page.locator('.thumbnail img')).toBeVisible()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -7,3 +7,4 @@ export const mediaSlug = 'media'
|
||||
export const reduceSlug = 'reduce'
|
||||
export const relationSlug = 'relation'
|
||||
export const versionSlug = 'versions'
|
||||
export const globalWithMedia = 'global-with-media'
|
||||
|
||||
Reference in New Issue
Block a user