From 40b4d07ad00dcda978155af6b2c6030b615a1a2a Mon Sep 17 00:00:00 2001 From: Radoslaw Szwajkowski Date: Thu, 26 May 2022 12:17:03 +0200 Subject: [PATCH] Display notification after successful snapshot restore --- .../VmDetails/cards/SnapshotsCard/actions.js | 4 +++- .../VmDetails/cards/SnapshotsCard/sagas.js | 12 +++++++++++- src/intl/messages.js | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/VmDetails/cards/SnapshotsCard/actions.js b/src/components/VmDetails/cards/SnapshotsCard/actions.js index 67d5279cca..2ae092b69a 100644 --- a/src/components/VmDetails/cards/SnapshotsCard/actions.js +++ b/src/components/VmDetails/cards/SnapshotsCard/actions.js @@ -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, }, } } diff --git a/src/components/VmDetails/cards/SnapshotsCard/sagas.js b/src/components/VmDetails/cards/SnapshotsCard/sagas.js index c9163d5518..c9256fc4de 100644 --- a/src/components/VmDetails/cards/SnapshotsCard/sagas.js +++ b/src/components/VmDetails/cards/SnapshotsCard/sagas.js @@ -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' @@ -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 @@ -68,6 +70,10 @@ 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' })) @@ -75,6 +81,10 @@ function* restoreVmSnapshot (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 [ diff --git a/src/intl/messages.js b/src/intl/messages.js index aa3c5e4bf4..7a476b697b 100644 --- a/src/intl/messages.js +++ b/src/intl/messages.js @@ -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)',