Settings list columns and filters
Page summary:2 experimental hooks let a plugin extend the API tokens, roles, users, and audit logs lists in Settings.
unstable_inject-column-in-tableadds a column with a custom cell.unstable_inject-in-filtersadds a filter: either one on a core field that joins the existing filters popover, or a plugin-defined dropdown that renders in the toolbar and that the plugin applies on the server.
Before diving deeper into the concepts on this page, please ensure you have:
- created a Strapi plugin,
- read and understood the basics of the Admin Panel API
Both hooks are experimental, hence the unstable_ prefix on their names and on the exported types. Their shape can change in a minor release.
These hooks work like the Content Manager list view hooks, such as the inject-column-in-table hook described in Admin hooks. They apply to 4 Settings lists instead: API tokens, Roles, Users, and Audit logs. With no handler registered, these lists are unchanged.
Adding columns
The Admin/Settings/pages/ListPage/unstable_inject-column-in-table hook receives { list, displayedHeaders } and returns it. A plugin can add, move, or remove headers. A header the plugin adds renders its cell with cellFormatter.
Each list starts with the following core headers, in order:
| List | Core headers |
|---|---|
api-tokens | name, description, createdAt, lastUsedAt |
audit-logs | action, date, user |
roles | name, description, usersCount |
users | firstname, lastname, email, roles, username, isActive |
The following example adds a Team column after the email of each user. The handler returns JSX, so it lives in its own .jsx or .tsx file and the plugin's entry file registers it:
- JavaScript
- TypeScript
// TeamChip is a component of your plugin
import { TeamChip } from '../components/TeamChip';
export const addTeamColumn = ({ list, displayedHeaders }) => {
if (list !== 'users') {
return { list, displayedHeaders };
}
const index = displayedHeaders.findIndex(({ name }) => name === 'email');
const team = {
name: 'my-plugin.team',
label: { id: 'my-plugin.users.team', defaultMessage: 'Team' },
cellFormatter: (user) => <TeamChip user={user} />,
};
return {
list,
displayedHeaders: [
...displayedHeaders.slice(0, index + 1),
team,
...displayedHeaders.slice(index + 1),
],
};
};
import { addTeamColumn } from './hooks/addTeamColumn';
export default {
bootstrap(app) {
app.registerHook(
'Admin/Settings/pages/ListPage/unstable_inject-column-in-table',
addTeamColumn
);
},
};
import type { unstable_InjectSettingsListColumnsArgs as InjectSettingsListColumnsArgs } from '@strapi/admin/strapi-admin';
// TeamChip is a component of your plugin
import { TeamChip } from '../components/TeamChip';
export const addTeamColumn = ({ list, displayedHeaders }: InjectSettingsListColumnsArgs) => {
if (list !== 'users') {
return { list, displayedHeaders };
}
const index = displayedHeaders.findIndex(({ name }) => name === 'email');
const team: (typeof displayedHeaders)[number] = {
name: 'my-plugin.team',
label: { id: 'my-plugin.users.team', defaultMessage: 'Team' },
cellFormatter: (user) => <TeamChip user={user} />,
};
return {
list,
displayedHeaders: [
...displayedHeaders.slice(0, index + 1),
team,
...displayedHeaders.slice(index + 1),
],
};
};
import type { StrapiApp } from '@strapi/admin/strapi-admin';
import { addTeamColumn } from './hooks/addTeamColumn';
export default {
bootstrap(app: StrapiApp) {
app.registerHook(
'Admin/Settings/pages/ListPage/unstable_inject-column-in-table',
addTeamColumn
);
},
};
A header the plugin adds uses the following properties:
| Property | Description |
|---|---|
name | Name of the column. Use a name no core column uses, for example prefixed with the plugin id: a header that reuses the name of a core column conflicts with that column. |
label | Title of the column, as a string or a message descriptor. |
cellFormatter | Function that receives the row and returns the content of the cell. |
Plugin headers are never sortable, because the server only sorts on its own fields.
The hook returns the whole header list, as the Content Manager hook does, so a handler that drops core headers removes those columns. Keep the core headers and add to them.
In TypeScript, checking list narrows the row type: once list === 'users', the headers of displayedHeaders format users. Type the added header as an element of displayedHeaders, as in the example, so its cellFormatter receives a typed user.
Adding filters
The Admin/Settings/pages/ListPage/unstable_inject-in-filters hook receives { list, displayedFilters } and returns it, like the Content Manager's Admin/CM/pages/ListView/inject-in-filters hook. A filter takes one of 2 shapes:
| Shape | Renders in | Sent in | Available on | Applied by |
|---|---|---|---|---|
| Filter on a core field | The filters popover | filters | Users, Roles, and Audit logs | Core |
| Filter on a plugin-defined value | A dropdown in the toolbar | plugins | All 4 lists | The plugin, on the server |
Popover filter on a core field
A filter on a field of the core model joins the list's filters popover and is sent in filters, the same as in the Content Manager.
On Roles, the popover only shows once a plugin adds a filter, and that filter then applies together with the search. API tokens has no popover: its route lists every token and reads no query, so that page ignores filters of this shape.
Toolbar filter on a plugin-defined value
A filter on a value the core model doesn't have, for example a custom scope, uses placement: 'toolbar'. It renders on the right of the toolbar, like the Content Manager's locale picker.
The plugin provides a Component: core passes it value and onChange and keeps the URL in sync. The component loads its own options with hooks, usually rendering unstable_SettingsListToolbarSelect.
- JavaScript
- TypeScript
import { unstable_SettingsListToolbarSelect as SettingsListToolbarSelect } from '@strapi/admin/strapi-admin';
// useGetTeamsQuery is a data-fetching hook of your plugin
import { useGetTeamsQuery } from '../services/teams';
export const TeamFilter = (props) => {
const { data: teams, isLoading } = useGetTeamsQuery();
return (
<SettingsListToolbarSelect
{...props}
label={{ id: 'my-plugin.team', defaultMessage: 'Team' }}
placeholder={{ id: 'my-plugin.team.all', defaultMessage: 'All teams' }}
options={(teams ?? []).map(({ slug, name }) => ({ label: name, value: slug }))}
isLoading={isLoading}
/>
);
};
import { TeamFilter } from './components/TeamFilter';
export default {
bootstrap(app) {
app.registerHook(
'Admin/Settings/pages/ListPage/unstable_inject-in-filters',
({ list, displayedFilters }) => ({
list,
displayedFilters: [
...displayedFilters,
{ placement: 'toolbar', pluginId: 'my-plugin', name: 'team', Component: TeamFilter },
],
})
);
},
};
import { unstable_SettingsListToolbarSelect as SettingsListToolbarSelect } from '@strapi/admin/strapi-admin';
import type { unstable_SettingsListToolbarFilterProps as ToolbarFilterProps } from '@strapi/admin/strapi-admin';
// useGetTeamsQuery is a data-fetching hook of your plugin
import { useGetTeamsQuery } from '../services/teams';
export const TeamFilter = (props: ToolbarFilterProps) => {
const { data: teams, isLoading } = useGetTeamsQuery();
return (
<SettingsListToolbarSelect
{...props}
label={{ id: 'my-plugin.team', defaultMessage: 'Team' }}
placeholder={{ id: 'my-plugin.team.all', defaultMessage: 'All teams' }}
options={(teams ?? []).map(({ slug, name }) => ({ label: name, value: slug }))}
isLoading={isLoading}
/>
);
};
import type {
StrapiApp,
unstable_InjectSettingsListFiltersArgs as InjectSettingsListFiltersArgs,
} from '@strapi/admin/strapi-admin';
import { TeamFilter } from './components/TeamFilter';
export default {
bootstrap(app: StrapiApp) {
app.registerHook(
'Admin/Settings/pages/ListPage/unstable_inject-in-filters',
({ list, displayedFilters }: InjectSettingsListFiltersArgs) => ({
list,
displayedFilters: [
...displayedFilters,
{ placement: 'toolbar', pluginId: 'my-plugin', name: 'team', Component: TeamFilter },
],
})
);
},
};
The example passes the following props to unstable_SettingsListToolbarSelect, in addition to the value and onChange that core passes to the component:
| Prop | Description |
|---|---|
label | Label of the dropdown. |
placeholder | Option that clears the filter. |
options | Options of the dropdown, as { label, value } objects. |
isLoading | Whether the options are loading. While isLoading is true, the dropdown keeps a value from the URL. Once the options are loaded, it clears the value if no option matches it, for example from an outdated link. Without isLoading, a value from the URL is cleared before the options arrive. |
Picking an option brings a paginated list back to its first page.
The dropdown's value goes to the URL and to the list request as plugins[<pluginId>][<name>], for example plugins[my-plugin][team]=blue. It stays apart from filters, which the server validates against the core model. The lists only send the values of registered dropdowns, so a link with a plugins value that no dropdown reads does not filter anything.
Applying a toolbar filter on the server
Core never applies a toolbar filter's value. The Roles, Users, and Audit logs routes, as well as the audit logs export, drop plugins from the query before they read the database, and the API tokens route reads no query at all. The plugin applies the value itself, in 2 parts:
- A middleware on the list route reads
ctx.request.query.plugins[<pluginId>]and keeps the value for the request, for example in anAsyncLocalStoragestore or withstrapi.requestContext. Attach the middleware to the routes, for example in theirconfig.middlewares, rather than comparingctx.path: the Users and Roles pages request/admin/users/and/admin/roles/, with a trailing slash. - A query scope registered with
strapi.db.unstable_scopes.register()turns that value into awherecondition on the listed model.strapi.db.unstable_scopesis experimental too: its name and contract can change in a minor release.
On Audit logs, the export streams its rows after the controller returns, but core reads them in the request's async context. A scope that reads an AsyncLocalStorage store or strapi.requestContext therefore applies to the export as it does to the list. The options of the User filter come from GET /admin/audit-logs/users, which a scope on admin::audit-log does not narrow. A scope on admin::user narrows the users it loads.
The export's continuation token and audit event only cover filters, not plugins. Enforce the plugin's own scope on the server, and never trust the plugins value for access control.