react 16 upgrade
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / versionsPage / VersionsPageActionHelper.js
1 /*!
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 import ItemsHelper from '../../common/helpers/ItemsHelper.js';
17 import { actionTypes } from './VersionsPageConstants.js';
18 import { itemTypes } from './VersionsPageConstants.js';
19 import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js';
20 import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js';
21 import i18n from 'nfvo-utils/i18n/i18n.js';
22 import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
23 import {
24     enums,
25     screenTypes,
26     onboardingActions
27 } from 'sdc-app/onboarding/OnboardingConstants.js';
28 import { notificationActions } from 'nfvo-components/notification/NotificationsConstants.js';
29
30 const VersionsPageActionHelper = {
31     fetchVersions(dispatch, { itemType, itemId }) {
32         return ItemsHelper.fetchVersions({ itemId }).then(response => {
33             dispatch({
34                 type: actionTypes.VERSIONS_LOADED,
35                 versions: response.results,
36                 itemType,
37                 itemId
38             });
39             return Promise.resolve(response);
40         });
41     },
42
43     selectVersion(dispatch, { version }) {
44         dispatch({
45             type: actionTypes.SELECT_VERSION,
46             versionId: version.id
47         });
48     },
49
50     selectNone(dispatch) {
51         dispatch({ type: actionTypes.SELECT_NONE });
52     },
53
54     onNavigateToVersion(dispatch, { version, itemId, itemType }) {
55         switch (itemType) {
56             case itemTypes.LICENSE_MODEL:
57                 ScreensHelper.loadScreen(dispatch, {
58                     screen: enums.SCREEN.LICENSE_MODEL_OVERVIEW,
59                     screenType: screenTypes.LICENSE_MODEL,
60                     props: { licenseModelId: itemId, version }
61                 });
62                 break;
63             case itemTypes.SOFTWARE_PRODUCT:
64                 ScreensHelper.loadScreen(dispatch, {
65                     screen: enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE,
66                     screenType: screenTypes.SOFTWARE_PRODUCT,
67                     props: { softwareProductId: itemId, version }
68                 });
69                 break;
70         }
71     },
72
73     openTree(dispatch, treeProps) {
74         dispatch({
75             type: modalActionTypes.GLOBAL_MODAL_SHOW,
76             data: {
77                 modalComponentName: modalContentMapper.VERSION_TREE,
78                 modalComponentProps: treeProps,
79                 onDeclined: () =>
80                     dispatch({
81                         type: modalActionTypes.GLOBAL_MODAL_CLOSE
82                     }),
83                 bodyClassName: 'versions-tree-modal',
84                 cancelButtonText: i18n('Close'),
85                 title: i18n('Version Tree')
86             }
87         });
88     },
89
90     selectVersionFromModal(dispatch, { version }) {
91         dispatch({
92             type: modalActionTypes.GLOBAL_MODAL_CLOSE
93         });
94         this.selectVersion(dispatch, { version });
95     },
96
97     async archiveItem(dispatch, itemId) {
98         await ItemsHelper.archiveItem(itemId);
99         dispatch(onboardingActions.updateItemArchivedStatus(true));
100         dispatch(
101             notificationActions.showSuccess({
102                 message: i18n('Item successfully archived')
103             })
104         );
105     },
106
107     async restoreItemFromArchive(dispatch, itemId) {
108         await ItemsHelper.restoreItem(itemId);
109         dispatch(onboardingActions.updateItemArchivedStatus(false));
110         dispatch(
111             notificationActions.showSuccess({
112                 message: i18n('Item successfully restored')
113             })
114         );
115     }
116 };
117
118 export default VersionsPageActionHelper;