feat(grid): support selecting multiple fields for sorting
This commit is contained in:
1 parent
c840206b25
commit
a1e2d39ed3
37 files changed
+2033
-48
No files matched your search
@@ -583,6 +583,31 @@ describe("queryStore table data refresh", () => {
|
||||
expect(store.tabs.find((tab) => tab.id === secondTabId)?.result).toBeUndefined();
|
||||
});
|
||||
|
||||
it("rebuilds the structured sort from persisted tab state on refresh", async () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("pg-1", "app", "users", "data", "public");
|
||||
store.setTableMeta(tabId, {
|
||||
schema: "public",
|
||||
tableName: "users",
|
||||
tableType: "TABLE",
|
||||
columns: [
|
||||
{ name: "id", data_type: "integer", is_nullable: false, column_default: null, is_primary_key: true, extra: null },
|
||||
{ name: "status", data_type: "text", is_nullable: true, column_default: null, is_primary_key: false, extra: null },
|
||||
{ name: "created_at", data_type: "timestamp", is_nullable: false, column_default: null, is_primary_key: false, extra: null },
|
||||
],
|
||||
primaryKeys: ["id"],
|
||||
});
|
||||
const tab = store.tabs.find((tab) => tab.id === tabId)!;
|
||||
tab.orderByInput = '"status" ASC';
|
||||
tab.structuredOrderByInput = '"created_at" DESC';
|
||||
|
||||
const refreshed = await store.refreshDataTab(tabId);
|
||||
|
||||
expect(refreshed).toBe(true);
|
||||
expect(mocks.buildTableSelectSql).toHaveBeenCalledWith(expect.objectContaining({ orderBy: '"status" ASC, "created_at" DESC' }));
|
||||
});
|
||||
|
||||
it("keeps the configured MySQL page size when results contain large-value previews", async () => {
|
||||
mocks.getConnectionConfig.mockReturnValue({
|
||||
id: "mysql-1",
|
||||
@@ -679,6 +704,7 @@ describe("queryStore table data refresh", () => {
|
||||
const tab = store.tabs.find((candidate) => candidate.id === tabId)!;
|
||||
tab.whereInput = "id > 0";
|
||||
tab.orderByInput = '"old_name" ASC';
|
||||
tab.structuredOrderByInput = '"old_name" DESC';
|
||||
tab.resultSortColumn = "old_name";
|
||||
tab.resultSortColumnIndex = 1;
|
||||
tab.resultSortDirection = "asc";
|
||||
@@ -712,6 +738,7 @@ describe("queryStore table data refresh", () => {
|
||||
expect(tab.resultLocalSortOriginalMongoDocuments).toBeUndefined();
|
||||
expect(tab.resultLocalSortOriginalMongoCopyDocuments).toBeUndefined();
|
||||
expect(tab.orderByInput).toBeUndefined();
|
||||
expect(tab.structuredOrderByInput).toBeUndefined();
|
||||
expect(tab.whereInput).toBe("id > 0");
|
||||
expect(tab.resultPageLimit).toBe(25);
|
||||
expect(tab.resultPageOffset).toBe(50);
|
||||
|
||||
@@ -103,6 +103,7 @@ import { replaceSqlServerLeadingUseQuery, sqlServerLeadingUseScript, switchesDat
|
||||
import { classifySqlRisk } from "@/lib/sql/sqlRisk";
|
||||
import { externalSqlFileDisplayTitles, normalizeExternalSqlPath } from "@/lib/sql/sqlFileOpen";
|
||||
import { clearDataGridPendingSnapshot, clearDataGridPendingSnapshotsForTab } from "@/composables/useDataGridEditor";
|
||||
import { combineDataGridOrderByInputs } from "@/composables/useDataGridSortBuilder";
|
||||
import { beginClosingDataGridViewSnapshotsForTab, clearDataGridViewSnapshot, clearDataGridViewSnapshotsForTab } from "@/lib/dataGrid/dataGridViewStateCache";
|
||||
import { beginClosingBrowserState } from "@/lib/tabs/documentBrowserStateCache";
|
||||
import { clearDataGridStructuredFilterStatesForTab } from "@/lib/dataGrid/dataGridFilterBuilderPersistence";
|
||||
@@ -1776,6 +1777,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
tab.resultLocalSortOriginalMongoDocuments = undefined;
|
||||
tab.resultLocalSortOriginalMongoCopyDocuments = undefined;
|
||||
tab.orderByInput = undefined;
|
||||
tab.structuredOrderByInput = undefined;
|
||||
tab.resultPageSql = undefined;
|
||||
tab.resultPageLimit = undefined;
|
||||
tab.resultPageOffset = undefined;
|
||||
@@ -2597,6 +2599,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
resultSortDirection: t.resultSortDirection,
|
||||
resultSortMode: t.resultSortMode,
|
||||
orderByInput: t.orderByInput,
|
||||
structuredOrderByInput: t.structuredOrderByInput,
|
||||
whereInput: t.whereInput,
|
||||
pinned: t.pinned,
|
||||
mode: t.mode,
|
||||
@@ -4660,6 +4663,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
resultLocalSortOriginalMongoDocuments: undefined,
|
||||
resultLocalSortOriginalMongoCopyDocuments: undefined,
|
||||
orderByInput: original.mode === "data" ? original.orderByInput : undefined,
|
||||
structuredOrderByInput: original.mode === "data" ? original.structuredOrderByInput : undefined,
|
||||
resultPageSql: undefined,
|
||||
resultPageLimit: original.mode === "data" ? original.resultPageLimit : undefined,
|
||||
resultPageOffset: original.mode === "data" ? original.resultPageOffset : undefined,
|
||||
@@ -4890,7 +4894,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
clearInvalidDataTabSortState(tab, tableMeta.columns);
|
||||
const primaryKeys = tab.tableMeta ? tab.tableMeta.primaryKeys : tableMeta.primaryKeys;
|
||||
const sortOrder = tab.resultSortColumn && tab.resultSortDirection ? `${quoteTableDataIdentifier(effectiveDbType, tab.resultSortColumn, identifierQuote)} ${tab.resultSortDirection.toUpperCase()}` : undefined;
|
||||
const orderBy = tab.orderByInput?.trim() || sortOrder;
|
||||
const orderBy = combineDataGridOrderByInputs(tab.orderByInput, tab.structuredOrderByInput) || sortOrder;
|
||||
const limit = tab.resultPageLimit ?? tableOpenPageLimit(settingsStore.editorSettings.tableOpenPageSize);
|
||||
const offset = tab.resultPageOffset ?? 0;
|
||||
const useDriverRowOffset = jdbcConnectionUsesDriverRowOffset(conn, effectiveDbType);
|
||||
@@ -5638,7 +5642,11 @@ export const useQueryStore = defineStore("query", () => {
|
||||
tab.orderByInput,
|
||||
columns.map((column) => column.name),
|
||||
);
|
||||
if (!structuredSortMissing && !simpleOrderMissing) return false;
|
||||
const structuredOrderMissing = simpleDataGridOrderByReferencesMissingColumn(
|
||||
tab.structuredOrderByInput,
|
||||
columns.map((column) => column.name),
|
||||
);
|
||||
if (!structuredSortMissing && !simpleOrderMissing && !structuredOrderMissing) return false;
|
||||
if (structuredSortMissing) {
|
||||
tab.resultSortColumn = undefined;
|
||||
tab.resultSortColumnIndex = undefined;
|
||||
@@ -5651,6 +5659,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
tab.resultLocalSortOriginalMongoCopyDocuments = undefined;
|
||||
}
|
||||
if (simpleOrderMissing) tab.orderByInput = undefined;
|
||||
if (structuredOrderMissing) tab.structuredOrderByInput = undefined;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9037,7 +9046,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
const identifierQuote = connStore.connectionIdentifierQuote?.(tab.connectionId);
|
||||
const primaryKeys = tab.tableMeta ? tab.tableMeta.primaryKeys : tableMeta.primaryKeys;
|
||||
const sortOrder = tab.resultSortColumn && tab.resultSortDirection ? `${quoteTableDataIdentifier(effectiveDbType, tab.resultSortColumn, identifierQuote)} ${tab.resultSortDirection.toUpperCase()}` : undefined;
|
||||
const orderBy = tab.orderByInput?.trim() || sortOrder;
|
||||
const orderBy = combineDataGridOrderByInputs(tab.orderByInput, tab.structuredOrderByInput) || sortOrder;
|
||||
const queryTimeoutSecs = queryTimeoutSecsForConnection(conn, settingsStore.editorSettings.globalQueryTimeoutSecs);
|
||||
const executionDatabase = tab.database;
|
||||
const rows: QueryResult["rows"] = [];
|
||||
|
||||
Reference in new issue
Block a user