blob: 8443fe950b1887638b279a21b3622080c8e064f7 [file] [log] [blame]
svishnevea5e43c2018-04-15 09:06:57 +03001/*
2 * Copyright © 2016-2018 European Support Limited
AviZi280f8012017-06-09 02:39:56 +03003 *
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
svishnevea5e43c2018-04-15 09:06:57 +03007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
AviZi280f8012017-06-09 02:39:56 +030010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
svishnevea5e43c2018-04-15 09:06:57 +030012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
AviZi280f8012017-06-09 02:39:56 +030015 */
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020016import { tabsMapping, actionTypes } from './OnboardConstants.js';
miriamed411d152018-01-02 15:35:55 +020017import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020018import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js';
miriamed411d152018-01-02 15:35:55 +020019import VersionsPageActionHelper from 'sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js';
svishnevea5e43c2018-04-15 09:06:57 +030020
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020021import { itemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
miriamed411d152018-01-02 15:35:55 +020022import PermissionsActionHelper from 'sdc-app/onboarding/permissions/PermissionsActionHelper.js';
svishnevea5e43c2018-04-15 09:06:57 +030023import { actionTypes as filterActionTypes } from './filter/FilterConstants.js';
svishnevcee71ef2018-05-01 17:56:49 +030024import { versionStatus } from 'sdc-app/common/helpers/ItemsHelperConstants.js';
AviZi280f8012017-06-09 02:39:56 +030025
26const OnboardActionHelper = {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020027 resetOnboardStore(dispatch) {
28 dispatch({
29 type: actionTypes.RESET_ONBOARD_STORE
30 });
31 },
32 changeActiveTab(dispatch, activeTab) {
33 this.clearSearchValue(dispatch);
34 dispatch({
35 type: actionTypes.CHANGE_ACTIVE_ONBOARD_TAB,
36 activeTab
37 });
svishnevea5e43c2018-04-15 09:06:57 +030038 dispatch({
39 type: filterActionTypes.FILTER_DATA_CHANGED,
40 deltaData:
41 activeTab === tabsMapping.WORKSPACE
42 ? {
svishnevcee71ef2018-05-01 17:56:49 +030043 versionStatus: versionStatus.DRAFT
svishnevea5e43c2018-04-15 09:06:57 +030044 }
45 : {
46 versionStatus: versionStatus.CERTIFIED
47 }
48 });
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020049 },
50 changeSearchValue(dispatch, searchValue) {
51 dispatch({
52 type: actionTypes.CHANGE_SEARCH_VALUE,
53 searchValue
54 });
55 },
56 clearSearchValue(dispatch) {
57 dispatch({
58 type: actionTypes.CHANGE_SEARCH_VALUE,
59 searchValue: ''
60 });
61 },
miriamed411d152018-01-02 15:35:55 +020062
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020063 loadVLMScreen(dispatch, { id: licenseModelId, name }, users, tab) {
64 if (tab === tabsMapping.WORKSPACE) {
65 VersionsPageActionHelper.fetchVersions(dispatch, {
66 itemId: licenseModelId,
67 itemType: itemTypes.LICENSE_MODEL
68 }).then(({ results }) => {
69 results = results.filter(
svishnevea5e43c2018-04-15 09:06:57 +030070 version => version.status === versionStatus.DRAFT
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020071 );
72 if (results.length !== 1) {
73 ScreensHelper.loadScreen(dispatch, {
74 screen: enums.SCREEN.VERSIONS_PAGE,
75 screenType: screenTypes.LICENSE_MODEL,
76 props: {
77 licenseModelId,
78 licenseModel: { name },
79 usersList: users
80 }
81 });
82 } else {
83 PermissionsActionHelper.fetchItemUsers(dispatch, {
84 itemId: licenseModelId,
85 allUsers: users
86 }).then(() =>
87 ScreensHelper.loadLandingScreen(dispatch, {
88 screenType: screenTypes.LICENSE_MODEL,
89 props: { licenseModelId, version: results[0] }
90 })
91 );
92 }
93 });
94 }
95 if (tab === tabsMapping.CATALOG) {
96 ScreensHelper.loadScreen(dispatch, {
97 screen: enums.SCREEN.VERSIONS_PAGE,
98 screenType: screenTypes.LICENSE_MODEL,
99 props: {
100 licenseModelId,
101 licenseModel: { name },
102 usersList: users
103 }
104 });
105 }
106 },
107 loadVSPScreen(dispatch, softwareProduct, users, tab) {
108 let {
109 id: softwareProductId,
110 vendorId: licenseModelId,
111 licensingVersion,
112 name
113 } = softwareProduct;
114 if (tab === tabsMapping.WORKSPACE) {
115 VersionsPageActionHelper.fetchVersions(dispatch, {
116 itemId: softwareProductId,
117 itemType: itemTypes.SOFTWARE_PRODUCT
118 }).then(({ results }) => {
119 results = results.filter(
svishnevea5e43c2018-04-15 09:06:57 +0300120 version => version.status === versionStatus.DRAFT
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200121 );
122 if (results.length !== 1) {
123 ScreensHelper.loadScreen(dispatch, {
124 screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE,
125 screenType: screenTypes.SOFTWARE_PRODUCT,
126 props: {
127 softwareProductId,
128 softwareProduct: {
129 name,
130 vendorId: licenseModelId,
131 licensingVersion
132 },
133 usersList: users
134 }
135 });
136 } else {
137 PermissionsActionHelper.fetchItemUsers(dispatch, {
138 itemId: softwareProductId,
139 allUsers: users
140 }).then(() =>
141 ScreensHelper.loadLandingScreen(dispatch, {
142 screenType: screenTypes.SOFTWARE_PRODUCT,
143 props: {
144 softwareProductId,
145 licenseModelId,
146 version: results[0]
147 }
148 })
149 );
150 }
151 });
152 }
153 if (tab === tabsMapping.CATALOG) {
154 ScreensHelper.loadScreen(dispatch, {
155 screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE,
156 screenType: screenTypes.SOFTWARE_PRODUCT,
157 props: {
158 softwareProductId,
159 softwareProduct: {
160 name,
161 vendorId: licenseModelId,
162 licensingVersion
163 },
164 usersList: users
165 }
166 });
167 }
168 }
AviZi280f8012017-06-09 02:39:56 +0300169};
170
171export default OnboardActionHelper;