fix(grid): reset query result sorting on rerun

This commit is contained in:
zipg 2026-07-21 17:29:47 +08:00 committed by GitHub
parent cdfcbad4e9
commit 423d20bdd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 5 deletions

View File

@ -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

View File

@ -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,

View File

@ -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 });
}