Skip to content

Commit

Permalink
chore: use UserList userActionItems
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Nov 3, 2024
1 parent 5f36b3a commit 4a99fc4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 42 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"require": {
"php": "8.*",
"flarum/core": "^1.8.3",
"flarum/core": "^1.8.6",
"nelexa/zip": "^4.0.2"
},
"autoload": {
Expand Down
47 changes: 7 additions & 40 deletions js/src/admin/extendUserListPage.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,18 @@
import app from 'flarum/admin/app';
import { extend } from 'flarum/common/extend';
import UserListPage from 'flarum/admin/components/UserListPage';
import ItemList from 'flarum/common/utils/ItemList';
import User from 'flarum/common/models/User';
import Tooltip from 'flarum/common/components/Tooltip';
import Button from 'flarum/common/components/Button';
import type Mithril from 'mithril';
import username from 'flarum/common/helpers/username';
import RequestDataExportModal from '../common/components/RequestDataExportModal';

type ColumnData = {
/**
* Column title
*/
name: Mithril.Children;
/**
* Component(s) to show for this column.
*/
content: (user: User) => Mithril.Children;
};

export default function extendUserListPage() {
extend(UserListPage.prototype, 'columns', function (columns: ItemList<ColumnData>) {
columns.add(
'gdpr',
{
name: app.translator.trans('flarum-gdpr.admin.userlist.columns.gdpr_actions.title'),
content: (user: User) => {
return <div className="gdprActions">{this.gdprActions(user).toArray()}</div>;
},
},
50
extend(UserListPage.prototype, 'userActionItems', function (items, user) {
if (!user.canModerateExports()) return;
items.add(
'export-data',
<Button className="Button" icon="fas fa-file-export" onclick={() => app.modal.show(RequestDataExportModal, { user: user })}>
{app.translator.trans('flarum-gdpr.admin.userlist.columns.gdpr_actions.export', { username: username(user) })}
</Button>
);
});

UserListPage.prototype.gdprActions = function (user: User): ItemList<Mithril.Children> {
const items = new ItemList<Mithril.Children>();

if (user.canModerateExports()) {
items.add(
'export-data',
<Tooltip text={app.translator.trans('flarum-gdpr.admin.userlist.columns.gdpr_actions.export', { username: username(user) })}>
<Button className="Button Button--icon" icon="fas fa-file-export" onclick={() => app.modal.show(RequestDataExportModal, { user: user })} />
</Tooltip>
);
}

return items;
};
}
1 change: 0 additions & 1 deletion resources/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ flarum-gdpr:
userlist:
columns:
gdpr_actions:
title: GDPR Actions
export: Export data for {username}

lib:
Expand Down

0 comments on commit 4a99fc4

Please sign in to comment.