blob: 9f2b3ddb1230bb0d9225656791279e5f19efdd39 [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
Yarin Dekel811fb482018-11-04 15:00:34 +02007 *
svishnevea5e43c2018-04-15 09:06:57 +03008 * http://www.apache.org/licenses/LICENSE-2.0
Yarin Dekel811fb482018-11-04 15:00:34 +02009 *
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 */
Yarin Dekel811fb482018-11-04 15:00:34 +020016import {
17 tabsMapping,
18 actionTypes,
19 searchValueObj
20} from './OnboardConstants.js';
miriamed411d152018-01-02 15:35:55 +020021import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020022import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js';
miriamed411d152018-01-02 15:35:55 +020023import VersionsPageActionHelper from 'sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js';
svishnevea5e43c2018-04-15 09:06:57 +030024
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020025import { itemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
miriamed411d152018-01-02 15:35:55 +020026import PermissionsActionHelper from 'sdc-app/onboarding/permissions/PermissionsActionHelper.js';
svishnevea5e43c2018-04-15 09:06:57 +030027import { actionTypes as filterActionTypes } from './filter/FilterConstants.js';
svishnevcee71ef2018-05-01 17:56:49 +030028import { versionStatus } from 'sdc-app/common/helpers/ItemsHelperConstants.js';
AviZi280f8012017-06-09 02:39:56 +030029
30const OnboardActionHelper = {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020031 resetOnboardStore(dispatch) {
32 dispatch({
33 type: actionTypes.RESET_ONBOARD_STORE
34 });
35 },
36 changeActiveTab(dispatch, activeTab) {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020037 dispatch({
38 type: actionTypes.CHANGE_ACTIVE_ONBOARD_TAB,
39 activeTab
40 });
svishnevea5e43c2018-04-15 09:06:57 +030041 dispatch({
42 type: filterActionTypes.FILTER_DATA_CHANGED,
43 deltaData:
44 activeTab === tabsMapping.WORKSPACE
45 ? {
svishnevcee71ef2018-05-01 17:56:49 +030046 versionStatus: versionStatus.DRAFT
svishnevea5e43c2018-04-15 09:06:57 +030047 }
48 : {
49 versionStatus: versionStatus.CERTIFIED
50 }
51 });
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020052 },
Yarin Dekel811fb482018-11-04 15:00:34 +020053 changeSearchValue(dispatch, searchValue, activeTab) {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020054 dispatch({
55 type: actionTypes.CHANGE_SEARCH_VALUE,
Yarin Dekel811fb482018-11-04 15:00:34 +020056 payload: { searchValue, activeTab }
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020057 });
58 },
59 clearSearchValue(dispatch) {
60 dispatch({
Yarin Dekel811fb482018-11-04 15:00:34 +020061 type: actionTypes.CLEAR_SEARCH_VALUE,
62 payload: {
63 searchValue: searchValueObj
64 }
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020065 });
66 },
miriamed411d152018-01-02 15:35:55 +020067
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020068 loadVLMScreen(dispatch, { id: licenseModelId, name }, users, tab) {
69 if (tab === tabsMapping.WORKSPACE) {
70 VersionsPageActionHelper.fetchVersions(dispatch, {
71 itemId: licenseModelId,
72 itemType: itemTypes.LICENSE_MODEL
73 }).then(({ results }) => {
74 results = results.filter(
svishnevea5e43c2018-04-15 09:06:57 +030075 version => version.status === versionStatus.DRAFT
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020076 );
77 if (results.length !== 1) {
78 ScreensHelper.loadScreen(dispatch, {
79 screen: enums.SCREEN.VERSIONS_PAGE,
80 screenType: screenTypes.LICENSE_MODEL,
81 props: {
82 licenseModelId,
83 licenseModel: { name },
84 usersList: users
85 }
86 });
87 } else {
88 PermissionsActionHelper.fetchItemUsers(dispatch, {
89 itemId: licenseModelId,
90 allUsers: users
91 }).then(() =>
92 ScreensHelper.loadLandingScreen(dispatch, {
93 screenType: screenTypes.LICENSE_MODEL,
94 props: { licenseModelId, version: results[0] }
95 })
96 );
97 }
98 });
99 }
100 if (tab === tabsMapping.CATALOG) {
101 ScreensHelper.loadScreen(dispatch, {
102 screen: enums.SCREEN.VERSIONS_PAGE,
103 screenType: screenTypes.LICENSE_MODEL,
104 props: {
105 licenseModelId,
106 licenseModel: { name },
107 usersList: users
108 }
109 });
110 }
111 },
112 loadVSPScreen(dispatch, softwareProduct, users, tab) {
113 let {
114 id: softwareProductId,
115 vendorId: licenseModelId,
116 licensingVersion,
117 name
118 } = softwareProduct;
119 if (tab === tabsMapping.WORKSPACE) {
120 VersionsPageActionHelper.fetchVersions(dispatch, {
121 itemId: softwareProductId,
122 itemType: itemTypes.SOFTWARE_PRODUCT
123 }).then(({ results }) => {
124 results = results.filter(
svishnevea5e43c2018-04-15 09:06:57 +0300125 version => version.status === versionStatus.DRAFT
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200126 );
127 if (results.length !== 1) {
128 ScreensHelper.loadScreen(dispatch, {
129 screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE,
130 screenType: screenTypes.SOFTWARE_PRODUCT,
131 props: {
132 softwareProductId,
133 softwareProduct: {
134 name,
135 vendorId: licenseModelId,
136 licensingVersion
137 },
138 usersList: users
139 }
140 });
141 } else {
142 PermissionsActionHelper.fetchItemUsers(dispatch, {
143 itemId: softwareProductId,
144 allUsers: users
145 }).then(() =>
146 ScreensHelper.loadLandingScreen(dispatch, {
147 screenType: screenTypes.SOFTWARE_PRODUCT,
148 props: {
149 softwareProductId,
150 licenseModelId,
151 version: results[0]
152 }
153 })
154 );
155 }
156 });
157 }
158 if (tab === tabsMapping.CATALOG) {
159 ScreensHelper.loadScreen(dispatch, {
160 screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE,
161 screenType: screenTypes.SOFTWARE_PRODUCT,
162 props: {
163 softwareProductId,
164 softwareProduct: {
165 name,
166 vendorId: licenseModelId,
167 licensingVersion
168 },
169 usersList: users
170 }
171 });
172 }
173 }
AviZi280f8012017-06-09 02:39:56 +0300174};
175
176export default OnboardActionHelper;