Fix off-by-one error when placing category into 2nd-to-last place (#3241)

* Fix off-by-one error when placing category into 2nd-to-last place

Signed-off-by: JL102 <jordanlees@mailbox.org>

* Add changelog file

Signed-off-by: JL102 <jordanlees@mailbox.org>

---------

Signed-off-by: JL102 <jordanlees@mailbox.org>
This commit is contained in:
Jordan Lees
2024-08-12 01:49:17 -04:00
committed by GitHub
parent d1362c3d74
commit 119d0b339d
3 changed files with 15 additions and 3 deletions

View File

@@ -9,7 +9,12 @@ import { BudgetCategories } from './BudgetCategories';
import { BudgetSummaries } from './BudgetSummaries';
import { BudgetTotals } from './BudgetTotals';
import { MonthsProvider } from './MonthsContext';
import { findSortDown, findSortUp, getScrollbarWidth } from './util';
import {
findSortDown,
findSortUp,
getScrollbarWidth,
separateGroups,
} from './util';
export function BudgetTable(props) {
const {
@@ -86,9 +91,10 @@ export function BudgetTable(props) {
};
const _onReorderGroup = (id, dropPos, targetId) => {
const [expenseGroups] = separateGroups(categoryGroups); // exclude Income group from sortable groups to fix off-by-one error
onReorderGroup({
id,
...findSortDown(categoryGroups, dropPos, targetId),
...findSortDown(expenseGroups, dropPos, targetId),
});
};

View File

@@ -103,7 +103,7 @@ export function findSortDown(
}
const newIdx = idx + 1;
if (newIdx < arr.length - 1) {
if (newIdx < arr.length) {
return { targetId: arr[newIdx].id };
} else {
// Move to the end

View File

@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [JL102]
---
Fixed category appearing in last slot when you drag it to the second-to-last slot