Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: tab view state (#15745)
ecmadao0ccae095a7f0
diff --git a/frontend/src/store/modules/sqlEditor/editor.ts b/frontend/src/store/modules/sqlEditor/editor.tsindex bc5422f5f2..3d4c8fe8c1 100644--- a/frontend/src/store/modules/sqlEditor/editor.ts+++ b/frontend/src/store/modules/sqlEditor/editor.ts@@ -104,5 +104,6 @@ export const useSQLEditorStore = defineStore("sqlEditor", () => {prepareDatabases,fetchDatabases,loading: computed(() => fetchDataState.value.loading),+ canLoadMore: computed(() => !!fetchDataState.value.nextPageToken),};});diff --git a/frontend/src/store/modules/sqlEditor/index.ts b/frontend/src/store/modules/sqlEditor/index.tsindex 8f62bc4914..95ca2f5072 100644--- a/frontend/src/store/modules/sqlEditor/index.ts+++ b/frontend/src/store/modules/sqlEditor/index.ts@@ -3,3 +3,4 @@ export * from "./tab";export * from "./tree";export * from "./queryHistory";export * from "./webTerminal";+export * from "./tabViewState";diff --git a/frontend/src/store/modules/sqlEditor/tab.ts b/frontend/src/store/modules/sqlEditor/tab.tsindex 1e3c481353..a772b9b489 100644--- a/frontend/src/store/modules/sqlEditor/tab.ts+++ b/frontend/src/store/modules/sqlEditor/tab.ts@@ -31,6 +31,7 @@ import {useExtendedTabStore,type ExtendedTab,} from "./extendedTab";+import { useTabViewStateStore } from "./tabViewState";import { useWebTerminalStore } from "./webTerminal";const LOCAL_STORAGE_KEY_PREFIX = "bb.sql-editor-tab";@@ -61,6 +62,8 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {deleteExtendedTab,cleanupExtendedTabs,} = useExtendedTabStore();+ const tabViewStateStore = useTabViewStateStore();+const me = useCurrentUserV1();const userUID = computed(() => extractUserId(me.value.name));const keyNamespace = computed(@@ -262,7 +265,10 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {curr.connection = tab.connection;curr.worksheet = tab.worksheet;curr.mode = tab.mode;- if (defaultTitle) {+ if (+ defaultTitle &&+ tabViewStateStore.getViewState(curr.id).view === "CODE"+ ) {curr.title = defaultTitle;}return;diff --git a/frontend/src/store/modules/sqlEditor/tabViewState.ts b/frontend/src/store/modules/sqlEditor/tabViewState.tsnew file mode 100644index 0000000000..f20fed1e72--- /dev/null+++ b/frontend/src/store/modules/sqlEditor/tabViewState.ts@@ -0,0 +1,52 @@+import { cloneDeep } from "lodash-es";+import { defineStore } from "pinia";+import { computed } from "vue";+import { useCurrentUserV1, extractUserId } from "@/store";+import {+ defaultViewState,+ type EditorPanelViewState as ViewState,+} from "@/types";+import { useDynamicLocalStorage } from "@/utils";++export const useTabViewStateStore = defineStore("tabViewState", () => {+ const me = useCurrentUserV1();+ const userUID = computed(() => extractUserId(me.value.name));++ const viewStateByTab = useDynamicLocalStorage<+ Map</* tab.id */ string, ViewState>+ >(+ computed(() => `bb.sql-editor-tab-state.${userUID.value}`),+ new Map()+ );++ const removeViewState = (tabId: string) => {+ viewStateByTab.value.delete(tabId);+ };++ const getViewState = (tabId: string) => {+ return viewStateByTab.value.get(tabId) ?? defaultViewState();+ };++ const updateViewState = (tabId: string, patch: Partial<ViewState>) => {+ const curr = getViewState(tabId);+ if (!curr) return;++ Object.assign(curr, patch);+ viewStateByTab.value.set(tabId, curr);+ };++ const cloneViewState = (from: string, to: string) => {+ const vs = viewStateByTab.value.get(from);+ if (!vs) return;+ const cloned = cloneDeep(vs);+ viewStateByTab.value.set(to, cloned);+ return cloned;+ };++ return {+ getViewState,+ removeViewState,+ updateViewState,+ cloneViewState,+ };+});diff --git a/frontend/src/types/sqlEditor/index.ts b/frontend/src/types/sqlEditor/index.tsindex 6cad6a7266..02d72b06d8 100644--- a/frontend/src/types/sqlEditor/index.ts+++ b/frontend/src/types/sqlEditor/index.ts@@ -1,3 +1,4 @@export * from "./editor";export * from "./tab";export * from "./tree";+export * from "./tabViewState";diff --git a/frontend/src/views/sql-editor/EditorPanel/types.ts b/frontend/src/types/sqlEditor/tabViewState.tssimilarity index 100%rename from frontend/src/views/sql-editor/EditorPanel/types.tsrename to frontend/src/types/sqlEditor/tabViewState.tsdiff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vueindex f433b2efa6..ce98a4d8b0 100644--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/SchemaPane.vue@@ -109,7 +109,7 @@ import {findAncestor,isDescendantOf,} from "@/utils";-import { useEditorPanelContext } from "../../EditorPanel";+import { useCurrentTabViewStateContext } from "../../EditorPanel";import { useSQLEditorContext } from "../../context";import HoverPanel, { provideHoverStateContext } from "./HoverPanel";import SyncSchemaButton from "./SyncSchemaButton.vue";@@ -135,7 +135,7 @@ const { height: treeContainerHeight } = useElementSize(});const searchPatternByTabId = reactive(new Map<string, string>());-const { viewState: panelViewState } = useEditorPanelContext();+const { viewState: panelViewState } = useCurrentTabViewStateContext();const { schemaViewer } = useSQLEditorContext();const {show: showDropdown,diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsxindex ac6c42ad5e..478cc35436 100644--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx@@ -38,6 +38,9 @@ import {type ComposedDatabase,type Position,type SQLEditorConnection,+ type EditorPanelView,+ type EditorPanelViewState,+ typeToView,} from "@/types";import { Engine } from "@/types/proto/v1/common";import {@@ -60,9 +63,7 @@ import {} from "@/utils";import { keyWithPosition } from "../../EditorCommon";import {- type EditorPanelView,- useEditorPanelContext,- type EditorPanelViewState,+ useCurrentTabViewStateContext,} from "../../EditorPanel";import { useSQLEditorContext } from "../../context";import type { NodeTarget, NodeType, TreeNode } from "./common";@@ -131,7 +132,7 @@ const confirmOverrideStatement = async (};export const useActions = () => {- const { updateViewState, typeToView } = useEditorPanelContext();+ const { updateViewState } = useCurrentTabViewStateContext();const selectAllFromTableOrView = async (node: TreeNode) => {const { target } = (node as TreeNode<"table" | "view">).meta;diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vueindex 298b17d53e..d36e5c5f81 100644--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue@@ -43,7 +43,10 @@:theme-overrides="{ nodeHeight: '21px' }":render-label="renderLabel"/>- <div class="w-full flex items-center justify-center">+ <div+ v-if="editorStore.canLoadMore"+ class="w-full flex items-center justify-center"+ ><NButtonquaternary:size="'small'"diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTableColumnsTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTableColumnsTable.vueindex d05d2880d4..2fddca2259 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTableColumnsTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTableColumnsTable.vue@@ -32,7 +32,7 @@ import type {} from "@/types/proto/v1/database_service";import { getHighlightHTMLByRegExp, useAutoHeightDataTable } from "@/utils";import { EllipsisCell } from "../../common";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";const props = defineProps<{db: ComposedDatabase;@@ -42,7 +42,7 @@ const props = defineProps<{keyword?: string;}>();-const { viewState } = useEditorPanelContext();+const { viewState } = useCurrentTabViewStateContext();const { containerElRef, tableBodyHeight, layoutReady, virtualListRef } =useAutoHeightDataTable();const dataTableRef = ref<DataTableInst>();diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTablesPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTablesPanel.vueindex a00729d07e..5110af64f1 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTablesPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTablesPanel.vue@@ -70,12 +70,12 @@ import {SchemaMetadata,ExternalTableMetadata,} from "@/types/proto/v1/database_service";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";import ExternalTableColumnsTable from "./ExternalTableColumnsTable.vue";import ExternalTablesTable from "./ExternalTablesTable.vue";const { database } = useConnectionOfCurrentSQLEditorTab();-const { viewState, updateViewState } = useEditorPanelContext();+const { viewState, updateViewState } = useCurrentTabViewStateContext();const databaseMetadata = computed(() => {return useDBSchemaV1Store().getDatabaseMetadata(database.value.name);});diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTablesTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTablesTable.vueindex 8311f5dafc..ed62669c3d 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTablesTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTablesTable.vue@@ -29,7 +29,7 @@ import type {ExternalTableMetadata,} from "@/types/proto/v1/database_service";import { getHighlightHTMLByRegExp, useAutoHeightDataTable } from "@/utils";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";const props = defineProps<{db: ComposedDatabase;@@ -51,7 +51,7 @@ const emit = defineEmits<{): void;}>();-const { viewState } = useEditorPanelContext();+const { viewState } = useCurrentTabViewStateContext();const { t } = useI18n();const filteredExternalTables = computed(() => {const keyword = props.keyword?.trim().toLowerCase();diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsPanel.vueindex a6c576eb10..f3a443aa76 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsPanel.vue@@ -52,12 +52,12 @@ import {extractKeyWithPosition,keyWithPosition,} from "@/views/sql-editor/EditorCommon";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";import { CodeViewer } from "../common";import FunctionsTable from "./FunctionsTable.vue";const { database } = useConnectionOfCurrentSQLEditorTab();-const { viewState, updateViewState } = useEditorPanelContext();+const { viewState, updateViewState } = useCurrentTabViewStateContext();const databaseMetadata = computed(() => {return useDBSchemaV1Store().getDatabaseMetadata(database.value.name);});diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsTable.vueindex 54400d33eb..4226578ca7 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsTable.vue@@ -30,7 +30,7 @@ import type {} from "@/types/proto/v1/database_service";import { getHighlightHTMLByRegExp, useAutoHeightDataTable } from "@/utils";import { keyWithPosition } from "@/views/sql-editor/EditorCommon";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";type FunctionWithPosition = { func: FunctionMetadata; position: number };@@ -56,7 +56,7 @@ const emit = defineEmits<{}>();const { t } = useI18n();-const { viewState } = useEditorPanelContext();+const { viewState } = useCurrentTabViewStateContext();const funcsWithPosition = computed(() => {return props.funcs.map<FunctionWithPosition>((func, position) => ({diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/InfoPanel/InfoPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/InfoPanel/InfoPanel.vueindex 953001dcc0..35f4d50495 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/InfoPanel/InfoPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/InfoPanel/InfoPanel.vue@@ -220,7 +220,7 @@ import {instanceV1SupportsSequence,} from "@/utils";import { keyWithPosition } from "@/views/sql-editor/EditorCommon";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";import ExternalTablesTable from "../ExternalTablesPanel/ExternalTablesTable.vue";import FunctionsTable from "../FunctionsPanel/FunctionsTable.vue";import PackagesTable from "../PackagesPanel/PackagesTable.vue";@@ -242,7 +242,7 @@ const state = reactive({});const { database } = useConnectionOfCurrentSQLEditorTab();-const { viewState, updateViewState } = useEditorPanelContext();+const { viewState, updateViewState } = useCurrentTabViewStateContext();const databaseMetadata = computed(() => {return useDBSchemaV1Store().getDatabaseMetadata(database.value.name);});diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/PackagesPanel/PackagesPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/PackagesPanel/PackagesPanel.vueindex 366a8f7113..a22683ac4b 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/PackagesPanel/PackagesPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/PackagesPanel/PackagesPanel.vue@@ -52,12 +52,12 @@ import {extractKeyWithPosition,keyWithPosition,} from "@/views/sql-editor/EditorCommon";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";import { CodeViewer } from "../common";import PackagesTable from "./PackagesTable.vue";const { database } = useConnectionOfCurrentSQLEditorTab();-const { viewState, updateViewState } = useEditorPanelContext();+const { viewState, updateViewState } = useCurrentTabViewStateContext();const databaseMetadata = computed(() => {return useDBSchemaV1Store().getDatabaseMetadata(database.value.name);});diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/PackagesPanel/PackagesTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/PackagesPanel/PackagesTable.vueindex 8cebcd66ac..eebd3f8925 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/PackagesPanel/PackagesTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/PackagesPanel/PackagesTable.vue@@ -32,7 +32,7 @@ import type {} from "@/types/proto/v1/database_service";import { getHighlightHTMLByRegExp, useAutoHeightDataTable } from "@/utils";import { keyWithPosition } from "@/views/sql-editor/EditorCommon";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";type PackageWithPosition = {package: PackageMetadata;@@ -61,7 +61,7 @@ const emit = defineEmits<{}>();const { t } = useI18n();-const { viewState } = useEditorPanelContext();+const { viewState } = useCurrentTabViewStateContext();const packagesWithPosition = computed(() => {return props.packages.map<PackageWithPosition>((pack, position) => ({diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/Panels.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/Panels.vueindex 6dee1e783e..00492d6b92 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/Panels.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/Panels.vue@@ -66,7 +66,7 @@ import {type VueClass,} from "@/utils";import DatabaseChooser from "@/views/sql-editor/EditorCommon/DatabaseChooser.vue";-import { useEditorPanelContext } from "../context";+import { useCurrentTabViewStateContext } from "../context";import DiagramPanel from "./DiagramPanel";import ExternalTablesPanel from "./ExternalTablesPanel";import FunctionsPanel from "./FunctionsPanel";@@ -85,7 +85,7 @@ defineProps<{const { currentTab: tab } = storeToRefs(useSQLEditorTabStore());const { viewState, selectedSchemaName, updateViewState } =- useEditorPanelContext();+ useCurrentTabViewStateContext();const { database } = useConnectionOfCurrentSQLEditorTab();const { execute } = useExecuteSQL();const { events: AIEvents } = useAIContext();diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresPanel.vueindex 822293d90c..ba16b6ea27 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresPanel.vue@@ -52,12 +52,12 @@ import {extractKeyWithPosition,keyWithPosition,} from "@/views/sql-editor/EditorCommon";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";import { CodeViewer } from "../common";import ProceduresTable from "./ProceduresTable.vue";const { database } = useConnectionOfCurrentSQLEditorTab();-const { viewState, updateViewState } = useEditorPanelContext();+const { viewState, updateViewState } = useCurrentTabViewStateContext();const databaseMetadata = computed(() => {return useDBSchemaV1Store().getDatabaseMetadata(database.value.name);});diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresTable.vueindex d47f0bf374..73cd03a3e8 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresTable.vue@@ -32,7 +32,7 @@ import type {} from "@/types/proto/v1/database_service";import { getHighlightHTMLByRegExp, useAutoHeightDataTable } from "@/utils";import { keyWithPosition } from "@/views/sql-editor/EditorCommon";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";type ProcedureWithPosition = {procedure: ProcedureMetadata;@@ -61,7 +61,7 @@ const emit = defineEmits<{}>();const { t } = useI18n();-const { viewState } = useEditorPanelContext();+const { viewState } = useCurrentTabViewStateContext();const proceduresWithPosition = computed(() => {return props.procedures.map<ProcedureWithPosition>((procedure, position) => ({diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/SequencesPanel/SequencesPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/SequencesPanel/SequencesPanel.vueindex e992130ff7..3c58a69cf1 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/SequencesPanel/SequencesPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/SequencesPanel/SequencesPanel.vue@@ -37,11 +37,11 @@ import {extractKeyWithPosition,keyWithPosition,} from "@/views/sql-editor/EditorCommon";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";import SequencesTable from "./SequencesTable.vue";const { database } = useConnectionOfCurrentSQLEditorTab();-const { viewState, updateViewState } = useEditorPanelContext();+const { viewState, updateViewState } = useCurrentTabViewStateContext();const databaseMetadata = computed(() => {return useDBSchemaV1Store().getDatabaseMetadata(database.value.name);});diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/SequencesPanel/SequencesTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/SequencesPanel/SequencesTable.vueindex 32bcf82738..dba6bd9205 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/SequencesPanel/SequencesTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/SequencesPanel/SequencesTable.vue@@ -33,7 +33,7 @@ import type {import { useAutoHeightDataTable } from "@/utils";import { keyWithPosition } from "@/views/sql-editor/EditorCommon";import { EllipsisCell } from "../../common";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";type SequenceWithPosition = { sequence: SequenceMetadata; position: number };@@ -59,7 +59,7 @@ const emit = defineEmits<{}>();const { t } = useI18n();-const { viewState } = useEditorPanelContext();+const { viewState } = useCurrentTabViewStateContext();const funcsWithPosition = computed(() => {return props.sequences.map<SequenceWithPosition>((sequence, position) => ({diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/ColumnsTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/ColumnsTable.vueindex 1bb4f722ab..45bf8d51da 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/ColumnsTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/ColumnsTable.vue@@ -36,7 +36,7 @@ import type {} from "@/types/proto/v1/database_service";import { getHighlightHTMLByRegExp, useAutoHeightDataTable } from "@/utils";import { EllipsisCell } from "../../common";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";const props = defineProps<{db: ComposedDatabase;@@ -46,7 +46,7 @@ const props = defineProps<{keyword?: string;}>();-const { viewState } = useEditorPanelContext();+const { viewState } = useCurrentTabViewStateContext();const { containerElRef, virtualListRef, tableBodyHeight, layoutReady } =useAutoHeightDataTable();const dataTableRef = ref<DataTableInst>();diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/ForeignKeysTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/ForeignKeysTable.vueindex 605ed84273..25b7b6bac6 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/ForeignKeysTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/ForeignKeysTable.vue@@ -31,7 +31,7 @@ import type {TableMetadata,} from "@/types/proto/v1/database_service";import { getHighlightHTMLByRegExp, useAutoHeightDataTable } from "@/utils";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";const props = defineProps<{db: ComposedDatabase;@@ -41,7 +41,7 @@ const props = defineProps<{keyword?: string;}>();-const { viewState } = useEditorPanelContext();+const { viewState } = useCurrentTabViewStateContext();const { containerElRef, virtualListRef, tableBodyHeight, layoutReady } =useAutoHeightDataTable();const dataTableRef = ref<DataTableInst>();diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/IndexesTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/IndexesTable.vueindex e4343c29bb..91de0ccec6 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/IndexesTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/IndexesTable.vue@@ -31,7 +31,7 @@ import type {} from "@/types/proto/v1/database_service";import { getHighlightHTMLByRegExp, useAutoHeightDataTable } from "@/utils";import { EllipsisCell } from "../../common";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";const props = defineProps<{db: ComposedDatabase;@@ -41,7 +41,7 @@ const props = defineProps<{keyword?: string;}>();-const { viewState } = useEditorPanelContext();+const { viewState } = useCurrentTabViewStateContext();const {containerElRef,dataTableRef,diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/PartitionsTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/PartitionsTable.vueindex e3bc743251..112fd04cf5 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/PartitionsTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/PartitionsTable.vue@@ -30,7 +30,7 @@ import {type TableMetadata,} from "@/types/proto/v1/database_service";import { getHighlightHTMLByRegExp, useAutoHeightDataTable } from "@/utils";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";type FlattenTablePartitionMetadata = {partition: TablePartitionMetadata;@@ -46,7 +46,7 @@ const props = defineProps<{}>();const { t } = useI18n();-const { viewState } = useEditorPanelContext();+const { viewState } = useCurrentTabViewStateContext();const {dataTableRef,containerElRef,diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TableDetail.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TableDetail.vueindex 470dfa2783..f5ef40bfc8 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TableDetail.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TableDetail.vue@@ -105,7 +105,7 @@ import type {TableMetadata,} from "@/types/proto/v1/database_service";import { keyWithPosition } from "@/views/sql-editor/EditorCommon";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";import ColumnsTable from "./ColumnsTable.vue";import ForeignKeysTable from "./ForeignKeysTable.vue";import IndexesTable from "./IndexesTable.vue";@@ -126,7 +126,7 @@ const props = defineProps<{}>();const { t } = useI18n();-const { viewState, updateViewState } = useEditorPanelContext();+const { viewState, updateViewState } = useCurrentTabViewStateContext();const state = reactive<LocalState>({view: "COLUMNS",keyword: "",diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TablesPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TablesPanel.vueindex 388c624b96..6676560490 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TablesPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TablesPanel.vue@@ -46,12 +46,12 @@ import {TableMetadata,TablePartitionMetadata,} from "@/types/proto/v1/database_service";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";import TableDetail from "./TableDetail.vue";import TablesTable from "./TablesTable.vue";const { database } = useConnectionOfCurrentSQLEditorTab();-const { viewState, updateViewState } = useEditorPanelContext();+const { viewState, updateViewState } = useCurrentTabViewStateContext();const databaseMetadata = computed(() => {return useDBSchemaV1Store().getDatabaseMetadata(database.value.name);});diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TablesTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TablesTable.vueindex ecd78c2629..f00c01a73d 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TablesTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TablesTable.vue@@ -37,7 +37,7 @@ import {useAutoHeightDataTable,} from "@/utils";import { EllipsisCell } from "../../common";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";const props = defineProps<{db: ComposedDatabase;@@ -59,7 +59,7 @@ const emit = defineEmits<{): void;}>();-const { viewState } = useEditorPanelContext();+const { viewState } = useCurrentTabViewStateContext();const { t } = useI18n();const instanceEngine = computed(() => {return props.db.instanceResource.engine;diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TriggersTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TriggersTable.vueindex 608821e052..da94f2caac 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TriggersTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TriggersTable.vue@@ -69,7 +69,7 @@ import {keyWithPosition,} from "@/views/sql-editor/EditorCommon";import { EllipsisCell } from "../../common";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";import { CodeViewer } from "../common";type TriggerWithPosition = {@@ -100,7 +100,7 @@ const emit = defineEmits<{}>();const { t } = useI18n();-const { viewState, updateViewState } = useEditorPanelContext();+const { viewState, updateViewState } = useCurrentTabViewStateContext();const detail = ref<TriggerWithPosition>();diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ColumnsTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ColumnsTable.vueindex 0c8b7edb9b..af0c1b597f 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ColumnsTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ColumnsTable.vue@@ -32,7 +32,7 @@ import type {} from "@/types/proto/v1/database_service";import { getHighlightHTMLByRegExp, useAutoHeightDataTable } from "@/utils";import { EllipsisCell } from "../../common";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";const props = defineProps<{db: ComposedDatabase;@@ -42,7 +42,7 @@ const props = defineProps<{keyword?: string;}>();-const { viewState } = useEditorPanelContext();+const { viewState } = useCurrentTabViewStateContext();const {dataTableRef,containerElRef,diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/DependencyColumnsTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/DependencyColumnsTable.vueindex 71ed02eeb9..dd5a97dc7e 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/DependencyColumnsTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/DependencyColumnsTable.vue@@ -36,7 +36,7 @@ import {keyForDependencyColumn,useAutoHeightDataTable,} from "@/utils";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";const props = defineProps<{db: ComposedDatabase;@@ -46,7 +46,7 @@ const props = defineProps<{keyword?: string;}>();-const { viewState, updateViewState } = useEditorPanelContext();+const { viewState, updateViewState } = useCurrentTabViewStateContext();const {dataTableRef,containerElRef,diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewDetail.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewDetail.vueindex abd5eecb73..3c233d6be5 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewDetail.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewDetail.vue@@ -88,7 +88,7 @@ import type {ViewMetadata,} from "@/types/proto/v1/database_service";import { OpenAIButton } from "@/views/sql-editor/EditorCommon";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";import ColumnsTable from "./ColumnsTable.vue";import DefinitionViewer from "./DefinitionViewer.vue";import DependencyColumnsTable from "./DependencyColumnsTable.vue";@@ -107,7 +107,7 @@ const props = defineProps<{}>();const { t } = useI18n();-const { viewState, updateViewState } = useEditorPanelContext();+const { viewState, updateViewState } = useCurrentTabViewStateContext();const state = reactive<LocalState>({mode: "COLUMNS",keyword: "",diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewsPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewsPanel.vueindex ad029b8b1e..41cd5ae40d 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewsPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewsPanel.vue@@ -43,12 +43,12 @@ import {ViewMetadata,SchemaMetadata,} from "@/types/proto/v1/database_service";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";import ViewDetail from "./ViewDetail.vue";import ViewsTable from "./ViewsTable.vue";const { database } = useConnectionOfCurrentSQLEditorTab();-const { viewState, updateViewState } = useEditorPanelContext();+const { viewState, updateViewState } = useCurrentTabViewStateContext();const databaseMetadata = computed(() => {return useDBSchemaV1Store().getDatabaseMetadata(database.value.name);});diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewsTable.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewsTable.vueindex 878e661ce9..f15ed6f3bb 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewsTable.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewsTable.vue@@ -30,7 +30,7 @@ import type {} from "@/types/proto/v1/database_service";import { getHighlightHTMLByRegExp, useAutoHeightDataTable } from "@/utils";import { EllipsisCell } from "../../common";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";const props = defineProps<{db: ComposedDatabase;@@ -53,7 +53,7 @@ const emit = defineEmits<{}>();const { t } = useI18n();-const { viewState } = useEditorPanelContext();+const { viewState } = useCurrentTabViewStateContext();const filteredViews = computed(() => {const keyword = props.keyword?.trim().toLowerCase();diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/common/SchemaSelectToolbar.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/common/SchemaSelectToolbar.vueindex 297903ef1c..56537e68f8 100644--- a/frontend/src/views/sql-editor/EditorPanel/Panels/common/SchemaSelectToolbar.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/common/SchemaSelectToolbar.vue@@ -38,7 +38,7 @@ import {useDBSchemaV1Store,} from "@/store";import { hasSchemaProperty } from "@/utils";-import { useEditorPanelContext } from "../../context";+import { useCurrentTabViewStateContext } from "../../context";defineOptions({inheritAttrs: false,@@ -50,7 +50,7 @@ defineProps<{const { t } = useI18n();const { database, instance } = useConnectionOfCurrentSQLEditorTab();-const { selectedSchemaName } = useEditorPanelContext();+const { selectedSchemaName } = useCurrentTabViewStateContext();const databaseMetadata = computed(() => {return useDBSchemaV1Store().getDatabaseMetadata(database.value.name);});diff --git a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vueindex e96579ac9e..4625ac5d28 100644--- a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue@@ -79,6 +79,7 @@ import { AIChatToSQL } from "@/plugins/ai";import {useConnectionOfCurrentSQLEditorTab,useSQLEditorTabStore,+ useTabViewStateStore,} from "@/store";import type { SQLEditorQueryParams } from "@/types";import {@@ -95,7 +96,6 @@ import { useSQLEditorContext } from "../../context";import ReadonlyModeNotSupported from "../ReadonlyModeNotSupported.vue";import ResultPanel from "../ResultPanel";import Welcome from "../Welcome";-import { useEditorPanelContext } from "../context";const SQLEditor = defineAsyncComponent(() => import("./SQLEditor.vue"));@@ -103,7 +103,7 @@ const tabStore = useSQLEditorTabStore();const { currentTab: tab, isDisconnected } = storeToRefs(tabStore);const { instance } = useConnectionOfCurrentSQLEditorTab();const { showAIPanel, AIPanelSize, handleAIPanelResize } = useSQLEditorContext();-const { cloneViewState } = useEditorPanelContext();+const { cloneViewState } = useTabViewStateStore();const sqlEditorRef = ref<InstanceType<typeof SQLEditor>>();const allowReadonlyMode = computed(() => {diff --git a/frontend/src/views/sql-editor/EditorPanel/common/common.ts b/frontend/src/views/sql-editor/EditorPanel/common/common.tsindex 0ba61f16a6..c65893bac3 100644--- a/frontend/src/views/sql-editor/EditorPanel/common/common.ts+++ b/frontend/src/views/sql-editor/EditorPanel/common/common.ts@@ -6,11 +6,11 @@ import {useDBSchemaV1Store,} from "@/store";import { hasSchemaProperty } from "@/utils";-import { useEditorPanelContext } from "../context";+import { useCurrentTabViewStateContext } from "../context";export const useSelectSchema = () => {const { database, instance } = useConnectionOfCurrentSQLEditorTab();- const { selectedSchemaName } = useEditorPanelContext();+ const { selectedSchemaName } = useCurrentTabViewStateContext();const databaseMetadata = computed(() => {return useDBSchemaV1Store().getDatabaseMetadata(database.value.name);});diff --git a/frontend/src/views/sql-editor/EditorPanel/context/index.ts b/frontend/src/views/sql-editor/EditorPanel/context/index.tsindex 6960c6a658..14ef09f92e 100644--- a/frontend/src/views/sql-editor/EditorPanel/context/index.ts+++ b/frontend/src/views/sql-editor/EditorPanel/context/index.ts@@ -1,43 +1,37 @@-import { cloneDeep, head } from "lodash-es";+import { head } from "lodash-es";+import { storeToRefs } from "pinia";+import { computed, inject, provide, watch, type InjectionKey } from "vue";import {- computed,- inject,- provide,- reactive,- watch,- type InjectionKey,- type Ref,-} from "vue";-import { useConnectionOfCurrentSQLEditorTab } from "@/store";-import type { SQLEditorTab } from "@/types";+ useConnectionOfCurrentSQLEditorTab,+ useSQLEditorTabStore,+ useTabViewStateStore,+} from "@/store";+import {+ type EditorPanelView,+ type EditorPanelViewState as ViewState,+} from "@/types";import {instanceV1SupportsExternalTable,instanceV1SupportsPackage,instanceV1SupportsSequence,} from "@/utils";-import {- defaultViewState,- typeToView,- type EditorPanelView,- type EditorPanelViewState as ViewState,-} from "../types";const KEY = Symbol("bb.sql-editor.editor-panel") as InjectionKey<EditorPanelContext>;-const viewStateByTab = reactive(new Map</* tab.id */ string, ViewState>());+export const provideCurrentTabViewStateContext = () => {+ const tabStore = useSQLEditorTabStore();+ const tabViewStateStore = useTabViewStateStore();+ const { currentTab: tab } = storeToRefs(tabStore);-export const provideEditorPanelContext = (base: {- tab: Ref<SQLEditorTab | undefined>;-}) => {- const { tab } = base;const { instance } = useConnectionOfCurrentSQLEditorTab();const viewState = computed(() => {if (!tab.value) return undefined;- return viewStateByTab.get(tab.value.id) ?? defaultViewState();+ return tabViewStateStore.getViewState(tab.value.id);});+const availableViews = computed(() => {const views: EditorPanelView[] = ["CODE",@@ -73,20 +67,8 @@ export const provideEditorPanelContext = (base: {});const updateViewState = (patch: Partial<ViewState>) => {- const curr = viewState.value;- if (!curr) return;if (!tab.value) return;-- Object.assign(curr, patch);- viewStateByTab.set(tab.value.id, curr);- };-- const cloneViewState = (from: string, to: string) => {- const vs = viewStateByTab.get(from);- if (!vs) return;- const cloned = cloneDeep(vs);- viewStateByTab.set(to, cloned);- return cloned;+ tabViewStateStore.updateViewState(tab.value.id, patch);};watch(@@ -111,6 +93,7 @@ export const provideEditorPanelContext = (base: {},{ immediate: true });+watch(() => viewState.value?.schema,(schema) => {@@ -124,13 +107,10 @@ export const provideEditorPanelContext = (base: {);const context = {- ...base,viewState,selectedSchemaName,availableViews,updateViewState,- cloneViewState,- typeToView,};provide(KEY, context);@@ -138,8 +118,10 @@ export const provideEditorPanelContext = (base: {return context;};-export const useEditorPanelContext = () => {+export const useCurrentTabViewStateContext = () => {return inject(KEY)!;};-export type EditorPanelContext = ReturnType<typeof provideEditorPanelContext>;+export type EditorPanelContext = ReturnType<+ typeof provideCurrentTabViewStateContext+>;diff --git a/frontend/src/views/sql-editor/EditorPanel/index.ts b/frontend/src/views/sql-editor/EditorPanel/index.tsindex 9af60eedc4..3d5e5a29aa 100644--- a/frontend/src/views/sql-editor/EditorPanel/index.ts+++ b/frontend/src/views/sql-editor/EditorPanel/index.ts@@ -1,6 +1,5 @@import EditorPanel from "./EditorPanel.vue";export * from "./context";-export * from "./types";export default EditorPanel;diff --git a/frontend/src/views/sql-editor/SQLEditorHomePage.vue b/frontend/src/views/sql-editor/SQLEditorHomePage.vueindex 9958b2958b..3301c0476d 100644--- a/frontend/src/views/sql-editor/SQLEditorHomePage.vue+++ b/frontend/src/views/sql-editor/SQLEditorHomePage.vue@@ -89,7 +89,7 @@ import { extractProjectResourceName } from "@/utils";import AsidePanel from "./AsidePanel";import ConnectionPanel from "./ConnectionPanel";import EditorPanel from "./EditorPanel";-import { provideEditorPanelContext } from "./EditorPanel/context";+import { provideCurrentTabViewStateContext } from "./EditorPanel/context";import { useSheetContext } from "./Sheet";import SheetPanel from "./SheetPanel";import TabList from "./TabList";@@ -150,9 +150,7 @@ useEmitteryEventListener(});-const editorPanelContext = provideEditorPanelContext({- tab: currentTab,-});+const editorPanelContext = provideCurrentTabViewStateContext();useEmitteryEventListener(editorEvents,diff --git a/frontend/src/views/sql-editor/Sheet/common/Dropdown.vue b/frontend/src/views/sql-editor/Sheet/common/Dropdown.vueindex e2180fe22f..5a3a4f4dc1 100644--- a/frontend/src/views/sql-editor/Sheet/common/Dropdown.vue+++ b/frontend/src/views/sql-editor/Sheet/common/Dropdown.vue@@ -45,6 +45,7 @@ import {useWorkSheetStore,pushNotification,useSQLEditorTabStore,+ useTabViewStateStore,} from "@/store";import {Worksheet,@@ -76,6 +77,7 @@ const worksheetV1Store = useWorkSheetStore();const dialog = useDialog();const { events } = useSheetContext();const { events: editorEvents } = useSQLEditorContext();+const { removeViewState } = useTabViewStateStore();const options = computed(() => {const options: DropdownOption[] = [];@@ -203,6 +205,7 @@ const turnSheetToUnsavedTab = (sheet: Worksheet) => {const tab = tabStore.tabList.find((tab) => tab.worksheet === sheet.name);if (tab) {tabStore.removeTab(tab);+ removeViewState(tab.id);}};</script>diff --git a/frontend/src/views/sql-editor/TabList/ContextMenu.vue b/frontend/src/views/sql-editor/TabList/ContextMenu.vueindex 74bd3ce914..34c5f4ae14 100644--- a/frontend/src/views/sql-editor/TabList/ContextMenu.vue+++ b/frontend/src/views/sql-editor/TabList/ContextMenu.vue@@ -18,12 +18,14 @@ import type { DropdownOption } from "naive-ui";import { NDropdown } from "naive-ui";import { computed, nextTick } from "vue";import { useI18n } from "vue-i18n";+import { useTabViewStateStore } from "@/store";import type { SQLEditorTab } from "@/types";import type { CloseTabAction } from "./context";import { useTabListContext } from "./context";const { t } = useI18n();const { contextMenu: state, events } = useTabListContext();+const tabViewStateStore = useTabViewStateStore();const options = computed((): DropdownOption[] => {if (!state.value) {@@ -60,17 +62,20 @@ const options = computed((): DropdownOption[] => {];const { tab } = state.value;- if (tab.mode === "WORKSHEET") {- const DIVIDER: DropdownOption = {- type: "divider",- key: "DIVIDER",- };- const RENAME: DropdownOption = {- key: "RENAME",- label: t("sql-editor.tab.context-menu.actions.rename"),- };-- options.push(DIVIDER, RENAME);+ if (+ tab.mode === "WORKSHEET" &&+ tabViewStateStore.getViewState(tab.id).view === "CODE"+ ) {+ options.push(+ {+ type: "divider",+ key: "DIVIDER",+ },+ {+ key: "RENAME",+ label: t("sql-editor.tab.context-menu.actions.rename"),+ }+ );}return options;diff --git a/frontend/src/views/sql-editor/TabList/TabItem/Label.vue b/frontend/src/views/sql-editor/TabList/TabItem/Label.vueindex ea52335107..3a61688430 100644--- a/frontend/src/views/sql-editor/TabList/TabItem/Label.vue+++ b/frontend/src/views/sql-editor/TabList/TabItem/Label.vue@@ -28,7 +28,11 @@import { NEllipsis } from "naive-ui";import { computed, nextTick, reactive, ref, watch } from "vue";import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";-import { useSQLEditorTabStore, useWorkSheetStore } from "@/store";+import {+ useSQLEditorTabStore,+ useWorkSheetStore,+ useTabViewStateStore,+} from "@/store";import type { SQLEditorTab } from "@/types";import { useTabListContext } from "../context";@@ -48,9 +52,14 @@ const state = reactive<LocalState>({const tabStore = useSQLEditorTabStore();const worksheetV1Store = useWorkSheetStore();+const tabViewStateStore = useTabViewStateStore();const inputRef = ref<HTMLInputElement>();const { events } = useTabListContext();+const readonly = computed(+ () => tabViewStateStore.getViewState(props.tab.id).view !== "CODE"+);+const isCurrentTab = computed(() => props.tab.id === tabStore.currentTabId);useEmitteryEventListener(events, "rename-tab", ({ tab }) => {@@ -61,6 +70,9 @@ useEmitteryEventListener(events, "rename-tab", ({ tab }) => {});const beginEdit = () => {+ if (readonly.value) {+ return;+ }state.editing = true;state.title = props.tab.title;nextTick(() => {diff --git a/frontend/src/views/sql-editor/TabList/TabList.vue b/frontend/src/views/sql-editor/TabList/TabList.vueindex ab76706e83..009d78f429 100644--- a/frontend/src/views/sql-editor/TabList/TabList.vue+++ b/frontend/src/views/sql-editor/TabList/TabList.vue@@ -80,6 +80,7 @@ import {useAppFeature,useSQLEditorStore,useSQLEditorTabStore,+ useTabViewStateStore,} from "@/store";import type { SQLEditorTab } from "@/types";import {@@ -88,7 +89,6 @@ import {suggestedTabTitleForSQLEditorConnection,usePreventBackAndForward,} from "@/utils";-import { useEditorPanelContext } from "../EditorPanel";import { SettingButton } from "../Setting";import { useSheetContext } from "../Sheet";import BrandingLogoWrapper from "./BrandingLogoWrapper.vue";@@ -116,7 +116,7 @@ const { events: sheetEvents } = useSheetContext();const scrollbarRef = ref<InstanceType<typeof NScrollbar>>();const tabListRef = ref<InstanceType<typeof Draggable>>();const { strictProject } = storeToRefs(useSQLEditorStore());-const { cloneViewState } = useEditorPanelContext();+const { cloneViewState, removeViewState } = useTabViewStateStore();const context = provideTabListContext();const contextMenuRef = ref<InstanceType<typeof ContextMenu>>();@@ -215,6 +215,7 @@ const handleRemoveTab = async (function remove(index: number) {tabStore.removeTab(tab);+ removeViewState(tab.id);// select a tab near the removed tab.const nextIndex = Math.min(index, tabStore.tabList.length - 1);