Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(views/table): insert row before
Elian Doran8cced607ebd9
diff --git a/apps/client/src/widgets/view_widgets/table_view/context_menu.ts b/apps/client/src/widgets/view_widgets/table_view/context_menu.tsindex a9cf68be19..af463027b0 100644--- a/apps/client/src/widgets/view_widgets/table_view/context_menu.ts+++ b/apps/client/src/widgets/view_widgets/table_view/context_menu.ts@@ -22,7 +22,17 @@ export function showRowContextMenu(_e: UIEvent, row: RowComponent, parentNote: Ftitle: "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,+ }+ });}},{diff --git a/apps/server/src/routes/api/notes.ts b/apps/server/src/routes/api/notes.tsindex 40a955be9d..b53bb1a2a4 100644--- a/apps/server/src/routes/api/notes.ts+++ b/apps/server/src/routes/api/notes.ts@@ -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.");}diff --git a/apps/server/src/services/notes.ts b/apps/server/src/services/notes.tsindex 4c82c0e8c9..998da821b1 100644--- a/apps/server/src/services/notes.ts+++ b/apps/server/src/services/notes.ts@@ -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: strinentityChangesService.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}'`);