From cb7987d94515c975ba3f2055956d5363100f3c5d Mon Sep 17 00:00:00 2001 From: Regourd Colin Date: Mon, 4 Nov 2024 14:04:13 +0100 Subject: [PATCH] Fix advanced filter on nullable field (#482) --- .changeset/chilled-mice-approve.md | 5 +++++ packages/next-admin/src/utils/advancedSearch.ts | 15 +++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 .changeset/chilled-mice-approve.md diff --git a/.changeset/chilled-mice-approve.md b/.changeset/chilled-mice-approve.md new file mode 100644 index 00000000..2db63461 --- /dev/null +++ b/.changeset/chilled-mice-approve.md @@ -0,0 +1,5 @@ +--- +"@premieroctet/next-admin": patch +--- + +Fix advanced filter on nullable field diff --git a/packages/next-admin/src/utils/advancedSearch.ts b/packages/next-admin/src/utils/advancedSearch.ts index 9c74ddda..ac655425 100644 --- a/packages/next-admin/src/utils/advancedSearch.ts +++ b/packages/next-admin/src/utils/advancedSearch.ts @@ -1,3 +1,4 @@ +import { JSONSchema7 } from "json-schema"; import get from "lodash.get"; import set from "lodash.set"; import z from "zod"; @@ -330,8 +331,8 @@ export const buildUIBlocks = ( const childResourceName = ( isArrayConditionKey - ? schemaProperty.items?.$ref - : schemaProperty.$ref + ? schemaProperty.items?.$ref || (schemaProperty?.anyOf?.[0] as JSONSchema7)?.$ref + : schemaProperty.$ref || (schemaProperty?.anyOf?.[0] as JSONSchema7)?.$ref ) ?.split("/") ?.at(-1)! as keyof typeof schema.definitions; @@ -497,8 +498,14 @@ export const buildQueryBlocks = ( [path, basePath, "some"].filter(Boolean).join(".") ); } - } else if (schemaProperty?.$ref) { - const childResource = schemaProperty.$ref.split("/").at(-1)!; + } else if ( + schemaProperty && + (schemaProperty?.$ref || (schemaProperty?.anyOf?.[0] as JSONSchema7)?.$ref) + ) { + const ref = + schemaProperty.$ref || + (schemaProperty.anyOf?.[0] as JSONSchema7)?.$ref; + const childResource = ref!.split("/").at(-1)!; if (!get(acc, [path, basePath].filter(Boolean))) { set(acc, [path, basePath].filter(Boolean).join("."), {});