RIFT-14856: launchpad UI - Logging - default category severity
[osm/UI.git] / skyquake / plugins / logging / src / categorySeverityGrid.jsx
1  /*
2  * 
3  *   Copyright 2016 RIFT.IO Inc
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  *
17  */
18 import React from 'react';
19
20 import {DropList, RadioButtonGroup, CardSection } from './loggingWidgets.jsx';
21 import { Grid } from './gridWidgets.jsx';
22 import LoggingStore from './loggingStore.js';
23
24
25 export default class CategorySeverityGrid extends React.Component {
26
27   generateRows(defaultSeverities, severityOptions) {
28     let self = this;
29     return defaultSeverities.map(function(catsev) {
30       // let dropList = (<DropList options={severityOptions}
31       //   selectedOption={catsev.severity}
32       //   onChange={self.onChangeSeverity(catsev.category)} />);
33       let dropList = (<DropList options={severityOptions}
34         selectedOption={catsev.severity}
35         onChange={self.onChangeSyslogSeverity(catsev.name)} />);
36       return [catsev.name, dropList];
37     });
38   }
39
40   // onChangeSeverity (category) {
41   //   return function(e) {
42   //     LoggingStore.updateCategoryDefaultSeverity({
43   //       category: category,
44   //       severity: e
45   //     });
46   //   }
47   // }
48
49   onChangeSyslogSeverity (name) {
50     return function(e) {
51       LoggingStore.updateCategoryDefaultSyslogSeverity({
52         name: name,
53         severity: e
54       });
55     }
56   }
57
58   render() {
59     const {cellLabels, severityOptions, defaultSeverities, columnClasses,
60        ...props} = this.props;
61     let rows = null;
62     if (defaultSeverities) {
63       rows = this.generateRows(defaultSeverities, severityOptions);
64     }
65     return (<Grid className="categorySeverityGrid"
66       cellLabels={cellLabels}
67       rows={rows}
68       columnClasses={columnClasses}
69       />);
70   }
71 }
72
73 CategorySeverityGrid.defaultProps = {
74   cellLabels: [
75     'Name', 'Severity'
76   ],
77   columnClasses: [
78     'category', 'severity'
79   ]
80 }