From 46a3dbab9b40f535b880fc28f66c7ab39df4feec Mon Sep 17 00:00:00 2001 From: Didrik Munther <5240046+didrikmunther@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:50:49 +0100 Subject: [PATCH] feat: Add where in options (#487) * Add where in options * Add changeset * Comment options and turn into patch --------- Co-authored-by: Colin Regourd --- .changeset/blue-carrots-pump.md | 5 +++++ apps/example/options.tsx | 5 +++++ packages/next-admin/src/types.ts | 4 ++++ packages/next-admin/src/utils/prisma.ts | 5 ++++- 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .changeset/blue-carrots-pump.md diff --git a/.changeset/blue-carrots-pump.md b/.changeset/blue-carrots-pump.md new file mode 100644 index 00000000..4ade96c4 --- /dev/null +++ b/.changeset/blue-carrots-pump.md @@ -0,0 +1,5 @@ +--- +"@premieroctet/next-admin": patch +--- + +Add where clause to model options diff --git a/apps/example/options.tsx b/apps/example/options.tsx index 9c427b72..3d975f57 100644 --- a/apps/example/options.tsx +++ b/apps/example/options.tsx @@ -35,6 +35,11 @@ export const options: NextAdminOptions = { ], search: ["name", "email", "role"], copy: ["email"], + // where: [{ + // role: { + // equals: "USER", + // }, + // }], filters: [ { name: "is Admin", diff --git a/packages/next-admin/src/types.ts b/packages/next-admin/src/types.ts index 25907e1e..3f633f19 100644 --- a/packages/next-admin/src/types.ts +++ b/packages/next-admin/src/types.ts @@ -420,6 +420,10 @@ export type ListOptions = { * define a set of Prisma filters that user can choose in list */ filters?: FilterWrapper[]; + /** + * define a set of Prisma filters that are always active in list + */ + where?: Filter[]; }; export type SubmitResourceResponse = diff --git a/packages/next-admin/src/utils/prisma.ts b/packages/next-admin/src/utils/prisma.ts index 22450e5a..47ec1a15 100644 --- a/packages/next-admin/src/utils/prisma.ts +++ b/packages/next-admin/src/utils/prisma.ts @@ -331,7 +331,10 @@ const preparePrismaListRequest = ( resource, options, search, - otherFilters: fieldFilters, + otherFilters: [ + ...fieldFilters ?? [], + ...list?.where ?? [] + ], advancedSearch, });