-
Notifications
You must be signed in to change notification settings - Fork 58
Issue #149 - It is possible to select more than maxSelectedItems when #158
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,50 @@ export const getMinMaxIndexes = (currentIndex, firstItemShiftSelected) => | |
| ? { minIndex: currentIndex, maxIndex: firstItemShiftSelected } | ||
| : { minIndex: firstItemShiftSelected, maxIndex: currentIndex }; | ||
|
|
||
| export const getAvailableIntervalForSelection = ( | ||
| interval, | ||
| outsideSelectedItems, | ||
| maxSelectedItems, | ||
| firstItemShiftSelected | ||
| ) => { | ||
| const { minIndex, maxIndex } = interval; | ||
| const shouldBeSelect = outsideSelectedItems + (maxIndex - minIndex); | ||
| return maxSelectedItems > 0 && maxSelectedItems <= shouldBeSelect | ||
|
||
| ? getFixedInterval( | ||
| interval, | ||
| outsideSelectedItems, | ||
| maxSelectedItems, | ||
| firstItemShiftSelected | ||
| ) | ||
| : interval; | ||
| }; | ||
|
|
||
| const getFixedInterval = ( | ||
| { minIndex, maxIndex }, | ||
| outsideSelectedItems, | ||
| maxSelectedItems, | ||
| firstItemShiftSelected | ||
| ) => ({ | ||
| minIndex: | ||
| maxIndex === firstItemShiftSelected | ||
| ? maxIndex - (maxSelectedItems - outsideSelectedItems - 1) | ||
| : minIndex, | ||
| maxIndex: | ||
| minIndex === firstItemShiftSelected | ||
| ? minIndex + (maxSelectedItems - outsideSelectedItems - 1) | ||
| : maxIndex | ||
| }); | ||
|
|
||
| export const getSelectedItemsOutsideInterval = ( | ||
| sourceItems, | ||
| selectedItems, | ||
| interval | ||
| ) => | ||
| selectedItems.filter(selectedItem => { | ||
| const index = sourceItems.findIndex(item => item.id === selectedItem.id); | ||
| return !isWithin(index, interval) || selectedItem.disabled; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do u need the disable check? can u give me scenario?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }); | ||
|
|
||
| export const isWithin = (index, { minIndex, maxIndex }) => | ||
| index >= minIndex && index <= maxIndex; | ||
|
|
||
|
|
||

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