[AAI] Remove Robby Maharajh & Harish Kajur as committers
[aai/sparky-fe.git] / src / app / model / modelSearch / components / ModelCard.jsx
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2021 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *       http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 import React from 'react';
22 import ModelRelationships from './ModelRelationships.jsx';
23 import { Link } from 'react-router-dom';
24 import {ExportExcel} from 'utils/ExportExcel.js';
25 let buildAttrList = ExportExcel.buildAttrList;
26
27 const modelCard = (props) => {
28
29   var propKey = '';
30   var navigateQueryBuilder = '';
31   var editModalIcon = '';
32   var requiredParams = buildAttrList(props.nodeType,[],'mandatory');
33   const properties = Object.keys(props.nodeProps).map((prop, idx) => {
34     let description='';
35     for(var a in requiredParams){
36       if(requiredParams[a].value === prop){
37         description=requiredParams[a].description;
38         if(propKey === ''){
39           propKey = prop + ':' + btoa('<pre>' + props.nodeProps[prop].toString() + '</pre>');
40         }else{
41           propKey = propKey + ';' + prop + ':' + btoa('<pre>' + props.nodeProps[prop].toString() + '</pre>');
42         }
43       }
44     }
45     return (
46       <p className='pre-wrap-text' key={idx}><strong title={description}>{prop}:</strong> {props.nodeProps[prop].toString()}</p>
47     );
48   });
49   let pathNameStr = '/customDslBuilder/' + props.nodeType + '/' + propKey;
50   editModalIcon = <a className={props.isWriteAllowed ? 'show' : 'hidden'} onClick={e => {props.openEditNodeModal(props.nodeUrl)}}><i style={{cursor: 'pointer'}} className="pull-right fa fa-pencil-square-o" aria-hidden="true"></i></a>;
51   navigateQueryBuilder = <Link
52                   to={{
53                     pathname: pathNameStr
54                    }}>
55                    <i className={'icon-misc-operationsL pull-right'} role="img"></i>
56                    </Link>;
57   return (
58     <div className='card model-card'>
59       <div className='card-header'>
60         <h4 className='card-title'>{props['nodeType']}{editModalIcon}{navigateQueryBuilder}</h4>
61       </div>
62       <div className='card-header'>
63         {props.nodeUrl}
64       </div>
65       <div className='card-content model-card-content'>
66         {properties}
67       </div>
68       <div className='card-footer'>
69         <ModelRelationships historyStackString={props.historyStackString} relatives={props} openHistoryModal={props.openHistoryModal} />
70       </div>
71     </div>
72   );
73 };
74
75 export default modelCard;