feat(xo-web/vms-import): redirect to VM or home page (#2942)

If a single VM has been imported, redirect to its page.

If multiple VMs has been imported, redirect to the homepage with all other VMs filtered out.
This commit is contained in:
Nicolas Raynaud 2018-05-14 08:42:11 -07:00 committed by Julien Fontanet
parent 31314d201b
commit fdde916388
2 changed files with 6 additions and 1 deletions

View File

@ -1204,6 +1204,7 @@ export const importVm = (file, type = 'xva', data = undefined, sr) => {
throw res.status
}
success(_('vmImportSuccess'), name)
return res.json().then(body => body.result)
})
.catch(() => {
error(_('vmImportFailed'), name)

View File

@ -235,6 +235,10 @@ const parseFile = async (file, type, func) => {
}
}
const getRedirectionUrl = vms => vms.length === 1
? `/vms/${vms[0]}`
: `/home?s=${encodeURIComponent(`id:|(${vms.join(' ')})`)}&t=VM`
export default class Import extends Component {
constructor (props) {
super(props)
@ -397,7 +401,7 @@ export default class Import extends Component {
form='import-form'
handler={this._import}
icon='import'
redirectOnSuccess='/'
redirectOnSuccess={getRedirectionUrl}
type='submit'
>
{_('newImport')}