Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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