Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maintain order of original data if no search term is provided #39

Closed
hozefaj opened this issue Mar 14, 2018 · 2 comments
Closed

maintain order of original data if no search term is provided #39

hozefaj opened this issue Mar 14, 2018 · 2 comments

Comments

@hozefaj
Copy link
Contributor

hozefaj commented Mar 14, 2018

  • match-sorter version: 2.2.0
  • node version: v8.9.3
  • npm (or yarn) version: npm v5.7.1

Relevant code or config

segments = matchSorter(this.props.segments.list, searchTerm, {
  keys: ['id', 'code', 'description'],
});

What you did:

  1. perform a search with proper value of searchTerm
  2. empty searchTerm out. matchSorter modifies the order of the response, does not maintain the original order when no search term is entered.

Suggested solution:
I guess checking for value before the actual search and sorting is performed. So if searchTerm is empty just return the input as is.

@hozefaj hozefaj changed the title return item if no search term is provided maintain order of original data if no search term is provided Mar 14, 2018
@kentcdodds
Copy link
Owner

So you're suggesting this change?

 function matchSorter(items, value, options = {}) {
+   if (!value) {
+     return  items
+   }
   const {keys, threshold = rankings.MATCHES} = options
   const matchedItems = items.reduce(reduceItemsToRanked, [])
   return matchedItems.sort(sortRankedItems).map(({item}) => item)

I think I'm good with that. Want to make a PR?

@hozefaj
Copy link
Contributor Author

hozefaj commented Mar 14, 2018

Yeah sure. Will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants