-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add selectionMatchFunction option #824
Conversation
@mixonic what's blocking this to be merged? missing tests? |
Never mind I’m not sure what this PR actually does |
f19e0aa
to
edd5087
Compare
edd5087
to
6a3ffb7
Compare
6a3ffb7
to
e516eb8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 A couple of thoughts:
- can we add a test for this change?
- should we consider updating the docs to reflect this new API?
e516eb8
to
efeffb8
Compare
/** | ||
A function that will override how selection is compared to row value. | ||
|
||
@argument selectionMatchFunction | ||
@type function? | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@twokul I added a test. For docs, see above how the JSDoc comment gets displayed on the docs website. I'm not sure that this function really warrants a full section in the examples. |
efeffb8
to
7696f96
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Provisional ✅ (pending tests)
isGroupSelected: computed( | ||
'_tree.{selection.[],selectionMatchFunction}', | ||
'_parentMeta.isSelected', | ||
function() { | ||
let rowValue = get(this, '_rowValue'); | ||
let selection = get(this, '_tree.selection'); | ||
let selectionMatchFunction = get(this, '_tree.selectionMatchFunction'); | ||
|
||
isGroupSelected: computed('_tree.selection.[]', '_parentMeta.isSelected', function() { | ||
let rowValue = get(this, '_rowValue'); | ||
let selection = get(this, '_tree.selection'); | ||
if (!selection || !isArray(selection)) { | ||
return false; | ||
} | ||
|
||
if (!selection || !isArray(selection)) { | ||
return false; | ||
let isSelectionMatch = selectionMatchFunction | ||
? selection.filter(item => selectionMatchFunction(item, rowValue)).length > 0 | ||
: selection.includes(rowValue); | ||
return isSelectionMatch || get(this, '_parentMeta.isGroupSelected'); | ||
} | ||
|
||
return selection.includes(rowValue) || get(this, '_parentMeta.isGroupSelected'); | ||
}), | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@twokul This set of changes is new and could probably use a final 👀
Adding the tests made me realize that the isGroupSelected
CP also needed to use the selectionMatchFunction
when matching selection
against rows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional tests have been added to ensure that selectionMatchFunction
works in both single
and multiple
modes
@kpfefferle did you get to follow up on the tests you wanted to add here? |
@mixonic I have not yet done that and it fell off my radar. I'll try to carve out some time to get back to that this week. |
78f58cd
to
c1f8391
Compare
c1f8391
to
4b29a50
Compare
4b29a50
to
37cdfcc
Compare
@kpfefferle Thanks! Merging this. |
an example would be nice for this func |
This PR adds an optional
selectionMatchFunction
to theember-tbody
component. When set, this function will be used in place of===
when checking to see if a row should be marked as selected.Fixes #823 (at least offers a workaround)