talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 1 | /*! |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 2 | * Copyright © 2016-2018 European Support Limited |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [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 |
| 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 | */ |
| 16 | import ItemsHelper from '../../common/helpers/ItemsHelper.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 17 | import { actionTypes } from './VersionsPageConstants.js'; |
| 18 | import { itemTypes } from './VersionsPageConstants.js'; |
| 19 | import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js'; |
| 20 | import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 21 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
| 22 | import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js'; |
svishnev | fa538a1 | 2018-05-31 15:01:00 +0300 | [diff] [blame] | 23 | import { |
| 24 | enums, |
| 25 | screenTypes, |
| 26 | onboardingActions |
| 27 | } from 'sdc-app/onboarding/OnboardingConstants.js'; |
| 28 | import { notificationActions } from 'nfvo-components/notification/NotificationsConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 29 | |
| 30 | const VersionsPageActionHelper = { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 31 | fetchVersions(dispatch, { itemType, itemId }) { |
| 32 | return ItemsHelper.fetchVersions({ itemId }).then(response => { |
| 33 | dispatch({ |
| 34 | type: actionTypes.VERSIONS_LOADED, |
| 35 | versions: response.results, |
| 36 | itemType, |
| 37 | itemId |
| 38 | }); |
| 39 | return Promise.resolve(response); |
| 40 | }); |
| 41 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 42 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 43 | selectVersion(dispatch, { version }) { |
| 44 | dispatch({ |
| 45 | type: actionTypes.SELECT_VERSION, |
| 46 | versionId: version.id |
| 47 | }); |
| 48 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 49 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 50 | selectNone(dispatch) { |
| 51 | dispatch({ type: actionTypes.SELECT_NONE }); |
| 52 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 53 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 54 | onNavigateToVersion(dispatch, { version, itemId, itemType }) { |
| 55 | switch (itemType) { |
| 56 | case itemTypes.LICENSE_MODEL: |
| 57 | ScreensHelper.loadScreen(dispatch, { |
| 58 | screen: enums.SCREEN.LICENSE_MODEL_OVERVIEW, |
| 59 | screenType: screenTypes.LICENSE_MODEL, |
| 60 | props: { licenseModelId: itemId, version } |
| 61 | }); |
| 62 | break; |
| 63 | case itemTypes.SOFTWARE_PRODUCT: |
| 64 | ScreensHelper.loadScreen(dispatch, { |
| 65 | screen: enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE, |
| 66 | screenType: screenTypes.SOFTWARE_PRODUCT, |
| 67 | props: { softwareProductId: itemId, version } |
| 68 | }); |
| 69 | break; |
| 70 | } |
| 71 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 72 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 73 | openTree(dispatch, treeProps) { |
| 74 | dispatch({ |
| 75 | type: modalActionTypes.GLOBAL_MODAL_SHOW, |
| 76 | data: { |
| 77 | modalComponentName: modalContentMapper.VERSION_TREE, |
| 78 | modalComponentProps: treeProps, |
| 79 | onDeclined: () => |
| 80 | dispatch({ |
| 81 | type: modalActionTypes.GLOBAL_MODAL_CLOSE |
| 82 | }), |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 83 | bodyClassName: 'versions-tree-modal', |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 84 | cancelButtonText: i18n('Close'), |
| 85 | title: i18n('Version Tree') |
| 86 | } |
| 87 | }); |
| 88 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 89 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 90 | selectVersionFromModal(dispatch, { version }) { |
| 91 | dispatch({ |
| 92 | type: modalActionTypes.GLOBAL_MODAL_CLOSE |
| 93 | }); |
| 94 | this.selectVersion(dispatch, { version }); |
| 95 | }, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 96 | |
svishnev | fa538a1 | 2018-05-31 15:01:00 +0300 | [diff] [blame] | 97 | async archiveItem(dispatch, itemId) { |
| 98 | await ItemsHelper.archiveItem(itemId); |
| 99 | dispatch(onboardingActions.updateItemArchivedStatus(true)); |
| 100 | dispatch( |
| 101 | notificationActions.showSuccess({ |
| 102 | message: i18n('Item successfully archived') |
| 103 | }) |
| 104 | ); |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 105 | }, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 106 | |
svishnev | fa538a1 | 2018-05-31 15:01:00 +0300 | [diff] [blame] | 107 | async restoreItemFromArchive(dispatch, itemId) { |
| 108 | await ItemsHelper.restoreItem(itemId); |
| 109 | dispatch(onboardingActions.updateItemArchivedStatus(false)); |
| 110 | dispatch( |
| 111 | notificationActions.showSuccess({ |
| 112 | message: i18n('Item successfully restored') |
| 113 | }) |
| 114 | ); |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 115 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | export default VersionsPageActionHelper; |