Skip to content

Build your personal knowledge base with Trilium Notes

client/deleted notes dialog: tweak the empty list placeholder

Adorian Dorand955ca7ed335
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 07c2bc61e4..a36b3a5702 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -424,7 +424,7 @@
"deleted_notes_settings": "Deleted Notes Settings",
"deleted_notes_message": "Deleted notes have been erased.",
"no_changes_message": "No changes yet...",
- "no_deleted_notes_message": "No deleted notes.",
+ "no_deleted_notes_message": "There are no deleted notes to show. Deleted notes are kept for {{- duration}} before being permanently erased.",
"undelete_link": "undelete",
"confirm_undelete": "Do you want to undelete this note and its sub-notes?",
"confirm_undelete_to_default_location": "The parent of this note no longer exists, so it can't be restored to its original location. Restore it to the default location for new notes instead?",
@@ -2495,6 +2495,16 @@
"hours": "Hours",
"days": "Days"
},
+ "time_interval": {
+ "seconds_one": "{{count}} second",
+ "seconds_other": "{{count}} seconds",
+ "minutes_one": "{{count}} minute",
+ "minutes_other": "{{count}} minutes",
+ "hours_one": "{{count}} hour",
+ "hours_other": "{{count}} hours",
+ "days_one": "{{count}} day",
+ "days_other": "{{count}} days"
+ },
"share": {
"title": "Share",
"redirect_bare_domain": "Redirect bare domain to Share page",
diff --git a/apps/client/src/utils/formatters.spec.ts b/apps/client/src/utils/formatters.spec.ts
index a0b3324196..78aea3db84 100644
--- a/apps/client/src/utils/formatters.spec.ts
+++ b/apps/client/src/utils/formatters.spec.ts
@@ -1,7 +1,14 @@
-import { describe, expect, it } from "vitest";
+import { describe, expect, it, vi } from "vitest";
+
+// i18next is not initialised here, so have t() echo the key and the interpolated count. That lets the
+// tests assert exactly which unit was chosen and what count was computed — the real logic — while
+// leaving the plural rendering itself to i18next.
+vi.mock("../services/i18n", () => ({
+ t: (key: string, opts?: { count?: number }) => `${key}|${opts?.count}`
+}));
import options from "../services/options";
-import { formatDateTime, normalizeLocale } from "./formatters";
+import { formatDateTime, formatDuration, normalizeLocale } from "./formatters";
describe("formatters", () => {
it("tolerates incorrect locale", () => {
@@ -86,4 +93,36 @@ describe("formatters", () => {
// skipped and execution reaches the final guard.
expect(() => formatDateTime(new Date(), "none", "none")).toThrow("Incorrect state.");
});
+
+ describe("formatDuration", () => {
+ it("reports the value in the unit the user picked, for every time scale", () => {
+ expect(formatDuration(30, 1)).toBe("time_interval.seconds|30");
+ expect(formatDuration(300, 60)).toBe("time_interval.minutes|5");
+ expect(formatDuration(43200, 3600)).toBe("time_interval.hours|12");
+ // The shipped default: 604800s at a day scale.
+ expect(formatDuration(604800, 86400)).toBe("time_interval.days|7");
+ });
+
+ it("passes the count through so i18next can pluralize (1 vs many)", () => {
+ expect(formatDuration(86400, 86400)).toBe("time_interval.days|1");
+ expect(formatDuration(172800, 86400)).toBe("time_interval.days|2");
+ });
+
+ it("keeps distinct windows distinguishable, unlike a fuzzy humanizer", () => {
+ // dayjs humanize() renders both of these as "a month", which would misreport when a
+ // note is actually destroyed. They must stay apart.
+ expect(formatDuration(2592000, 86400)).toBe("time_interval.days|30");
+ expect(formatDuration(3888000, 86400)).toBe("time_interval.days|45");
+ });
+
+ it("falls back to days when the scale is missing or unusable", () => {
+ expect(formatDuration(604800, 0)).toBe("time_interval.days|7");
+ expect(formatDuration(604800, -1)).toBe("time_interval.days|7");
+ });
+
+ it("reports an unrecognized scale in days derived from the raw seconds", () => {
+ // 7 is not one of the offered scales, so the unit cannot be named from it.
+ expect(formatDuration(604800, 7)).toBe("time_interval.days|7");
+ });
+ });
});
diff --git a/apps/client/src/utils/formatters.ts b/apps/client/src/utils/formatters.ts
index f9d5ab234f..ebe79b163f 100644
--- a/apps/client/src/utils/formatters.ts
+++ b/apps/client/src/utils/formatters.ts
@@ -1,7 +1,42 @@
+import { t } from "../services/i18n";
import options from "../services/options";
type DateTimeStyle = "full" | "long" | "medium" | "short" | "none" | undefined;
+/** Seconds-per-unit multipliers offered by the settings time-scale dropdowns. */
+const SECONDS_PER_MINUTE = 60;
+const SECONDS_PER_HOUR = 3600;
+const SECONDS_PER_DAY = 86400;
+
+/**
+ * Formats a duration held as a settings pair — a total in `seconds` plus the seconds-per-unit
+ * `timeScale` the user picked (1 / 60 / 3600 / 86400) — into a localized, pluralized phrase such as
+ * "7 days" or "12 hours".
+ *
+ * The value is reported in the unit the user actually chose rather than being re-derived from the
+ * raw seconds, so it always matches what the settings page shows. A fuzzy humanizer would instead
+ * collapse distinct windows (both 30 and 45 days become "a month") — misleading for a setting that
+ * governs when data is destroyed.
+ */
+export function formatDuration(seconds: number, timeScale: number) {
+ const scale = timeScale > 0 ? timeScale : SECONDS_PER_DAY;
+ const count = Math.round(seconds / scale);
+
+ switch (scale) {
+ case 1:
+ return t("time_interval.seconds", { count });
+ case SECONDS_PER_MINUTE:
+ return t("time_interval.minutes", { count });
+ case SECONDS_PER_HOUR:
+ return t("time_interval.hours", { count });
+ case SECONDS_PER_DAY:
+ return t("time_interval.days", { count });
+ default:
+ // An unrecognized scale can't name a unit, so report the window in days.
+ return t("time_interval.days", { count: Math.round(seconds / SECONDS_PER_DAY) });
+ }
+}
+
/**
* Formats the given date and time to a string based on the current locale.
*/
diff --git a/apps/client/src/widgets/dialogs/recent_changes.tsx b/apps/client/src/widgets/dialogs/recent_changes.tsx
index 8bf2bb0b61..219b915715 100644
--- a/apps/client/src/widgets/dialogs/recent_changes.tsx
+++ b/apps/client/src/widgets/dialogs/recent_changes.tsx
@@ -11,11 +11,11 @@ import Modal from "../react/Modal";
import hoisted_note from "../../services/hoisted_note";
import type { RecentChangeRow } from "@triliumnext/commons";
import froca from "../../services/froca";
-import { formatDateTime } from "../../utils/formatters";
+import { formatDateTime, formatDuration } from "../../utils/formatters";
import link from "../../services/link";
import RawHtml from "../react/RawHtml";
import ws from "../../services/ws";
-import { useTriliumEvent } from "../react/hooks";
+import { useTriliumEvent, useTriliumOptionInt } from "../react/hooks";
export default function RecentChangesDialog() {
const [ ancestorNoteId, setAncestorNoteId ] = useState<string>();
@@ -24,6 +24,8 @@ export default function RecentChangesDialog() {
const [ shown, setShown ] = useState(false);
const [ deletedOnly, setDeletedOnly ] = useState(false);
const [ ancestorTitle, setAncestorTitle ] = useState<string>();
+ const [ eraseAfterSeconds ] = useTriliumOptionInt("eraseEntitiesAfterTimeInSeconds");
+ const [ eraseTimeScale ] = useTriliumOptionInt("eraseEntitiesAfterTimeScale");
useTriliumEvent("showRecentChanges", ({ ancestorNoteId }) => {
setAncestorNoteId(ancestorNoteId ?? hoisted_note.getHoistedNoteId());
@@ -105,7 +107,9 @@ export default function RecentChangesDialog() {
<div className="recent-changes-content">
{groupedByDate?.size
? <RecentChangesTimeline groupedByDate={groupedByDate} setShown={setShown} />
- : <>{deletedOnly ? t("recent_changes.no_deleted_notes_message") : t("recent_changes.no_changes_message")}</>}
+ : <>{deletedOnly
+ ? t("recent_changes.no_deleted_notes_message", { duration: formatDuration(eraseAfterSeconds, eraseTimeScale) })
+ : t("recent_changes.no_changes_message")}</>}
</div>
</Modal>
)