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, });