Refactor sort order

pull/1679/head
Andrew Watkins 2017-06-29 11:34:25 -07:00
parent 646aba5f89
commit fcb872a4c8
2 changed files with 7 additions and 17 deletions

View File

@ -22,7 +22,7 @@ export default class Dygraph extends Component {
},
sortType: '',
filterText: '',
legendOrder: 'asc',
isAscending: true,
}
this.getTimeSeries = ::this.getTimeSeries
@ -45,17 +45,7 @@ export default class Dygraph extends Component {
}
handleSortLegend(sortType) {
if (this.state.legendOrder === 'asc') {
return this.setState({
sortType,
legendOrder: 'desc',
})
}
this.setState({
sortType,
legendOrder: 'asc',
})
this.setState({sortType, isAscending: !this.state.isAscending})
}
handleLegendInputChange(e) {
@ -280,7 +270,7 @@ export default class Dygraph extends Component {
}
render() {
const {legend, filterText, legendOrder, sortType, isHidden} = this.state
const {legend, filterText, isAscending, sortType, isHidden} = this.state
return (
<div className="dygraph-child">
@ -289,7 +279,7 @@ export default class Dygraph extends Component {
onSort={this.handleSortLegend}
onInputChange={this.handleLegendInputChange}
filterText={filterText}
sortOrder={legendOrder}
isAscending={isAscending}
sortType={sortType}
legendRef={el => this.legendRef = el}
isHidden={isHidden}

View File

@ -8,14 +8,14 @@ const DygraphLegend = ({
legendRef,
filterText,
onInputChange,
sortOrder,
isAscending,
sortType,
}) => {
const sorted = _.sortBy(
series,
({y, label}) => (sortType === 'numeric' ? y : label)
)
const ordered = sortOrder === 'desc' ? sorted.reverse() : sorted
const ordered = isAscending ? sorted : sorted.reverse()
const filtered = ordered.filter(s => s.label.match(filterText))
const hidden = isHidden ? 'hidden' : ''
@ -87,7 +87,7 @@ DygraphLegend.propTypes = {
onSort: func.isRequired,
onInputChange: func.isRequired,
filterText: string.isRequired,
sortOrder: string.isRequired,
isAscending: bool.isRequired,
sortType: string.isRequired,
isHidden: bool.isRequired,
legendRef: func.isRequired,