From c58414bbc13ba8657a4c57776cba7e5712bd25dd Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 29 Sep 2025 21:11:40 +0300 Subject: [PATCH] chore(type_widgets): relation map rename title --- .../type_widgets/relation_map/RelationMap.tsx | 22 ++++++++++-- .../widgets/type_widgets_old/relation_map.ts | 34 ------------------- 2 files changed, 20 insertions(+), 36 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx index 753cfa5da..705e5bee9 100644 --- a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx +++ b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx @@ -1,7 +1,7 @@ import { useCallback, useEffect, useRef, useState } from "preact/hooks"; import { TypeWidgetProps } from "../type_widget"; import { Defaults, jsPlumb, jsPlumbInstance, OverlaySpec } from "jsplumb"; -import { useEditorSpacedUpdate, useNoteBlob, useTriliumEvent, useTriliumEvents } from "../../react/hooks"; +import { useEditorSpacedUpdate, useNoteBlob, useNoteProperty, useTriliumEvent, useTriliumEvents } from "../../react/hooks"; import FNote from "../../../entities/fnote"; import { ComponentChildren, RefObject } from "preact"; import froca from "../../../services/froca"; @@ -259,6 +259,7 @@ function JsPlumb({ className, props, children, containerRef: externalContainerRe function NoteBox({ noteId, x, y, mapApiRef }: MapDataNoteEntry & { mapApiRef: RefObject }) { const [ note, setNote ] = useState(); + const title = useNoteProperty(note, "title"); useEffect(() => { froca.getNote(noteId).then(setNote); }, [ noteId ]); @@ -284,6 +285,23 @@ function NoteBox({ noteId, x, y, mapApiRef }: MapDataNoteEntry & { mapApiRef: Re mapApiRef.current?.removeItem(noteId, result.isDeleteNoteChecked); } + }, + { + title: t("relation_map.edit_title"), + uiIcon: "bx bx-pencil", + handler: async () => { + const title = await dialog.prompt({ + title: t("relation_map.rename_note"), + message: t("relation_map.enter_new_title"), + defaultValue: note?.title, + }); + + if (!title) { + return; + } + + await server.put(`notes/${noteId}/title`, { title }); + } } ], selectMenuItemHandler() {} @@ -300,7 +318,7 @@ function NoteBox({ noteId, x, y, mapApiRef }: MapDataNoteEntry & { mapApiRef: Re top: y }} > - +
) diff --git a/apps/client/src/widgets/type_widgets_old/relation_map.ts b/apps/client/src/widgets/type_widgets_old/relation_map.ts index 5430f9bd5..2c9e211d8 100644 --- a/apps/client/src/widgets/type_widgets_old/relation_map.ts +++ b/apps/client/src/widgets/type_widgets_old/relation_map.ts @@ -143,16 +143,6 @@ export default class RelationMapTypeWidget extends TypeWidget { }); this.$relationMapContainer.attr("id", "relation-map-container-" + containerCounter++); - this.$relationMapContainer.on("contextmenu", ".note-box", (e) => { - contextMenu.show({ - x: e.pageX, - y: e.pageY, - items: [ - { title: t("relation_map.edit_title"), command: "editTitle", uiIcon: "bx bx-pencil" } - ], - selectMenuItemHandler: ({ command }) => this.contextMenuHandler(command, e.target) - }); - }); this.clipboard = null; @@ -168,30 +158,6 @@ export default class RelationMapTypeWidget extends TypeWidget { super.doRender(); } - async contextMenuHandler(command: MenuCommands | undefined, originalTarget: HTMLElement) { - const $noteBox = $(originalTarget).closest(".note-box"); - const $title = $noteBox.find(".title a"); - const noteId = this.idToNoteId($noteBox.prop("id")); - - } else if (command === "editTitle") { - const title = await dialogService.prompt({ - title: t("relation_map.rename_note"), - message: t("relation_map.enter_new_title"), - defaultValue: $title.text() - }); - - if (!title) { - return; - } - - await server.put(`notes/${noteId}/title`, { title }); - - $title.text(title); - } - } - - - async doRefresh(note: FNote) { await this.initJsPlumbInstance(); this.loadNotesAndRelations();