-
Notifications
You must be signed in to change notification settings - Fork 54
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
Issue #149 - It is possible to select more than maxSelectedItems when #158
base: master
Are you sure you want to change the base?
Conversation
4589986
to
9a4c39f
Compare
@liorheber please take a look and what do you think? |
Sorry for the delay here. |
@talyak I've been having a hard time getting to this PR. |
@liorheber, @yegor-babiy - I will review it today. |
@yegor-babiy - why not to change the following function like this: export const getMinMaxIndexes = ( |
@talyak |
src/components/multi_select_state.js
Outdated
} = this.state; | ||
|
||
const initialInterval = getMinMaxIndexes(index, firstItemShiftSelected); | ||
const outsideIntervalSelectedItems = getSelectedItemsOutsideInterval( |
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.
all this logic should happen just when the Shift pressed, right?
also, I prefer to extract all the logic to the utils.
the MinMax function will give the interval and will do all the necessary calculation in it.
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.
Updated, I believe that it looks better, thanks for your feedback and please review again
) => | ||
selectedItems.filter(selectedItem => { | ||
const index = sourceItems.findIndex(item => item.id === selectedItem.id); | ||
return !isWithin(index, interval) || selectedItem.disabled; |
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.
why do u need the disable check? can u give me scenario?
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.
) => { | ||
const { minIndex, maxIndex } = interval; | ||
const shouldBeSelect = outsideSelectedItems + (maxIndex - minIndex); | ||
return maxSelectedItems > 0 && maxSelectedItems <= shouldBeSelect |
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.
why you need to check > 0 ? is it not enough to do it like this:
maxSelectedItems && maxSelectedItems <= shouldBeSelect
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.
Updated
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.
some small comments, sorry.
this logic is complicated and I want to keep it as clear as possible.
const shouldBeSelect = | ||
outsideSelected + Math.abs(firstItemShiftSelected - currentIndex) + 1; | ||
|
||
if (maxSelected && maxSelected <= shouldBeSelect) { |
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.
can u extract this logic to function with clear name, something like: getIndexesWhenShiftSelected ?
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.
Updated
selectedItems, | ||
maxSelected | ||
) => { | ||
const outsideSelected = getSelectedItemsOutsideInterval( |
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.
numberOfItemsOutsideSelected ?
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.
Done
items, | ||
selectedItems | ||
).length; | ||
const shouldBeSelect = |
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.
sumItemsToSelect or sumItemsShouldBeSelect ?
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.
Done
outsideSelected + Math.abs(firstItemShiftSelected - currentIndex) + 1; | ||
|
||
if (maxSelected && maxSelected <= shouldBeSelect) { | ||
const availableToSelect = maxSelected - outsideSelected - 1; |
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.
sumItemsAllowToSelect ?
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.
Done
@talyak can be merged? |
@liorheber @talyak guess it can be merged, |
#Fixes #149
Proposed Changes