-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(plugin-multi-tenant): allow overriding filter options #13937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
field.filterOptions = async (args) => { | ||
const originalFilterResult = | ||
typeof originalFilter === 'function' ? await originalFilter(args) : (originalFilter ?? true) | ||
const getResult = async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff from line 173 - 211 is just wrapping the original code inside getResult
.
and: [originalFilterResult, tenantFilterResults], | ||
} | ||
} | ||
let result = await getResult() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New functionality is implemented starting here
By default, relationships fields where relationTo links to a multi-tenant enabled collection will automatically have filterOptions attached by the plugin. These ensure you can only link to documents within the same tenant.
In some cases, you may want to override these filterOptions to allow linking to documents from certain different tenant.
My use-case:
We have a relationship field that links to documents from the
users
collection. By default, you can only select users from the same tenant as the parent document. However, I would also like to allow selecting admin users that have access to all tenants. To do that, I would do the following: