Refactor sort order
parent
5c786b4b80
commit
b2387d3ab7
|
@ -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}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue