Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: clear states when switching tab mode (#3489)

Liu Jic50a56cf76dd
diff --git a/frontend/src/store/modules/tab.ts b/frontend/src/store/modules/tab.ts
index aea3b6a171..a5d3df15ff 100644
--- a/frontend/src/store/modules/tab.ts
+++ b/frontend/src/store/modules/tab.ts
@@ -3,7 +3,7 @@ import { computed, reactive, ref, watch } from "vue";
import { pick } from "lodash-es";
import { watchThrottled } from "@vueuse/core";
import type { TabInfo, AnyTabInfo } from "@/types";
-import { UNKNOWN_ID } from "@/types";
+import { UNKNOWN_ID, TabMode } from "@/types";
import {
getDefaultTab,
INITIAL_TAB,
@@ -12,6 +12,7 @@ import {
} from "@/utils";
import { useInstanceStore } from "./instance";
import { useSheetStore } from "./sheet";
+import { useWebTerminalStore } from "./webTerminal";
const LOCAL_STORAGE_KEY_PREFIX = "bb.sql-editor.tab-list";
const KEYS = {
@@ -129,6 +130,23 @@ export const useTabStore = defineStore("tab", () => {
},
{ deep: true, immediate, throttle: 100, trailing: true }
);
+
+ watch(
+ () => tab.mode,
+ (mode) => {
+ // When switched to read-only-mode, clear the tab's query list
+ // so we can re-init it next-time.
+ if (mode === TabMode.ReadOnly) {
+ useWebTerminalStore().clearQueryListByTab(tab);
+ }
+
+ // And we should clear the tab's query result
+ // so we won't carry the results in Admin mode to read-only mode.
+ // vice versa
+ tab.executeParams = undefined;
+ tab.queryResult = undefined;
+ }
+ );
};
// Load session from local storage.