Skip to content
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

[1.x] [extensibility] feat: provide an 'actions' dropdown for extensions to add their additional buttons to the admin UserListPage #4054

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions framework/core/js/src/admin/components/UserListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import extractText from '../../common/utils/extractText';
import AdminPage from './AdminPage';
import { debounce } from '../../common/utils/throttleDebounce';
import CreateUserModal from './CreateUserModal';
import Dropdown from '../../common/components/Dropdown';

type ColumnData = {
/**
Expand Down Expand Up @@ -425,17 +426,18 @@ export default class UserListPage extends AdminPage {
);

columns.add(
'editUser',
'userActions',
{
name: app.translator.trans('core.admin.users.grid.columns.edit_user.title'),
name: app.translator.trans('core.admin.users.grid.columns.user_actions.title'),
content: (user: User) => (
<Button
className="Button UserList-editModalBtn"
title={app.translator.trans('core.admin.users.grid.columns.edit_user.tooltip', { username: user.username() })}
onclick={() => app.modal.show(EditUserModal, { user })}
<Dropdown
className="User-controls"
buttonClassName="Button Button--icon Button--flat"
menuClassName="Dropdown-menu--right"
icon="fas fa-ellipsis-h"
>
{app.translator.trans('core.admin.users.grid.columns.edit_user.button')}
</Button>
{this.userActionItems(user).toArray()}
</Dropdown>
),
},
-90
Expand All @@ -453,6 +455,24 @@ export default class UserListPage extends AdminPage {
};
}

userActionItems(user: User): ItemList<Mithril.Children> {
const items = new ItemList<Mithril.Children>();

items.add(
'editUser',
<Button
icon="fas fa-pencil-alt"
className="Button UserList-editModalBtn"
title={app.translator.trans('core.admin.users.grid.columns.edit_user.tooltip', { username: user.username() })}
onclick={() => app.modal.show(EditUserModal, { user })}
>
{app.translator.trans('core.admin.users.grid.columns.edit_user.button')}
</Button>
);

return items;
}

/**
* Asynchronously fetch the next set of users to be rendered.
*
Expand Down
4 changes: 3 additions & 1 deletion framework/core/locale/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ core:

edit_user:
button: => core.ref.edit
title: => core.ref.edit_user
tooltip: Edit {username}

email:
Expand All @@ -286,6 +285,9 @@ core:
join_time:
title: Joined

user_actions:
title: Actions

user_id:
title: ID

Expand Down
Loading