Refactor sort order
parent
646aba5f89
commit
fcb872a4c8
|
@ -22,7 +22,7 @@ export default class Dygraph extends Component {
|
||||||
},
|
},
|
||||||
sortType: '',
|
sortType: '',
|
||||||
filterText: '',
|
filterText: '',
|
||||||
legendOrder: 'asc',
|
isAscending: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getTimeSeries = ::this.getTimeSeries
|
this.getTimeSeries = ::this.getTimeSeries
|
||||||
|
@ -45,17 +45,7 @@ export default class Dygraph extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSortLegend(sortType) {
|
handleSortLegend(sortType) {
|
||||||
if (this.state.legendOrder === 'asc') {
|
this.setState({sortType, isAscending: !this.state.isAscending})
|
||||||
return this.setState({
|
|
||||||
sortType,
|
|
||||||
legendOrder: 'desc',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
sortType,
|
|
||||||
legendOrder: 'asc',
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleLegendInputChange(e) {
|
handleLegendInputChange(e) {
|
||||||
|
@ -280,7 +270,7 @@ export default class Dygraph extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {legend, filterText, legendOrder, sortType, isHidden} = this.state
|
const {legend, filterText, isAscending, sortType, isHidden} = this.state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="dygraph-child">
|
<div className="dygraph-child">
|
||||||
|
@ -289,7 +279,7 @@ export default class Dygraph extends Component {
|
||||||
onSort={this.handleSortLegend}
|
onSort={this.handleSortLegend}
|
||||||
onInputChange={this.handleLegendInputChange}
|
onInputChange={this.handleLegendInputChange}
|
||||||
filterText={filterText}
|
filterText={filterText}
|
||||||
sortOrder={legendOrder}
|
isAscending={isAscending}
|
||||||
sortType={sortType}
|
sortType={sortType}
|
||||||
legendRef={el => this.legendRef = el}
|
legendRef={el => this.legendRef = el}
|
||||||
isHidden={isHidden}
|
isHidden={isHidden}
|
||||||
|
|
|
@ -8,14 +8,14 @@ const DygraphLegend = ({
|
||||||
legendRef,
|
legendRef,
|
||||||
filterText,
|
filterText,
|
||||||
onInputChange,
|
onInputChange,
|
||||||
sortOrder,
|
isAscending,
|
||||||
sortType,
|
sortType,
|
||||||
}) => {
|
}) => {
|
||||||
const sorted = _.sortBy(
|
const sorted = _.sortBy(
|
||||||
series,
|
series,
|
||||||
({y, label}) => (sortType === 'numeric' ? y : label)
|
({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 filtered = ordered.filter(s => s.label.match(filterText))
|
||||||
const hidden = isHidden ? 'hidden' : ''
|
const hidden = isHidden ? 'hidden' : ''
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ DygraphLegend.propTypes = {
|
||||||
onSort: func.isRequired,
|
onSort: func.isRequired,
|
||||||
onInputChange: func.isRequired,
|
onInputChange: func.isRequired,
|
||||||
filterText: string.isRequired,
|
filterText: string.isRequired,
|
||||||
sortOrder: string.isRequired,
|
isAscending: bool.isRequired,
|
||||||
sortType: string.isRequired,
|
sortType: string.isRequired,
|
||||||
isHidden: bool.isRequired,
|
isHidden: bool.isRequired,
|
||||||
legendRef: func.isRequired,
|
legendRef: func.isRequired,
|
||||||
|
|
Loading…
Reference in New Issue