Adding filter bar
[aai/sparky-fe.git] / src / editAttributes / EditAttributes.jsx
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 import React, {Component} from 'react';
24 import {connect} from 'react-redux';
25 import i18n from 'utils/i18n/i18n';
26
27 import InlineMessage from 'generic-components/InlineMessage/InlineMessage.jsx';
28 import {
29   clearFeebackMessage,
30   requestEditEntityAttributes
31 } from './EditAttributeActions.js';
32 import {
33   SET_ATTRIBUTE_TITLE,
34   ATTRIBUTE_MODIFICATION
35 } from './EditAttributeConstants.js';
36 import ChangeAttributeForm from 'editAttributes/changeAttributeForm/ChangeAttributeForm.jsx';
37 import {NO_VALUE_SELECTED} from 'editAttributes/changeAttributeForm/ChangeAttributeFormConstants.js';
38
39 let mapStateToProps = ({setAttributes}) => {
40   let {
41         feedbackMsgText = '',
42         feedbackMsgSeverity = ''
43       } = setAttributes;
44
45   return {
46     feedbackMsgText,
47     feedbackMsgSeverity
48   };
49 };
50
51 let mapActionToProps = (dispatch) => {
52   return {
53     handleSubmit: (values) => {
54       let uri = values.uri;
55       let attrMap = new Map();
56       attrMap.set('provStatus', 'prov-status');
57       attrMap.set('inMaint', 'in-maint');
58       attrMap.set('isClosedLoopDisabled', 'is-closed-loop-disabled');
59   
60       let attributes = {};
61       let valueString = JSON.stringify(values);
62       JSON.parse(valueString, (key, value) => {
63         if(value !== NO_VALUE_SELECTED) {
64           let formattedKey = attrMap.get(key);
65           if(formattedKey !== undefined) {
66             attributes = {
67               ...attributes, [formattedKey]: value
68             };
69           }
70           return value;
71         }
72       });
73       
74       dispatch(requestEditEntityAttributes(uri, attributes));
75     },
76     clearFeedbackMessage: () => {
77       dispatch(clearFeebackMessage());
78     }
79   };
80 };
81
82 class SetAttribute extends Component {
83   render() {
84     let {
85                         feedbackMsgText,
86                         feedbackMsgSeverity,
87                         handleSubmit,
88                         clearFeedbackMessage} = this.props;
89     return (
90       <div>
91         <div className='header'>
92           <div className='application-title'>{i18n(SET_ATTRIBUTE_TITLE)}</div>
93         </div>
94         <div className='secondary-header'>
95           <span
96             className='secondary-title'>{i18n(ATTRIBUTE_MODIFICATION)}</span>
97           <InlineMessage level={feedbackMsgSeverity}
98                          messageTxt={feedbackMsgText}/>
99         </div>
100
101         <ChangeAttributeForm
102           onSubmit={(values) => {
103             handleSubmit(values);
104           }}
105           buttonSelected={() => {
106             clearFeedbackMessage();
107           }}/>
108       </div>
109     );
110   }
111 }
112
113 export default connect(mapStateToProps, mapActionToProps)(SetAttribute);