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
standalone/backup: improve the UI
Adorian Dorand62c3248edf7
diff --git a/apps/client/src/setup_backup.css b/apps/client/src/setup_backup.cssindex 0bec6fa519..8ffe49fb5b 100644--- a/apps/client/src/setup_backup.css+++ b/apps/client/src/setup_backup.css@@ -1,4 +1,4 @@-/* The download action with its state under it, centred like the other setup waits. */+/* The download action, with what it will write above it and how it is going below. */.backup-download {display: flex;flex-direction: column;@@ -6,13 +6,27 @@gap: 1em;margin-block: 3em;+ .backup-download-file {+ /* A file name has no spaces to break at, and it is the one thing on this screen the user+ has to recognise afterwards. */+ overflow-wrap: anywhere;+ text-align: center;+ }+.backup-download-message {display: flex;align-items: center;gap: 0.75em;}-}-.page.setup-backup-database .setup-backup-note {- margin-top: 16px;+ .backup-download-hint {+ text-align: center;+ opacity: 0.7;+ }++ .backup-download-outcome {+ /* The panel centres its children, which would leave a full-width block floating. */+ align-self: stretch;+ margin-bottom: 40px;+ }}diff --git a/apps/client/src/setup_backup.spec.tsx b/apps/client/src/setup_backup.spec.tsxindex e9602ed664..73952c0ec1 100644--- a/apps/client/src/setup_backup.spec.tsx+++ b/apps/client/src/setup_backup.spec.tsx@@ -52,10 +52,14 @@ describe("backing up from the setup screen", () => {renderScreen();await settle();- expect(container.textContent).toContain("setup.backup-database");+ expect(container.textContent).toContain("setup.backup-data");+ // The name is on the screen before the download, since it is what the user goes looking+ // for afterwards, and it is the one part of the line that is not boilerplate.+ expect(container.querySelector(".backup-download-file strong")?.textContent)+ .toBe("Backup 2026-08-08 10-00-00.tnbackup");expect(mocks.startBackupDownload).not.toHaveBeenCalled();// Nothing here is destructive, so leaving is available from the start.- expect(button("setup.continue")?.disabled).toBe(false);+ expect(button("setup.backup-finish")?.disabled).toBe(false);});it("downloads on request, and says so while it runs and once it is done", async () => {@@ -66,18 +70,28 @@ describe("backing up from the setup screen", () => {renderScreen();await settle();- button("setup.existing-data-download")?.click();+ button("setup.backup-download")?.click();await settle();expect(mocks.startBackupDownload).toHaveBeenCalledWith("Backup 2026-08-08 10-00-00.tnbackup");- expect(container.textContent).toContain("setup.existing-data-downloading-in-progress");+ expect(container.textContent).toContain("setup.backup-downloading");+ // Said while it runs, because leaving the screen is exactly what would break it.+ expect(container.textContent).toContain("setup.backup-do-not-close");+ // The running download has the screen to itself: nothing to press, nothing to re-read.+ expect(button("setup.backup-download")).toBeUndefined();+ expect(container.querySelector(".backup-download-file")).toBeNull();// Leaving mid-stream would abandon the download, so that one moment is held.- expect(button("setup.continue")?.disabled).toBe(true);+ expect(button("setup.backup-finish")?.disabled).toBe(true);finish({ status: "done" });await settle();- expect(container.textContent).toContain("setup.existing-data-downloading-done");- expect(button("setup.backup-database-finish")?.disabled).toBe(false);+ // The outcome is stated where it cannot be missed, and taking another copy is offered again.+ expect(container.querySelector(".backup-download-outcome")?.textContent)+ .toContain("setup.backup-downloaded");+ expect(container.textContent).not.toContain("setup.backup-do-not-close");+ expect(button("setup.backup-download")?.disabled).toBe(false);+ expect(container.querySelector(".backup-download-file")).not.toBeNull();+ expect(button("setup.backup-finish")?.disabled).toBe(false);});it("shows what stopped a failed download, and offers another go", async () => {@@ -85,20 +99,23 @@ describe("backing up from the setup screen", () => {renderScreen();await settle();- button("setup.existing-data-download")?.click();+ button("setup.backup-download")?.click();await settle();- expect(container.textContent).toContain("the stream broke");- expect(button("setup.existing-data-download")?.disabled).toBe(false);+ expect(container.querySelector(".backup-download-outcome")?.textContent)+ .toContain("the stream broke");+ // Trying again is the way out, so the button and the name it writes are both back.+ expect(button("setup.backup-download")?.disabled).toBe(false);+ expect(container.querySelector(".backup-download-file")).not.toBeNull();// Still not trapped: the way back to the notes stays open through a failure.- expect(button("setup.continue")?.disabled).toBe(false);+ expect(button("setup.backup-finish")?.disabled).toBe(false);});it("hands back to the application when it is done with", async () => {renderScreen();await settle();- button("setup.continue")?.click();+ button("setup.backup-finish")?.click();await settle();expect(onDone).toHaveBeenCalled();diff --git a/apps/client/src/setup_backup.tsx b/apps/client/src/setup_backup.tsxindex 5fc28846f7..57a151a475 100644--- a/apps/client/src/setup_backup.tsx+++ b/apps/client/src/setup_backup.tsx@@ -62,28 +62,46 @@ export function useBackupDownload(): BackupDownload {* for its own sake are the same thing to a user.*/export function BackupDownloadPanel({ download }: { download: BackupDownload }) {- return (- <div class="backup-download">- <Button- text={t("setup.existing-data-download")}- icon="bx bx-download"- kind="primary"- disabled={download.state === "running"}- onClick={download.start}- />-- {download.state === "running" && (+ // A download in flight takes the screen over: the file it is writing is named in the browser's+ // own downloads, and offering the button again while it runs only invites a second copy of a+ // download the user has just been asked not to disturb.+ if (download.state === "running") {+ return (+ <div class="backup-download"><div class="backup-download-message"><span class="spinner-border" role="status" aria-hidden="true" />- <span>{t("setup.existing-data-downloading-in-progress")}</span>+ <span>{t("setup.backup-downloading")}</span></div>+ <div class="backup-download-hint">{t("setup.backup-do-not-close")}</div>+ </div>+ );+ }++ return (+ <div class="backup-download">+ {/* What became of the last attempt comes first: it is the answer to the button below+ it, and the button is what the user does next either way. */}+ {download.state === "done" && (+ <Admonition type="note" className="backup-download-outcome">+ {t("setup.backup-downloaded")}+ </Admonition>)}- {download.state === "done" && <span>{t("setup.existing-data-downloading-done")}</span>}{download.state === "failed" && (- <Admonition type="warning" className="backup-download-error">- {download.error ?? t("setup.existing-data-download-failed")}+ <Admonition type="warning" className="backup-download-outcome">+ {download.error ?? t("setup.backup-download-failed")}</Admonition>)}++ <div class="backup-download-file">+ {t("setup.backup-file")} <strong>{download.fileName}</strong>+ </div>++ <Button+ text={t("setup.backup-download")}+ icon="bx bx-download"+ kind="primary"+ onClick={download.start}+ /></div>);}@@ -104,12 +122,11 @@ export default function SetupBackupDatabase({ onDone }: { onDone: () => void })return (<SetupPageclassName="setup-backup-database top-aligned"- title={t("setup.backup-database")}- description={t("setup.backup-database-description", { fileName: download.fileName })}+ title={t("setup.backup-data")}illustration={<Icon icon="bx bx-archive-out" className="illustration-icon" />}footer={<Button- text={download.state === "done" ? t("setup.backup-database-finish") : t("setup.continue")}+ text={t("setup.backup-finish")}kind="primary"disabled={download.state === "running"}onClick={onDone}@@ -117,10 +134,6 @@ export default function SetupBackupDatabase({ onDone }: { onDone: () => void })}><BackupDownloadPanel download={download} />-- <Admonition type="note" className="setup-backup-note">- {t("setup.backup-database-note")}- </Admonition></SetupPage>);}diff --git a/apps/client/src/setup_existing.css b/apps/client/src/setup_existing.cssindex 06ea27c71d..cab1f762be 100644--- a/apps/client/src/setup_existing.css+++ b/apps/client/src/setup_existing.css@@ -6,6 +6,7 @@}}+.page.existing-data .existing-data-choices .tn-card-section {padding-block: 12px;}diff --git a/apps/client/src/setup_existing.spec.tsx b/apps/client/src/setup_existing.spec.tsxindex 4d30c1aec5..11b12f66cd 100644--- a/apps/client/src/setup_existing.spec.tsx+++ b/apps/client/src/setup_existing.spec.tsx@@ -340,22 +340,22 @@ describe("backing up straight to a download on standalone", () => {await reachDownloadScreen();// Arrived, but nothing downloads until the user says so, and Continue is not on offer.- expect(container.textContent).toContain("setup.existing-data-downloading");+ expect(container.textContent).toContain("setup.backup-data");expect(downloadDatabase).not.toHaveBeenCalled();expect(arrivingButton("setup.continue")?.disabled).toBe(true);expect(serverMock.post).not.toHaveBeenCalledWith("setup/existing/backup");- arrivingButton("setup.existing-data-download")?.click();+ arrivingButton("setup.backup-download")?.click();await settle();expect(downloadDatabase).toHaveBeenCalledWith(expect.stringMatching(/^Backup \d{4}-\d{2}-\d{2} \d{2}-\d{2}-\d{2}\.tnbackup$/),"123456");- expect(container.textContent).toContain("setup.existing-data-downloading-in-progress");+ expect(container.textContent).toContain("setup.backup-downloading");expect(arrivingButton("setup.continue")?.disabled).toBe(true);finish({ status: "done" });await settle();- expect(container.textContent).toContain("setup.existing-data-downloading-done");+ expect(container.textContent).toContain("setup.backup-downloaded");expect(arrivingButton("setup.continue")?.disabled).toBe(false);arrivingButton("setup.continue")?.click();@@ -368,13 +368,13 @@ describe("backing up straight to a download on standalone", () => {downloadDatabase.mockResolvedValue({ status: "failed", message: "the stream broke" });await reachDownloadScreen();- arrivingButton("setup.existing-data-download")?.click();+ arrivingButton("setup.backup-download")?.click();await settle();expect(container.textContent).toContain("the stream broke");expect(arrivingButton("setup.continue")?.disabled).toBe(true);// The button is back, because trying again is the way out.- expect(arrivingButton("setup.existing-data-download")?.disabled).toBe(false);+ expect(arrivingButton("setup.backup-download")?.disabled).toBe(false);expect(serverMock.post).not.toHaveBeenCalledWith("setup/existing/delete");});diff --git a/apps/client/src/setup_existing.tsx b/apps/client/src/setup_existing.tsxindex ade1dc188f..69929a7dc1 100644--- a/apps/client/src/setup_existing.tsx+++ b/apps/client/src/setup_existing.tsx@@ -304,8 +304,7 @@ export function ExistingDataDownloading({ download, onContinue, onCancel }: {return (<SetupPageclassName="existing-data-downloading top-aligned"- title={t("setup.existing-data-downloading")}- description={t("setup.existing-data-downloading-description", { fileName: download.fileName })}+ title={t("setup.backup-data")}illustration={<Icon icon="bx bx-download" className="illustration-icon" />}footer={<>diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 69338f57c2..39baefa317 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -3703,16 +3703,15 @@"existing-data-file-size": "Size","existing-data-encrypted-warning": "This backup is encrypted with the backup password you set in the options, which is not your Trilium password. If you no longer have that password, press Cancel now: nothing has been deleted yet, and you can change the password before trying again. Without it the backup cannot be restored.","existing-data-backup-failed": "The backup could not be created.",- "existing-data-downloading": "Download a backup",- "existing-data-downloading-description": "Your knowledge base will be saved as a download named {{- fileName}}. Your browser shows its progress among your downloads.",- "existing-data-downloading-in-progress": "Downloading...",- "existing-data-downloading-done": "The download has finished.",- "existing-data-download-failed": "The download did not finish.","existing-data-downloading-warning": "Once the download has finished and you press Continue, the knowledge base it was taken from is permanently erased. Keep the downloaded file somewhere safe.",- "backup-database": "Back up your knowledge base",- "backup-database-description": "Your knowledge base will be saved as a download named {{- fileName}}. Your browser shows its progress among your downloads.",- "backup-database-note": "Trilium waits here while your backup is saved. When the download has finished, press Continue to go back to your notes.",- "backup-database-finish": "Back to my notes",+ "backup-data": "Backup your Trilium data",+ "backup-file": "Backup file:",+ "backup-download": "Download",+ "backup-downloading": "Downloading...",+ "backup-do-not-close": "Please do not switch away or close this screen until the download completes.",+ "backup-downloaded": "The download has completed. Press \"Finish\" to return to the application.",+ "backup-download-failed": "The download did not finish.",+ "backup-finish": "Finish","existing-data-delete-failed": "The existing knowledge base could not be deleted.","existing-data-keep-failed": "The existing knowledge base could not be reopened.","restore-from-backup": "Restore from backup",