Skip to content

Commit e83f452

Browse files
authored
fix(plugin-import-export): translated preview labels (#11758)
### What? The import-export preview UI component does not handle localized fields and crash the UI when they are used. This fixes that issue. ### Why? We were not properly handling the label translated object notation that field.label can have. ### How? Now we call `getTranslation` with the field label to handle language keyed labels. Fixes # #11668
1 parent f31e5e6 commit e83f452

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

packages/plugin-import-export/src/components/Preview/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import type { Column } from '@payloadcms/ui'
33
import type { ClientField, FieldAffectingDataClient } from 'payload'
44

5-
import { Table, useConfig, useField } from '@payloadcms/ui'
5+
import { getTranslation } from '@payloadcms/translations'
6+
import { Table, useConfig, useField, useTranslation } from '@payloadcms/ui'
67
import { fieldAffectsData } from 'payload/shared'
78
import * as qs from 'qs-esm'
89
import React from 'react'
@@ -23,6 +24,7 @@ export const Preview = () => {
2324
const [dataToRender, setDataToRender] = React.useState<any[]>([])
2425
const [resultCount, setResultCount] = React.useState<any>('')
2526
const [columns, setColumns] = React.useState<Column[]>([])
27+
const { i18n } = useTranslation()
2628

2729
const collectionSlug = typeof collection === 'string' && collection
2830
const collectionConfig = config.collections.find(
@@ -75,7 +77,7 @@ export const Preview = () => {
7577
accessor: field.name || '',
7678
active: true,
7779
field: field as ClientField,
78-
Heading: field?.label || field.name,
80+
Heading: getTranslation(field?.label || (field.name as string), i18n),
7981
renderedCells: data.docs.map((doc: Record<string, unknown>) => {
8082
if (!field.name || !doc[field.name]) {
8183
return null

test/plugin-import-export/collections/Pages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const Pages: CollectionConfig = {
1717
fields: [
1818
{
1919
name: 'title',
20-
label: 'Title',
20+
label: { en: 'Title', es: 'Título', de: 'Titel' },
2121
type: 'text',
2222
required: true,
2323
},

test/plugin-import-export/payload-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export type SupportedTimezones =
5454
| 'Asia/Singapore'
5555
| 'Asia/Tokyo'
5656
| 'Asia/Seoul'
57+
| 'Australia/Brisbane'
5758
| 'Australia/Sydney'
5859
| 'Pacific/Guam'
5960
| 'Pacific/Noumea'

0 commit comments

Comments
 (0)