Skip to content

Commit

Permalink
fix(xo-web/home/vm): show error toaster when deleting VMs failed (#6323)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdonias committed Jul 21, 2022
1 parent 9ccb5f8 commit 11e09e1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

> Users must be able to say: “I had this issue, happy to know it's fixed”
- [Home/VM] Show error when deleting VMs failed (PR [#6323](https://github.com/vatesfr/xen-orchestra/pull/6323))

### Packages to release

> When modifying a package, add it here with its release type.
Expand All @@ -28,5 +30,6 @@
<!--packages-start-->

- @vates/async-each major
- xo-web patch

<!--packages-end-->
3 changes: 2 additions & 1 deletion packages/xo-web/src/common/intl/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -1728,8 +1728,9 @@ const messages = {
blockedStartVmsModalMessage: 'Forbidden operation start for {nVms, number} vm{nVms, plural, one {} other {s}}.',
startVmsModalMessage: 'Are you sure you want to start {vms, number} VM{vms, plural, one {} other {s}}?',
failedVmsErrorMessage:
'{nVms, number} vm{nVms, plural, one {} other {s}} are failed. Please see your logs to get more information',
'{nVms, number} VM{nVms, plural, one {} other {s}} failed. Please check logs for more information',
failedVmsErrorTitle: 'Start failed',
failedDeleteErrorTitle: 'Delete failed',
stopHostsModalTitle: 'Stop Host{nHosts, plural, one {} other {s}}',
stopHostsModalMessage: 'Are you sure you want to stop {nHosts, number} Host{nHosts, plural, one {} other {s}}?',
stopVmsModalTitle: 'Stop VM{vms, plural, one {} other {s}}',
Expand Down
23 changes: 20 additions & 3 deletions packages/xo-web/src/common/xo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1626,15 +1626,32 @@ export const deleteVm = (vm, retryWithForce = true) =>
throw error
})

export const deleteVms = vms =>
confirm({
export const deleteVms = async vms => {
if (vms.length === 1) {
return deleteVm(vms[0])
}
await confirm({
title: _('deleteVmsModalTitle', { vms: vms.length }),
body: _('deleteVmsModalMessage', { vms: vms.length }),
strongConfirm: vms.length > 1 && {
messageId: 'deleteVmsConfirmText',
values: { nVms: vms.length },
},
}).then(() => Promise.all(map(vms, vmId => _call('vm.delete', { id: resolveId(vmId) }))), noop)
}).catch(noop)

let nErrors = 0
await Promise.all(
map(vms, vmId =>
_call('vm.delete', { id: resolveId(vmId) }).catch(() => {
nErrors++
})
)
)

if (nErrors > 0) {
error(_('failedDeleteErrorTitle'), _('failedVmsErrorMessage', { nVms: nErrors }))
}
}

export const importBackup = ({ remote, file, sr }) => _call('vm.importBackup', resolveIds({ remote, file, sr }))

Expand Down

0 comments on commit 11e09e1

Please sign in to comment.