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
chore(type_widgets): relation map rename title
Elian Doranc58414bbc13b
diff --git a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsxindex 753cfa5da2..705e5bee9d 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: externalContainerRefunction NoteBox({ noteId, x, y, mapApiRef }: MapDataNoteEntry & { mapApiRef: RefObject<RelationMapApi> }) {const [ note, setNote ] = useState<FNote | null>();+ const title = useNoteProperty(note, "title");useEffect(() => {froca.getNote(noteId).then(setNote);}, [ noteId ]);@@ -284,6 +285,23 @@ function NoteBox({ noteId, x, y, mapApiRef }: MapDataNoteEntry & { mapApiRef: RemapApiRef.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: Retop: y}}>- <NoteLink className="title" notePath={noteId} noTnLink noContextMenu />+ <NoteLink className="title" title={title} notePath={noteId} noTnLink noContextMenu /><div className="endpoint" title={t("relation_map.start_dragging_relations")} /></div>)diff --git a/apps/client/src/widgets/type_widgets_old/relation_map.ts b/apps/client/src/widgets/type_widgets_old/relation_map.tsindex 5430f9bd50..2c9e211d8c 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<MenuCommands>({- 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();