From 8e2b79f01f6b58a95c6f1b159f44f752b498df5d Mon Sep 17 00:00:00 2001 From: Vadym Samoilenko Date: Fri, 5 Jun 2026 11:59:44 +0100 Subject: [PATCH] =?UTF-8?q?revert(admin):=20remove=20MediaThumbnailCell=20?= =?UTF-8?q?=E2=80=94=20crashes=20admin=20list=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/collections/Media.ts | 14 +----------- src/components/admin/MediaThumbnailCell.tsx | 25 ++++++++++++++++----- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/collections/Media.ts b/src/collections/Media.ts index ad337a9..32af577 100644 --- a/src/collections/Media.ts +++ b/src/collections/Media.ts @@ -43,17 +43,5 @@ export const Media: CollectionConfig = { update: isAdminOrEditor, delete: isAdminOrEditor, }, - fields: [ - { - name: 'alt', - type: 'text', - required: true, - label: 'Alt text', - admin: { - components: { - Cell: '@/components/admin/MediaThumbnailCell', - }, - }, - }, - ], + fields: [{ name: 'alt', type: 'text', required: true, label: 'Alt text' }], } diff --git a/src/components/admin/MediaThumbnailCell.tsx b/src/components/admin/MediaThumbnailCell.tsx index ed3d646..495e77c 100644 --- a/src/components/admin/MediaThumbnailCell.tsx +++ b/src/components/admin/MediaThumbnailCell.tsx @@ -2,22 +2,37 @@ interface Props { cellData?: string - rowData?: Record + // Payload v3 passes the full document as rowData + rowData?: { + url?: string + filename?: string + mimeType?: string + alt?: string + sizes?: { tablet?: { url?: string }; mobile?: { url?: string } } + [key: string]: unknown + } } export default function MediaThumbnailCell({ cellData, rowData }: Props) { - const url = (rowData as { url?: string })?.url + const text = cellData ?? rowData?.alt ?? '' + const imgUrl = + rowData?.sizes?.tablet?.url ?? + rowData?.sizes?.mobile?.url ?? + rowData?.url ?? + (rowData?.filename ? `/api/media/file/${rowData.filename}` : undefined) + const isImage = rowData?.mimeType?.startsWith('image/') ?? !!imgUrl + return (
- {url && ( + {imgUrl && isImage && ( // eslint-disable-next-line @next/next/no-img-element )} - {cellData} + {text}
) }