diff --git a/src/app/shared/table-helpers.ts b/src/app/shared/table-helpers.ts index c0bc41fcc2..d95f245263 100644 --- a/src/app/shared/table-helpers.ts +++ b/src/app/shared/table-helpers.ts @@ -103,15 +103,31 @@ export const filterFieldExists = (filterFields: string[], trueIfExists: boolean) }; }; -const matchAllItems = (filterItems: string[], propItems: string[]) => { - return filterItems.reduce((isMatch, filter) => isMatch && propItems.indexOf(filter) > -1, true); -}; - -export const filterArrayField = (filterField: string, filterItems: string[]) => { - return (data: any, filter: string) => { - return matchAllItems(filterItems, getProperty(data, filterField) || []); - }; -}; +const normalizeToArray = (value: any): any[] => { + if (value === undefined || value === null) { + return []; + } + + return Array.isArray(value) ? value : [ value ]; +}; + +const matchAllItems = (filterItems: string[], propItems: any) => { + const normalizedFilterItems = normalizeToArray(filterItems); + + if (normalizedFilterItems.length === 0) { + return true; + } + + const normalizedPropItems = normalizeToArray(propItems); + + return normalizedFilterItems.reduce((isMatch, filter) => isMatch && normalizedPropItems.indexOf(filter) > -1, true); +}; + +export const filterArrayField = (filterField: string, filterItems: string[]) => { + return (data: any, filter: string) => { + return matchAllItems(filterItems, getProperty(data, filterField)); + }; +}; export const filterTags = (filterControl: FormControl) => { return (data: any, filter: string) => {