fix: error when passing functions to array or block fields labels property (#11056)
Fixes https://github.com/payloadcms/payload/issues/11055 Functions passed to array field, block field or block `labels` were not properly handled in the client config, causing those functions to be sent to the client. This leads to a "Functions cannot be passed directly to Client Component" error
This commit is contained in:
@@ -133,6 +133,13 @@ describe('Array', () => {
|
||||
await expect(page.locator('#field-items #items-row-0 .row-label')).toContainText('Item 01')
|
||||
})
|
||||
|
||||
test('ensure functions passed to array field labels property are respected', async () => {
|
||||
await page.goto(url.create)
|
||||
|
||||
const arrayWithLabelsField = page.locator('#field-arrayWithLabels')
|
||||
await expect(arrayWithLabelsField.locator('.array-field__add-row')).toHaveText('Add Account')
|
||||
})
|
||||
|
||||
describe('row manipulation', () => {
|
||||
test('should add, remove and duplicate rows', async () => {
|
||||
const assertText0 = 'array row 1'
|
||||
|
||||
@@ -246,6 +246,20 @@ const ArrayFields: CollectionConfig = {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'arrayWithLabels',
|
||||
type: 'array',
|
||||
labels: {
|
||||
singular: ({ t }) => t('authentication:account'),
|
||||
plural: ({ t }) => t('authentication:generate'),
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'text',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
slug: arrayFieldsSlug,
|
||||
versions: true,
|
||||
|
||||
@@ -212,7 +212,7 @@ describe('Block fields', () => {
|
||||
.click()
|
||||
|
||||
await expect(
|
||||
await page.locator('#field-blocks .blocks-field__row .blocks-field__block-header', {
|
||||
page.locator('#field-blocks .blocks-field__row .blocks-field__block-header', {
|
||||
hasText: 'Custom Block Label',
|
||||
}),
|
||||
).toBeVisible()
|
||||
@@ -292,6 +292,16 @@ describe('Block fields', () => {
|
||||
)
|
||||
})
|
||||
|
||||
test('ensure functions passed to blocks field labels property are respected', async () => {
|
||||
await page.goto(url.create)
|
||||
|
||||
const blocksFieldWithLabels = page.locator('#field-blockWithLabels')
|
||||
|
||||
await expect(blocksFieldWithLabels.locator('.blocks-field__drawer-toggler')).toHaveText(
|
||||
'Add Account',
|
||||
)
|
||||
})
|
||||
|
||||
describe('row manipulation', () => {
|
||||
describe('react hooks', () => {
|
||||
test('should add 2 new block rows', async () => {
|
||||
|
||||
@@ -373,6 +373,29 @@ const BlockFields: CollectionConfig = {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'blockWithLabels',
|
||||
type: 'blocks',
|
||||
labels: {
|
||||
singular: ({ t }) => t('authentication:account'),
|
||||
plural: ({ t }) => t('authentication:generate'),
|
||||
},
|
||||
blocks: [
|
||||
{
|
||||
labels: {
|
||||
singular: ({ t }) => t('authentication:account'),
|
||||
plural: ({ t }) => t('authentication:generate'),
|
||||
},
|
||||
slug: 'text',
|
||||
fields: [
|
||||
{
|
||||
name: 'text',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@@ -595,6 +595,12 @@ export interface ArrayField {
|
||||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
arrayWithLabels?:
|
||||
| {
|
||||
text?: string | null;
|
||||
id?: string | null;
|
||||
}[]
|
||||
| null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
@@ -727,6 +733,14 @@ export interface BlockField {
|
||||
blockType: 'relationships';
|
||||
}[]
|
||||
| null;
|
||||
blockWithLabels?:
|
||||
| {
|
||||
text?: string | null;
|
||||
id?: string | null;
|
||||
blockName?: string | null;
|
||||
blockType: 'text';
|
||||
}[]
|
||||
| null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
@@ -2265,6 +2279,12 @@ export interface ArrayFieldsSelect<T extends boolean = true> {
|
||||
text?: T;
|
||||
id?: T;
|
||||
};
|
||||
arrayWithLabels?:
|
||||
| T
|
||||
| {
|
||||
text?: T;
|
||||
id?: T;
|
||||
};
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
}
|
||||
@@ -2446,6 +2466,17 @@ export interface BlockFieldsSelect<T extends boolean = true> {
|
||||
blockName?: T;
|
||||
};
|
||||
};
|
||||
blockWithLabels?:
|
||||
| T
|
||||
| {
|
||||
text?:
|
||||
| T
|
||||
| {
|
||||
text?: T;
|
||||
id?: T;
|
||||
blockName?: T;
|
||||
};
|
||||
};
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user