Skip to content

Commit

Permalink
fix(ui): error in filtered relationship field component while scrolli…
Browse files Browse the repository at this point in the history
…ng, if the select option label is a number (#9117)

1. Open fields test suite
2. Type in relationship field, that has a relation to the numbers
collection
3. Scroll

You will get an error, as the label for the entry corresponding to the
numbers collection is of type number, and it attempts to use the
.toString() method on it
  • Loading branch information
AlessioGr authored Nov 12, 2024
1 parent 9c559d7 commit 2ad9917
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/ui/src/fields/Relationship/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -537,17 +537,19 @@ const RelationshipFieldComponent: RelationshipFieldClientComponent = (props) =>
const r = wordBoundariesRegex(searchFilter || '')
// breaking the labels to search into smaller parts increases performance
const breakApartThreshold = 250
let string = item.label
let labelString = String(item.label)
// strings less than breakApartThreshold length won't be chunked
while (string.length > breakApartThreshold) {
while (labelString.length > breakApartThreshold) {
// slicing by the next space after the length of the search input prevents slicing the string up by partial words
const indexOfSpace = string.indexOf(' ', searchFilter.length)
if (r.test(string.slice(0, indexOfSpace === -1 ? searchFilter.length : indexOfSpace + 1))) {
const indexOfSpace = labelString.indexOf(' ', searchFilter.length)
if (
r.test(labelString.slice(0, indexOfSpace === -1 ? searchFilter.length : indexOfSpace + 1))
) {
return true
}
string = string.slice(indexOfSpace === -1 ? searchFilter.length : indexOfSpace + 1)
labelString = labelString.slice(indexOfSpace === -1 ? searchFilter.length : indexOfSpace + 1)
}
return r.test(string.slice(-breakApartThreshold))
return r.test(labelString.slice(-breakApartThreshold))
}, [])

const onDocumentDrawerOpen = useCallback<
Expand Down

0 comments on commit 2ad9917

Please sign in to comment.