From caca13351cc2c5f8994132d4d16f054e23cda9d5 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/sagas.js | 12 +++++++++++- src/intl/messages.js | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/VmDetails/cards/SnapshotsCard/sagas.js b/src/components/VmDetails/cards/SnapshotsCard/sagas.js index c9163d551..c9256fc4d 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 e7c03f623..7d27d5d1e 100644 --- a/src/intl/messages.js +++ b/src/intl/messages.js @@ -596,6 +596,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)',