blob: 2826e324b31afa28eafb5aae36123a624a2c4cd5 [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';
24import {
25 versionStatus,
26 itemStatus
27} from 'sdc-app/common/helpers/ItemsHelperConstants.js';
AviZi280f8012017-06-09 02:39:56 +030028
29const OnboardActionHelper = {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020030 resetOnboardStore(dispatch) {
31 dispatch({
32 type: actionTypes.RESET_ONBOARD_STORE
33 });
34 },
35 changeActiveTab(dispatch, activeTab) {
36 this.clearSearchValue(dispatch);
37 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 ? {
46 versionStatus: versionStatus.DRAFT,
47 itemStatus: itemStatus.ACTIVE
48 }
49 : {
50 versionStatus: versionStatus.CERTIFIED
51 }
52 });
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020053 },
54 changeSearchValue(dispatch, searchValue) {
55 dispatch({
56 type: actionTypes.CHANGE_SEARCH_VALUE,
57 searchValue
58 });
59 },
60 clearSearchValue(dispatch) {
61 dispatch({
62 type: actionTypes.CHANGE_SEARCH_VALUE,
63 searchValue: ''
64 });
65 },
miriamed411d152018-01-02 15:35:55 +020066
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020067 loadVLMScreen(dispatch, { id: licenseModelId, name }, users, tab) {
68 if (tab === tabsMapping.WORKSPACE) {
69 VersionsPageActionHelper.fetchVersions(dispatch, {
70 itemId: licenseModelId,
71 itemType: itemTypes.LICENSE_MODEL
72 }).then(({ results }) => {
73 results = results.filter(
svishnevea5e43c2018-04-15 09:06:57 +030074 version => version.status === versionStatus.DRAFT
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020075 );
76 if (results.length !== 1) {
77 ScreensHelper.loadScreen(dispatch, {
78 screen: enums.SCREEN.VERSIONS_PAGE,
79 screenType: screenTypes.LICENSE_MODEL,
80 props: {
81 licenseModelId,
82 licenseModel: { name },
83 usersList: users
84 }
85 });
86 } else {
87 PermissionsActionHelper.fetchItemUsers(dispatch, {
88 itemId: licenseModelId,
89 allUsers: users
90 }).then(() =>
91 ScreensHelper.loadLandingScreen(dispatch, {
92 screenType: screenTypes.LICENSE_MODEL,
93 props: { licenseModelId, version: results[0] }
94 })
95 );
96 }
97 });
98 }
99 if (tab === tabsMapping.CATALOG) {
100 ScreensHelper.loadScreen(dispatch, {
101 screen: enums.SCREEN.VERSIONS_PAGE,
102 screenType: screenTypes.LICENSE_MODEL,
103 props: {
104 licenseModelId,
105 licenseModel: { name },
106 usersList: users
107 }
108 });
109 }
110 },
111 loadVSPScreen(dispatch, softwareProduct, users, tab) {
112 let {
113 id: softwareProductId,
114 vendorId: licenseModelId,
115 licensingVersion,
116 name
117 } = softwareProduct;
118 if (tab === tabsMapping.WORKSPACE) {
119 VersionsPageActionHelper.fetchVersions(dispatch, {
120 itemId: softwareProductId,
121 itemType: itemTypes.SOFTWARE_PRODUCT
122 }).then(({ results }) => {
123 results = results.filter(
svishnevea5e43c2018-04-15 09:06:57 +0300124 version => version.status === versionStatus.DRAFT
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200125 );
126 if (results.length !== 1) {
127 ScreensHelper.loadScreen(dispatch, {
128 screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE,
129 screenType: screenTypes.SOFTWARE_PRODUCT,
130 props: {
131 softwareProductId,
132 softwareProduct: {
133 name,
134 vendorId: licenseModelId,
135 licensingVersion
136 },
137 usersList: users
138 }
139 });
140 } else {
141 PermissionsActionHelper.fetchItemUsers(dispatch, {
142 itemId: softwareProductId,
143 allUsers: users
144 }).then(() =>
145 ScreensHelper.loadLandingScreen(dispatch, {
146 screenType: screenTypes.SOFTWARE_PRODUCT,
147 props: {
148 softwareProductId,
149 licenseModelId,
150 version: results[0]
151 }
152 })
153 );
154 }
155 });
156 }
157 if (tab === tabsMapping.CATALOG) {
158 ScreensHelper.loadScreen(dispatch, {
159 screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE,
160 screenType: screenTypes.SOFTWARE_PRODUCT,
161 props: {
162 softwareProductId,
163 softwareProduct: {
164 name,
165 vendorId: licenseModelId,
166 licensingVersion
167 },
168 usersList: users
169 }
170 });
171 }
172 }
AviZi280f8012017-06-09 02:39:56 +0300173};
174
175export default OnboardActionHelper;