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

Fuzzysearch in names

parent 1ed7446d
......@@ -11,6 +11,7 @@ import Paper from '@material-ui/core/Paper';
import MenuItem from '@material-ui/core/MenuItem';
import Chip from '@material-ui/core/Chip';
import _ from 'underscore';
import fuzzysort from 'fuzzysort';
function renderInput(inputProps) {
......@@ -80,23 +81,12 @@ class DownshiftMultiple extends React.Component {
getSuggestions(value) {
const { options } = this.props;
const { selectedItems } = this.state;
const inputValue = deburr(value.trim()).toLowerCase();
const inputLength = inputValue.length;
let count = 0;
if (inputLength === 0) {
return []
let possible = _.difference(options, selectedItems);
const search = fuzzysort.go(value, possible, { limit: 5, key: 'label' });
if (search.length > 0){
return _.map(search, (item) => item.obj)
} else {
let out = _.difference(options, selectedItems).filter(suggestion => {
const keep =
count < 5 && suggestion.label.slice(0, inputLength).toLowerCase() === inputValue;
if (keep) {
count += 1;
}
return keep;
});
return out;
return possible.slice(0,4)
}
}
......
......@@ -3640,6 +3640,11 @@
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
"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": {
"version": "1.0.3",
"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