-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make positions possibly negatives (#5690)
Closes #5427
- Loading branch information
Showing
6 changed files
with
66 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...dules/object-record/record-board/utils/__tests__/get-dragged-record-position.util.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getDraggedRecordPosition } from '../get-dragged-record-position.util'; | ||
|
||
describe('getDraggedRecordPosition', () => { | ||
it('when both records defined and positive, should return the average of the two positions', () => { | ||
expect(getDraggedRecordPosition(1, 3)).toBe(2); | ||
}); | ||
|
||
it('when both records defined and negative, should return the average of the two positions', () => { | ||
expect(getDraggedRecordPosition(-3, -1)).toBe(-2); | ||
}); | ||
|
||
it('when both records defined and one negative, should return the average of the two positions', () => { | ||
expect(getDraggedRecordPosition(-1, 3)).toBe(1); | ||
}); | ||
|
||
it('when only record after, should return the position - 1', () => { | ||
expect(getDraggedRecordPosition(undefined, 3)).toBe(2); | ||
}); | ||
|
||
it('when only record before, should return the position + 1', () => { | ||
expect(getDraggedRecordPosition(1, undefined)).toBe(2); | ||
}); | ||
|
||
it('when both records undefined, should return 1', () => { | ||
expect(getDraggedRecordPosition(undefined, undefined)).toBe(1); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
...ty-front/src/modules/object-record/record-board/utils/get-dragged-record-position.util.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { isDefined } from '~/utils/isDefined'; | ||
|
||
export const getDraggedRecordPosition = ( | ||
recordBeforePosition?: number, | ||
recordAfterPosition?: number, | ||
): number => { | ||
if (isDefined(recordAfterPosition) && isDefined(recordBeforePosition)) { | ||
return (recordBeforePosition + recordAfterPosition) / 2; | ||
} else if (isDefined(recordAfterPosition)) { | ||
return recordAfterPosition - 1; | ||
} else if (isDefined(recordBeforePosition)) { | ||
return recordBeforePosition + 1; | ||
} else { | ||
return 1; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters