Skip to content

Build your personal knowledge base with Trilium Notes

feat(views/table): insert child note

Elian Doranc13969217c29
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 637b1fb493..4cb8bbefe2 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1952,7 +1952,8 @@
"hide-column": "Hide column \"{{title}}\"",
"show-hide-columns": "Show/hide columns",
"row-insert-above": "Insert row above",
- "row-insert-below": "Insert row below"
+ "row-insert-below": "Insert row below",
+ "row-insert-child": "Insert child note"
},
"book_properties_config": {
"hide-weekends": "Hide weekends",
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.ts
index 55fb75002f..4eff60a046 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
@@ -5,6 +5,7 @@ import branches from "../../../services/branches.js";
import { t } from "../../../services/i18n.js";
import link_context_menu from "../../../menus/link_context_menu.js";
import type FNote from "../../../entities/fnote.js";
+import froca from "../../../services/froca.js";
export function setupContextMenu(tabulator: Tabulator, parentNote: FNote) {
tabulator.on("rowContext", (e, row) => showRowContextMenu(e, row, parentNote));
@@ -118,6 +119,23 @@ export function showRowContextMenu(_e: UIEvent, row: RowComponent, parentNote: F
});
}
},
+ {
+ title: t("table_view.row-insert-child"),
+ uiIcon: "bx bx-empty",
+ handler: async () => {
+ const branchId = row.getData().branchId;
+ const note = await froca.getBranch(branchId)?.getNote();
+ const bestNotePath = note?.getBestNotePath(parentNote.noteId);
+ const target = e.target;
+ if (!target) {
+ return;
+ }
+ const component = $(target).closest(".component").prop("component");
+ component.triggerCommand("addNewRow", {
+ parentNotePath: bestNotePath?.join("/")
+ });
+ }
+ },
{
title: t("table_view.row-insert-below"),
uiIcon: "bx bx-empty",
diff --git a/apps/client/src/widgets/view_widgets/table_view/index.ts b/apps/client/src/widgets/view_widgets/table_view/index.ts
index fd6da37814..9dc3617227 100644
--- a/apps/client/src/widgets/view_widgets/table_view/index.ts
+++ b/apps/client/src/widgets/view_widgets/table_view/index.ts
@@ -229,8 +229,8 @@ export default class TableView extends ViewMode<StateInfo> {
console.log("Save attributes", this.newAttribute);
}
- addNewRowCommand({ customOpts }: { customOpts: CreateNoteOpts }) {
- const parentNotePath = this.args.parentNotePath;
+ addNewRowCommand({ customOpts, parentNotePath: customNotePath }: { customOpts: CreateNoteOpts, parentNotePath?: string }) {
+ const parentNotePath = customNotePath ?? this.args.parentNotePath;
if (parentNotePath) {
const opts: CreateNoteOpts = {
activate: false,