Skip to content

Commit bbfe3b5

Browse files
committed
fix UUID breaking relationship filters
1 parent 9b6b74a commit bbfe3b5

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

.changeset/fix-uuid-rel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@keystone-6/core': patch
3+
---
4+
5+
Fix UUID breaking relationship filters

.changeset/light-lamps-eat.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"@keystone-6/core": minor
2+
'@keystone-6/core': minor
33
---
44

55
Add exports for internal AdminUI pagination components `Pagination`, `PaginationLabel` and `usePaginationParams` for use in custom pages

packages/core/src/fields/types/relationship/views/RelationshipSelect.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ function isBigInt (x: string) {
5757
}
5858
}
5959

60+
// TODO: this is unfortunate, remove in breaking change?
61+
function isUuid (x: unknown) {
62+
if (typeof x !== 'string') return
63+
if (x.length !== 36) return
64+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(x)
65+
}
66+
6067
export function useFilter (search: string, list: ListMeta, searchFields: string[]) {
6168
return useMemo(() => {
6269
const trimmedSearch = search.trim()
@@ -70,8 +77,12 @@ export function useFilter (search: string, list: ListMeta, searchFields: string[
7077
conditions.push({ id: { equals: Number(trimmedSearch) } })
7178
} else if (idFieldType === 'BigInt' && isBigInt(trimmedSearch)) {
7279
conditions.push({ id: { equals: trimmedSearch } })
80+
81+
// TODO: remove in breaking change?
7382
} else if (idFieldType === 'UUID') {
74-
conditions.push({ id: { equals: trimmedSearch } }) // TODO: remove in breaking change?
83+
if (isUuid(search)) {
84+
conditions.push({ id: { equals: trimmedSearch } })
85+
}
7586
}
7687

7788
if ((list.fields.id.fieldMeta as any)?.type === 'String') {

packages/core/src/lib/id-field.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function isString (x: IDType) {
3232
return x
3333
}
3434

35-
// TODO: this should be on the user, remove in breaking change
35+
// TODO: this should be on the user, remove in breaking change?
3636
function isUuid (x: IDType) {
3737
if (typeof x !== 'string') return
3838
if (x === '') return

0 commit comments

Comments
 (0)