Skip to content

armgit / dbx

Public Imported from GitHub
0

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。

fix(grid): reset query result sorting on rerun

zipg423d20bdd7e0
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index 7ff191742f..8c8fc8ce00 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -35,6 +35,7 @@ import {
PanelRight,
TableProperties,
Database,
+ Eraser,
Columns3,
PencilRuler,
WandSparkles,
@@ -492,7 +493,7 @@ function sortMenuItems(column: string, columnIndex: number) {
currentPageDescending: t("grid.sortCurrentPageDescending"),
clear: t("grid.clearSort"),
},
- icons: { database: Database, ascending: ArrowUp, descending: ArrowDown, clear: ArrowUpDown },
+ icons: { database: Database, ascending: ArrowUp, descending: ArrowDown, clear: Eraser },
});
}
@@ -7364,7 +7365,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
localDescending: t("grid.sortCurrentPageDescending"),
clearSort: t("grid.clearSort"),
},
- icons: { copy: Copy, columnDetails: TableProperties, database: Database, ascending: ArrowUp, descending: ArrowDown, clearSort: ArrowUpDown },
+ icons: { copy: Copy, columnDetails: TableProperties, database: Database, ascending: ArrowUp, descending: ArrowDown, clearSort: Eraser },
actions: { copyName: copyHeaderColumn, copyNames: copyColumnNames, details: openContextColumnDetailDialog, copyAlterSql: copyAlterColumnSql, sort: applyContextSort },
filterSubmenu: filterSubmenu(),
}),
@@ -7847,9 +7848,10 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
:items="sortMenuItems(col.name, col.actualColIdx)"
:open="headerSortMenuOpenColumn === col.actualColIdx"
:selected-value="selectedSortMenuValue(col.name, col.actualColIdx)"
+ check-position="none"
align="end"
content-class="w-max min-w-28 p-0.5"
- item-class="gap-1 px-1.5 py-0.5 text-xs"
+ item-class="gap-1 rounded-none px-1.5 py-0.5 text-xs"
item-icon-class="h-3 w-3"
:match-trigger-width="false"
@update:open="(value: boolean) => (headerSortMenuOpenColumn = value ? col.actualColIdx : null)"
@@ -7858,8 +7860,8 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
<template #trigger="{ open, toggle }">
<button
type="button"
- class="flex h-4 w-4 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-gray-200 dark:hover:bg-gray-800 hover:text-foreground"
- :class="columnIsSorted(col.name, col.actualColIdx) ? 'text-primary opacity-100' : 'opacity-80'"
+ class="flex h-4 w-4 shrink-0 items-center justify-center rounded"
+ :class="columnIsSorted(col.name, col.actualColIdx) ? 'bg-primary text-primary-foreground opacity-100 shadow-sm hover:bg-primary/90' : 'text-muted-foreground opacity-80 hover:bg-accent hover:text-foreground'"
:title="t('grid.sort')"
:aria-expanded="open"
@mousedown.stop
diff --git a/apps/desktop/src/stores/__tests__/queryStore.hiddenPrimaryKey.spec.ts b/apps/desktop/src/stores/__tests__/queryStore.hiddenPrimaryKey.spec.ts
index 3b6c3bc96f..43006e35d7 100644
--- a/apps/desktop/src/stores/__tests__/queryStore.hiddenPrimaryKey.spec.ts
+++ b/apps/desktop/src/stores/__tests__/queryStore.hiddenPrimaryKey.spec.ts
@@ -332,6 +332,27 @@ describe("queryStore hidden primary key editing", () => {
expect(tab.queryAnalysis).toBeDefined();
});
+ it("clears result sorting when the editor SQL is executed again", async () => {
+ const { useQueryStore } = await import("@/stores/queryStore");
+ const store = useQueryStore();
+ const tabId = store.createTab("mysql-1", "app", "Query");
+ const tab = store.tabs.find((item) => item.id === tabId)!;
+ tab.resultSortColumn = "name";
+ tab.resultSortColumnIndex = 0;
+ tab.resultSortDirection = "desc";
+ tab.resultSortMode = "database";
+ tab.resultSortedSql = "SELECT name FROM users ORDER BY name DESC";
+
+ await store.executeCurrentSql("SELECT name FROM users");
+
+ expect(tab.resultSortColumn).toBeUndefined();
+ expect(tab.resultSortColumnIndex).toBeUndefined();
+ expect(tab.resultSortDirection).toBeUndefined();
+ expect(tab.resultSortMode).toBeUndefined();
+ expect(tab.resultSortedSql).toBeUndefined();
+ expect(executeMulti).toHaveBeenLastCalledWith("mysql-1", "app", "SELECT name, `id` AS `__DBX_PK_0` FROM users", undefined, expect.any(String), expect.objectContaining({ timeoutSecs: 30 }));
+ });
+
it("preserves the original query behavior when the primary key is already returned", async () => {
analyzeEditableQueryEditability.mockResolvedValue({
editable: true,
diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.ts
index 1770a6d182..de9c4339d8 100644
--- a/apps/desktop/src/stores/queryStore.ts
+++ b/apps/desktop/src/stores/queryStore.ts
@@ -2357,6 +2357,14 @@ export const useQueryStore = defineStore("query", () => {
async function executeCurrentSql(sql: string, options?: { skipRedisSafetyCheck?: boolean; sourceOffset?: number }) {
if (!activeTabId.value) return;
+ const tab = tabs.value.find((item) => item.id === activeTabId.value);
+ if (tab?.mode === "query") {
+ tab.resultSortColumn = undefined;
+ tab.resultSortColumnIndex = undefined;
+ tab.resultSortDirection = undefined;
+ tab.resultSortMode = undefined;
+ tab.resultSortedSql = undefined;
+ }
await executeTabSql(activeTabId.value, sql, { resultBaseSql: sql, resultSortedSql: undefined, ...options });
}