Commit 9e91cba3 authored by Florent Chehab's avatar Florent Chehab
Browse files

Fuzzysearch in names

parent 1ed7446d
...@@ -11,6 +11,7 @@ import Paper from '@material-ui/core/Paper'; ...@@ -11,6 +11,7 @@ import Paper from '@material-ui/core/Paper';
import MenuItem from '@material-ui/core/MenuItem'; import MenuItem from '@material-ui/core/MenuItem';
import Chip from '@material-ui/core/Chip'; import Chip from '@material-ui/core/Chip';
import _ from 'underscore'; import _ from 'underscore';
import fuzzysort from 'fuzzysort';
function renderInput(inputProps) { function renderInput(inputProps) {
...@@ -80,23 +81,12 @@ class DownshiftMultiple extends React.Component { ...@@ -80,23 +81,12 @@ class DownshiftMultiple extends React.Component {
getSuggestions(value) { getSuggestions(value) {
const { options } = this.props; const { options } = this.props;
const { selectedItems } = this.state; const { selectedItems } = this.state;
const inputValue = deburr(value.trim()).toLowerCase(); let possible = _.difference(options, selectedItems);
const inputLength = inputValue.length; const search = fuzzysort.go(value, possible, { limit: 5, key: 'label' });
let count = 0; if (search.length > 0){
if (inputLength === 0) { return _.map(search, (item) => item.obj)
return []
} else { } else {
let out = _.difference(options, selectedItems).filter(suggestion => { return possible.slice(0,4)
const keep =
count < 5 && suggestion.label.slice(0, inputLength).toLowerCase() === inputValue;
if (keep) {
count += 1;
}
return keep;
});
return out;
} }
} }
......
...@@ -3640,6 +3640,11 @@ ...@@ -3640,6 +3640,11 @@
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
"dev": true "dev": true
}, },
"fuzzysort": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/fuzzysort/-/fuzzysort-1.1.4.tgz",
"integrity": "sha512-JzK/lHjVZ6joAg3OnCjylwYXYVjRiwTY6Yb25LvfpJHK8bjisfnZJ5bY8aVWwTwCXgxPNgLAtmHL+Hs5q1ddLQ=="
},
"get-caller-file": { "get-caller-file": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment