X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/3b2372cd1ce9528803e32393132b16645aff25f7..074cc61145869165217e2d35a4b949f92a6829e7:/src/store/collections/collection-version-actions.ts diff --git a/src/store/collections/collection-version-actions.ts b/src/store/collections/collection-version-actions.ts index 007dedcd..7d2511ed 100644 --- a/src/store/collections/collection-version-actions.ts +++ b/src/store/collections/collection-version-actions.ts @@ -3,18 +3,42 @@ // SPDX-License-Identifier: AGPL-3.0 import { Dispatch } from "redux"; -import { RootState } from '~/store/store'; -import { ServiceRepository } from '~/services/services'; +import { RootState } from 'store/store'; +import { ServiceRepository } from 'services/services'; import { snackbarActions, SnackbarKind } from "../snackbar/snackbar-actions"; import { resourcesActions } from "../resources/resources-actions"; import { navigateTo } from "../navigation/navigation-action"; +import { dialogActions } from "../dialog/dialog-actions"; +import { getResource } from "store/resources/resources"; +import { CollectionResource } from "models/collection"; -export const recoverVersion = (resourceUuid: string) => +export const COLLECTION_RESTORE_VERSION_DIALOG = 'collectionRestoreVersionDialog'; + +export const openRestoreCollectionVersionDialog = (uuid: string) => + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + dispatch(dialogActions.OPEN_DIALOG({ + id: COLLECTION_RESTORE_VERSION_DIALOG, + data: { + title: 'Restore version', + text: "This will copy the content of the selected version to the head. To make a new collection with the content of the selected version, use 'Make a copy' instead.", + confirmButtonLabel: 'Restore', + uuid + } + })); + }; + +export const restoreVersion = (resourceUuid: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { try { - // Request que entire record because stored old versions usually - // don't include the manifest_text field. - const oldVersion = await services.collectionService.get(resourceUuid); + // Request the manifest text because stored old versions usually + // don't include them. + let oldVersion = getResource(resourceUuid)(getState().resources); + if (!oldVersion) { + oldVersion = await services.collectionService.get(resourceUuid); + } + const oldVersionManifest = await services.collectionService.get(resourceUuid, undefined, ['manifestText']); + oldVersion.manifestText = oldVersionManifest.manifestText; + const { uuid, version, ...rest} = oldVersion; const headVersion = await services.collectionService.update( oldVersion.currentVersionUuid, @@ -24,7 +48,7 @@ export const recoverVersion = (resourceUuid: string) => dispatch(navigateTo(headVersion.uuid)); } catch (e) { dispatch(snackbarActions.OPEN_SNACKBAR({ - message: `Couldn't recover version: ${e.errors[0]}`, + message: `Couldn't restore version: ${e.errors[0]}`, hideDuration: 2000, kind: SnackbarKind.ERROR }));