Skip to main content

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-table adds a column with a custom cell. unstable_inject-in-filters adds 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.

Prerequisites

Before diving deeper into the concepts on this page, please ensure you have:

Caution

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:

ListCore headers
api-tokensname, description, createdAt, lastUsedAt
audit-logsaction, date, user
rolesname, description, usersCount
usersfirstname, 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:

my-plugin/admin/src/hooks/addTeamColumn.jsx
// 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),
],
};
};
my-plugin/admin/src/index.js
import { addTeamColumn } from './hooks/addTeamColumn';

export default {
bootstrap(app) {
app.registerHook(
'Admin/Settings/pages/ListPage/unstable_inject-column-in-table',
addTeamColumn
);
},
};

A header the plugin adds uses the following properties:

PropertyDescription
nameName 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.
labelTitle of the column, as a string or a message descriptor.
cellFormatterFunction 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:

ShapeRenders inSent inAvailable onApplied by
Filter on a core fieldThe filters popoverfiltersUsers, Roles, and Audit logsCore
Filter on a plugin-defined valueA dropdown in the toolbarpluginsAll 4 listsThe 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.

my-plugin/admin/src/components/TeamFilter.jsx
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}
/>
);
};
my-plugin/admin/src/index.js
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 },
],
})
);
},
};

The example passes the following props to unstable_SettingsListToolbarSelect, in addition to the value and onChange that core passes to the component:

PropDescription
labelLabel of the dropdown.
placeholderOption that clears the filter.
optionsOptions of the dropdown, as { label, value } objects.
isLoadingWhether 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:

  1. A middleware on the list route reads ctx.request.query.plugins[<pluginId>] and keeps the value for the request, for example in an AsyncLocalStorage store or with strapi.requestContext. Attach the middleware to the routes, for example in their config.middlewares, rather than comparing ctx.path: the Users and Roles pages request /admin/users/ and /admin/roles/, with a trailing slash.
  2. A query scope registered with strapi.db.unstable_scopes.register() turns that value into a where condition on the listed model. strapi.db.unstable_scopes is 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.

Caution

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.

Was this page helpful?