blob: 457d096219ddf50030779d5fb4b2cc93cd637a36 [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
svishnev091edfd2018-03-19 12:15:19 +02002 * Copyright © 2016-2018 European Support Limited
talig8e9c0652017-12-20 14:30:43 +02003 *
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 Keidar7fdf7332018-03-20 14:45:40 +020017import { connect } from 'react-redux';
talig8e9c0652017-12-20 14:30:43 +020018import VersionsPageActionHelper from './VersionsPageActionHelper.js';
19import VersionsPageCreationActionHelper from './creation/VersionsPageCreationActionHelper.js';
20import PermissionsActionHelper from '../permissions/PermissionsActionHelper.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020021import { onboardingMethod as onboardingMethodType } from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js';
talig8e9c0652017-12-20 14:30:43 +020022import VersionsPageView from './VersionsPage.jsx';
23
24export const mapStateToProps = ({
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020025 users: { userInfo },
26 versionsPage: { permissions, versionsList },
27 currentScreen: {
28 itemPermission: { isCollaborator, isArchived },
29 props: { itemId }
30 },
31 softwareProductList = []
talig8e9c0652017-12-20 14:30:43 +020032}) => {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020033 let { versions = [], selectedVersion } = versionsList;
34 let { owner, contributors, viewers } = permissions;
talig8e9c0652017-12-20 14:30:43 +020035
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020036 // 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 };
talig8e9c0652017-12-20 14:30:43 +020062};
63
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020064export 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 },
talig8e9c0652017-12-20 14:30:43 +020077
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020078 onSelectVersion({ version }) {
79 VersionsPageActionHelper.selectVersion(dispatch, { version });
80 },
talig8e9c0652017-12-20 14:30:43 +020081
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020082 onCreateVersion({ version }) {
83 VersionsPageCreationActionHelper.open(dispatch, {
84 baseVersion: version,
85 itemId,
86 itemType,
87 additionalProps
88 });
89 },
talig8e9c0652017-12-20 14:30:43 +020090
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020091 onManagePermissions() {
92 PermissionsActionHelper.openPermissonsManager(dispatch, {
93 itemId,
94 askForRights: false
95 });
96 },
talig8e9c0652017-12-20 14:30:43 +020097
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020098 onTreeFullScreen(treeProps) {
99 VersionsPageActionHelper.openTree(dispatch, treeProps);
100 },
talig8e9c0652017-12-20 14:30:43 +0200101
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200102 onModalNodeClick({ version }) {
103 VersionsPageActionHelper.selectVersionFromModal(dispatch, {
104 version
105 });
106 },
107 onArchive: () => VersionsPageActionHelper.archiveItem(dispatch, itemId),
108 onRestore: () =>
109 VersionsPageActionHelper.restoreItemFromArchive(dispatch, itemId)
110 };
talig8e9c0652017-12-20 14:30:43 +0200111};
112
113export default connect(mapStateToProps, mapActionsToProps)(VersionsPageView);