Skip to content

Commit

Permalink
fix: Dragging categories on axis (PT-187539044) (#1254)
Browse files Browse the repository at this point in the history
* fix: Dragging categories on axis (PT-187539044)

PT Story: https://www.pivotaltracker.com/story/show/187539044
  • Loading branch information
emcelroy authored May 13, 2024
1 parent e0ae927 commit 489cfa8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion v3/src/components/axis/hooks/use-sub-axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export const useSubAxis = ({
// Figure out the label of the category before which the dragged category should be placed
const moveToGreater = newCatIndex > dI.indexOfCategory,
catToMoveBefore = moveToGreater
? (newCatIndex === numCategories - 1 ? '' : dI.categories[newCatIndex])
? (newCatIndex === numCategories - 1 ? '' : dI.categories[newCatIndex + 1])
: dI.categories[newCatIndex]
dI.indexOfCategory = newCatIndex
dI.categorySet?.move(dI.catName, catToMoveBefore)
Expand Down
8 changes: 7 additions & 1 deletion v3/src/models/data/category-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,13 @@ export const CategorySet = types.model("CategorySet", {
move(value: string, beforeValue?: string) {
const fromIndex = self.index(value)
if (fromIndex == null) return
const toIndex = (beforeValue != null) ? self.index(beforeValue) ?? self.values.length - 1 : self.values.length - 1
let toIndex = (beforeValue != null) ? self.index(beforeValue) : undefined
if (toIndex === undefined) {
toIndex = self.values.length - 1
} else if (fromIndex < toIndex) {
toIndex--
}

const afterIndex = toIndex === 0 ? undefined : toIndex < fromIndex ? toIndex - 1 : toIndex
const afterValue = afterIndex != null ? self.values[afterIndex] : undefined
const move: ICategoryMove = {
Expand Down

0 comments on commit 489cfa8

Please sign in to comment.