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
@@ -27,6 +27,13 @@ describe("openTabsPersistence originalSql round-trip", () => {
|
||||
expect(restored.uiState).toEqual({ activeOutputView: "chart", redisResultViewMode: "console", resultPaneOpen: false });
|
||||
});
|
||||
|
||||
it("preserves the structured sort field across a data tab round-trip", () => {
|
||||
const [restored] = roundTrip([queryTab({ mode: "data", orderByInput: '"status" ASC', structuredOrderByInput: '"created_at" DESC' })]);
|
||||
|
||||
expect(restored.orderByInput).toBe('"status" ASC');
|
||||
expect(restored.structuredOrderByInput).toBe('"created_at" DESC');
|
||||
});
|
||||
|
||||
it("preserves namespaced special-page state across a round-trip", () => {
|
||||
const uiState = {
|
||||
page: {
|
||||
|
||||
@@ -50,6 +50,7 @@ export interface SavedOpenTab {
|
||||
resultSortDirection?: QueryTab["resultSortDirection"];
|
||||
resultSortMode?: QueryTab["resultSortMode"];
|
||||
orderByInput?: string;
|
||||
structuredOrderByInput?: string;
|
||||
resultPageLimit?: number;
|
||||
resultPageOffset?: number;
|
||||
whereInput?: string;
|
||||
@@ -196,6 +197,7 @@ export function serializeOpenTabs(tabs: QueryTab[]): SavedOpenTab[] {
|
||||
...(tab.resultSortDirection !== undefined ? { resultSortDirection: tab.resultSortDirection } : {}),
|
||||
...(tab.resultSortMode !== undefined ? { resultSortMode: tab.resultSortMode } : {}),
|
||||
...(tab.orderByInput !== undefined ? { orderByInput: tab.orderByInput } : {}),
|
||||
...(tab.structuredOrderByInput !== undefined ? { structuredOrderByInput: tab.structuredOrderByInput } : {}),
|
||||
...(tab.resultPageLimit !== undefined ? { resultPageLimit: tab.resultPageLimit } : {}),
|
||||
...(tab.resultPageOffset !== undefined ? { resultPageOffset: tab.resultPageOffset } : {}),
|
||||
...(tab.whereInput !== undefined ? { whereInput: tab.whereInput } : {}),
|
||||
|
||||
@@ -30,6 +30,23 @@ describe("restoredDataTabReloadFilters", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("recombines the persisted structured ORDER BY with the manual input for restored tabs", () => {
|
||||
expect(
|
||||
restoredDataTabReloadFilters({
|
||||
whereInput: "status = 'active'",
|
||||
orderByInput: '"name" ASC',
|
||||
structuredOrderByInput: '"age" DESC, "created_at" ASC',
|
||||
}),
|
||||
).toEqual({
|
||||
whereInput: "status = 'active'",
|
||||
orderBy: '"name" ASC, "age" DESC, "created_at" ASC',
|
||||
});
|
||||
expect(restoredDataTabReloadFilters({ whereInput: undefined, orderByInput: undefined, structuredOrderByInput: '"age" DESC' })).toEqual({
|
||||
whereInput: undefined,
|
||||
orderBy: '"age" DESC',
|
||||
});
|
||||
});
|
||||
|
||||
it("reports blank filters as absent so the reload does not emit an empty WHERE/ORDER BY", () => {
|
||||
expect(restoredDataTabReloadFilters({ whereInput: "", orderByInput: undefined })).toEqual({ whereInput: undefined, orderBy: undefined });
|
||||
expect(restoredDataTabReloadFilters({ whereInput: " ", orderByInput: " " })).toEqual({ whereInput: undefined, orderBy: undefined });
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { combineDataGridOrderByInputs } from "@/composables/useDataGridSortBuilder";
|
||||
import type { QueryTab } from "@/types/database";
|
||||
|
||||
type RefreshableDataTab = Pick<QueryTab, "mode" | "result" | "isExecuting">;
|
||||
@@ -6,7 +7,7 @@ export function canReloadUnavailableDataTab(tab: RefreshableDataTab): boolean {
|
||||
return tab.mode === "data" && !tab.result && !tab.isExecuting;
|
||||
}
|
||||
|
||||
type RestoredDataTabFilters = Pick<QueryTab, "whereInput" | "orderByInput">;
|
||||
type RestoredDataTabFilters = Pick<QueryTab, "whereInput" | "orderByInput" | "structuredOrderByInput">;
|
||||
|
||||
// 恢复的数据标签页没有 result,刷新走的是 DataGrid 之外那条不带参数的 reload 入口。
|
||||
// onReloadData 把缺省的 whereInput/orderBy 当成“用户已清空”(DataGrid 清空筛选时
|
||||
@@ -15,6 +16,6 @@ type RestoredDataTabFilters = Pick<QueryTab, "whereInput" | "orderByInput">;
|
||||
export function restoredDataTabReloadFilters(tab: RestoredDataTabFilters): { whereInput?: string; orderBy?: string } {
|
||||
return {
|
||||
whereInput: tab.whereInput?.trim() || undefined,
|
||||
orderBy: tab.orderByInput?.trim() || undefined,
|
||||
orderBy: combineDataGridOrderByInputs(tab.orderByInput, tab.structuredOrderByInput),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user