Skip to content

Commit

Permalink
Display notification after successful snapshot restore
Browse files Browse the repository at this point in the history
  • Loading branch information
rszwajko committed Jun 9, 2022
1 parent 6e2ba4d commit 43c835f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/components/VmDetails/cards/SnapshotsCard/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ export function addVmSnapshot ({ vmId, snapshot }) {
}
}

export function restoreVmSnapshot ({ vmId, snapshotId }) {
export function restoreVmSnapshot ({ vmId, vmName, snapshotId, snapshotName }) {
return {
type: RESTORE_VM_SNAPSHOT,
payload: {
vmId,
snapshotId,
vmName,
snapshotName,
},
}
}
12 changes: 11 additions & 1 deletion src/components/VmDetails/cards/SnapshotsCard/sagas.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { takeEvery, put } from 'redux-saga/effects'
import { takeEvery, put, select } from 'redux-saga/effects'

import Api, { Transforms } from '_/ovirtapi'
import { callExternalAction, delay, delayInMsSteps } from '_/sagas/utils'
Expand All @@ -13,9 +13,11 @@ import {
updateVmSnapshot,
startActionInProgress,
stopActionInProgress,
addUserMessage,
} from '_/actions'

import { ADD_VM_SNAPSHOT, DELETE_VM_SNAPSHOT, RESTORE_VM_SNAPSHOT } from './constants'
import { toJS } from '_/helpers'

function* addVmSnapshot (action) {
const { vmId } = action.payload
Expand Down Expand Up @@ -68,13 +70,21 @@ function* deleteVmSnapshot (action) {

function* restoreVmSnapshot (action) {
const { vmId, snapshotId } = action.payload
const [{ description: snapshotName } = {}, vmName] = yield select(({ vms }) => [
toJS(vms.getIn(['vms', vmId, 'snapshots'], [])).find(({ id }) => id === snapshotId),
vms.getIn(['vms', vmId, 'name']),
])
yield put(addSnapshotRestorePendingTask(vmId, snapshotId))
yield put(startActionInProgress({ vmId, name: 'restoreSnapshot' }))

const result = yield callExternalAction(Api.restoreSnapshot, action)

yield put(stopActionInProgress({ vmId, name: 'restoreSnapshot', result }))
yield put(removeSnapshotRestorePendingTask(vmId, snapshotId))
if (!result.error) {
// restore is synchronous operation so we can interpret completed operation as success
yield put(addUserMessage({ messageDescriptor: { id: 'restoredSnapshot', params: { snapshotName, vmName } }, type: 'SUCCESS' }))
}
}

export default [
Expand Down
1 change: 1 addition & 0 deletions src/intl/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ export const messages: { [messageId: string]: MessageType } = {
description: 'Confirmation modal action button label for a Restore operation',
},
restoreSnapshot: 'Restore Snapshot?',
restoredSnapshot: 'Finished restoring snapshot {snapshotName} of VM {vmName}',
results: {
message: '{total} Results',
description: 'Number of filtered fetched VMs (including pools)',
Expand Down

0 comments on commit 43c835f

Please sign in to comment.