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