All files / actions index.js

100% Statements 14/14
100% Branches 8/8
100% Functions 6/6
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30      5x 7x 7x           2x 3x 3x         7x 7x   7x 1x 6x 3x   3x      
import {isEmpty, get, escapeRegExp} from 'lodash';
 
export function filterByLabel(data, filterableProperty, filterValue) {
    return data.filter(row => {
            const value = get(row, filterableProperty);
            return Boolean(value.match(RegExp(escapeRegExp(filterValue), 'i')));
        }
    )
}
 
export function filterByMultiSelectLabel(data, filterableProperty, filterValues) {
    return data.filter(row => {
        const value = get(row, filterableProperty);
        return filterValues.find(filterValue => filterValue.value == value);
    });
}
 
export function sorting(a, b, order, propertyName) {
    const firstValue = get(a, propertyName);
    const secondValue = get(b, propertyName);
 
    if (firstValue == secondValue) {
        return 0;
    } else if (firstValue < secondValue) {
        return order == 'ASC' ? -1 : 1;
    } else {
        return order == 'ASC' ? 1 : -1;
    }
}