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
client: fix some issues
Adorian Doranf07a160f1552
diff --git a/apps/client/src/stylesheets/theme-next/dialogs.css b/apps/client/src/stylesheets/theme-next/dialogs.cssindex f45d9e3cbf..a7ed1be080 100644--- a/apps/client/src/stylesheets/theme-next/dialogs.css+++ b/apps/client/src/stylesheets/theme-next/dialogs.css@@ -262,6 +262,13 @@ div.tn-tool-dialog {text-decoration: underline;}+/* Undelete affordance disabled because the note has no surviving parent to restore into. */+.recent-changes-content ul li .undelete-disabled {+ opacity: 0.5;+ cursor: help;+ text-decoration: underline dotted;+}+/* Item title for deleted notes */.recent-changes-dialog-view-mode-all-changes ul li.deleted-note .note-title {text-decoration: line-through;diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex d8d6f83526..5f031f9af8 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -425,7 +425,9 @@"no_changes_message": "No changes yet...","no_deleted_notes_message": "No deleted notes.","undelete_link": "undelete",- "confirm_undelete": "Do you want to undelete this note and its sub-notes?"+ "confirm_undelete": "Do you want to undelete this note and its sub-notes?",+ "cannot_undelete": "This note can't be restored because its parent has also been deleted. Restore the parent first.",+ "undelete_failed": "The note could not be restored — it may have been permanently erased or its parent is no longer available."},"revisions": {"note_revisions": "Note Revisions",diff --git a/apps/client/src/widgets/dialogs/recent_changes.tsx b/apps/client/src/widgets/dialogs/recent_changes.tsxindex d11cffd0fd..2f466068c5 100644--- a/apps/client/src/widgets/dialogs/recent_changes.tsx+++ b/apps/client/src/widgets/dialogs/recent_changes.tsx@@ -149,27 +149,32 @@ function DeletedNoteLink({ change, setShown }: { change: RecentChangeRow, setSho`data-note-deleted` tells the tooltip to resolve it via the deleted-content route. */}<span className="note-title" data-href={`#${change.noteId}?`} data-note-deleted>{change.current_title}</span> - (<a href="javascript:"- onClick={async () => {- const text = t("recent_changes.confirm_undelete");-- if (await dialog.confirm(text)) {- await server.put(`notes/${change.noteId}/undelete`);- setShown(false);- await ws.waitForMaxKnownEntityChangeId();-- const activeContext = appContext.tabManager.getActiveContext();- if (activeContext) {- activeContext.setNote(change.noteId);- }- }- }}>- {t("recent_changes.undelete_link")})- </a>+ {/* A note can only be restored if it still has a surviving (undeleted) parent to reattach to.+ When it doesn't (its parent is itself deleted or erased) the undelete link is disabled. */}+ ({change.canBeUndeleted+ ? <a href="javascript:" onClick={() => undeleteNote(change, setShown)}>{t("recent_changes.undelete_link")}</a>+ : <span className="undelete-disabled" title={t("recent_changes.cannot_undelete")}>{t("recent_changes.undelete_link")}</span>})</>);}+async function undeleteNote(change: RecentChangeRow, setShown: Dispatch<StateUpdater<boolean>>) {+ if (!await dialog.confirm(t("recent_changes.confirm_undelete"))) {+ return;+ }++ // The note may fail to restore if it was erased since the dialog opened, so act on the reported result.+ const { undeleted } = await server.put<{ undeleted: boolean }>(`notes/${change.noteId}/undelete`);+ if (!undeleted) {+ toast.showError(t("recent_changes.undelete_failed"));+ return;+ }++ setShown(false);+ await ws.waitForMaxKnownEntityChangeId();+ appContext.tabManager.getActiveContext()?.setNote(change.noteId);+}+function groupByDate(rows: RecentChangeRow[]) {const groupedByDate = new Map<string, RecentChangeRow[]>();