feat: adds upload's relationship thumbnail (#5015)
## Description I've made an implementation of the feature requested here: https://github.com/payloadcms/payload/discussions/3407 Before:  After:  - [x] I have read and understand the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository. ## Type of change <!-- Please delete options that are not relevant. --> - [x] New feature (non-breaking change which adds functionality) ## Checklist: - [x] I have added tests that prove my fix is effective or that my feature works - [x] Existing test suite passes locally with my changes
This commit is contained in:
@@ -15,7 +15,10 @@ import {
|
||||
focalOnlySlug,
|
||||
globalWithMedia,
|
||||
mediaSlug,
|
||||
mediaWithRelationPreviewSlug,
|
||||
mediaWithoutRelationPreviewSlug,
|
||||
reduceSlug,
|
||||
relationPreviewSlug,
|
||||
relationSlug,
|
||||
versionSlug,
|
||||
} from './shared'
|
||||
@@ -583,6 +586,67 @@ export default buildConfigWithDefaults({
|
||||
drafts: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
slug: mediaWithRelationPreviewSlug,
|
||||
fields: [
|
||||
{
|
||||
name: 'title',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
upload: {
|
||||
displayPreview: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
slug: mediaWithoutRelationPreviewSlug,
|
||||
fields: [
|
||||
{
|
||||
name: 'title',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
upload: true,
|
||||
},
|
||||
{
|
||||
slug: relationPreviewSlug,
|
||||
fields: [
|
||||
{
|
||||
name: 'imageWithPreview1',
|
||||
type: 'upload',
|
||||
relationTo: mediaWithRelationPreviewSlug,
|
||||
},
|
||||
{
|
||||
name: 'imageWithPreview2',
|
||||
type: 'upload',
|
||||
relationTo: mediaWithRelationPreviewSlug,
|
||||
displayPreview: true,
|
||||
},
|
||||
{
|
||||
name: 'imageWithoutPreview1',
|
||||
type: 'upload',
|
||||
relationTo: mediaWithRelationPreviewSlug,
|
||||
displayPreview: false,
|
||||
},
|
||||
{
|
||||
name: 'imageWithoutPreview2',
|
||||
type: 'upload',
|
||||
relationTo: mediaWithoutRelationPreviewSlug,
|
||||
},
|
||||
{
|
||||
name: 'imageWithPreview3',
|
||||
type: 'upload',
|
||||
relationTo: mediaWithoutRelationPreviewSlug,
|
||||
displayPreview: true,
|
||||
},
|
||||
{
|
||||
name: 'imageWithoutPreview3',
|
||||
type: 'upload',
|
||||
relationTo: mediaWithoutRelationPreviewSlug,
|
||||
displayPreview: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
globals: [
|
||||
{
|
||||
@@ -707,6 +771,31 @@ export default buildConfigWithDefaults({
|
||||
name: `thumb-${imageFile.name}`,
|
||||
},
|
||||
})
|
||||
|
||||
// Create media with and without relation preview
|
||||
const { id: uploadedImageWithPreview } = await payload.create({
|
||||
collection: mediaWithRelationPreviewSlug,
|
||||
data: {},
|
||||
file: imageFile,
|
||||
})
|
||||
|
||||
const { id: uploadedImageWithoutPreview } = await payload.create({
|
||||
collection: mediaWithoutRelationPreviewSlug,
|
||||
data: {},
|
||||
file: imageFile,
|
||||
})
|
||||
|
||||
await payload.create({
|
||||
collection: relationPreviewSlug,
|
||||
data: {
|
||||
imageWithPreview1: uploadedImageWithPreview,
|
||||
imageWithPreview2: uploadedImageWithPreview,
|
||||
imageWithoutPreview1: uploadedImageWithPreview,
|
||||
imageWithoutPreview2: uploadedImageWithoutPreview,
|
||||
imageWithPreview3: uploadedImageWithoutPreview,
|
||||
imageWithoutPreview3: uploadedImageWithoutPreview,
|
||||
},
|
||||
})
|
||||
},
|
||||
serverURL: undefined,
|
||||
})
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { Media } from './payload-types'
|
||||
|
||||
import payload from '../../packages/payload/src'
|
||||
import wait from '../../packages/payload/src/utilities/wait'
|
||||
import { initPageConsoleErrorCatch, saveDocAndAssert } from '../helpers'
|
||||
import { exactText, initPageConsoleErrorCatch, saveDocAndAssert } from '../helpers'
|
||||
import { AdminUrlUtil } from '../helpers/adminUrlUtil'
|
||||
import { initPayloadE2E } from '../helpers/configHelpers'
|
||||
import { RESTClient } from '../helpers/rest'
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
focalOnlySlug,
|
||||
globalWithMedia,
|
||||
mediaSlug,
|
||||
relationPreviewSlug,
|
||||
relationSlug,
|
||||
withMetadataSlug,
|
||||
withOnlyJPEGMetadataSlug,
|
||||
@@ -38,6 +39,7 @@ let focalOnlyURL: AdminUrlUtil
|
||||
let withMetadataURL: AdminUrlUtil
|
||||
let withoutMetadataURL: AdminUrlUtil
|
||||
let withOnlyJPEGMetadataURL: AdminUrlUtil
|
||||
let relationPreviewURL: AdminUrlUtil
|
||||
|
||||
describe('uploads', () => {
|
||||
let page: Page
|
||||
@@ -59,6 +61,7 @@ describe('uploads', () => {
|
||||
withMetadataURL = new AdminUrlUtil(serverURL, withMetadataSlug)
|
||||
withoutMetadataURL = new AdminUrlUtil(serverURL, withoutMetadataSlug)
|
||||
withOnlyJPEGMetadataURL = new AdminUrlUtil(serverURL, withOnlyJPEGMetadataSlug)
|
||||
relationPreviewURL = new AdminUrlUtil(serverURL, relationPreviewSlug)
|
||||
|
||||
const context = await browser.newContext()
|
||||
page = await context.newPage()
|
||||
@@ -536,6 +539,50 @@ describe('uploads', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('should see upload previews in relation list if allowed in config', async () => {
|
||||
await page.goto(relationPreviewURL.list)
|
||||
|
||||
await wait(110)
|
||||
|
||||
// Show all columns with relations
|
||||
await page.locator('.list-controls__toggle-columns').click()
|
||||
await expect(page.locator('.column-selector')).toBeVisible()
|
||||
const imageWithoutPreview2Button = page.locator(`.column-selector .column-selector__column`, {
|
||||
hasText: exactText('Image Without Preview2'),
|
||||
})
|
||||
const imageWithPreview3Button = page.locator(`.column-selector .column-selector__column`, {
|
||||
hasText: exactText('Image With Preview3'),
|
||||
})
|
||||
const imageWithoutPreview3Button = page.locator(`.column-selector .column-selector__column`, {
|
||||
hasText: exactText('Image Without Preview3'),
|
||||
})
|
||||
await imageWithoutPreview2Button.click()
|
||||
await imageWithPreview3Button.click()
|
||||
await imageWithoutPreview3Button.click()
|
||||
|
||||
// Wait for the columns to be displayed
|
||||
await expect(page.locator('.cell-imageWithoutPreview3')).toBeVisible()
|
||||
|
||||
// collection's displayPreview: true, field's displayPreview: unset
|
||||
const relationPreview1 = page.locator('.cell-imageWithPreview1 img')
|
||||
await expect(relationPreview1).toBeVisible()
|
||||
// collection's displayPreview: true, field's displayPreview: true
|
||||
const relationPreview2 = page.locator('.cell-imageWithPreview2 img')
|
||||
await expect(relationPreview2).toBeVisible()
|
||||
// collection's displayPreview: true, field's displayPreview: false
|
||||
const relationPreview3 = page.locator('.cell-imageWithoutPreview1 img')
|
||||
await expect(relationPreview3).toBeHidden()
|
||||
// collection's displayPreview: false, field's displayPreview: unset
|
||||
const relationPreview4 = page.locator('.cell-imageWithoutPreview2 img')
|
||||
await expect(relationPreview4).toBeHidden()
|
||||
// collection's displayPreview: false, field's displayPreview: true
|
||||
const relationPreview5 = page.locator('.cell-imageWithPreview3 img')
|
||||
await expect(relationPreview5).toBeVisible()
|
||||
// collection's displayPreview: false, field's displayPreview: false
|
||||
const relationPreview6 = page.locator('.cell-imageWithoutPreview3 img')
|
||||
await expect(relationPreview6).toBeHidden()
|
||||
})
|
||||
|
||||
describe('globals', () => {
|
||||
test('should be able to crop media from a global', async () => {
|
||||
await page.goto(globalURL)
|
||||
|
||||
@@ -6,6 +6,9 @@ export const focalOnlySlug = 'focal-only'
|
||||
export const mediaSlug = 'media'
|
||||
export const reduceSlug = 'reduce'
|
||||
export const relationSlug = 'relation'
|
||||
export const relationPreviewSlug = 'relation-preview'
|
||||
export const mediaWithRelationPreviewSlug = 'media-with-relation-preview'
|
||||
export const mediaWithoutRelationPreviewSlug = 'media-without-relation-preview'
|
||||
export const versionSlug = 'versions'
|
||||
export const globalWithMedia = 'global-with-media'
|
||||
export const animatedTypeMedia = 'animated-type-media'
|
||||
|
||||
Reference in New Issue
Block a user