import React from 'react';
import PropTypes from 'prop-types';

import { SELECTION_ALL_PHASES } from 'interface/report/PhaseParser';

class PhaseSelector extends React.PureComponent {
  static propTypes = {
    phases: PropTypes.object.isRequired,
    selectedPhase: PropTypes.string.isRequired,
    handlePhaseSelection: PropTypes.func.isRequired,
  };

  constructor(...args){
    super(...args);
    this.handleChange = this.handleChange.bind(this);
    this.state = {
      phase: this.props.selectedPhase,
    };
  }

  componentDidUpdate(prevProps, prevState, prevContext) {
    const changed = this.props.selectedPhase !== prevProps.selectedPhase
      || this.props.selectedPhase !== this.state.phase;
    if (changed) {
      this.setState({
        phase: this.props.selectedPhase,
      });
    }
  }

  handleChange(e) {
    const phase = e.target.value || SELECTION_ALL_PHASES;
    this.setState({
      phase: phase,
    });
    this.props.handlePhaseSelection(phase);
  }

  render() {
    const {phases} = this.props;
    return (
      //<form>
        <select
          className="form-control region"
          //ref={this.regionInput}
          defaultValue={this.state.phase}
          onChange={this.handleChange}
          >
          <option key="all" value={SELECTION_ALL_PHASES}>All Phases</option>
          {Object.keys(phases).map(key =>
            <option key={key} value={key}>{phases[key].name}</option>
          )}
          </select>
      //</form>
    );
  }
}

export default PhaseSelector;

@@ -1044,25 +1044,8 @@
 n (%0A
-      //%3Cform%3E%0A  
     
@@ -1054,18 +1054,16 @@
 %3Cselect%0A
-  
         
@@ -1102,18 +1102,16 @@
         
-  
 //ref=%7Bt
@@ -1135,18 +1135,16 @@
         
- 
- 
 defaultV
@@ -1175,18 +1175,16 @@
         
-  
 onChange
@@ -1204,20 +1204,16 @@
 Change%7D%0A
-    
       %3E%0A
@@ -1212,34 +1212,32 @@
       %3E%0A        
-  
 %3Coption key=%22all
@@ -1279,34 +1279,32 @@
 Phases%3C/option%3E%0A
-  
         %7BObject.
@@ -1333,26 +1333,24 @@
 %3E%0A          
-  
 %3Coption key=
@@ -1407,17 +1407,11 @@
     
- 
- 
 )%7D%0A
-    
     
@@ -1426,24 +1426,8 @@
 ct%3E%0A
-      //%3C/form%3E%0A
     

remove form wrapping