fix(xo-web/home/vm): show error toaster when deleting VMs failed (#6323)

This commit is contained in:
Pierre Donias 2022-07-21 09:42:16 +02:00 committed by GitHub
parent 9ccb5f8aa9
commit 11e09e1f87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 4 deletions

View File

@ -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.
@ -28,5 +30,6 @@
<!--packages-start-->
- @vates/async-each major
- xo-web patch
<!--packages-end-->

View File

@ -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}}',

View File

@ -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 }))