Skip to content

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

chore: ignore project switch in sql editor (#18339)

ecmadaod2111eef291b
diff --git a/frontend/src/components/v2/Select/ProjectSelect.vue b/frontend/src/components/v2/Select/ProjectSelect.vue
index 7086aabf07..99eea5fc29 100644
--- a/frontend/src/components/v2/Select/ProjectSelect.vue
+++ b/frontend/src/components/v2/Select/ProjectSelect.vue
@@ -24,7 +24,7 @@
<script lang="tsx" setup>
import { useDebounceFn } from "@vueuse/core";
import { intersection } from "lodash-es";
-import { computed, onMounted, reactive, watchEffect } from "vue";
+import { computed, reactive, watch, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
import { ProjectNameCell } from "@/components/v2/Model/cells";
import { usePermissionStore, useProjectV1Store } from "@/store";
@@ -177,11 +177,25 @@ const handleSearch = useDebounceFn(async (search: string) => {
}
}, DEBOUNCE_SEARCH_DELAY);
-// Only fetch selected project(s) on mount, not the entire list.
-// The full list will be fetched lazily when dropdown is opened.
-onMounted(async () => {
- await initProjectList();
-});
+watch(
+ () => props.projectName,
+ async (newVal) => {
+ if (newVal) {
+ await initSelectedProjects([newVal]);
+ }
+ },
+ { immediate: true }
+);
+
+watch(
+ () => props.projectNames,
+ async (newVal) => {
+ if (newVal) {
+ await initSelectedProjects(newVal);
+ }
+ },
+ { immediate: true }
+);
const options = computed(
(): {
diff --git a/frontend/src/store/modules/sqlEditor/editor.ts b/frontend/src/store/modules/sqlEditor/editor.ts
index 04921186a3..60c9790f2e 100644
--- a/frontend/src/store/modules/sqlEditor/editor.ts
+++ b/frontend/src/store/modules/sqlEditor/editor.ts
@@ -39,7 +39,8 @@ export const useSQLEditorStore = defineStore("sqlEditor", () => {
const projectContextReady = ref<boolean>(false);
const storedLastViewedProject = useLocalStorage<string>(
"bb.sql-editor.last-viewed-project",
- ""
+ "",
+ { listenToStorageChanges: false }
);
const allowViewALLProjects = computed(() => {
diff --git a/frontend/src/store/modules/sqlEditor/tab.ts b/frontend/src/store/modules/sqlEditor/tab.ts
index e4703644c1..52e480a556 100644
--- a/frontend/src/store/modules/sqlEditor/tab.ts
+++ b/frontend/src/store/modules/sqlEditor/tab.ts
@@ -238,6 +238,26 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
}
};
+ const updateCache = (tab: SQLEditorTab) => {
+ const draftIndex = draftTabList.value.findIndex(
+ (item) => item.id === tab.id
+ );
+ if (draftIndex >= 0) {
+ Object.assign(draftTabList.value[draftIndex], tab);
+ }
+
+ const openTabIndex = openTabList.value.findIndex(
+ (item) => item.id === tab.id
+ );
+ if (openTabIndex >= 0) {
+ const persistentTab = pick(
+ tab,
+ ...PERSISTENT_TAB_FIELDS
+ ) as PersistentTab;
+ Object.assign(openTabList.value[openTabIndex], persistentTab);
+ }
+ };
+
const updateTab = (id: string, payload: Partial<SQLEditorTab>) => {
const tab = tabById(id);
if (!tab) return;
@@ -245,6 +265,8 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
if (payload.worksheet) {
removeDraft(tab);
+ } else {
+ updateCache(tab);
}
};