From c13969217c2945139c21629efdc0269c80258e44 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 14 Jul 2025 13:37:18 +0300 Subject: [PATCH] feat(views/table): insert child note --- .../src/translations/en/translation.json | 3 ++- .../view_widgets/table_view/context_menu.ts | 18 ++++++++++++++++++ .../widgets/view_widgets/table_view/index.ts | 4 ++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index 637b1fb49..4cb8bbefe 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 55fb75002..4eff60a04 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 fd6da3781..9dc361722 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 { 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,