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/options/database: adapt for the standalone version
Adorian Doranf5722918526a
diff --git a/apps/client/src/widgets/type_widgets/options/database.spec.tsx b/apps/client/src/widgets/type_widgets/options/database.spec.tsxindex 4625e700be..68d28e8466 100644--- a/apps/client/src/widgets/type_widgets/options/database.spec.tsx+++ b/apps/client/src/widgets/type_widgets/options/database.spec.tsx@@ -37,11 +37,16 @@ let INFO: typeof DATABASE_INFO = DATABASE_INFO;/** Set where a test needs the info card to have nothing to say. */const failing = vi.hoisted(() => ({ info: false }));-/** The browser build, which keeps no backups and has no path to its database. */+/** The browser build, which keeps no backups, has no path to its database and cannot compact it. */const standalone = vi.hoisted(() => ({ enabled: false }));vi.mock("../../../services/backup_download", () => ({isBackupDownloadSupported: () => standalone.enabled}));+vi.mock("../../../services/utils", async (importOriginal) => ({+ ...(await importOriginal<typeof import("../../../services/utils")>()),+ // A getter, since the real one is read from `window.glob` when the module loads.+ get isStandalone() { return standalone.enabled; }+}));/** What the backup page would list; emptied by the test about a database never backed up. */let BACKUPS: { mtime: Date }[] = [];@@ -205,6 +210,17 @@ describe("what the database is", () => {// The rest of the card holds: the figures come from the database itself, wherever it lives.expect(infoValues()).toHaveLength(4);expect(server.get).not.toHaveBeenCalledWith("database/backups");++ // Compacting rebuilds through a temporary store this build keeps in memory, so it is not+ // offered; the checks beside it are, both being things the engine does on its own.+ expect(button("vacuum-database-button")).toBeNull();+ expect(button("check-integrity-button")).not.toBeNull();+ expect(button("fix-consistency-issues-button")).not.toBeNull();++ // An anonymized copy is a file written beside the database, of which there is neither here.+ expect(container.querySelector(".database-anonymization")).toBeNull();+ expect(container.querySelector(".database-file-list")).toBeNull();+ expect(server.get).not.toHaveBeenCalledWith("database/anonymized-databases");});it("says a database has never been backed up rather than leaving the row blank", async () => {diff --git a/apps/client/src/widgets/type_widgets/options/database.tsx b/apps/client/src/widgets/type_widgets/options/database.tsxindex f7864a1abb..340163ca6f 100644--- a/apps/client/src/widgets/type_widgets/options/database.tsx+++ b/apps/client/src/widgets/type_widgets/options/database.tsx@@ -24,7 +24,7 @@ import {startOver} from "../../../services/setup_mode";import toast from "../../../services/toast";-import { formatSize } from "../../../services/utils";+import { formatSize, isStandalone } from "../../../services/utils";import { formatDateTime } from "../../../utils/formatters";import Admonition from "../../react/Admonition";import Button from "../../react/Button";@@ -77,7 +77,9 @@ export default function DatabaseSettings() {<DatabaseInfo refreshToken={infoToken} /><MaintenanceOptions onDatabaseChanged={refreshInfo} /><StartOverOption state={startOverState} />- <AnonymizationOptions />+ {/* An anonymized copy is a file written beside the database and handed to someone else.+ The browser build has nowhere to write one and no database file to copy. */}+ {!isStandalone && <AnonymizationOptions />}<RelatedSettings items={[{@@ -249,20 +251,26 @@ function MaintenanceOptions({ onDatabaseChanged }: { onDatabaseChanged: () => vo/></CardOption>- <CardOption- label={t("vacuum_database.vacuum_label")}- description={t("vacuum_database.vacuum_description")}- >- <Button- name="vacuum-database-button"- text={t("vacuum_database.button_text")}- size="micro"- onClick={async () => {- await vacuumDatabase();- onDatabaseChanged();- }}- />- </CardOption>+ {/* Offered everywhere the rebuild has somewhere to happen. The browser build keeps+ the temporary store in memory, so compacting would ask it for the size of the+ database over again at the very moment there is too little room — which is why+ the cleanup tool leaves compaction out there as well. */}+ {!isStandalone && (+ <CardOption+ label={t("vacuum_database.vacuum_label")}+ description={t("vacuum_database.vacuum_description")}+ >+ <Button+ name="vacuum-database-button"+ text={t("vacuum_database.button_text")}+ size="micro"+ onClick={async () => {+ await vacuumDatabase();+ onDatabaseChanged();+ }}+ />+ </CardOption>+ )}</Card></div>);