Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client/options): move the space tools out of the Database maintenance card

Elian Doranbc3f6b5387fb
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index daa7088d5c..df3b4e80ff 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1770,7 +1770,7 @@
"analyze_space_usage": "Analyze space usage",
"analyze_space_usage_description": "Identify which notes take up the most space, and get a clearer picture of how large your notes are.",
"analyze_space_usage_button": "Analyze",
- "cleanup": "Perform a cleanup",
+ "cleanup": "Clean up the database",
"cleanup_description": "Erase deleted notes and attachments, trim revision snapshots and compress images to keep the database slim.",
"start_over_description": "Switch to a new blank database, start again syncing with a new server or restore a backup. You will be prompted to backup your data before discarding the existing data.",
"start_over": "Start over",
@@ -3436,9 +3436,7 @@
},
"settings": {
"related_settings": "Related settings",
- "related_actions": "Related actions",
- "related_space_usage": "Analyze the space usage within the database",
- "related_space_usage_description": "See which notes, revisions and attachments take up the most space, and reclaim it."
+ "related_actions": "Related actions"
},
"settings_appearance": {
"related_code_blocks": "Color scheme for code blocks in text notes",
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 a0fdefc4d2..87c8691194 100644
--- a/apps/client/src/widgets/type_widgets/options/database.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/database.spec.tsx
@@ -247,15 +247,18 @@ describe("what the database is", () => {
renderPage();
await settle();
- // A card of empty rows would state no less, and rather less clearly. The rest of the page
- // stands: each card answers for itself.
+ // Only `DatabaseInfo` depends on the figures; the other cards render regardless. That
+ // matters most for `SpaceOptions`: a database too large to measure quickly is exactly the
+ // one that needs analyzing and cleaning up.
expect(container.querySelector(".database-info")).toBeNull();
+ expect(button("analyze-space-usage-button")).not.toBeNull();
+ expect(button("cleanup-button")).not.toBeNull();
expect(button("check-integrity-button")).not.toBeNull();
});
});
-describe("database maintenance", () => {
- it("hands the two tools over to Space Usage rather than repeating them", async () => {
+describe("space usage and cleanup", () => {
+ it("hands both tools over to Space Usage rather than repeating them", async () => {
renderPage();
await settle();
@@ -285,7 +288,9 @@ describe("database maintenance", () => {
expect(server.get.mock.calls.filter(([ url ]) => url === "database/info")).toHaveLength(1);
});
+});
+describe("database maintenance", () => {
it("runs each check against its own endpoint, and says how it went", 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 4e3bb9f661..d389e400eb 100644
--- a/apps/client/src/widgets/type_widgets/options/database.tsx
+++ b/apps/client/src/widgets/type_widgets/options/database.tsx
@@ -48,8 +48,8 @@ import RelatedSettings from "./components/RelatedSettings";
*/
export default function DatabaseSettings() {
const startOverState = useStartOver();
- // Maintenance is what changes the figures the card above it states — a rebuild its size, a
- // cleanup what it holds — so they are read again afterwards rather than left as they were.
+ // The space and maintenance actions change what `DatabaseInfo` states, so bumping this token
+ // makes it read the figures again.
const [ infoToken, setInfoToken ] = useState(0);
const refreshInfo = useCallback(() => setInfoToken((token) => token + 1), []);
@@ -75,6 +75,7 @@ export default function DatabaseSettings() {
)}
<DatabaseInfo refreshToken={infoToken} />
+ <SpaceOptions onDatabaseChanged={refreshInfo} />
<MaintenanceOptions onDatabaseChanged={refreshInfo} />
<StartOverOption state={startOverState} />
{/* An anonymized copy is a file written beside the database and handed to someone else.
@@ -175,52 +176,65 @@ function BackupStanding({ refreshToken }: { refreshToken: number }) {
const BACKUP_PAGE_LINK = "#root/_hidden/_options/_optionsBackup";
/**
- * Keeping the database in good order: finding out what it is spent on, taking back what is no longer
- * needed, and the checks and repairs that act on the file itself rather than on what is kept in it.
+ * Entry points to the two space tools: the Space Usage page reports where the space went, and
+ * `showCleanupDialog()` reclaims it. Analysis comes first because it informs the cleanup.
*
- * The first two hand over to the tools that do the work, the Space Usage page and the cleanup
- * dialog, which is why they are named here rather than duplicated.
+ * Headingless, since it continues the figures in `DatabaseInfo`. It is a separate card because
+ * `DatabaseInfo` renders nothing until `database/info` resolves, and these actions must stay
+ * available when that request is slow or fails.
*/
-function MaintenanceOptions({ onDatabaseChanged }: { onDatabaseChanged: () => void }) {
+function SpaceOptions({ onDatabaseChanged }: { onDatabaseChanged: () => void }) {
return (
- <Card heading={t("database.maintenance")}>
+ <Card className="database-space">
+ <OptionCardSection
+ label={t("database.analyze_space_usage")}
+ description={t("database.analyze_space_usage_description")}
+ >
+ <Button
+ name="analyze-space-usage-button"
+ text={t("database.analyze_space_usage_button")}
+ size="micro"
+ onClick={() => {
+ // Space Usage opens in its own tab, so close the options dialog first;
+ // it would otherwise cover the tab.
+ closeActiveDialog();
+ void appContext.triggerCommand("showSpaceUsage");
+ }}
+ />
+ </OptionCardSection>
+
<OptionCardSection
label={t("database.cleanup")}
description={t("database.cleanup_description")}
>
- {/* Named after the tool it opens, so the button and the dialog's own heading
- cannot come to say different things. */}
+ {/* Reuses the dialog's own title so the two cannot disagree. */}
<Button
name="cleanup-button"
text={t("space_usage.cleanup_title")}
size="micro"
onClick={() => void showCleanupDialog().then((reclaimed) => {
- // Erasing frees pages inside the file rather than shrinking it, so what
- // the card above has to re-read is what the database holds.
+ // Erasing changes the note and attachment counts, so `DatabaseInfo`
+ // reads them again.
if (reclaimed !== null) {
onDatabaseChanged();
}
})}
/>
</OptionCardSection>
+ </Card>
+ );
+}
- <OptionCardSection
- label={t("database.analyze_space_usage")}
- description={t("database.analyze_space_usage_description")}
- >
- <Button
- name="analyze-space-usage-button"
- text={t("database.analyze_space_usage_button")}
- size="micro"
- onClick={() => {
- // A tab of its own rather than this page's context: the tool outlives the
- // settings that sent the user to it, so the dialog stands down first.
- closeActiveDialog();
- void appContext.triggerCommand("showSpaceUsage");
- }}
- />
- </OptionCardSection>
-
+/**
+ * Repairs that act on the database file rather than on its contents: consistency checks, SQLite's
+ * `integrity_check`, and `VACUUM`.
+ *
+ * These are troubleshooting tools, so they sit below `SpaceOptions`, which holds the actions most
+ * users come to this page for.
+ */
+function MaintenanceOptions({ onDatabaseChanged }: { onDatabaseChanged: () => void }) {
+ return (
+ <Card heading={t("database.maintenance")}>
<OptionCardSection
label={t("consistency_checks.find_and_fix_label")}
description={t("consistency_checks.find_and_fix_description")}
diff --git a/apps/client/src/widgets/type_widgets/options/other.tsx b/apps/client/src/widgets/type_widgets/options/other.tsx
index 00f7d78d22..29918cd281 100644
--- a/apps/client/src/widgets/type_widgets/options/other.tsx
+++ b/apps/client/src/widgets/type_widgets/options/other.tsx
@@ -2,8 +2,6 @@ import "./other.css";
import { SANITIZER_DEFAULT_ALLOWED_TAGS } from "@triliumnext/commons";
-import appContext from "../../../components/app_context";
-import { closeActiveDialog } from "../../../services/dialog";
import { t } from "../../../services/i18n";
import search from "../../../services/search";
import server from "../../../services/server";
@@ -14,7 +12,6 @@ import { FormTextBoxWithUnit } from "../../react/FormTextBox";
import FormToggle from "../../react/FormToggle";
import { useTriliumOption, useTriliumOptionBool, useTriliumOptionJson } from "../../react/hooks";
import OptionsPageHeader from "./components/OptionsPageHeader";
-import RelatedSettings from "./components/RelatedSettings";
import TimeSelector from "./components/TimeSelector";
export default function OtherSettings() {
@@ -28,36 +25,10 @@ export default function OtherSettings() {
<HtmlImportTags />
<ShareSettings />
<NetworkSettings />
- <RelatedActions />
</>
);
}
-function RelatedActions() {
- return (
- <RelatedSettings
- title={t("settings.related_actions")}
- items={[
- {
- title: t("settings.related_space_usage"),
- description: t("settings.related_space_usage_description"),
- targetNoteId: "_spaceUsage",
- onClick: (e) => {
- // Opened as the tool it is, in a tab of its own, rather than followed as a
- // link into the hidden subtree; stopping the event keeps the global link
- // handler (link.ts goToLink) from navigating by the href instead.
- e.preventDefault();
- e.stopPropagation();
- // The tool outlives the settings that sent the user to it.
- closeActiveDialog();
- void appContext.triggerCommand("showSpaceUsage");
- }
- }
- ]}
- />
- );
-}
-
function SearchSettings() {
const [ fuzzyEnabled, setFuzzyEnabled ] = useTriliumOptionBool("searchEnableFuzzyMatching");
const [ autocompleteFuzzy, setAutocompleteFuzzy ] = useTriliumOptionBool("searchAutocompleteFuzzy");