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 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 17 | import { connect } from 'react-redux'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 18 | import VersionsPageActionHelper from './VersionsPageActionHelper.js'; |
| 19 | import VersionsPageCreationActionHelper from './creation/VersionsPageCreationActionHelper.js'; |
| 20 | import PermissionsActionHelper from '../permissions/PermissionsActionHelper.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 21 | import { onboardingMethod as onboardingMethodType } from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 22 | import VersionsPageView from './VersionsPage.jsx'; |
| 23 | |
| 24 | export const mapStateToProps = ({ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 25 | users: { userInfo }, |
| 26 | versionsPage: { permissions, versionsList }, |
| 27 | currentScreen: { |
| 28 | itemPermission: { isCollaborator, isArchived }, |
| 29 | props: { itemId } |
| 30 | }, |
| 31 | softwareProductList = [] |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 32 | }) => { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 33 | let { versions = [], selectedVersion } = versionsList; |
| 34 | let { owner, contributors, viewers } = permissions; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 35 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 36 | // sorting the version list |
| 37 | versions.sort((a, b) => { |
| 38 | let statusCompare = b.status.localeCompare(a.status); |
| 39 | if (statusCompare === 0) { |
| 40 | return b.modificationTime - a.modificationTime; |
| 41 | } else { |
| 42 | return statusCompare; |
| 43 | } |
| 44 | }); |
| 45 | const curentSoftwareProduct = softwareProductList.find( |
| 46 | item => item.id === itemId |
| 47 | ); |
| 48 | return { |
| 49 | versions, |
| 50 | contributors, |
| 51 | viewers, |
| 52 | owner, |
| 53 | currentUser: userInfo, |
| 54 | selectedVersion, |
| 55 | isCollaborator, |
| 56 | isManual: |
| 57 | curentSoftwareProduct && |
| 58 | curentSoftwareProduct.onboardingMethod === |
| 59 | onboardingMethodType.MANUAL, |
| 60 | isArchived |
| 61 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 64 | export const mapActionsToProps = ( |
| 65 | dispatch, |
| 66 | { itemType, itemId, additionalProps } |
| 67 | ) => { |
| 68 | return { |
| 69 | onNavigateToVersion({ version }) { |
| 70 | VersionsPageActionHelper.onNavigateToVersion(dispatch, { |
| 71 | version, |
| 72 | itemId, |
| 73 | itemType, |
| 74 | additionalProps |
| 75 | }); |
| 76 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 77 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 78 | onSelectVersion({ version }) { |
| 79 | VersionsPageActionHelper.selectVersion(dispatch, { version }); |
| 80 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 81 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 82 | onCreateVersion({ version }) { |
| 83 | VersionsPageCreationActionHelper.open(dispatch, { |
| 84 | baseVersion: version, |
| 85 | itemId, |
| 86 | itemType, |
| 87 | additionalProps |
| 88 | }); |
| 89 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 90 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 91 | onManagePermissions() { |
| 92 | PermissionsActionHelper.openPermissonsManager(dispatch, { |
| 93 | itemId, |
| 94 | askForRights: false |
| 95 | }); |
| 96 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 97 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 98 | onTreeFullScreen(treeProps) { |
| 99 | VersionsPageActionHelper.openTree(dispatch, treeProps); |
| 100 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 101 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 102 | onModalNodeClick({ version }) { |
| 103 | VersionsPageActionHelper.selectVersionFromModal(dispatch, { |
| 104 | version |
| 105 | }); |
| 106 | }, |
| 107 | onArchive: () => VersionsPageActionHelper.archiveItem(dispatch, itemId), |
| 108 | onRestore: () => |
| 109 | VersionsPageActionHelper.restoreItemFromArchive(dispatch, itemId) |
| 110 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | export default connect(mapStateToProps, mapActionsToProps)(VersionsPageView); |