feat(data-grid): add configurable default sorting
This commit is contained in:
24 files changed
+720
-17
No files matched your search
@@ -8,6 +8,7 @@ const mocks = vi.hoisted(() => ({
|
||||
executeMulti: vi.fn(),
|
||||
getConnectionConfig: vi.fn(),
|
||||
saveOpenTabsState: vi.fn(),
|
||||
openTableDefaultSortMode: "none" as "none" | "primary-key-asc" | "primary-key-desc",
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/backend/api", () => ({
|
||||
@@ -22,13 +23,14 @@ vi.mock("@/stores/connectionStore", () => ({
|
||||
useConnectionStore: () => ({
|
||||
ensureConnected: vi.fn().mockResolvedValue(undefined),
|
||||
getConfig: mocks.getConnectionConfig,
|
||||
connectionIdentifierQuote: () => undefined,
|
||||
recordConnectionLostError: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/stores/settingsStore", () => ({
|
||||
useSettingsStore: () => ({
|
||||
editorSettings: { pageSize: 1000 },
|
||||
editorSettings: { pageSize: 1000, tableOpenPageSize: 100, openTableDefaultSortMode: mocks.openTableDefaultSortMode },
|
||||
}),
|
||||
}));
|
||||
|
||||
@@ -47,6 +49,7 @@ describe("queryStore table data refresh", () => {
|
||||
vi.unstubAllGlobals();
|
||||
installLocalStorage();
|
||||
setActivePinia(createPinia());
|
||||
mocks.openTableDefaultSortMode = "none";
|
||||
mocks.getConnectionConfig.mockReturnValue({
|
||||
id: "pg-1",
|
||||
name: "Postgres",
|
||||
@@ -291,4 +294,35 @@ describe("queryStore table data refresh", () => {
|
||||
expect(tab.result?.execution_error).toBe(true);
|
||||
expect(mocks.executeMulti).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("rebuilds persisted default sorting with every composite primary-key column", async () => {
|
||||
mocks.openTableDefaultSortMode = "primary-key-desc";
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("pg-1", "app", "orders", "data", "public");
|
||||
store.setTableMeta(tabId, {
|
||||
schema: "public",
|
||||
tableName: "orders",
|
||||
tableType: "TABLE",
|
||||
columns: [
|
||||
{ name: "Tenant", data_type: "text", is_nullable: false, column_default: null, is_primary_key: true, extra: null },
|
||||
{ name: "Order", data_type: "bigint", is_nullable: false, column_default: null, is_primary_key: true, extra: null },
|
||||
],
|
||||
primaryKeys: ["Tenant", "Order"],
|
||||
});
|
||||
const tab = store.tabs.find((candidate) => candidate.id === tabId)!;
|
||||
tab.openTableDefaultSortApplied = true;
|
||||
tab.openTableDefaultSortOrderBy = '"Tenant" ASC, "Order" ASC';
|
||||
tab.orderByInput = tab.openTableDefaultSortOrderBy;
|
||||
|
||||
await expect(store.refreshDataTab(tabId)).resolves.toBe(true);
|
||||
|
||||
expect(mocks.buildTableSelectSql).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
primaryKeys: ["Tenant", "Order"],
|
||||
orderBy: '"Tenant" DESC, "Order" DESC',
|
||||
}),
|
||||
);
|
||||
expect(tab.orderByInput).toBe('"Tenant" DESC, "Order" DESC');
|
||||
});
|
||||
});
|
||||
@@ -5,6 +5,31 @@ import { isProxy } from "vue";
|
||||
import type { AiConfigItem } from "@/types/ai";
|
||||
|
||||
describe("normalizeEditorSettings", () => {
|
||||
it("keeps quick sorting disabled unless current or legacy settings explicitly enable it", () => {
|
||||
const missing = normalizeEditorSettings({});
|
||||
expect(missing.dataGridQuickSortEnabled).toBe(false);
|
||||
expect(missing.dataGridQuickSortMode).toBe("local");
|
||||
expect(missing.dataGridQuickSortDirection).toBe("asc");
|
||||
|
||||
const legacyEnabled = normalizeEditorSettings({
|
||||
defaultDataGridSortEnabled: true,
|
||||
defaultDataGridSortMode: "database",
|
||||
defaultDataGridSortDirection: "desc",
|
||||
} as any);
|
||||
expect(legacyEnabled.dataGridQuickSortEnabled).toBe(true);
|
||||
expect(legacyEnabled.dataGridQuickSortMode).toBe("database");
|
||||
expect(legacyEnabled.dataGridQuickSortDirection).toBe("desc");
|
||||
|
||||
const legacyDisabled = normalizeEditorSettings({
|
||||
defaultDataGridSortEnabled: false,
|
||||
defaultDataGridSortMode: "database",
|
||||
defaultDataGridSortDirection: "desc",
|
||||
} as any);
|
||||
expect(legacyDisabled.dataGridQuickSortEnabled).toBe(false);
|
||||
expect(legacyDisabled.dataGridQuickSortMode).toBe("database");
|
||||
expect(legacyDisabled.dataGridQuickSortDirection).toBe("desc");
|
||||
});
|
||||
|
||||
it("uses aligned comments by default and preserves legacy comment visibility", () => {
|
||||
expect(normalizeEditorSettings({}).sidebarObjectInfoMode).toBe("comment-aligned");
|
||||
expect(normalizeEditorSettings({ sidebarObjectInfoMode: "comment-aligned" }).sidebarObjectInfoMode).toBe("comment-aligned");
|
||||
|
||||
Reference in new issue
Block a user