2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 import {actionTypes, enums} from './OnboardingConstants.js';
17 import {actionTypes as permissionActionTypes} from './permissions/PermissionsConstants.js';
18 import {actionTypes as licenseModelCreateActionTypes} from './licenseModel/creation/LicenseModelCreationConstants.js';
19 import {actionTypes as softwareProductCreateActionTypes} from './softwareProduct/creation/SoftwareProductCreationConstants.js';
20 import {actionTypes as versionCreateActionTypes} from './versionsPage/creation/VersionsPageCreationConstants.js';
21 import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js';
23 import {catalogItemStatuses} from './onboard/onboardingCatalog/OnboardingCatalogConstants.js';
24 import Configuration from 'sdc-app/config/Configuration.js';
26 const checkReadOnly = ({isCollaborator = true, inMerge = false, isCertified = false}) => !isCollaborator || inMerge || isCertified;
28 const currentScreen = (state = {
29 forceBreadCrumbsUpdate: false,
30 screen: enums.SCREEN.ONBOARDING_CATALOG,
35 switch (action.type) {
37 case actionTypes.SET_CURRENT_SCREEN: {
38 let itemPermission = {...state.itemPermission};
39 let {currentScreen} = action;
41 if (currentScreen.props.version) {
42 let {status} = currentScreen.props.version;
43 itemPermission.isCertified = itemPermission.isCertified && status === catalogItemStatuses.CERTIFIED;
46 let isReadOnlyMode = checkReadOnly(itemPermission);
47 let props = {...currentScreen.props, isReadOnlyMode};
57 case actionTypes.UPDATE_CURRENT_SCREEN_PROPS:
63 isReadOnlyMode: checkReadOnly(state.itemPermission)
67 case actionTypes.SET_CURRENT_SCREEN_VERSION:
72 version: action.version,
73 isReadOnlyMode: checkReadOnly(state.itemPermission)
77 case licenseModelCreateActionTypes.LICENSE_MODEL_CREATED:
78 case softwareProductCreateActionTypes.SOFTWARE_PRODUCT_CREATED:
79 case versionCreateActionTypes.VERSION_CREATED:
93 case permissionActionTypes.ITEM_USERS_LOADED: {
94 let userId = Configuration.get('UserID');
95 let isCollaborator = false;
97 if (userId === action.owner.userId) {
98 isCollaborator = true;
100 isCollaborator = action.contributors.reduce(
101 (foundUser, contributor) => foundUser || contributor.userId === userId, false
105 let itemPermission = {...state.itemPermission, isCollaborator};
106 let isReadOnlyMode = checkReadOnly(itemPermission);
107 let props = {...state.props, isReadOnlyMode};
116 case actionTypes.UPDATE_ITEM_STATUS: {
117 const {itemState: {synchronizationState, dirty}, itemStatus, updatedVersion} = action;
118 const inMerge = synchronizationState === SyncStates.MERGE;
119 const isOutOfSync = synchronizationState === SyncStates.OUT_OF_SYNC;
120 const isUpToDate = synchronizationState === SyncStates.UP_TO_DATE;
121 const isCertified = itemStatus === catalogItemStatuses.CERTIFIED;
122 const itemPermission = {...state.itemPermission, inMerge, isDirty: dirty, isOutOfSync, isUpToDate, isCertified};
123 const isReadOnlyMode = checkReadOnly(itemPermission);
124 const props = {...state.props, isReadOnlyMode, version: {...state.props.version, ...updatedVersion}};
140 export default currentScreen;