-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
709 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React from 'react'; | ||
import {connect} from 'react-redux'; | ||
|
||
const DEFAULT_FILTER_COUNT = 3; | ||
|
||
class DataSelectorFilterComponent extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
filters: { | ||
filter1: { | ||
label: 'Filter 1', | ||
operators: ['<', '>', '<='], | ||
type: 'number' | ||
}, | ||
filter2: { | ||
label: 'Filter 2', | ||
operators: ['===', '!='], | ||
type: 'text' | ||
} | ||
}, | ||
selectedFilters: [{filter: null, selectedOperator: null, type: 'text', value: null, operators: []}, {filter: null, selectedOperator: null, type: 'text', value: null, operators: []}, {filter: null, selectedOperator: null, type: 'text', value: null, operators: []}], | ||
|
||
}; | ||
} | ||
|
||
componentDidMount() { | ||
} | ||
|
||
handleFilterChange(event, index) { | ||
var selectedFilters = this.state.selectedFilters; | ||
var filterInfo = this.state.filters[event.target.value]; | ||
var operators = []; | ||
var type = 'text' | ||
if (filterInfo) { | ||
operators = filterInfo.operators; | ||
type = filterInfo.type; | ||
} | ||
selectedFilters[index].operators = operators; | ||
selectedFilters[index].type = type; | ||
this.setState(selectedFilters); | ||
} | ||
|
||
getFilters(filterCount) { | ||
return this.state.selectedFilters.map((filter, index) => { | ||
return <tr> | ||
<td style={{padding: '0 20px'}}> | ||
<select className="form-control" onChange={(event) => this.handleFilterChange(event, index)} value={filter.filter}> | ||
<option value="">{__('Select Filter')}</option> | ||
{Object.keys(this.state.filters).map((filterKey) => <option value={filterKey}>{this.state.filters[filterKey].label}</option>)} | ||
</select> | ||
</td> | ||
<td style={{padding: '0 5px'}}> | ||
<select className="filter-operators form-control" style={{width: '50px', textAlign: 'center'}} value={filter.selectedOperator}> | ||
{filter.operators.map((operator) => { | ||
return <option value={operator}>{operator}</option> | ||
})} | ||
</select> | ||
</td> | ||
<td style={{padding: '0 5px'}}> | ||
<input type={filter.type} className='form-control' /> | ||
</td> | ||
</tr> | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div style={{paddingTop: '10px', paddingLeft: '20px' }}> | ||
{__('Match')} | ||
<select className="condition-type-filter"> | ||
<option value="all">{__('All')}</option> | ||
<option value="any">{__('Any')}</option> | ||
</select> | ||
{__(' the conditions')} | ||
<div className="filters"> | ||
<table> | ||
<tbody> | ||
{this.getFilters(DEFAULT_FILTER_COUNT)} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div>) | ||
} | ||
} | ||
|
||
DataSelectorFilterComponent.propTypes = { | ||
}; | ||
|
||
|
||
const mapStateToProps = state => ({ | ||
}); | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(DataSelectorFilterComponent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react'; | ||
import {connect} from 'react-redux'; | ||
import {selectStartDate, selectEndDate, selectMeasurementCount} from "../redux/actions"; | ||
|
||
class DataSelectorGlobalFilterComponent extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
startDate: null, | ||
endDate: null, | ||
count: null | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
} | ||
|
||
render() { | ||
return ( | ||
<div style={{paddingTop: '10px', paddingLeft: '20px'}}> | ||
<div className="filters"> | ||
<h4>Periode</h4> | ||
<div className="row"> | ||
<div className="col-md-6">Fra <input type="date" onChange={(e) => { | ||
e.preventDefault(); | ||
this.props.selectStartDate(e.target.value) | ||
}} className='form-control' | ||
value={this.props.selectedStartDate}/></div> | ||
<div className="col-md-6">Til <input type="date" onChange={(e) => { | ||
e.preventDefault(); | ||
this.props.selectEndDate(e.target.value) | ||
}} className='form-control' | ||
value={this.props.selectedEndDate}/></div> | ||
</div> | ||
<div className="row"> | ||
<div className="col-md-6"> | ||
<h4>Antal målinger</h4> | ||
<input type="number" onChange={(e) => { | ||
e.preventDefault(); | ||
this.props.selectMeasurementCount(e.target.value) | ||
}} className='form-control' | ||
value={this.props.selectedMeasurementCount}/> | ||
</div> | ||
</div> | ||
</div> | ||
</div>) | ||
} | ||
} | ||
|
||
DataSelectorGlobalFilterComponent.propTypes = {}; | ||
|
||
const mapStateToProps = state => ({ | ||
selectedStartDate: state.global.selectedStartDate, | ||
selectedEndDate: state.global.selectedEndDate, | ||
selectedMeasurementCount: state.global.selectedMeasurementCount | ||
}); | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
selectStartDate: (date) => dispatch(selectStartDate(date)), | ||
selectEndDate: (date) => dispatch(selectEndDate(date)), | ||
selectMeasurementCount: (count) => dispatch(selectMeasurementCount(count)) | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(DataSelectorGlobalFilterComponent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.