Skip to content

Commit f1b005c

Browse files
authored
fix(ui): object type field labels not displaying in search filter (#11366)
This PR ensures that when `titleField.label` is provided as an object, it is correctly translated and displayed in the search filter's placeholder. Previously, the implementation only supported string values, which could lead to issues with object type labels. With these changes, object type labels will now properly show as intended in the search filter. Fixes #11348
1 parent dc9e8fa commit f1b005c

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed

packages/ui/src/elements/ListControls/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export const ListControls: React.FC<ListControlsProps> = (props) => {
7373
const searchLabel =
7474
(titleField &&
7575
getTranslation(
76-
'label' in titleField && typeof titleField.label === 'string'
76+
'label' in titleField &&
77+
(typeof titleField.label === 'string' || typeof titleField.label === 'object')
7778
? titleField.label
7879
: 'name' in titleField
7980
? titleField.name

test/localization/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,16 @@ export default buildConfigWithDefaults({
6464
NestedArray,
6565
NestedFields,
6666
{
67+
admin: {
68+
listSearchableFields: 'name',
69+
},
6770
auth: true,
6871
fields: [
72+
{
73+
name: 'name',
74+
label: { en: 'Full name' },
75+
type: 'text',
76+
},
6977
{
7078
name: 'relation',
7179
relationTo: localizedPostsSlug,
@@ -83,6 +91,7 @@ export default buildConfigWithDefaults({
8391
fields: [
8492
{
8593
name: 'title',
94+
label: { en: 'Full title' },
8695
index: true,
8796
localized: true,
8897
type: 'text',

test/localization/e2e.spec.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import type { BrowserContext, Page } from '@playwright/test'
2+
import type { GeneratedTypes } from 'helpers/sdk/types.js'
23

34
import { expect, test } from '@playwright/test'
5+
import { navigateToDoc } from 'helpers/e2e/navigateToDoc.js'
46
import { openDocControls } from 'helpers/e2e/openDocControls.js'
7+
import { upsertPrefs } from 'helpers/e2e/upsertPrefs.js'
8+
import { RESTClient } from 'helpers/rest.js'
59
import path from 'path'
610
import { fileURLToPath } from 'url'
711

@@ -31,11 +35,6 @@ import {
3135
spanishLocale,
3236
withRequiredLocalizedFields,
3337
} from './shared.js'
34-
import { navigateToDoc } from 'helpers/e2e/navigateToDoc.js'
35-
36-
import { upsertPrefs } from 'helpers/e2e/upsertPrefs.js'
37-
import { RESTClient } from 'helpers/rest.js'
38-
import { GeneratedTypes } from 'helpers/sdk/types.js'
3938

4039
const filename = fileURLToPath(import.meta.url)
4140
const dirname = path.dirname(filename)
@@ -119,16 +118,16 @@ describe('Localization', () => {
119118

120119
await expect(page.locator('.localizer .popup')).toHaveClass(/popup--active/)
121120

122-
const activeOption = await page.locator(
121+
const activeOption = page.locator(
123122
`.localizer .popup.popup--active .popup-button-list__button--selected`,
124123
)
125124

126125
await expect(activeOption).toBeVisible()
127126
const tagName = await activeOption.evaluate((node) => node.tagName)
128-
await expect(tagName).not.toBe('A')
127+
expect(tagName).not.toBe('A')
129128
await expect(activeOption).not.toHaveAttribute('href')
130-
await expect(tagName).not.toBe('BUTTON')
131-
await expect(tagName).toBe('DIV')
129+
expect(tagName).not.toBe('BUTTON')
130+
expect(tagName).toBe('DIV')
132131
})
133132
})
134133

@@ -140,7 +139,7 @@ describe('Localization', () => {
140139
const createNewButtonLocator =
141140
'.collection-list a[href="/admin/collections/cannot-create-default-locale/create"]'
142141

143-
await expect(page.locator(createNewButtonLocator)).not.toBeVisible()
142+
await expect(page.locator(createNewButtonLocator)).toBeHidden()
144143
await changeLocale(page, spanishLocale)
145144
await expect(page.locator(createNewButtonLocator).first()).toBeVisible()
146145
await page.goto(urlCannotCreateDefaultLocale.create)
@@ -330,11 +329,11 @@ describe('Localization', () => {
330329

331330
await page.goto(url.list)
332331

333-
const localeLabel = await page
332+
const localeLabel = page
334333
.locator('.localizer.app-header__localizer .localizer-button__current-label')
335-
.innerText()
334+
336335

337-
expect(localeLabel).not.toEqual('English')
336+
await expect(localeLabel).not.toHaveText('English')
338337
})
339338
})
340339

@@ -351,7 +350,7 @@ describe('Localization', () => {
351350
await navigateToDoc(page, urlRelationshipLocalized)
352351
const drawerToggler =
353352
'#field-relationMultiRelationTo .relationship--single-value__drawer-toggler'
354-
expect(page.locator(drawerToggler)).toBeEnabled()
353+
await expect(page.locator(drawerToggler)).toBeEnabled()
355354
await openDocDrawer(page, drawerToggler)
356355
await expect(page.locator('.doc-drawer__header-text')).toContainText('spanish-relation2')
357356
await page.locator('.doc-drawer__header-close').click()
@@ -518,7 +517,7 @@ describe('Localization', () => {
518517

519518
// only throttle test after initial load to avoid timeouts
520519
const cdpSession = await throttleTest({
521-
page: page,
520+
page,
522521
context,
523522
delay: 'Fast 4G',
524523
})
@@ -541,6 +540,13 @@ describe('Localization', () => {
541540
await cdpSession.detach()
542541
})
543542
})
543+
544+
test('should use label in search filter when string or object', async () => {
545+
await page.goto(url.list)
546+
const searchInput = page.locator('.search-filter__input')
547+
await expect(searchInput).toBeVisible()
548+
await expect(searchInput).toHaveAttribute('placeholder', 'Search by Full title')
549+
})
544550
})
545551

546552
async function fillValues(data: Partial<LocalizedPost>) {

test/localization/payload-types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export interface Config {
6464
auth: {
6565
users: UserAuthOperations;
6666
};
67-
blocks: {};
6867
collections: {
6968
richText: RichText;
7069
'blocks-fields': BlocksField;
@@ -322,6 +321,7 @@ export interface NestedFieldTable {
322321
*/
323322
export interface User {
324323
id: string;
324+
name?: string | null;
325325
relation?: (string | null) | LocalizedPost;
326326
updatedAt: string;
327327
createdAt: string;
@@ -928,6 +928,7 @@ export interface NestedFieldTablesSelect<T extends boolean = true> {
928928
* via the `definition` "users_select".
929929
*/
930930
export interface UsersSelect<T extends boolean = true> {
931+
name?: T;
931932
relation?: T;
932933
updatedAt?: T;
933934
createdAt?: T;

0 commit comments

Comments
 (0)