diff --git a/ui/src/shared/components/Dygraph.js b/ui/src/shared/components/Dygraph.js
index 43d26c50c..8b1c52797 100644
--- a/ui/src/shared/components/Dygraph.js
+++ b/ui/src/shared/components/Dygraph.js
@@ -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 (
@@ -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}
diff --git a/ui/src/shared/components/DygraphLegend.js b/ui/src/shared/components/DygraphLegend.js
index c48f249d2..92d291459 100644
--- a/ui/src/shared/components/DygraphLegend.js
+++ b/ui/src/shared/components/DygraphLegend.js
@@ -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,