feat(views/table): insert row before

This commit is contained in:
Elian Doran 2025-07-13 14:10:37 +03:00
parent 5dd5af90c2
commit 8cced607eb
No known key found for this signature in database
3 changed files with 26 additions and 3 deletions

View file

@ -22,7 +22,17 @@ export function showRowContextMenu(_e: UIEvent, row: RowComponent, parentNote: F
title: "Insert row above",
uiIcon: "bx bx-list-plus",
handler: () => {
const target = e.target;
if (!target) {
return;
}
const component = $(target).closest(".component").prop("component");
component.triggerCommand("addNewRow", {
customOpts: {
target: "before",
targetBranchId: rowData.branchId,
}
});
}
},
{

View file

@ -110,7 +110,7 @@ function createNote(req: Request) {
const { target, targetBranchId } = req.query;
if (target !== "into" && target !== "after") {
if (target !== "into" && target !== "after" && target !== "before") {
throw new ValidationError("Invalid target type.");
}

View file

@ -254,7 +254,7 @@ function createNewNote(params: NoteParams): {
});
}
function createNewNoteWithTarget(target: "into" | "after", targetBranchId: string | undefined, params: NoteParams) {
function createNewNoteWithTarget(target: "into" | "after" | "before", targetBranchId: string | undefined, params: NoteParams) {
if (!params.type) {
const parentNote = becca.notes[params.parentNoteId];
@ -277,6 +277,19 @@ function createNewNoteWithTarget(target: "into" | "after", targetBranchId: strin
entityChangesService.putNoteReorderingEntityChange(params.parentNoteId);
return retObject;
} else if (target === "before" && targetBranchId) {
const beforeBranch = becca.branches[targetBranchId];
// not updating utcDateModified to avoid having to sync whole rows
sql.execute("UPDATE branches SET notePosition = notePosition - 10 WHERE parentNoteId = ? AND notePosition < ? AND isDeleted = 0", [params.parentNoteId, beforeBranch.notePosition]);
params.notePosition = beforeBranch.notePosition - 10;
const retObject = createNewNote(params);
entityChangesService.putNoteReorderingEntityChange(params.parentNoteId);
return retObject;
} else {
throw new Error(`Unknown target '${target}'`);