Add collaboration feature
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / versionsPage / VersionsPageActionHelper.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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 {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js';
24
25
26 const VersionsPageActionHelper = {
27         fetchVersions(dispatch, {itemType, itemId}) {
28                 return ItemsHelper.fetchVersions({itemId}).then(response => {
29                         dispatch({
30                                 type: actionTypes.VERSIONS_LOADED,
31                                 versions: response.results,
32                                 itemType,
33                                 itemId
34                         });
35                 });
36         },
37
38         selectVersion(dispatch, {version}) {
39                 dispatch({
40                         type: actionTypes.SELECT_VERSION,
41                         versionId: version.id
42                 });
43         },
44
45         selectNone(dispatch) {
46                 dispatch({ type: actionTypes.SELECT_NONE });
47         },
48
49         onNavigateToVersion(dispatch, {version, itemId, itemType}) {
50                 switch (itemType) {
51                         case itemTypes.LICENSE_MODEL:
52                                 ScreensHelper.loadScreen(dispatch, {
53                                         screen: enums.SCREEN.LICENSE_MODEL_OVERVIEW, screenType: screenTypes.LICENSE_MODEL,
54                                         props: {licenseModelId: itemId, version}
55                                 });
56                                 break;
57                         case itemTypes.SOFTWARE_PRODUCT:
58                                 ScreensHelper.loadScreen(dispatch, {
59                                         screen: enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE, screenType: screenTypes.SOFTWARE_PRODUCT,
60                                         props: {softwareProductId: itemId, version}
61                                 });
62                                 break;
63                 }
64         },
65
66         openTree(dispatch, treeProps) {
67                 dispatch({
68                         type: modalActionTypes.GLOBAL_MODAL_SHOW,
69                         data: {
70                                 modalComponentName: modalContentMapper.VERSION_TREE,
71                                 modalComponentProps: treeProps,
72                                 onDeclined: () => dispatch({
73                                         type: modalActionTypes.GLOBAL_MODAL_CLOSE
74                                 }),
75                                 modalClassName: 'versions-tree-modal',
76                                 cancelButtonText: i18n('Close'),
77                                 title: i18n('Version Tree')
78                         }
79                 });
80         },
81
82         selectVersionFromModal(dispatch, {version}) {
83                 dispatch({
84                         type: modalActionTypes.GLOBAL_MODAL_CLOSE
85                 });
86                 this.selectVersion(dispatch, {version});
87         }
88 };
89
90 export default VersionsPageActionHelper;