1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from "redux";
6 import { RootState } from '~/store/store';
7 import { ServiceRepository } from '~/services/services';
8 import { snackbarActions, SnackbarKind } from "../snackbar/snackbar-actions";
9 import { resourcesActions } from "../resources/resources-actions";
10 import { navigateTo } from "../navigation/navigation-action";
11 import { dialogActions } from "../dialog/dialog-actions";
13 export const COLLECTION_RESTORE_VERSION_DIALOG = 'collectionRestoreVersionDialog';
15 export const openRestoreCollectionVersionDialog = (uuid: string) =>
16 (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
17 dispatch(dialogActions.OPEN_DIALOG({
18 id: COLLECTION_RESTORE_VERSION_DIALOG,
20 title: 'Restore version',
21 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.",
22 confirmButtonLabel: 'Restore',
28 export const restoreVersion = (resourceUuid: string) =>
29 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
31 // Request que entire record because stored old versions usually
32 // don't include the manifest_text field.
33 const oldVersion = await services.collectionService.get(resourceUuid);
34 const { uuid, version, ...rest} = oldVersion;
35 const headVersion = await services.collectionService.update(
36 oldVersion.currentVersionUuid,
39 dispatch(resourcesActions.SET_RESOURCES([headVersion]));
40 dispatch<any>(navigateTo(headVersion.uuid));
42 dispatch(snackbarActions.OPEN_SNACKBAR({
43 message: `Couldn't restore version: ${e.errors[0]}`,
45 kind: SnackbarKind.ERROR