Skip to content

Build your personal knowledge base with Trilium Notes

client/options/database: improve the "Existing anonymized databases" card description

Adorian Doranee59c2e362f9
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 0c07ec1e17..20c4aa402d 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1714,7 +1714,7 @@
"choose_anonymization": "You can decide yourself if you want to provide a fully or lightly anonymized database. Even fully anonymized DB is very useful, however in some cases lightly anonymized database can speed up the process of bug identification and fixing.",
"save_lightly_anonymized_database": "Create copy",
"existing_anonymized_databases": "Existing anonymized databases",
- "anonymized_databases_location": "Anonymized databases are stored in {{- anonymizedFolder}}.",
+ "anonymized_databases_location": "Anonymized databases are stored in <Folder/>.",
"download": "Download",
"delete_confirmation": "Delete the anonymized database {{fileName}}? The original database is not affected.",
"creating_fully_anonymized_database": "Creating fully anonymized database...",
diff --git a/apps/client/src/widgets/type_widgets/options/database.spec.tsx b/apps/client/src/widgets/type_widgets/options/database.spec.tsx
index 517f9d64a5..7aaa39a1ba 100644
--- a/apps/client/src/widgets/type_widgets/options/database.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/database.spec.tsx
@@ -7,6 +7,14 @@ vi.mock("../../../services/i18n", () => ({
t: (key: string, params?: { count?: number }) => params?.count === undefined ? key : `${key}=${params.count}`
}));
+// The real i18n is not initialized under test, so `Trans` would render the bare key and drop what
+// it wires in; the stub renders the components themselves, which is what the page is answering for.
+vi.mock("react-i18next", () => ({
+ Trans: ({ i18nKey, components }: { i18nKey: string, components: Record<string, preact.VNode> }) => (
+ <span data-i18n-key={i18nKey}>{Object.values(components)}</span>
+ )
+}));
+
const setupMode = vi.hoisted(() => ({
canBootToSetup: vi.fn(() => true),
startOver: vi.fn(async () => "restarting" as string),
@@ -36,6 +44,9 @@ const ANONYMIZED_COPY = {
fileSize: 4096
};
+/** What the anonymized-databases endpoint would list; emptied by the test about having made none. */
+let ANONYMIZED: (typeof ANONYMIZED_COPY)[] = [];
+
// The info, maintenance and anonymization cards call the backend as they render and as they are used.
const server = vi.hoisted(() => ({
get: vi.fn(async (url: string) => {
@@ -50,7 +61,7 @@ const server = vi.hoisted(() => ({
case "database/check-integrity":
return { results: [{ integrity_check: "ok" }] };
case "database/anonymized-databases":
- return { databases: [ ANONYMIZED_COPY ], anonymizedFolderPath: "/data/anonymized" };
+ return { databases: ANONYMIZED, anonymizedFolderPath: "/data/anonymized" };
// Whatever the page's own imports ask for while they load, e.g. keyboard actions.
default:
return [];
@@ -119,6 +130,7 @@ beforeEach(() => {
setupMode.cancelStartOver.mockReset().mockResolvedValue(undefined);
failing.info = false;
BACKUPS = [ { mtime: new Date("2026-01-01T10:00:00Z") }, { mtime: new Date("2026-01-02T10:00:00Z") } ];
+ ANONYMIZED = [ ANONYMIZED_COPY ];
noteContext.setNote.mockClear();
contentManager.requestContentManagerSection.mockClear();
cleanup.showCleanupDialog.mockReset().mockResolvedValue(1234);
@@ -151,8 +163,7 @@ describe("what the database is", () => {
expect(server.get).toHaveBeenCalledWith("database/info");
const [ location, content, created, size ] = infoValues();
- // The file is named in full; the link behind it opens the folder holding it, since that is
- // what a file manager can be pointed at.
+ // Named in full; the desktop reveals it in the file manager rather than opening it.
expect(location).toBe(DATABASE_INFO.filePath);
expect(created).toContain("2020");
expect(content).toBe("database.info_notes=12, database.info_attachments=3");
@@ -257,6 +268,11 @@ describe("anonymized copies", () => {
expect(server.get).toHaveBeenCalledWith("database/anonymized-databases");
+ // Where the copies are kept is stated as a link into the sentence, so the folder can be
+ // opened rather than read out and typed somewhere else.
+ const location = container.querySelector(".database-file-list [data-i18n-key]");
+ expect(location?.textContent).toBe("/data/anonymized");
+
button("light-anonymization-button")?.click();
await settle();
@@ -265,6 +281,18 @@ describe("anonymized copies", () => {
expect(server.get.mock.calls.filter(([url]) => url === "database/anonymized-databases")).toHaveLength(2);
});
+ it("says nothing about where copies are kept while there are none", async () => {
+ ANONYMIZED = [];
+ renderPage();
+ await settle();
+
+ // A location is worth stating once something can be found there; the empty list says the
+ // rest on its own.
+ expect(container.querySelector(".database-file-list [data-i18n-key]")).toBeNull();
+ expect(container.querySelector(".database-file-list")?.textContent)
+ .toContain("database_anonymization.no_anonymized_database_yet");
+ });
+
it("throws a copy away once asked about, and lists what is left", async () => {
renderPage();
await settle();
diff --git a/apps/client/src/widgets/type_widgets/options/database.tsx b/apps/client/src/widgets/type_widgets/options/database.tsx
index 5e0642c3cf..671fd53ef1 100644
--- a/apps/client/src/widgets/type_widgets/options/database.tsx
+++ b/apps/client/src/widgets/type_widgets/options/database.tsx
@@ -9,6 +9,8 @@ import {
ExistingBackupsResponse
} from "@triliumnext/commons";
import { useCallback, useEffect, useState } from "preact/hooks";
+import type React from "react";
+import { Trans } from "react-i18next";
import { summarizeBackups } from "../../../services/database_files";
import dialogService from "../../../services/dialog";
@@ -26,7 +28,7 @@ import { formatDateTime } from "../../../utils/formatters";
import Admonition from "../../react/Admonition";
import Button from "../../react/Button";
import { Card, CardOption } from "../../react/Card";
-import { FileLink } from "../../react/DirectoryLink";
+import DirectoryLink, { FileLink } from "../../react/DirectoryLink";
import { useNoteContext } from "../../react/hooks";
import { useFetch } from "../../react/use_fetch";
import DatabaseFileList from "./components/DatabaseFileList";
@@ -369,14 +371,21 @@ function AnonymizationOptions() {
</Card>
</div>
+ {/* Where the copies are kept is stated only once there is one to find there: an empty
+ list saying where it would have been answers a question nobody asked. */}
<DatabaseFileList
title={t("database_anonymization.existing_anonymized_databases")}
- description={anonymizedFolderPath && (
- <span className="selectable-text">
- {t("database_anonymization.anonymized_databases_location", {
- anonymizedFolder: anonymizedFolderPath
- })}
- </span>
+ description={databases.length > 0 && anonymizedFolderPath && (
+ <Trans
+ i18nKey="database_anonymization.anonymized_databases_location"
+ // Kept beside the component: a locale still carrying the placeholder from
+ // before the folder became a link states the path as text rather than
+ // losing it, until its own translation catches up.
+ values={{ anonymizedFolder: anonymizedFolderPath }}
+ components={{
+ Folder: <DirectoryLink directory={anonymizedFolderPath} /> as React.ReactElement
+ }}
+ />
)}
files={databases}
downloadEndpoint="api/database/anonymized/download"