From 88eb72468ea6d69253fadb1a444c7b6309a38e1f Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Wed, 19 Oct 2016 13:01:06 +0200 Subject: [PATCH 1/2] Use AND instead of OR for tags search // Sort tags when displayed (#2719) --- js/src/ui/Tags/tags.js | 28 +++++++++++++++------------- js/src/views/Accounts/List/list.js | 16 ++++++++-------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/js/src/ui/Tags/tags.js b/js/src/ui/Tags/tags.js index 23501b24f..b52050649 100644 --- a/js/src/ui/Tags/tags.js +++ b/js/src/ui/Tags/tags.js @@ -38,19 +38,21 @@ export default class Tags extends Component { ? [ styles.tag, styles.tagClickable ] : [ styles.tag ]; - return tags.map((tag, idx) => { - const onClick = handleAddSearchToken - ? () => handleAddSearchToken(tag) - : null; + return tags + .sort() + .map((tag, idx) => { + const onClick = handleAddSearchToken + ? () => handleAddSearchToken(tag) + : null; - return ( -
- { tag } -
- ); - }); + return ( +
+ { tag } +
+ ); + }); } } diff --git a/js/src/views/Accounts/List/list.js b/js/src/views/Accounts/List/list.js index 81d83b60c..9cb2c547d 100644 --- a/js/src/views/Accounts/List/list.js +++ b/js/src/views/Accounts/List/list.js @@ -130,15 +130,15 @@ export default class List extends Component { .concat(tags, name) .map(v => v.toLowerCase()); - return values - .filter((value) => { - return searchValues - .map(searchValue => value.indexOf(searchValue) >= 0) - // `current && truth, true` => use tokens as AND - // `current || truth, false` => use tokens as OR - .reduce((current, truth) => current || truth, false); + return searchValues + .map(searchValue => { + return values + .filter(value => value.indexOf(searchValue) >= 0) + .length > 0; }) - .length > 0; + // `current && truth, true` => use tokens as AND + // `current || truth, false` => use tokens as OR + .reduce((current, truth) => current && truth, true); }); } } From 749e1e44b9ca977b8c989417c8156f848180e4ff Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Wed, 19 Oct 2016 13:15:01 +0200 Subject: [PATCH 2/2] Use Array.prototype.some instead of `filter` then `length` --- js/src/views/Accounts/List/list.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/js/src/views/Accounts/List/list.js b/js/src/views/Accounts/List/list.js index 9cb2c547d..bcdf7b072 100644 --- a/js/src/views/Accounts/List/list.js +++ b/js/src/views/Accounts/List/list.js @@ -133,8 +133,7 @@ export default class List extends Component { return searchValues .map(searchValue => { return values - .filter(value => value.indexOf(searchValue) >= 0) - .length > 0; + .some(value => value.indexOf(searchValue) >= 0); }) // `current && truth, true` => use tokens as AND // `current || truth, false` => use tokens as OR