svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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 |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame^] | 7 | * |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame^] | 9 | * |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 12 | * 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. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 15 | */ |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame^] | 16 | import { |
| 17 | tabsMapping, |
| 18 | actionTypes, |
| 19 | searchValueObj |
| 20 | } from './OnboardConstants.js'; |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 21 | import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 22 | import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js'; |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 23 | import VersionsPageActionHelper from 'sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js'; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 24 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 25 | import { itemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js'; |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 26 | import PermissionsActionHelper from 'sdc-app/onboarding/permissions/PermissionsActionHelper.js'; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 27 | import { actionTypes as filterActionTypes } from './filter/FilterConstants.js'; |
svishnev | cee71ef | 2018-05-01 17:56:49 +0300 | [diff] [blame] | 28 | import { versionStatus } from 'sdc-app/common/helpers/ItemsHelperConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 29 | |
| 30 | const OnboardActionHelper = { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 31 | resetOnboardStore(dispatch) { |
| 32 | dispatch({ |
| 33 | type: actionTypes.RESET_ONBOARD_STORE |
| 34 | }); |
| 35 | }, |
| 36 | changeActiveTab(dispatch, activeTab) { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 37 | dispatch({ |
| 38 | type: actionTypes.CHANGE_ACTIVE_ONBOARD_TAB, |
| 39 | activeTab |
| 40 | }); |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 41 | dispatch({ |
| 42 | type: filterActionTypes.FILTER_DATA_CHANGED, |
| 43 | deltaData: |
| 44 | activeTab === tabsMapping.WORKSPACE |
| 45 | ? { |
svishnev | cee71ef | 2018-05-01 17:56:49 +0300 | [diff] [blame] | 46 | versionStatus: versionStatus.DRAFT |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 47 | } |
| 48 | : { |
| 49 | versionStatus: versionStatus.CERTIFIED |
| 50 | } |
| 51 | }); |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 52 | }, |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame^] | 53 | changeSearchValue(dispatch, searchValue, activeTab) { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 54 | dispatch({ |
| 55 | type: actionTypes.CHANGE_SEARCH_VALUE, |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame^] | 56 | payload: { searchValue, activeTab } |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 57 | }); |
| 58 | }, |
| 59 | clearSearchValue(dispatch) { |
| 60 | dispatch({ |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame^] | 61 | type: actionTypes.CLEAR_SEARCH_VALUE, |
| 62 | payload: { |
| 63 | searchValue: searchValueObj |
| 64 | } |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 65 | }); |
| 66 | }, |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 67 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 68 | 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( |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 75 | version => version.status === versionStatus.DRAFT |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 76 | ); |
| 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( |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 125 | version => version.status === versionStatus.DRAFT |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 126 | ); |
| 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 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | export default OnboardActionHelper; |