25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(grid): clear the header sort state when a refresh drops the order (#13350) (#13371)
HighBigSkycaf09e948f09
diff --git a/apps/desktop/src/composables/__tests__/useDataGridActions.spec.ts b/apps/desktop/src/composables/__tests__/useDataGridActions.spec.tsindex c961046080..999c4141a7 100644--- a/apps/desktop/src/composables/__tests__/useDataGridActions.spec.ts+++ b/apps/desktop/src/composables/__tests__/useDataGridActions.spec.ts@@ -919,6 +919,76 @@ describe("useDataGridActions", () => {expect(tab.orderByInput).toBe("LOWER(new_name) ASC");});+ it("keeps the active column sort when a refresh rebuilds the same columns", async () => {+ // issue #13350 的期望行为:列头排序后点刷新,只要排序列仍在重建后的表结构里,+ // ORDER BY 必须原样下推,排序状态原样保留,数据继续按该列有序。+ const columns = [+ { name: "id", data_type: "integer", is_nullable: false, column_default: null, is_primary_key: true, extra: null },+ { name: "create_time", data_type: "timestamp", is_nullable: true, column_default: null, is_primary_key: false, extra: null },+ ];+ const tab = tableDataTab({+ resultSortColumn: "create_time",+ resultSortColumnIndex: 1,+ resultSortDirection: "asc",+ resultSortMode: "database",+ orderByInput: '"create_time" ASC',+ tableMeta: {+ schema: "public",+ tableName: "users",+ tableType: "TABLE",+ columns,+ primaryKeys: ["id"],+ },+ });+ mocks.tabs.push(tab);+ mocks.getColumns.mockResolvedValue(columns);+ const actions = useDataGridActions(computed(() => tab));++ await actions.onReloadData(tab.id, tab.sql, "", "", '"create_time" ASC', undefined, undefined, "refresh");++ expect(mocks.buildTableSelectSql).toHaveBeenCalledWith(expect.objectContaining({ orderBy: '"create_time" ASC' }));+ expect(tab.resultSortColumn).toBe("create_time");+ expect(tab.resultSortDirection).toBe("asc");+ expect(tab.orderByInput).toBe('"create_time" ASC');+ });++ it("clears the header sort state when a refresh drops the incoming order", async () => {+ // 不变量(issue #13350 的用户可见症状):刷新一旦移除 ORDER BY,列头排序图标+ // 必须同步熄灭,否则出现「图标亮、数据无序」的错位。构造 grid 发来的 orderBy+ // 引用了已不存在的列,而标签页排序状态仍指向存活的 create_time —— 元数据+ // 重建不会清理它,移除 ORDER BY 后排序状态必须一并清理。+ const columns = [+ { name: "id", data_type: "integer", is_nullable: false, column_default: null, is_primary_key: true, extra: null },+ { name: "create_time", data_type: "timestamp", is_nullable: true, column_default: null, is_primary_key: false, extra: null },+ ];+ const tab = tableDataTab({+ resultSortColumn: "create_time",+ resultSortColumnIndex: 1,+ resultSortDirection: "asc",+ resultSortMode: "database",+ orderByInput: '"create_time" ASC',+ tableMeta: {+ schema: "public",+ tableName: "users",+ tableType: "TABLE",+ columns,+ primaryKeys: ["id"],+ },+ });+ mocks.tabs.push(tab);+ mocks.getColumns.mockResolvedValue(columns);+ const actions = useDataGridActions(computed(() => tab));++ await actions.onReloadData(tab.id, tab.sql, "", "", '"ghost_col" ASC', undefined, undefined, "refresh");++ expect(mocks.buildTableSelectSql).toHaveBeenCalledWith(expect.objectContaining({ orderBy: undefined }));+ expect(tab.orderByInput).toBeUndefined();+ expect(tab.resultSortColumn).toBeUndefined();+ expect(tab.resultSortColumnIndex).toBeUndefined();+ expect(tab.resultSortDirection).toBeUndefined();+ expect(tab.resultSortMode).toBeUndefined();+ });+it("keeps SQL result toolbar reload free of table pagination defaults", async () => {const tab = {id: "tab-1",diff --git a/apps/desktop/src/composables/useDataGridActions.ts b/apps/desktop/src/composables/useDataGridActions.tsindex 34358d2b68..760950bf34 100644--- a/apps/desktop/src/composables/useDataGridActions.ts+++ b/apps/desktop/src/composables/useDataGridActions.ts@@ -448,7 +448,23 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)queryStore.clearInvalidDataTabSort(tab.id);const rebuiltColumnNames = tab.tableMeta?.columns.map((column) => column.name) ?? [];incomingSortMissing = rebuiltColumnNames.length > 0 && simpleDataGridOrderByReferencesMissingColumn(orderBy, rebuiltColumnNames);- if (incomingSortMissing) tab.orderByInput = undefined;+ if (incomingSortMissing) {+ // 移除 ORDER BY 时必须同步熄灭列头排序图标(issue #13350):这里的+ // 清理发生在元数据重建之后,clearInvalidDataTabSort 早已用旧列清单+ // 判定过一次;若排序状态仍指向存活的列,它不会被前者清掉,只清+ // orderByInput 会留下「图标亮、数据无序」的错位。字段集合与+ // queryStore.clearInvalidDataTabSortState 的失效排序清理保持一致。+ tab.orderByInput = undefined;+ tab.resultSortColumn = undefined;+ tab.resultSortColumnIndex = undefined;+ tab.resultSortDirection = undefined;+ tab.resultSortMode = undefined;+ tab.resultSortedSql = undefined;+ tab.resultLocalSortOriginalRows = undefined;+ tab.resultLocalSortOriginalLargeValueCells = undefined;+ tab.resultLocalSortOriginalMongoDocuments = undefined;+ tab.resultLocalSortOriginalMongoCopyDocuments = undefined;+ }if (intent === "refresh" && !lifecycleStale) {void refreshDataTabTableMeta(tab, { force: false, trace: { traceId, elapsed } }).then(() => {