@mservices-tech/strapi-plugin-relation-filter
v0.0.2
Published
Strapi plugin that filters entries offered in Content Manager relation pickers based on pluginOptions defined in content-type schemas.
Readme
@mservices-tech/strapi-plugin-relation-filter
Strapi plugin that filters entries offered in Content Manager relation pickers
(admin routes relations.findAvailable and relations.findExisting) based on
filters declared in content-type schemas.
Installation
yarn add @mservices-tech/strapi-plugin-relation-filterEnable the plugin in config/plugins.js:
module.exports = {
'relation-filter': {
enabled: true,
},
};Usage
Declare filters under pluginOptions["relation-filter"] of a relation attribute
in the content-type schema.json:
{
"pageContents": {
"type": "relation",
"pluginOptions": {
"relation-filter": {
"filters": {
"category": { "$eq": "brand manual" }
}
}
}
}
}The filter syntax is the standard Strapi filter syntax. The configured filters
override the query.filters of the admin panel request; picker search (_q)
keeps working as is.
Extension point
The config service (getAttributePluginConfig) is an intentional extension
point. Applications can wrap it in src/extensions/relation-filter/strapi-server.js
to make the filtering conditional (e.g. apply filters only for selected admin
roles).
Compatibility
The plugin relies on the content-manager admin routes relations.findAvailable
and relations.findExisting — verify they still exist when bumping Strapi.
