Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. class FilterAdd extends Filter {
  2. constructor(props) {
  3. super(props);
  4. this.state = {
  5. Filter: {
  6. Name: "",
  7. Field: 0,
  8. Operation: 0,
  9. Arguments: [""]
  10. }
  11. }
  12. }
  13.  
  14. render = () => {
  15. console.log(this.state.Filter);
  16. return (
  17. <div className="addFilter">
  18. <h2>New Filter</h2>
  19. <InputV3 Name="Name" handleOnChange={this.handleChange} />
  20. <DropDownV3 Name="Field" Options={this.fieldOptions} handleOnChange={this.handleChange} />
  21. <DropDownV3 Name="Operation" Options={this.operationOptions} handleOnChange={this.handleChange} />
  22. <FilterArgsInput {...this.state.Filter} handleChange={this.handleChange} />
  23. </div>
  24. )
  25. }
  26.  
  27. handleChange = (value, fieldName) => {
  28. this.setState((prevState) => {
  29. if (fieldName == "Operation" || fieldName == "Field") value = parseInt(value);
  30. if (fieldName == "Operation") prevState.Filter.Arguments = (value == 8) ? ["", ""] : [""];
  31. prevState.Filter[fieldName] = value;
  32. return { Filter: prevState.Filter }
  33. })
  34. }
  35.  
  36. }
  37.  
  38. class FilterArgsInput extends React.Component {
  39. render = () => {
  40. const InputSet = this.props.Arguments.map((arg, index) => <div key={index}>
  41. <InputV3 Value={arg} />
  42. {this.props.Operation === 8 && index < this.props.Arguments.length - 1 && " And "}
  43. {this.props.Operation === 7 && <i className="fa fa-times" onClick={() => { this.handleArgChange(this.props.Arguments.filter((arg, iterator) => iterator != index)) }}></i>}
  44. </div>);
  45.  
  46. return (
  47. <div onChange={this.handleArgumentsChange}>
  48. {InputSet}
  49. {this.props.Operation === 7 && <i className="fa fa-plus" onClick={() => { this.handleArgChange([...this.props.Arguments, ""]) }}></i>}
  50. </div>
  51. )
  52. }
  53.  
  54. handleArgChange = (args) => {
  55. this.props.handleChange(args, "Arguments");
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement