-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from codeforsanjose/issues-137-admin-search-f…
…ield Filter Search For Admin added
- Loading branch information
Showing
5 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Fuse from 'fuse.js'; | ||
/** | ||
* search through an arary of objects for a specifed search string | ||
* objects-array of objects to be filterd | ||
* propertyPath - property to be filtered on, can include sub objects | ||
* searchText - text to search for | ||
* minLength - min length of the match | ||
* @returns the filtered responses from the array | ||
*/ | ||
export const searchArrayObjects = ( | ||
objects, | ||
propertyPath, | ||
searchText, | ||
minLength = 3 | ||
) => { | ||
if (!searchText) { | ||
return objects; | ||
} | ||
const fuse = new Fuse(objects, { | ||
keys: [propertyPath], | ||
minMatchCharLength: minLength, | ||
}); | ||
const filterResponse = fuse.search(searchText).map((result) => result.item); | ||
return filterResponse; | ||
}; |