feat(settings): configure table open page size
This commit is contained in:
21 files changed
+156
-31
No files matched your search
@@ -1,11 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { EDITOR_SETTINGS_DRAFT_KEYS, editorSettingsDraftFromSettings, editorSettingsDraftChanged, editorSettingsPatchFromDraft } from "../editorSettingsDraft";
|
||||
import { EDITOR_SETTINGS_DRAFT_KEYS, editorSettingsDraftFromSettings, editorSettingsDraftChanged, editorSettingsPatchFromDraft, normalizeTableOpenPageSizeDraft } from "../editorSettingsDraft";
|
||||
import type { EditorSettings } from "@/stores/settingsStore";
|
||||
|
||||
function makeSettings(overrides: Partial<EditorSettings> = {}): EditorSettings {
|
||||
return {
|
||||
autoCalculateTotalRows: false,
|
||||
pageSize: 100,
|
||||
tableOpenPageSize: 100,
|
||||
sqlEngine: "desktop",
|
||||
tabSize: 2,
|
||||
keywordCase: "upper",
|
||||
@@ -31,6 +32,10 @@ describe("EDITOR_SETTINGS_DRAFT_KEYS", () => {
|
||||
it("includes continueOnErrorOnBatch", () => {
|
||||
expect(EDITOR_SETTINGS_DRAFT_KEYS).toContain("continueOnErrorOnBatch");
|
||||
});
|
||||
|
||||
it("includes the table-open page size", () => {
|
||||
expect(EDITOR_SETTINGS_DRAFT_KEYS).toContain("tableOpenPageSize");
|
||||
});
|
||||
});
|
||||
|
||||
describe("editorSettingsDraftFromSettings", () => {
|
||||
@@ -43,6 +48,27 @@ describe("editorSettingsDraftFromSettings", () => {
|
||||
const draft = editorSettingsDraftFromSettings(makeSettings({ continueOnErrorOnBatch: false }));
|
||||
expect(draft.continueOnErrorOnBatch).toBe(false);
|
||||
});
|
||||
|
||||
it("preserves the table-open default for legacy settings", () => {
|
||||
const settings = makeSettings();
|
||||
delete (settings as Partial<EditorSettings>).tableOpenPageSize;
|
||||
expect(editorSettingsDraftFromSettings(settings).tableOpenPageSize).toBe(100);
|
||||
});
|
||||
});
|
||||
|
||||
describe("normalizeTableOpenPageSizeDraft", () => {
|
||||
it.each([
|
||||
[200000, 100000],
|
||||
[0, 100],
|
||||
[-1, 100],
|
||||
["123.9", 123],
|
||||
[Number.NaN, 100],
|
||||
[Number.POSITIVE_INFINITY, 100],
|
||||
["not-a-number", 100],
|
||||
[500, 500],
|
||||
])("normalizes %s to %s", (value, expected) => {
|
||||
expect(normalizeTableOpenPageSizeDraft(value)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("editorSettingsDraftChanged", () => {
|
||||
@@ -60,6 +86,14 @@ describe("editorSettingsDraftChanged", () => {
|
||||
const base = editorSettingsDraftFromSettings(settings);
|
||||
expect(editorSettingsDraftChanged(draft, base)).toBe(false);
|
||||
});
|
||||
|
||||
it("compares the normalized table-open page size", () => {
|
||||
const settings = makeSettings({ tableOpenPageSize: 100 });
|
||||
const draft = editorSettingsDraftFromSettings(settings);
|
||||
const base = editorSettingsDraftFromSettings(settings);
|
||||
draft.tableOpenPageSize = Number.NaN;
|
||||
expect(editorSettingsDraftChanged(draft, base)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("editorSettingsPatchFromDraft", () => {
|
||||
@@ -79,6 +113,14 @@ describe("editorSettingsPatchFromDraft", () => {
|
||||
const patch = editorSettingsPatchFromDraft(draft, base);
|
||||
expect(patch.continueOnErrorOnBatch).toBeUndefined();
|
||||
});
|
||||
|
||||
it("writes the normalized table-open page size", () => {
|
||||
const settings = makeSettings({ tableOpenPageSize: 100 });
|
||||
const draft = editorSettingsDraftFromSettings(settings);
|
||||
const base = editorSettingsDraftFromSettings(settings);
|
||||
draft.tableOpenPageSize = 200000.9;
|
||||
expect(editorSettingsPatchFromDraft(draft, base).tableOpenPageSize).toBe(100000);
|
||||
});
|
||||
});
|
||||
|
||||
describe("EDITOR_SETTINGS_DRAFT_KEYS - tabLayout", () => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { EditorSettings } from "@/stores/settingsStore";
|
||||
import { normalizeResultPageSize } from "@/lib/dataGrid/paginationPageSize";
|
||||
|
||||
export const EDITOR_SETTINGS_DRAFT_KEYS = [
|
||||
"fontFamily",
|
||||
@@ -26,6 +27,7 @@ export const EDITOR_SETTINGS_DRAFT_KEYS = [
|
||||
"showColumnTypesInHeader",
|
||||
"compactColumnHeaderActions",
|
||||
"dataGridQuickEntry",
|
||||
"tableOpenPageSize",
|
||||
"infiniteScroll",
|
||||
"infiniteScrollMaxRows",
|
||||
"autoCalculateTotalRows",
|
||||
@@ -66,14 +68,24 @@ function cloneDraftValue<T>(value: T): T {
|
||||
return JSON.parse(JSON.stringify(value)) as T;
|
||||
}
|
||||
|
||||
function draftValueChanged(a: unknown, b: unknown): boolean {
|
||||
return JSON.stringify(a) !== JSON.stringify(b);
|
||||
export function normalizeTableOpenPageSizeDraft(value: unknown): number {
|
||||
// Match persistence so legacy, invalid, and fractional values cannot leave the dialog dirty after apply.
|
||||
return normalizeResultPageSize(value);
|
||||
}
|
||||
|
||||
function normalizedDraftValue(key: EditorSettingsDraftKey, value: unknown): unknown {
|
||||
if (key === "tableOpenPageSize") return normalizeTableOpenPageSizeDraft(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
function draftValueChanged(key: EditorSettingsDraftKey, a: unknown, b: unknown): boolean {
|
||||
return JSON.stringify(normalizedDraftValue(key, a)) !== JSON.stringify(normalizedDraftValue(key, b));
|
||||
}
|
||||
|
||||
export function editorSettingsDraftFromSettings(settings: EditorSettings): EditorSettingsDraft {
|
||||
const draft = {} as EditorSettingsDraft;
|
||||
for (const key of EDITOR_SETTINGS_DRAFT_KEYS) {
|
||||
draft[key] = cloneDraftValue(settings[key]) as never;
|
||||
draft[key] = cloneDraftValue(normalizedDraftValue(key, settings[key])) as never;
|
||||
}
|
||||
return draft;
|
||||
}
|
||||
@@ -81,13 +93,13 @@ export function editorSettingsDraftFromSettings(settings: EditorSettings): Edito
|
||||
export function editorSettingsPatchFromDraft(draft: EditorSettingsDraft, base: EditorSettingsDraft): Partial<EditorSettings> {
|
||||
const patch: Partial<EditorSettings> = {};
|
||||
for (const key of EDITOR_SETTINGS_DRAFT_KEYS) {
|
||||
if (draftValueChanged(draft[key], base[key])) {
|
||||
patch[key] = cloneDraftValue(draft[key]) as never;
|
||||
if (draftValueChanged(key, draft[key], base[key])) {
|
||||
patch[key] = cloneDraftValue(normalizedDraftValue(key, draft[key])) as never;
|
||||
}
|
||||
}
|
||||
return patch;
|
||||
}
|
||||
|
||||
export function editorSettingsDraftChanged(draft: EditorSettingsDraft, base: EditorSettingsDraft): boolean {
|
||||
return EDITOR_SETTINGS_DRAFT_KEYS.some((key) => draftValueChanged(draft[key], base[key]));
|
||||
return EDITOR_SETTINGS_DRAFT_KEYS.some((key) => draftValueChanged(key, draft[key], base[key]));
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import { DEFAULT_RESULT_PAGE_SIZE, normalizeResultPageSize } from "@/lib/dataGri
|
||||
|
||||
export const DEFAULT_TABLE_OPEN_PAGE_LIMIT = DEFAULT_RESULT_PAGE_SIZE;
|
||||
|
||||
export function tableOpenPageLimit(): number {
|
||||
// Opening a table should not inherit the mutable SQL result-grid rows-per-page setting.
|
||||
return normalizeResultPageSize(DEFAULT_TABLE_OPEN_PAGE_LIMIT);
|
||||
export function tableOpenPageLimit(preferredLimit?: unknown): number {
|
||||
return normalizeResultPageSize(preferredLimit, DEFAULT_TABLE_OPEN_PAGE_LIMIT);
|
||||
}
|
||||
Reference in new issue
Block a user