blob: edf30fe4ef899420b432efa1c51d286876e9757b [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
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 */
16import ItemsHelper from '../../common/helpers/ItemsHelper.js';
17import {actionTypes} from './VersionsPageConstants.js';
18import {itemTypes} from './VersionsPageConstants.js';
19import {modalContentMapper} from 'sdc-app/common/modal/ModalContentMapper.js';
20import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
21import i18n from 'nfvo-utils/i18n/i18n.js';
22import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
23import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js';
24
25
26const 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 });
miriamed411d152018-01-02 15:35:55 +020035 return Promise.resolve(response);
talig8e9c0652017-12-20 14:30:43 +020036 });
37 },
38
39 selectVersion(dispatch, {version}) {
40 dispatch({
41 type: actionTypes.SELECT_VERSION,
42 versionId: version.id
43 });
44 },
45
46 selectNone(dispatch) {
47 dispatch({ type: actionTypes.SELECT_NONE });
48 },
49
50 onNavigateToVersion(dispatch, {version, itemId, itemType}) {
51 switch (itemType) {
52 case itemTypes.LICENSE_MODEL:
53 ScreensHelper.loadScreen(dispatch, {
54 screen: enums.SCREEN.LICENSE_MODEL_OVERVIEW, screenType: screenTypes.LICENSE_MODEL,
55 props: {licenseModelId: itemId, version}
56 });
57 break;
58 case itemTypes.SOFTWARE_PRODUCT:
59 ScreensHelper.loadScreen(dispatch, {
60 screen: enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE, screenType: screenTypes.SOFTWARE_PRODUCT,
61 props: {softwareProductId: itemId, version}
62 });
63 break;
64 }
65 },
66
67 openTree(dispatch, treeProps) {
68 dispatch({
69 type: modalActionTypes.GLOBAL_MODAL_SHOW,
70 data: {
71 modalComponentName: modalContentMapper.VERSION_TREE,
72 modalComponentProps: treeProps,
73 onDeclined: () => dispatch({
74 type: modalActionTypes.GLOBAL_MODAL_CLOSE
75 }),
76 modalClassName: 'versions-tree-modal',
77 cancelButtonText: i18n('Close'),
78 title: i18n('Version Tree')
79 }
80 });
81 },
82
83 selectVersionFromModal(dispatch, {version}) {
84 dispatch({
85 type: modalActionTypes.GLOBAL_MODAL_CLOSE
86 });
87 this.selectVersion(dispatch, {version});
88 }
89};
90
91export default VersionsPageActionHelper;