Skip to content

Commit

Permalink
feat: provide an 'actions' dropdown for extensions to add their addit…
Browse files Browse the repository at this point in the history
…ional buttons
  • Loading branch information
imorland committed Oct 2, 2024
1 parent 71717f9 commit 772852b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
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

0 comments on commit 772852b

Please sign in to comment.