fix(grid): persist WHERE filter input across tab switches (closes #210)

whereFilterInput was a component-local ref that got lost when switching
tabs because DataGrid is destroyed and recreated via :key binding.

Store whereInput in the QueryTab state and pass it as initialWhereInput
prop so it survives tab switches.
This commit is contained in:
t8y2
2026-05-11 12:24:08 +08:00
parent cb70625bd8
commit 8032c63727
4 changed files with 7 additions and 1 deletions
+2 -1
View File
@@ -80,6 +80,7 @@ const props = defineProps<{
connectionId?: string;
database?: string;
context?: "results" | "table-data";
initialWhereInput?: string;
tableMeta?: {
schema?: string;
tableName: string;
@@ -228,7 +229,7 @@ const orderBySuggestionLeft = ref(0);
const orderByInput = ref("");
const hasOrderByInput = computed(() => orderByInput.value.trim().length > 0);
const whereFilterInput = ref("");
const whereFilterInput = ref(props.initialWhereInput ?? "");
const hasWhereFilterInput = computed(() => whereFilterInput.value.trim().length > 0);
type LocalColumnFilterDraft = {
+1
View File
@@ -374,6 +374,7 @@ function onHandleCloseColumnPanel() {
:loading="activeTab.isExecuting"
:editable="!!activeTab.tableMeta?.primaryKeys?.length"
context="table-data"
:initial-where-input="activeTab.whereInput"
:database-type="activeConnection?.db_type"
:connection-id="activeTab.connectionId"
:database="activeTab.database"
+3
View File
@@ -48,6 +48,7 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)
const tab = activeTab.value;
if (!tab) return;
if (tab.mode === "data" && tab.tableMeta) {
tab.whereInput = whereInput ?? "";
queryStore.updateSql(tab.id, buildTableSql(tab, { whereInput, orderBy }));
await queryStore.executeCurrentTab();
return;
@@ -72,6 +73,7 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)
async function onPaginate(offset: number, limit: number, whereInput?: string, orderBy?: string) {
const tab = activeTab.value;
if (!tab?.tableMeta) return;
tab.whereInput = whereInput ?? "";
const sql = buildTableSql(tab, { limit, offset, whereInput, orderBy });
queryStore.updateSql(tab.id, sql);
await queryStore.executeCurrentTab();
@@ -83,6 +85,7 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)
if (tab.mode === "data") {
if (!tab.tableMeta) return;
tab.whereInput = whereInput ?? "";
const orderBy = direction ? `${quoteIdent(tab, column)} ${direction.toUpperCase()}` : undefined;
const sql = buildTableSql(tab, { orderBy, whereInput });
queryStore.updateSql(tab.id, sql);
+1
View File
@@ -251,6 +251,7 @@ export interface QueryTab {
selectStar: boolean;
columns: string[];
};
whereInput?: string;
}
export interface SavedSqlFolder {