[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / licenseModel / overview / summary / VendorDataView.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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 React from 'react';
17 import {connect} from 'react-redux';
18
19 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
20 import licenseModelOverviewActionHelper from '../licenseModelOverviewActionHelper.js';
21 import LicenseModelActionHelper from '../../LicenseModelActionHelper.js';
22 import LicenseModelDescriptionEdit from './LicenseModelDescriptionEdit.jsx';
23 import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js';
24 import {VLM_DESCRIPTION_FORM} from '../LicenseModelOverviewConstants.js';
25
26 export const mapStateToProps = ({licenseModel: {licenseModelEditor: {data}, licenseModelOverview: {descriptionEditor: {data: descriptionData, genericFieldInfo} }}}) => {
27         let description = (descriptionData && descriptionData.description) ? descriptionData.description : null;
28         let isReadOnlyMode = VersionControllerUtils.isReadOnly(data);
29         return {
30                 data,
31                 description,
32                 genericFieldInfo,
33                 isReadOnlyMode
34         };
35 };
36
37 const mapActionsToProps = (dispatch) => {
38         return {
39                 onDataChanged: (deltaData) => ValidationHelper.dataChanged(dispatch, {deltaData, formName: VLM_DESCRIPTION_FORM}),
40                 onCancel: () => licenseModelOverviewActionHelper.editDescriptionClose(dispatch),
41                 onSubmit: (licenseModel) => {
42                         licenseModelOverviewActionHelper.editDescriptionClose(dispatch);
43                         LicenseModelActionHelper.saveLicenseModel(dispatch, {licenseModel});
44                 },
45                 onVendorDescriptionEdit: description => licenseModelOverviewActionHelper.editDescriptionOpen(dispatch,{description})
46         };
47 };
48
49
50
51 export class VendorDataView extends React.Component {
52         render() {
53                 let {data: {vendorName}, description, isReadOnlyMode} = this.props;
54                 return (
55                         <div className='vendor-data-view'>
56                                 <div className='vendor-title'>vendor</div>
57                                 <div className='vendor-name' data-test-id='vlm-summary-vendor-name'>{vendorName}</div>
58                                 {
59                                         description && !isReadOnlyMode ? this.renderDescriptionEdit() : this.renderDescription()
60                                 }
61                         </div>
62                 );
63         }
64
65         renderDescription() {
66                 let {data: {description}, onVendorDescriptionEdit, isReadOnlyMode} = this.props;
67                 return (
68                         <div onClick={() => {if (!isReadOnlyMode) {onVendorDescriptionEdit(description);}}}  className={!isReadOnlyMode ? 'vendor-description' : 'vendor-description-readonly'}>
69                                 <div className='description-data' data-test-id='vlm-summary-vendor-description'>
70                                         {description}
71                                 </div>
72                         </div>
73                 );
74         }
75
76         renderDescriptionEdit() {
77                 let {onCancel, onDataChanged, onSubmit, description, genericFieldInfo, data} = this.props;
78                 return(
79                         <LicenseModelDescriptionEdit onClose={onCancel} onDataChanged={onDataChanged} onSubmit={onSubmit} data={data} genericFieldInfo={genericFieldInfo} description={description}/>
80                 );
81         }
82
83 }
84
85 export default connect(mapStateToProps, mapActionsToProps)(VendorDataView);
86