Merge pull request #83 from acelaya/feature/insensitive-ordering

Ensured bar graphs are sorted case insensitive
This commit is contained in:
Alejandro Celaya 2018-12-19 11:15:30 +01:00 committed by GitHub
commit 12cddac27a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -26,7 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
#### Fixed #### Fixed
* *Nothing* * [#77](https://github.com/shlinkio/shlink-web-client/issues/77) Sortable graphs ordering is now case insensitive.
## 1.2.0 - 2018-11-01 ## 1.2.0 - 2018-11-01

View file

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { fromPairs, head, keys, prop, reverse, sortBy, toPairs } from 'ramda'; import { fromPairs, head, identity, keys, pipe, prop, reverse, sortBy, toLower, toPairs, type } from 'ramda';
import SortingDropdown from '../utils/SortingDropdown'; import SortingDropdown from '../utils/SortingDropdown';
import GraphCard from './GraphCard'; import GraphCard from './GraphCard';
@ -23,7 +23,14 @@ export default class SortableBarGraph extends React.Component {
return stats; return stats;
} }
const sortedPairs = sortBy(prop(this.state.orderField === head(keys(sortingItems)) ? 0 : 1), toPairs(stats)); const toLowerIfString = (value) => type(value) === 'String' ? toLower(value) : identity(value);
const sortedPairs = sortBy(
pipe(
prop(this.state.orderField === head(keys(sortingItems)) ? 0 : 1),
toLowerIfString
),
toPairs(stats)
);
return fromPairs(this.state.orderDir === 'ASC' ? sortedPairs : reverse(sortedPairs)); return fromPairs(this.state.orderDir === 'ASC' ? sortedPairs : reverse(sortedPairs));
}; };