chore: added null safety while searching

This commit is contained in:
Anoop M D 2022-10-11 01:35:46 +05:30
parent 77568da03c
commit 62e9f4d5f0

View File

@ -2,18 +2,18 @@ import { flattenItems, isItemARequest } from "./index";
import filter from 'lodash/filter';
import find from 'lodash/find';
export const doesRequestMatchSearchText = (request, searchText) => {
export const doesRequestMatchSearchText = (request, searchText = '') => {
return request.name.toLowerCase().includes(searchText.toLowerCase());
};
export const doesFolderHaveItemsMatchSearchText = (item, searchText) => {
export const doesFolderHaveItemsMatchSearchText = (item, searchText = '') => {
let flattenedItems = flattenItems(item.items);
let requestItems = filter(flattenedItems, (item) => isItemARequest(item));
return find(requestItems, (request) => doesRequestMatchSearchText(request, searchText));
};
export const doesCollectionHaveItemsMatchingSearchText = (collection, searchText) => {
export const doesCollectionHaveItemsMatchingSearchText = (collection, searchText = '') => {
let flattenedItems = flattenItems(collection.items);
let requestItems = filter(flattenedItems, (item) => isItemARequest(item));