adds object/function filter to local plugin#747
Conversation
|
@dahlbyk ^ here is the PR as promised. |
dahlbyk
left a comment
There was a problem hiding this comment.
This looks great! I do have one refactoring suggestion for performance's sake, but other than that...
Also, can you add a test to prove that filtering by multiple keys is an AND rather than OR?
It would also be neat to have a Storybook entry that shows how to use this new filter functionality, but we can fill that in later if you're not up to it now.
Thanks!
| value.toString().toLowerCase().indexOf(filterToLower) > -1; | ||
| })); | ||
| return data.filter(row => { | ||
| switch (typeof (filter)) { |
There was a problem hiding this comment.
For performance, can you flip this to process filter outside the data.filter(...)? This would work particularly well if you curry the functions above, e.g.
switch (typeof filter) {
case 'string':
return data.filter(textFilterRowSearch(columnProperties, filter));
case 'object':
return data.filter(objectFilterRowSearch(columnProperties, filter));
case 'function':
return data.filter(filter);
default:
return data;
}|
Just as an update – looking to make this PR (with changes) some point over the weekend as OSS and my work are hard to balance at the minute. Got it working locally on my machine :) for now anyway |
|
No worries, @benoj, we appreciate the contribution whenever you can finish it! |
|
Hi there, any updates for this feature? I realy need this functionality. |
|
Hi @arnimhanke, Sorry I have kinda dropped the ball on getting this PR complete as had so much on with work. There are a few options for you
Cheers, Ben |
|
Hi @benoj, thx for the fast answer! As I can see, there are two todos: Do I have to make a new PR or can i somehow use yours (I am new to Github)? Greetings from Germany! Arnim |
|
Great news. I will provide you push access when I get into work. Just on
train at the minute.
…On Wed, 11 Apr 2018, 07:12 arnimhanke, ***@***.***> wrote:
Hi @benoj <https://github.com/benoj>,
thx for the fast answer!
I can try to continue the work.
As I can see, there are two todos:
1. Performance optimization (Switch-Case)
2. New Test to prove that filtering by multiple keys is an AND rather than
OR
Did I miss something?
Do I have to make a new PR or can i somehow use yours (I am new to Github)?
Greetings from Germany!
Arnim
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#747 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACi6PJGAZ9stjwY-d1XtgTWAX_FsTeviks5tnZ7ogaJpZM4PvvMy>
.
|
| if (filterable === false) { | ||
| return false; | ||
| } | ||
| return substringSearch(row.get(key), filter) |
There was a problem hiding this comment.
I just noticed we're missing semicolons on most of the new code.
There was a problem hiding this comment.
Ah yeah - I tend to write mine without semi-colons. Might be worth adding an eslint or similar to ensure consistent styling
The last nice-to-have would be a story to demonstrate advanced filter usage.
You can either make a new PR from a branch on your own fork, or you can push to @benoj's |
|
@arnimhanke I have added you as a collaborator on my branch so you should be able to push |
|
Also looking forward to this feature, let me know if I can help. |
|
I am nearly done with the work. filter: { id: '1', name: 'luke' } result: Is this the correct beahvior? Greetings! |
I think AND is a more useful default. This is why we write tests. 😀 |
|
I think I am done with the changes, they are pushed to the master branch. |
dahlbyk
left a comment
There was a problem hiding this comment.
Thanks, @arnimhanke! I've added a few more tests for quirks I found, and refactored the object filter a bit, if you could take a look. I also rebased onto master to resolve the conflicts from #800 (cc @mbland). I seem to have screwed something up on that rebase, though, as my build just broke. 😞
I think we're getting close, though we still don't have any Storybook entries to demonstrate usage and prove that our tests are testing what we think they're testing. This sort of logic is easy to mess up, so I'd appreciate any additional eyes here.
|
Hi, |
|
should this be closed or merged? |
|
Git's acting weird, somehow I pushed upstream |
|
Apparently I did |
|
hmm, that is interesting given that you aren't a collaborator on the project. I would have expected you to get your push rejected... |
|
I have push bit on this repo, so I was able to push to your PR branch. 🙃 I was not able to push to your |
|
Would love to use this now - I have a big need for this. What is the best way for me to get this? I'm currently in Meteor 1.6.1.1 with griddle-react npm package. Thanks! |
|
Just upgrade the version to 1.13.0 |
|
@arnimhanke Thank You! |
|
The only examples I see in the stories are the filter by text and object. Is there an example of using setFilter with a function? I only ask because I need to filter for a date column >= myFilterDate along with a text match. Thanks!! |
|
There is no example for that. |
|
@arnimhanke No, that example is perfect. Thank you! |
Griddle major version
1.9.0
Changes proposed in this pull request
Extends the functionality of the LocalPlugin in order to allow more customised filtering (closes #746). With this PR you can now call
setFilter()with an object{ [key1]: [filter], [key2]:[filter] }orfunction(row){ }or an object with functions{[key]: function() {} }this allows for filtering across multiple fields with different fields.This allows for more customised behaviour. The object filter allows individual parts of the row to be filtered which can be used to build more complex filter UI. The default behaviour is AND across the object filter however you can also set the filter to be a function which is called with the entire row. This allows the user to do more logic in the filter e.g. XOR, OR etc.. on different row properties.
This is backwards compatible so any existing custom filters will work.
e.g.
Data:
{ id: 1, name: "Bob", age: 20} , { id: 2, name: "Alice", age: 49} , { id: 3, name: "Jimmy", age: 47}, { id: 4, name: "Bob", age: 21}setFilter("Bob") // returns { id: 1, name: "Bob", age: 20}, { id: 4, name: "Bob", age: 21}setFilter({ name: "bob") // returns { id: 1, name: "Bob", age: 20}, { id: 4, name: "Bob", age: 21}setFilter({ name: "bob", age: function(age) { return age < 21; } ) // returns { id: 1, name: "Bob", age: 20}setFilter({ name: "bob", age: function(age) { return age < 49; } ) // returns { id: 1, name: "Bob", age: 20},{ id: 3, name: "Jimmy", age: 47}, { id: 4, name: "Bob", age: 21}setFilter(function(row) { return row.get("name") === "Bob" && row.get("age") < 21 } ) // returns { id: 1, name: "Bob", age: 20}Why these changes are made
Needed this functionality for a project I am working on.
Are there tests?
Yes.