Skip to content

Commit ffed540

Browse files
authored
fix(ui): listSearchableFields can resolve to multiple fields with the same name when using tabs (#13668)
Fixes #13665 This PR fixes the issue by searching only for the first field with the given name. I used a Set to iterate over the array of fields only once. The question remains: What happens if someone wants to search for a nested field that has the same name as a top-level field? I think this is a much less likely scenario than the one that happened to OP in #13665, and in that case the user would probably want to change the name of the nested field. If we see this as a problem in the future, we can consider something like using paths (`tabName.fieldName`). For review, the example snippet that appears in the issue can be used.
1 parent 15e462b commit ffed540

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/ui/src/elements/ListControls/getTextFieldsToBeSearched.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@ export const getTextFieldsToBeSearched = (
1515
moveSubFieldsToTop: true,
1616
}) as ClientField[]
1717

18-
return flattenedFields.filter(
19-
(field) => fieldAffectsData(field) && listSearchableFields.includes(field.name),
20-
)
18+
const searchableFieldNames = new Set(listSearchableFields)
19+
const matchingFields: typeof flattenedFields = []
20+
21+
for (const field of flattenedFields) {
22+
if (fieldAffectsData(field) && searchableFieldNames.has(field.name)) {
23+
matchingFields.push(field)
24+
searchableFieldNames.delete(field.name)
25+
}
26+
}
27+
28+
return matchingFields
2129
}
2230

2331
return null

0 commit comments

Comments
 (0)