revert(admin): remove MediaThumbnailCell — crashes admin list view
This commit is contained in:
parent
f6712ae8d2
commit
8e2b79f01f
2 changed files with 21 additions and 18 deletions
|
|
@ -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' }],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,22 +2,37 @@
|
|||
|
||||
interface Props {
|
||||
cellData?: string
|
||||
rowData?: Record<string, unknown>
|
||||
// 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 (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
{url && (
|
||||
{imgUrl && isImage && (
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img
|
||||
src={url}
|
||||
src={imgUrl}
|
||||
alt=""
|
||||
style={{ width: 40, height: 40, objectFit: 'cover', borderRadius: 4, flexShrink: 0 }}
|
||||
/>
|
||||
)}
|
||||
<span>{cellData}</span>
|
||||
<span>{text}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue