feat(xo-web/groups): bulk deletion (#5264)

This commit is contained in:
Pierre Donias 2020-09-16 10:46:35 +02:00 committed by GitHub
parent 7c802bbd33
commit bd9bf55e43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 9 deletions

View File

@ -10,6 +10,7 @@
- [VM Import] Make the `Description` field optional (PR [#5258](https://github.com/vatesfr/xen-orchestra/pull/5258)) - [VM Import] Make the `Description` field optional (PR [#5258](https://github.com/vatesfr/xen-orchestra/pull/5258))
- [New VM] Hide missing ISOs in selector [#5222](https://github.com/vatesfr/xen-orchestra/issues/5222) - [New VM] Hide missing ISOs in selector [#5222](https://github.com/vatesfr/xen-orchestra/issues/5222)
- [Dashboard/Health] Show VMs that have too many snapshots [#5238](https://github.com/vatesfr/xen-orchestra/pull/5238) - [Dashboard/Health] Show VMs that have too many snapshots [#5238](https://github.com/vatesfr/xen-orchestra/pull/5238)
- [Groups] Ability to delete multiple groups at once (PR [#5264](https://github.com/vatesfr/xen-orchestra/pull/5264))
### Bug fixes ### Bug fixes

View File

@ -656,6 +656,10 @@ const messages = {
createGroupButton: 'Create', createGroupButton: 'Create',
deleteGroup: 'Delete group', deleteGroup: 'Delete group',
deleteGroupConfirm: 'Are you sure you want to delete this group?', deleteGroupConfirm: 'Are you sure you want to delete this group?',
deleteSelectedGroups: 'Delete selected groups',
deleteGroupsModalTitle: 'Delete group{nGroups, plural, one {} other {s}}',
deleteGroupsModalMessage:
'Are you sure you want to delete {nGroups, number} group{nGroups, plural, one {} other {s}}?',
removeUserFromGroup: 'Remove user from group', removeUserFromGroup: 'Remove user from group',
deleteUserConfirm: 'Are you sure you want to delete this user?', deleteUserConfirm: 'Are you sure you want to delete this user?',
deleteUser: 'Delete user', deleteUser: 'Delete user',

View File

@ -2732,6 +2732,20 @@ export const deleteGroup = group =>
noop noop
) )
export const deleteGroups = groups =>
confirm({
title: _('deleteGroupsModalTitle', { nGroups: groups.length }),
body: <p>{_('deleteGroupsModalMessage', { nGroups: groups.length })}</p>,
}).then(
() =>
Promise.all(
groups.map(({ id }) => _call('group.delete', { id }))
)::tap(subscribeGroups.forceRefresh, err =>
error(_('deleteGroup'), err.message || String(err))
),
noop
)
export const removeUserFromGroup = (user, group) => export const removeUserFromGroup = (user, group) =>
_call( _call(
'group.removeUser', 'group.removeUser',

View File

@ -18,6 +18,7 @@ import {
addUserToGroup, addUserToGroup,
createGroup, createGroup,
deleteGroup, deleteGroup,
deleteGroups,
removeUserFromGroup, removeUserFromGroup,
setGroupName, setGroupName,
subscribeGroups, subscribeGroups,
@ -125,16 +126,16 @@ const GROUP_COLUMNS = [
/> />
), ),
}, },
]
const ACTIONS = [
{ {
name: '', handler: deleteGroups,
itemRenderer: group => ( icon: 'delete',
<ActionButton individualHandler: deleteGroup,
icon='delete' individualLabel: _('deleteGroup'),
handler={deleteGroup} label: _('deleteSelectedGroups'),
handlerParam={group} level: 'danger',
btnStyle='danger'
/>
),
}, },
] ]
@ -185,6 +186,7 @@ export default class Groups extends Component {
</p> </p>
) : ( ) : (
<SortedTable <SortedTable
actions={ACTIONS}
collection={groups} collection={groups}
columns={GROUP_COLUMNS} columns={GROUP_COLUMNS}
stateUrlParam='s' stateUrlParam='s'