refactor(settings): group SQL file size settings by category

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-09-09 12:26:39 +08:00
1 parent 776d01199c
commit 99c698f72e
12 files changed
+149 -70

No files matched your search

@@ -1,6 +1,16 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import { SETTINGS_SEARCH_DEFINITIONS, TOOLBAR_VISIBILITY_ITEMS, createShortcutSettingsSearchDefinitions, createToolbarVisibilitySettingsSearchDefinitions, resolveSettingsSearchEntries, searchSettings, type SettingsCategory, type SettingsSearchDefinition } from "@/lib/settings/settingsSearch";
import {
SETTINGS_SEARCH_DEFINITIONS,
TOOLBAR_VISIBILITY_ITEMS,
createShortcutSettingsSearchDefinitions,
createToolbarVisibilitySettingsSearchDefinitions,
resolveSettingsCategory,
resolveSettingsSearchEntries,
searchSettings,
type SettingsCategory,
type SettingsSearchDefinition,
} from "@/lib/settings/settingsSearch";
const settingsDialogSource = readFileSync(new URL("../../../components/editor/EditorSettingsDialog.vue", import.meta.url), "utf8");
@@ -78,6 +88,41 @@ describe("settings search", () => {
expect(settingsDialogSource).toContain('v-model="editMultiStatementDefaultView"');
});
it("places SQL file limits in their owning settings categories", () => {
expect(SETTINGS_SEARCH_DEFINITIONS).toContainEqual({
id: "sql-file-editor-max-mb",
category: "editor",
titleKey: "settings.externalSqlEditorMaxMb",
descriptionKey: "settings.externalSqlEditorMaxMbDescription",
targetId: "editor-sql-file",
});
expect(SETTINGS_SEARCH_DEFINITIONS).toContainEqual({
id: "sql-file-web-upload-max-mb",
category: "data",
titleKey: "settings.webSqlFileUploadMaxMb",
descriptionKey: "settings.webSqlFileUploadMaxMbDescription",
targetId: "data-sql-file-upload",
visible: expect.any(Function),
});
const desktopEntries = resolveSettingsSearchEntries(SETTINGS_SEARCH_DEFINITIONS, { isWeb: false, visibleCategories: new Set<SettingsCategory>(["editor", "data"]) }, translate, categoryLabels);
const webEntries = resolveSettingsSearchEntries(SETTINGS_SEARCH_DEFINITIONS, { isWeb: true, visibleCategories: new Set<SettingsCategory>(["editor", "data"]) }, translate, categoryLabels);
expect(desktopEntries.map((entry) => entry.id)).toContain("sql-file-editor-max-mb");
expect(desktopEntries.map((entry) => entry.id)).not.toContain("sql-file-web-upload-max-mb");
expect(webEntries.map((entry) => entry.id)).toEqual(expect.arrayContaining(["sql-file-editor-max-mb", "sql-file-web-upload-max-mb"]));
expect(settingsDialogSource).toContain('data-settings-search-id="editor-sql-file"');
expect(settingsDialogSource).toContain('data-settings-search-id="data-sql-file-upload"');
});
it("maps legacy SQL file settings navigation to the editor", () => {
expect(resolveSettingsCategory("sqlFile")).toBe("editor");
expect(resolveSettingsCategory()).toBe("appearance");
expect(resolveSettingsCategory("removed-category")).toBe("appearance");
expect(settingsDialogSource).not.toContain('value: "sqlFile"');
expect(settingsDialogSource).not.toContain("activeSettingsTab === 'sqlFile'");
expect(settingsDialogSource).toMatch(/if \(tab === "data" && isWeb\) void loadWebSqlFileUploadMaxMbSetting\(\)/);
});
it("matches translated title, description, and category without changing declared order", () => {
const entries = resolveSettingsSearchEntries(definitions, { isWeb: false, visibleCategories: allCategories }, translate, categoryLabels);
expect(searchSettings(entries, "TYPEFACE", "en").map((entry) => entry.id)).toEqual(["font"]);
@@ -1,4 +1,15 @@
export type SettingsCategory = "editor" | "formatter" | "appearance" | "navigation" | "data" | "sqlFile" | "backups" | "tunnels" | "shortcuts" | "snippets" | "sync" | "ai" | "mcp" | "security" | "about";
export type SettingsCategory = "editor" | "formatter" | "appearance" | "navigation" | "data" | "backups" | "tunnels" | "shortcuts" | "snippets" | "sync" | "ai" | "mcp" | "security" | "about";
const SETTINGS_CATEGORIES: readonly SettingsCategory[] = ["editor", "formatter", "appearance", "navigation", "data", "backups", "tunnels", "shortcuts", "snippets", "sync", "ai", "mcp", "security", "about"];
/**
* Maps retired settings tabs to their current home so saved links and external
* navigation requests continue to open a populated settings page.
*/
export function resolveSettingsCategory(initialTab?: string): SettingsCategory {
if (initialTab === "sqlFile") return "editor";
return SETTINGS_CATEGORIES.includes(initialTab as SettingsCategory) ? (initialTab as SettingsCategory) : "appearance";
}
export interface SettingsSearchContext {
isWeb: boolean;
@@ -199,8 +210,8 @@ export const SETTINGS_SEARCH_DEFINITIONS: readonly SettingsSearchDefinition[] =
{ id: "data-grid-quick-entry", category: "data", titleKey: "settings.dataGridQuickEntry", descriptionKey: "settings.dataGridQuickEntryDescription", targetId: "data" },
{ id: "data-grid-filter-view", category: "data", titleKey: "settings.dataGridFilterView", descriptionKey: "settings.dataGridFilterViewDescription", targetId: "data-grid-filter-view" },
{ id: "data-grid-flattening-multi-line", category: "data", titleKey: "settings.flatteningMultiLineText", descriptionKey: "settings.flatteningMultiLineTextDescription", targetId: "data" },
{ id: "sql-file-editor-max-mb", category: "sqlFile", titleKey: "settings.externalSqlEditorMaxMb", descriptionKey: "settings.externalSqlEditorMaxMbDescription", targetId: "sqlFile" },
{ id: "sql-file-web-upload-max-mb", category: "sqlFile", titleKey: "settings.webSqlFileUploadMaxMb", descriptionKey: "settings.webSqlFileUploadMaxMbDescription", targetId: "sqlFile", visible: (context) => context.isWeb },
{ id: "sql-file-editor-max-mb", category: "editor", titleKey: "settings.externalSqlEditorMaxMb", descriptionKey: "settings.externalSqlEditorMaxMbDescription", targetId: "editor-sql-file" },
{ id: "sql-file-web-upload-max-mb", category: "data", titleKey: "settings.webSqlFileUploadMaxMb", descriptionKey: "settings.webSqlFileUploadMaxMbDescription", targetId: "data-sql-file-upload", visible: (context) => context.isWeb },
{ id: "appearance-toolbar", category: "appearance", titleKey: "settings.toolbarTitle", descriptionKey: "settings.toolbarHiddenHint", targetId: "appearance" },
{ id: "appearance-exclusive-sidebar-panels", category: "appearance", titleKey: "settings.exclusiveRightSidebarPanels", descriptionKey: "settings.exclusiveRightSidebarPanelsDescription", targetId: "appearance" },
...createToolbarVisibilitySettingsSearchDefinitions(),