3 * Copyright 2016 RIFT.IO Inc
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 import React from 'react';
20 import LoggingStore from './loggingStore.js';
22 class DenyEvent extends React.Component {
27 eventID: props.eventID
31 componentWillReceiveProps(props) {
33 eventID: props.eventID
37 handleEventIdChange = (e) => {
38 //console.log("DenyEvent.handleEventIdChange called. value=", e.target.value);
39 // TODO: Save only if value is valid
42 eventID: e.target.value
46 isEventIdValid(eventID) {
47 // Return true if null, empty string or a number, else return false
48 if (!eventID || eventID.length == 0) {
51 return (isNaN(+eventID)) ? false : true;
56 const {className, onSave, onRemove, warnInvalidEventID, inputPattern,
57 ...props} = this.props;
58 let textBoxClassNames = "textBox";
59 if (warnInvalidEventID && !this.isEventIdValid(this.state.eventID)) {
60 //console.log("eventID is not valid: ", this.state.eventID);
61 textBoxClassNames += " invalidValue";
64 <div className={className} >
65 <input className={textBoxClassNames} type="text"
66 value={this.state.eventID}
67 pattern={inputPattern}
69 onChange={this.handleEventIdChange.bind(this)}
70 placeholder="Event ID"
72 <div className="removeButton"
74 <span className="oi" data-glyph="minus"
75 title="Remove event id" aria-hidden="true"></span>
81 DenyEvent.defaultProps = {
83 warnInvalidEventID: true,
84 inputPattern: "^\\d*$"
88 export default class DenyEventsEditGroup extends React.Component {
90 handleUpdateEvent = (index) => {
91 let enforceEventIdRules = this.props.enforceEventIdRules;
93 if (e.target.value && e.target.value.trim().length > 0) {
94 if (enforceEventIdRules) {
95 console.log("attempting to set eventID[] to ", e.target.value)
96 let value = +e.target.value;
98 //let value = parseInt(e.target.value, 10);
100 LoggingStore.updateDenyEvent(index, value);
102 // Error. Show input error on screen
105 LoggingStore.updateDenyEvent(index, e.target.value);
109 } else if (!e.target.value || e.target.value.trim().length == 0) {
110 LoggingStore.updateDenyEvent(index, null);
115 handleRemoveEvent(index) {
117 //console.log("handleRemoveEvent called for eventID: ", eventID);
118 LoggingStore.removeDenyEvent(index);
124 const {className, eventIDs, warnInvalidEventID, ...props} = this.props;
128 <div className={className}>
130 eventIDs.map(function(eventID, index) {
131 return (<DenyEvent className="eventEditRow"
135 onRemove={self.handleRemoveEvent(index)}
136 onSave={self.handleUpdateEvent(index)}
137 warnInvalidEventID={warnInvalidEventID}
145 DenyEventsEditGroup.defaultProps = {
147 enforceEventIdRules: false,
148 warnInvalidEventID: false