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
fix(quick-edit): close the popup when its note is deleted
Elian Doranbdbc288231df
diff --git a/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx b/apps/client/src/widgets/dialogs/PopupEditor.spec.tsxindex e098f98613..67990fbf73 100644--- a/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx+++ b/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx@@ -171,7 +171,22 @@ async function attachmentsReloaded(attachmentId: string) {await parent.handleEvent("entitiesReloaded", {loadResults: {getAttachmentRows: () => [ { attachmentId } ],- getAttributeRows: () => []+ getAttributeRows: () => [],+ isNoteReloaded: () => false+ }+ } as never);+ });+}++/** An entity reload of one note, deleted or not. */+async function noteReloaded(noteId: string, isDeleted: boolean) {+ await act(async () => {+ await parent.handleEvent("entitiesReloaded", {+ loadResults: {+ getAttachmentRows: () => [],+ getAttributeRows: () => [],+ isNoteReloaded: (id: string) => id === noteId,+ getEntityRow: (_entityName: string, id: string) => (id === noteId ? { noteId, isDeleted } : undefined)}} as never);});@@ -347,6 +362,17 @@ describe("PopupEditor", () => {expect(modal()?.dataset.shown).toBe("false");});+ it("closes when the note it shows is deleted, and only then", async () => {+ await openPopup({ noteIdOrPath: "root/n1" });++ await noteReloaded("other", true);+ await noteReloaded("n1", false);+ expect(modal()?.dataset.shown).toBe("true");++ await noteReloaded("n1", true);+ expect(modal()?.dataset.shown).toBe("false");+ });+it("stays put when there is no note to maximize", async () => {await openPopup({ noteIdOrPath: "root/n1" });const context = lastContext();diff --git a/apps/client/src/widgets/dialogs/PopupEditor.tsx b/apps/client/src/widgets/dialogs/PopupEditor.tsxindex 3c3c58921e..e853e8791a 100644--- a/apps/client/src/widgets/dialogs/PopupEditor.tsx+++ b/apps/client/src/widgets/dialogs/PopupEditor.tsx@@ -93,6 +93,14 @@ export default function PopupEditor({ ntxId = POPUP_EDITOR_NTX_ID, openCommand =// the note it has just gone to with a map of the note it came from.useTriliumEvent("closePopupEditor", () => setShown(false));+ // The popup's context is detached, so it never receives `entitiesReloaded` to clear a deleted note.+ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {+ const { noteId } = noteContext;+ if (noteId && loadResults.isNoteReloaded(noteId) && loadResults.getEntityRow("notes", noteId)?.isDeleted) {+ setShown(false);+ }+ });+// Keep navigation that follows internal links inside the popup, rather than letting the global// link handler open the target in the background tab. Settings links open the options dialog.const navigateInPopup = useCallback((notePath: string, viewScope: ViewScope | undefined) => {