Skip to content
This repository was archived by the owner on Jun 22, 2019. It is now read-only.

Commit dde1f0d

Browse files
committed
preliminary support for expressions
1 parent e611ede commit dde1f0d

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

src/data/filter.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
import R from 'ramda';
2+
import isNumeric from 'fast-isnumeric';
3+
4+
const FILTER_TERMS = {
5+
'<': (a, b) => a < b,
6+
'<=': (a, b) => a <= b,
7+
'>': (a, b) => a > b,
8+
'>=': (a, b) => a >= b
9+
}
210

311
export default function filterRows(filters, rows) {
412
return rows.filter(r => {
@@ -8,17 +16,31 @@ export default function filterRows(filters, rows) {
816
const colFilter = filters[columnKey];
917
const rowValue = r[columnKey];
1018

11-
/*
12-
* TODO:
13-
* - Options for lowercase
14-
* - Options for strict equality
15-
* - Numeric options: <5
16-
* - and / or: (<5, ==3) && NYC
17-
*/
18-
include = include && R.contains(
19-
R.toLower(colFilter.filterTerm+''),
20-
R.toLower(rowValue+'')
21-
);
19+
let matched = false;
20+
const strFilterTerm = colFilter.filterTerm+''
21+
R.keys(FILTER_TERMS).forEach(k => {
22+
const replacedFilterTerm = R.replace(k, '', strFilterTerm);
23+
if (!matched &&
24+
R.contains(k, strFilterTerm) &&
25+
isNumeric(replacedFilterTerm) &&
26+
isNumeric(rowValue) &&
27+
strFilterTerm !== k
28+
) {
29+
include = include && FILTER_TERMS[k](
30+
parseFloat(rowValue, 10),
31+
parseFloat(replacedFilterTerm, 10)
32+
);
33+
matched=true;
34+
}
35+
});
36+
if (!matched &&
37+
!R.contains(strFilterTerm, R.keys(FILTER_TERMS))
38+
) {
39+
include = include && R.contains(
40+
R.toLower(strFilterTerm),
41+
R.toLower(rowValue+'')
42+
);
43+
}
2244
});
2345

2446
return include;

0 commit comments

Comments
 (0)