Skip to content

Commit

Permalink
Fix advanced filter on nullable field (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
cregourd authored Nov 4, 2024
1 parent 0d2b092 commit cb7987d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-mice-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": patch
---

Fix advanced filter on nullable field
15 changes: 11 additions & 4 deletions packages/next-admin/src/utils/advancedSearch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { JSONSchema7 } from "json-schema";
import get from "lodash.get";
import set from "lodash.set";
import z from "zod";
Expand Down Expand Up @@ -330,8 +331,8 @@ export const buildUIBlocks = <M extends ModelName>(

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;
Expand Down Expand Up @@ -497,8 +498,14 @@ export const buildQueryBlocks = <M extends ModelName>(
[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("."), {});
Expand Down

0 comments on commit cb7987d

Please sign in to comment.