-
Notifications
You must be signed in to change notification settings - Fork 53
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?
Changes from 2 commits
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 |
---|---|---|
|
@@ -32,11 +32,55 @@ export const getSelectedByAllItems = (itemsToSelect, selectedItems, items) => { | |
return [...destinationItems, ...sourceItems]; | ||
}; | ||
|
||
export const getMinMaxIndexes = (currentIndex, firstItemShiftSelected) => | ||
export const getMinMaxIndexes = ( | ||
currentIndex, | ||
firstItemShiftSelected, | ||
items, | ||
selectedItems, | ||
maxSelected | ||
) => { | ||
const outsideSelected = getSelectedItemsOutsideInterval( | ||
currentIndex, | ||
firstItemShiftSelected, | ||
items, | ||
selectedItems | ||
).length; | ||
const shouldBeSelect = | ||
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. sumItemsToSelect or sumItemsShouldBeSelect ? 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. Done |
||
outsideSelected + Math.abs(firstItemShiftSelected - currentIndex) + 1; | ||
|
||
if (maxSelected && maxSelected <= shouldBeSelect) { | ||
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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
const availableToSelect = maxSelected - outsideSelected - 1; | ||
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. sumItemsAllowToSelect ? 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. Done |
||
return firstItemShiftSelected > currentIndex | ||
? { | ||
minIndex: firstItemShiftSelected - availableToSelect, | ||
maxIndex: firstItemShiftSelected | ||
} | ||
: { | ||
minIndex: firstItemShiftSelected, | ||
maxIndex: firstItemShiftSelected + availableToSelect | ||
}; | ||
} | ||
return getInputInterval(currentIndex, firstItemShiftSelected); | ||
}; | ||
|
||
const getInputInterval = (currentIndex, firstItemShiftSelected) => | ||
firstItemShiftSelected > currentIndex | ||
? { minIndex: currentIndex, maxIndex: firstItemShiftSelected } | ||
: { minIndex: firstItemShiftSelected, maxIndex: currentIndex }; | ||
|
||
export const getSelectedItemsOutsideInterval = ( | ||
currentIndex, | ||
firstItemShiftSelected, | ||
sourceItems, | ||
selectedItems | ||
) => { | ||
const interval = getInputInterval(currentIndex, firstItemShiftSelected); | ||
return 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 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? 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.
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