From 76e625494c3c9344c322604d1f4aaf17d3944dbd Mon Sep 17 00:00:00 2001 From: Steve 'Cutter' Blades Date: Tue, 9 Nov 2021 18:46:20 -0600 Subject: [PATCH 1/2] fix: Correct scrollToTime functionailty (#2055) * fix: Correct scrollToTime functionailty Fix the calculateScroll method in the TimeGrid #2028 #1717 * chore: Remove localIp bits git push * Revert "chore: Remove localIp bits" This reverts commit 0eaae8cfe3ef719dacbf4e4232c4b86ec4c7408b. * chore: Remove localIp bits --- src/TimeGrid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TimeGrid.js b/src/TimeGrid.js index b4220106b..b250b83b5 100644 --- a/src/TimeGrid.js +++ b/src/TimeGrid.js @@ -315,7 +315,7 @@ export default class TimeGrid extends Component { const { min, max, scrollToTime, localizer } = props const diffMillis = scrollToTime - localizer.startOf(scrollToTime, 'day') - const totalMillis = localizer.diff(max, min) + const totalMillis = localizer.diff(min, max, 'milliseconds') this._scrollRatio = diffMillis / totalMillis } From 5408236540f889a343a0853f04dad148d73353c7 Mon Sep 17 00:00:00 2001 From: Ryan Baker Date: Wed, 10 Nov 2021 12:13:02 -0500 Subject: [PATCH 2/2] Fix: make the isSelected function work if the value is equal without being the exact reference --- src/utils/selection.js | 6 ++++-- test/utils/selection.test.js | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 test/utils/selection.test.js diff --git a/src/utils/selection.js b/src/utils/selection.js index 2756279c7..982b2cdf6 100644 --- a/src/utils/selection.js +++ b/src/utils/selection.js @@ -1,6 +1,8 @@ +import isEqual from 'lodash/isEqual' + export function isSelected(event, selected) { if (!event || selected == null) return false - return [].concat(selected).indexOf(event) !== -1 + return isEqual(event, selected) } export function slotWidth(rowBox, slots) { @@ -18,7 +20,7 @@ export function getSlotAtX(rowBox, x, rtl, slots) { } export function pointInBox(box, { x, y }) { - return y >= box.top && y <= box.bottom && (x >= box.left && x <= box.right) + return y >= box.top && y <= box.bottom && x >= box.left && x <= box.right } export function dateCellSelection(start, rowBox, box, slots, rtl) { diff --git a/test/utils/selection.test.js b/test/utils/selection.test.js new file mode 100644 index 000000000..293084776 --- /dev/null +++ b/test/utils/selection.test.js @@ -0,0 +1,38 @@ +import { isSelected } from '../../src/utils/selection' + +describe('isSelected', () => { + test('it returns true if it is the same object by reference', () => { + const value = { + x: { sample: 'value' }, + y: 1, + } + expect(isSelected(value, value)).toBeTruthy() + }) + + test('it returns true if it is the same object by equality', () => { + const value = { + x: { sample: 'value' }, + y: 1, + } + + const equalivalentValue = { + x: { sample: 'value' }, + y: 1, + } + expect(isSelected(value, equalivalentValue)).toBeTruthy() + }) + + test('it returns false if the object is not equal', () => { + const value = { + x: { sample: 'value' }, + y: 1, + } + + const nonEqualivalentValue = { + x: { sample: 'value' }, + y: 2, + } + + expect(isSelected(value, nonEqualivalentValue)).toBeFalsy() + }) +})