From a4d0fa62d2040a83b674e939457ac37bbe39aabc Mon Sep 17 00:00:00 2001 From: Pierre Donias Date: Wed, 21 Mar 2018 15:51:12 +0100 Subject: [PATCH] chore(xo-web/restore): minor improvements & fixes (#2789) Fixes #2692 --- .../xo-web/src/xo-app/backup/restore/index.js | 68 +++++++++---------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/packages/xo-web/src/xo-app/backup/restore/index.js b/packages/xo-web/src/xo-app/backup/restore/index.js index 8615fba6e..11303c9bd 100644 --- a/packages/xo-web/src/xo-app/backup/restore/index.js +++ b/packages/xo-web/src/xo-app/backup/restore/index.js @@ -1,20 +1,10 @@ import _, { messages } from 'intl' import ChooseSrForEachVdisModal from 'xo/choose-sr-for-each-vdis-modal' import Component from 'base-component' -import every from 'lodash/every' -import filter from 'lodash/filter' -import find from 'lodash/find' -import forEach from 'lodash/forEach' -import groupBy from 'lodash/groupBy' import Icon from 'icon' -import isEmpty from 'lodash/isEmpty' -import map from 'lodash/map' -import mapValues from 'lodash/mapValues' import moment from 'moment' import React from 'react' -import reduce from 'lodash/reduce' import SortedTable from 'sorted-table' -import uniq from 'lodash/uniq' import Upgrade from 'xoa-upgrade' import { confirm } from 'modal' import { createSelector } from 'selectors' @@ -23,6 +13,19 @@ import { Container, Row, Col } from 'grid' import { FormattedDate, injectIntl } from 'react-intl' import { info, error } from 'notification' import { Select, Toggle } from 'form' +import { + countBy, + every, + filter, + find, + forEach, + groupBy, + isEmpty, + map, + mapValues, + reduce, + uniq, +} from 'lodash' import { importBackup, @@ -98,19 +101,19 @@ const VM_COLUMNS = [ }, { name: _('availableBackupsColumn'), - itemRenderer: ({ simpleCount, deltaCount }) => ( + itemRenderer: ({ count }) => ( - {!!simpleCount && ( + {count.simple > 0 && ( {_('simpleBackup')}{' '} - {simpleCount} + {count.simple} )} - {!!simpleCount && !!deltaCount && ', '} - {!!deltaCount && ( + {count.simple > 0 && count.delta > 0 && ', '} + {count.delta > 0 && ( {_('delta')}{' '} - {deltaCount} + {count.delta} )} @@ -140,8 +143,6 @@ const doImport = ({ backup, targetSrs, start }) => { mapVdisSrs: targetSrs.mapVdisSrs, remote: backup.remoteId, sr: targetSrs.mainSr, - }).then(id => { - return id }) if (start) { importPromise.then(id => startVm({ id })) @@ -242,16 +243,20 @@ const ImportModalBody = injectIntl(_ModalBody, { withRef: true }) }) export default class Restore extends Component { componentWillReceiveProps ({ rawRemotes }) { - let filteredRemotes - if ( - (filteredRemotes = filter(rawRemotes, 'enabled')) !== - filter(this.props.rawRemotes, 'enabled') - ) { - this._listAll(filteredRemotes).catch(noop) + if (rawRemotes !== this.props.rawRemotes) { + this._listAll(rawRemotes).catch(noop) } } - _listAll = async remotes => { + componentDidMount () { + const { rawRemotes } = this.props + if (rawRemotes !== undefined) { + this._listAll(rawRemotes).catch(noop) + } + } + + _listAll = async rawRemotes => { + const remotes = filter(rawRemotes, 'enabled') const remotesInfo = await Promise.all( map(remotes, async remote => ({ files: await listRemote(remote.id), @@ -309,24 +314,15 @@ export default class Restore extends Component { forEach(backupInfoByVm, (backups, vm) => { backupInfoByVm[vm] = { backups, + count: countBy(backups, 'type'), last: reduce(backups, (last, b) => (b.date > last.date ? b : last)), tagsByRemote: mapValues( groupBy(backups, 'remoteId'), (backups, remoteId) => ({ - remoteName: find(remotes, remote => remote.id === remoteId).name, + remoteName: backups[0].remoteName, tags: uniq(map(backups, 'tag')), }) ), - simpleCount: reduce( - backups, - (sum, b) => (b.type === 'simple' ? ++sum : sum), - 0 - ), - deltaCount: reduce( - backups, - (sum, b) => (b.type === 'delta' ? ++sum : sum), - 0 - ), } }) this.setState({ backupInfoByVm })