Skip to content

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

refactor: deprecate the draft local storage (#18397)

ecmadao00db4011473f
diff --git a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
index 5346b6e072..51f9b4a453 100644
--- a/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/Plan/components/StatementSection/EditorView/EditorView.vue
@@ -113,7 +113,7 @@
</template>
</BBAttention>
- <div class="relative flex-1 min-h-[256px]">
+ <div class="relative flex-1 min-h-64">
<MonacoEditor
class="w-full h-full min-h-[200px] border rounded-sm overflow-hidden"
:filename="filename"
diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vue
index e4bb498dd3..e41469d7a8 100644
--- a/frontend/src/components/ProvideSQLEditorContext.vue
+++ b/frontend/src/components/ProvideSQLEditorContext.vue
@@ -44,7 +44,6 @@ import {
useWorkSheetStore,
} from "@/store";
import { migrateLegacyCache } from "@/store/modules/sqlEditor/legacy/migration";
-import type { SQLEditorConnection } from "@/types";
import {
DEFAULT_PROJECT_NAME,
DEFAULT_SQL_EDITOR_TAB_MODE,
@@ -62,7 +61,6 @@ import {
getDefaultPagination,
getSheetStatement,
isDatabaseV1Queryable,
- isSameSQLEditorConnection,
isWorksheetReadableV1,
suggestedTabTitleForSQLEditorConnection,
} from "@/utils";
@@ -89,9 +87,7 @@ const {
useRouteChangeGuard(
computed(() => {
return (
- tabStore.openTabList.find(
- (tab) => !!tab?.worksheet && tab.status === "DIRTY"
- ) !== undefined
+ tabStore.openTabList.find((tab) => tab.status === "DIRTY") !== undefined
);
}),
`${t("sql-editor.tab.unsaved-worksheet")} ${t("common.leave-without-saving")}`
@@ -138,36 +134,21 @@ const initializeProject = async () => {
}
};
-const connect = (connection: SQLEditorConnection) => {
- const tabWithSameConnect = tabStore.draftList.find((tab) =>
- isSameSQLEditorConnection(tab.connection, connection)
- );
- if (tabWithSameConnect) {
- tabStore.addTab(tabWithSameConnect);
- return;
- }
-
- tabStore.addTab({
- connection,
- mode: DEFAULT_SQL_EDITOR_TAB_MODE,
- title: suggestedTabTitleForSQLEditorConnection(connection),
- });
-};
-
const switchWorksheet = async (sheetName: string) => {
- const openingSheetTab = tabStore.openTabList.find(
+ const openedSheetTab = tabStore.openTabList.find(
(tab) => tab.worksheet == sheetName
);
const sheet = await worksheetStore.getOrFetchWorksheetByName(sheetName);
-
if (!sheet) {
- if (openingSheetTab) {
+ if (openedSheetTab) {
// If a sheet is open in a tab but it returns 404 NOT_FOUND
// that means the sheet has been deleted somewhere else.
// We need to turn the sheet to an unsaved tab.
- openingSheetTab.worksheet = "";
- openingSheetTab.status = "DIRTY";
+ tabStore.updateTab(openedSheetTab.id, {
+ worksheet: "",
+ status: "DIRTY",
+ });
}
return false;
}
@@ -181,28 +162,14 @@ const switchWorksheet = async (sheetName: string) => {
}
const connection = await extractWorksheetConnection(sheet);
- if (openingSheetTab) {
- // Switch to a sheet tab if it's open already.
- // and don't touch it
- tabStore.setCurrentTabId(openingSheetTab.id);
- tabStore.updateCurrentTab({
- connection,
- worksheet: sheet.name,
- statement: getSheetStatement(sheet),
- status: "CLEAN",
- });
- return true;
- }
-
- // Open the sheet in a new tab otherwise.
tabStore.addTab({
+ id: openedSheetTab?.id,
connection,
worksheet: sheet.name,
title: sheet.title,
statement: getSheetStatement(sheet),
status: "CLEAN",
});
-
return true;
};
@@ -242,14 +209,19 @@ const prepareConnectionParams = async () => {
(tab) => tab.connection.database === database.name
);
for (const tab of tabs) {
- tabStore.closeTab(tab);
+ tabStore.closeTab(tab.id);
}
return false;
}
// connected to db
- connect({
+ const connection = {
instance: database.instance,
database: database.name,
+ };
+ tabStore.addTab({
+ connection,
+ mode: DEFAULT_SQL_EDITOR_TAB_MODE,
+ title: suggestedTabTitleForSQLEditorConnection(connection),
});
return true;
};
@@ -413,7 +385,6 @@ onMounted(async () => {
]);
await migrateLegacyCache();
- await tabStore.maybeInitProject();
await initializeConnectionFromQuery();
syncURLWithConnection();
});
diff --git a/frontend/src/layouts/SQLEditorLayout.vue b/frontend/src/layouts/SQLEditorLayout.vue
index bf87c9c601..bbae7b0f0a 100644
--- a/frontend/src/layouts/SQLEditorLayout.vue
+++ b/frontend/src/layouts/SQLEditorLayout.vue
@@ -25,6 +25,7 @@ import {
import { PolicyResourceType } from "@/types/proto-es/v1/org_policy_service_pb";
import { provideSQLEditorContext } from "@/views/sql-editor/context";
import { provideSheetContext } from "@/views/sql-editor/Sheet";
+import { provideTabListContext } from "@/views/sql-editor/TabList/context";
const router = useRouter();
@@ -32,6 +33,8 @@ const router = useRouter();
provideSQLEditorContext();
// provide context for sheets
provideSheetContext();
+// provide context for tabs
+provideTabListContext();
const ready = ref(false);
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index bb935b2ccd..cae008f41b 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -131,7 +131,6 @@
"n-seconds-ago": "{count} seconds ago",
"copy": "Copy",
"copied": "Copied",
- "click-to-copy": "Click to copy",
"manage": "Manage",
"table": "Table",
"search": "Search",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 9e64ea3ebe..ce5aeaf3a7 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -131,7 +131,6 @@
"n-seconds-ago": "Hace {count} segundos",
"copy": "Copiar",
"copied": "Copiado",
- "click-to-copy": "Haga clic para copiar",
"manage": "Administrar",
"table": "Tabla",
"search": "Buscar",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 2ad690838b..fef131fc41 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -131,7 +131,6 @@
"n-seconds-ago": "{count} 秒前",
"copy": "コピー",
"copied": "コピーされました",
- "click-to-copy": "クリックしてコピー",
"manage": "管理",
"table": "テーブル",
"search": "検索",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 56de71b76c..d1de79683e 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -131,7 +131,6 @@
"n-seconds-ago": "{count} giây trước",
"copy": "Sao chép",
"copied": "Đã sao chép",
- "click-to-copy": "Nhấp để sao chép",
"manage": "Quản lý",
"table": "Bảng",
"search": "Tìm kiếm",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index b5325bfc09..821b0452c9 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -131,7 +131,6 @@
"n-seconds-ago": "{count} 秒前",
"copy": "拷贝",
"copied": "已拷贝",
- "click-to-copy": "点击复制",
"manage": "管理",
"table": "表",
"search": "搜索",
diff --git a/frontend/src/store/modules/sqlEditor/index.ts b/frontend/src/store/modules/sqlEditor/index.ts
index 95ca2f5072..8f62bc4914 100644
--- a/frontend/src/store/modules/sqlEditor/index.ts
+++ b/frontend/src/store/modules/sqlEditor/index.ts
@@ -3,4 +3,3 @@ export * from "./tab";
export * from "./tree";
export * from "./queryHistory";
export * from "./webTerminal";
-export * from "./tabViewState";
diff --git a/frontend/src/store/modules/sqlEditor/legacy/migration.ts b/frontend/src/store/modules/sqlEditor/legacy/migration.ts
index c5b5a46e73..9f63ab1dd4 100644
--- a/frontend/src/store/modules/sqlEditor/legacy/migration.ts
+++ b/frontend/src/store/modules/sqlEditor/legacy/migration.ts
@@ -1,13 +1,18 @@
+import { create } from "@bufbuild/protobuf";
import { omit } from "lodash-es";
import { computed, reactive } from "vue";
-import type { SQLEditorTab } from "@/types";
+import type { EditorPanelViewState, SQLEditorTab } from "@/types";
import { DEFAULT_SQL_EDITOR_TAB_MODE } from "@/types";
+import {
+ Worksheet_Visibility,
+ WorksheetSchema,
+} from "@/types/proto-es/v1/worksheet_service_pb";
import {
defaultSQLEditorTab,
useDynamicLocalStorage,
WebStorageHelper,
} from "@/utils";
-import { extractUserId } from "../../v1";
+import { extractUserId, useWorkSheetStore } from "../../v1";
import { useCurrentUserV1 } from "../../v1/auth";
import { EXTENDED_TAB_FIELDS, useExtendedTabStore } from "./extendedTab";
@@ -102,3 +107,83 @@ export const migrateLegacyCache = async () => {
delete tabIdListMapByProject.value[project];
}
};
+
+export const migrateDraftsFromCache = async (project: string) => {
+ const me = useCurrentUserV1();
+ const userUID = computed(() => extractUserId(me.value.name));
+ const worksheetStore = useWorkSheetStore();
+
+ const viewStateByTab = useDynamicLocalStorage<
+ Map</* tab.id */ string, EditorPanelViewState>
+ >(
+ computed(() => `bb.sql-editor-tab-state.${userUID.value}`),
+ new Map()
+ );
+
+ const keyNamespace = computed(
+ () => `${LOCAL_STORAGE_KEY_PREFIX}.${project}.${userUID.value}`
+ );
+
+ const draftTabList = useDynamicLocalStorage<SQLEditorTab[]>(
+ computed(() => `${keyNamespace.value}.draft-tab-list`),
+ [],
+ localStorage,
+ {
+ listenToStorageChanges: true,
+ }
+ );
+
+ const drafts = [...draftTabList.value];
+ for (const draft of drafts) {
+ const viewState = viewStateByTab.value.get(draft.id);
+ if ((!viewState || viewState.view === "CODE") && draft.statement) {
+ // only store the draft with content
+ await worksheetStore.createWorksheet(
+ create(WorksheetSchema, {
+ title: draft.title,
+ database: draft.connection.database,
+ content: new TextEncoder().encode(draft.statement),
+ project: project,
+ visibility: Worksheet_Visibility.PRIVATE,
+ })
+ );
+ }
+ const index = draftTabList.value.findIndex((d) => d.id === draft.id);
+ if (index >= 0) {
+ draftTabList.value.splice(index, 1);
+ }
+ }
+};
+
+export const migrateTabViewState = (project: string) => {
+ const me = useCurrentUserV1();
+ const userUID = computed(() => extractUserId(me.value.name));
+
+ const keyNamespace = computed(
+ () => `${LOCAL_STORAGE_KEY_PREFIX}.${project}.${userUID.value}`
+ );
+
+ const viewStateByTab = useDynamicLocalStorage<
+ Map</* tab.id */ string, EditorPanelViewState>
+ >(
+ computed(() => `bb.sql-editor-tab-state.${userUID.value}`),
+ new Map()
+ );
+
+ const openTmpTabList = useDynamicLocalStorage<PersistentTab[]>(
+ computed(() => `${keyNamespace.value}.opening-tab-list`),
+ [],
+ localStorage,
+ {
+ listenToStorageChanges: false,
+ }
+ );
+
+ for (const openedTab of openTmpTabList.value) {
+ const viewState = viewStateByTab.value.get(openedTab.id);
+ if (viewState) {
+ Object.assign(openedTab, { viewState });
+ }
+ viewStateByTab.value.delete(openedTab.id);
+ }
+};
diff --git a/frontend/src/store/modules/sqlEditor/tab.ts b/frontend/src/store/modules/sqlEditor/tab.ts
index 669ba1e9dd..767ace8c37 100644
--- a/frontend/src/store/modules/sqlEditor/tab.ts
+++ b/frontend/src/store/modules/sqlEditor/tab.ts
@@ -1,5 +1,5 @@
import type { MaybeRef } from "@vueuse/core";
-import { head, pick, uniqBy } from "lodash-es";
+import { cloneDeep, head, isUndefined, omitBy, pick } from "lodash-es";
import { defineStore, storeToRefs } from "pinia";
import { computed, reactive, unref, watch } from "vue";
import type {
@@ -17,6 +17,7 @@ import {
extractWorksheetConnection,
getSheetStatement,
isConnectedSQLEditorTab,
+ suggestedTabTitleForSQLEditorConnection,
useDynamicLocalStorage,
} from "@/utils";
import {
@@ -29,6 +30,10 @@ import {
} from "../v1";
import { useCurrentUserV1 } from "../v1/auth";
import { useSQLEditorStore } from "./editor";
+import {
+ migrateDraftsFromCache,
+ migrateTabViewState,
+} from "./legacy/migration";
import { useWebTerminalStore } from "./webTerminal";
const PERSISTENT_TAB_FIELDS = [
@@ -37,6 +42,7 @@ const PERSISTENT_TAB_FIELDS = [
"mode",
"batchQueryContext",
"treeState",
+ "viewState",
] as const;
type PersistentTab = Pick<SQLEditorTab, (typeof PERSISTENT_TAB_FIELDS)[number]>;
@@ -54,15 +60,6 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
() => `${LOCAL_STORAGE_KEY_PREFIX}.${project.value}.${userUID.value}`
);
- const draftTabList = useDynamicLocalStorage<SQLEditorTab[]>(
- computed(() => `${keyNamespace.value}.draft-tab-list`),
- [],
- localStorage,
- {
- listenToStorageChanges: true,
- }
- );
-
const openTmpTabList = useDynamicLocalStorage<PersistentTab[]>(
computed(() => `${keyNamespace.value}.opening-tab-list`),
[],
@@ -87,44 +84,29 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
if (validOpenTabMap.has(tab.id)) {
continue;
}
- let fullTab: SQLEditorTab | undefined;
- if (tab.worksheet) {
- const worksheet = await worksheetStore.getOrFetchWorksheetByName(
- tab.worksheet,
- true
- );
- if (!worksheet) {
- continue;
- }
- const statement = getSheetStatement(worksheet);
- const connection = await extractWorksheetConnection(worksheet);
-
- fullTab = {
- ...defaultSQLEditorTab(),
- ...tab,
- connection,
- worksheet: worksheet.name,
- title: worksheet.title,
- statement,
- status: "CLEAN",
- databaseQueryContexts: undefined,
- };
- } else {
- const draft = draftTabList.value.find((item) => item.id === tab.id);
- if (!draft) {
- continue;
- }
- fullTab = {
- ...draft,
- databaseQueryContexts: undefined,
- };
- }
- if (!fullTab) {
+ if (!tab.worksheet) {
continue;
}
- if (!fullTab.mode) {
- fullTab.mode = "WORKSHEET";
+ const worksheet = await worksheetStore.getOrFetchWorksheetByName(
+ tab.worksheet,
+ true
+ );
+ if (!worksheet) {
+ continue;
}
+ const statement = getSheetStatement(worksheet);
+ const connection = await extractWorksheetConnection(worksheet);
+
+ const fullTab: SQLEditorTab = {
+ ...defaultSQLEditorTab(),
+ ...omitBy(tab, isUndefined),
+ connection,
+ worksheet: worksheet.name,
+ title: worksheet.title,
+ statement,
+ status: "CLEAN",
+ databaseQueryContexts: undefined,
+ };
validOpenTabMap.set(tab.id, tab);
tabsById.set(tab.id, fullTab);
@@ -135,21 +117,24 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
const maybeInitProject = async () => {
tabsById.clear();
- draftTabList.value = uniqBy(draftTabList.value, (draft) => draft.id);
await loadStoredTabs();
currentTabId.value = head(openTmpTabList.value)?.id ?? "";
};
+ const getTabById = (tabId: string) => {
+ return tabsById.get(tabId);
+ };
+
const openTabList = computed(() => {
return openTmpTabList.value.map((item) => {
- return tabsById.get(item.id) ?? defaultSQLEditorTab();
+ return getTabById(item.id) ?? defaultSQLEditorTab();
});
});
const currentTab = computed(() => {
const currId = currentTabId.value;
if (!currId) return undefined;
- return tabsById.get(currId);
+ return getTabById(currId);
});
const supportBatchMode = computed(() => currentTab.value?.mode !== "ADMIN");
@@ -177,109 +162,94 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
// actions
/**
- *
+ * Create or update the tab, and ensure the tab is open.
* @param payload
* @param beside `true` to add the tab beside currentTab, `false` to add the tab to the last, default to `false`
- * @returns
+ * @returns the tab
*/
const addTab = (payload?: Partial<SQLEditorTab>, beside = false) => {
- const newTab = reactive<SQLEditorTab>({
+ const defaultTab: SQLEditorTab = {
...defaultSQLEditorTab(),
- ...payload,
- });
- const { id, worksheet } = newTab;
-
- if (openTmpTabList.value.find((tab) => tab.id === id)) {
- setCurrentTabId(id);
- const response = tabsById.get(id) ?? newTab;
- tabsById.set(id, response);
- return newTab;
- }
+ ...omitBy(payload, isUndefined),
+ };
+ const { id } = defaultTab;
- const persistentTab = pick(
- newTab,
- ...PERSISTENT_TAB_FIELDS
- ) as PersistentTab;
- const position = openTmpTabList.value.findIndex(
- (item) => item.id === currentTabId.value
- );
- if (beside && position >= 0) {
- openTmpTabList.value.splice(position + 1, 0, persistentTab);
+ let newTab = getTabById(id);
+ if (newTab) {
+ Object.assign(newTab, omitBy(payload, isUndefined));
} else {
- openTmpTabList.value.push(persistentTab);
- }
- if (
- !worksheet &&
- !draftTabList.value.find((draft) => draft.id === newTab.id)
- ) {
- draftTabList.value.push(newTab);
+ newTab = defaultTab;
+ tabsById.set(id, newTab);
}
+ upsertCache(newTab, beside);
setCurrentTabId(id);
- tabsById.set(id, newTab);
-
return newTab;
};
- const removeDraft = (tab: SQLEditorTab) => {
- const draftIndex = draftTabList.value.findIndex(
- (item) => item.id === tab.id
- );
- if (draftIndex >= 0) {
- draftTabList.value.splice(draftIndex, 1);
- }
+ const cloneTab = (
+ targetId: string,
+ payload?: Partial<SQLEditorTab>
+ ): SQLEditorTab => {
+ const targetTab = getTabById(targetId);
+ const clonedTab: Partial<SQLEditorTab> = {
+ statement: targetTab?.statement,
+ connection: cloneDeep(targetTab?.connection),
+ treeState: cloneDeep(targetTab?.treeState),
+ editorState: cloneDeep(targetTab?.editorState),
+ batchQueryContext: cloneDeep(targetTab?.batchQueryContext),
+ title: suggestedTabTitleForSQLEditorConnection(
+ targetTab?.connection ?? emptySQLEditorConnection()
+ ),
+ ...payload,
+ };
+
+ return addTab(clonedTab, true);
};
- const closeTab = (tab: SQLEditorTab) => {
- const { id } = tab;
- const position = openTmpTabList.value.findIndex((item) => item.id === id);
+ const closeTab = (tabId: string) => {
+ const position = openTmpTabList.value.findIndex(
+ (item) => item.id === tabId
+ );
if (position < 0) {
return;
}
openTmpTabList.value.splice(position, 1);
- tabsById.delete(id);
+ tabsById.delete(tabId);
+ useWebTerminalStore().clearQueryStateByTab(tabId);
- if (tab.mode === "ADMIN") {
- useWebTerminalStore().clearQueryStateByTab(id);
- }
-
- if (id === currentTabId.value) {
+ if (tabId === currentTabId.value) {
const nextIndex = Math.min(position, openTmpTabList.value.length - 1);
const nextTab = openTmpTabList.value[nextIndex];
setCurrentTabId(nextTab?.id ?? "");
}
};
- const updateCache = (tab: SQLEditorTab) => {
- const draftIndex = draftTabList.value.findIndex(
- (item) => item.id === tab.id
- );
- if (draftIndex >= 0) {
- Object.assign(draftTabList.value[draftIndex], tab);
- }
+ const upsertCache = (tab: SQLEditorTab, beside = false) => {
+ const persistentTab = pick(tab, ...PERSISTENT_TAB_FIELDS) as PersistentTab;
- const openTabIndex = openTmpTabList.value.findIndex(
+ const position = openTmpTabList.value.findIndex(
(item) => item.id === tab.id
);
- if (openTabIndex >= 0) {
- const persistentTab = pick(
- tab,
- ...PERSISTENT_TAB_FIELDS
- ) as PersistentTab;
- Object.assign(openTmpTabList.value[openTabIndex], persistentTab);
+ if (position >= 0) {
+ Object.assign(openTmpTabList.value[position], persistentTab);
+ } else {
+ const currentPosition = openTmpTabList.value.findIndex(
+ (item) => item.id === currentTabId.value
+ );
+ if (beside && currentPosition >= 0) {
+ openTmpTabList.value.splice(currentPosition + 1, 0, persistentTab);
+ } else {
+ openTmpTabList.value.push(persistentTab);
+ }
}
};
const updateTab = (id: string, payload: Partial<SQLEditorTab>) => {
- const tab = tabsById.get(id);
+ const tab = getTabById(id);
if (!tab) return;
Object.assign(tab, payload);
-
- if (payload.worksheet) {
- removeDraft(tab);
- } else {
- updateCache(tab);
- }
+ upsertCache(tab);
};
const updateCurrentTab = (payload: Partial<SQLEditorTab>) => {
@@ -312,7 +282,7 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
database: string;
contextId: string;
}): SQLEditorDatabaseQueryContext | undefined => {
- const tab = tabsById.get(currentTabId.value);
+ const tab = getTabById(currentTabId.value);
if (!tab || !tab.databaseQueryContexts) {
return;
}
@@ -335,7 +305,7 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
database: string;
contextIds: string[];
}) => {
- const tab = tabsById.get(currentTabId.value);
+ const tab = getTabById(currentTabId.value);
if (!tab || !tab.databaseQueryContexts) {
return;
}
@@ -358,7 +328,7 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
};
const deleteDatabaseQueryContext = (database: string) => {
- const tab = tabsById.get(currentTabId.value);
+ const tab = getTabById(currentTabId.value);
if (!tab || !tab.databaseQueryContexts) {
return;
}
@@ -374,7 +344,7 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
contextId: string;
context: Partial<SQLEditorDatabaseQueryContext>;
}) => {
- const tab = tabsById.get(currentTabId.value);
+ const tab = getTabById(currentTabId.value);
if (!tab || !tab.databaseQueryContexts) {
return;
}
@@ -397,9 +367,12 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
watch(
() => project.value,
- () => {
- maybeInitProject();
- }
+ async (project) => {
+ await migrateDraftsFromCache(project);
+ migrateTabViewState(project);
+ await maybeInitProject();
+ },
+ { immediate: true }
);
// some shortcuts
@@ -411,12 +384,12 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
return {
project,
+ getTabById,
openTabList,
- draftList: computed(() => draftTabList.value),
currentTabId,
currentTab,
addTab,
- removeDraft,
+ cloneTab,
closeTab,
updateTab,
updateCurrentTab,
@@ -426,7 +399,6 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {
batchRemoveDatabaseQueryContext,
deleteDatabaseQueryContext,
setCurrentTabId,
- maybeInitProject,
isDisconnected,
isInBatchMode,
supportBatchMode,
diff --git a/frontend/src/store/modules/sqlEditor/tabViewState.ts b/frontend/src/store/modules/sqlEditor/tabViewState.ts
deleted file mode 100644
index b8d4a08fa0..0000000000
--- a/frontend/src/store/modules/sqlEditor/tabViewState.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import { cloneDeep } from "lodash-es";
-import { defineStore } from "pinia";
-import { computed } from "vue";
-import { extractUserId, useCurrentUserV1 } 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/editor.ts b/frontend/src/types/sqlEditor/editor.ts
index f8370ba8ac..61e768eba2 100644
--- a/frontend/src/types/sqlEditor/editor.ts
+++ b/frontend/src/types/sqlEditor/editor.ts
@@ -2,23 +2,17 @@ import type * as monaco from "monaco-editor";
import { Engine } from "../proto-es/v1/common_pb";
import { type QueryOption } from "../proto-es/v1/sql_service_pb";
-export type EditorModel = monaco.editor.ITextModel;
-export type EditorPosition = monaco.Position;
-export type CompletionItems = monaco.languages.CompletionItem[];
-
export type Language = "sql" | "javascript" | "redis" | "json";
-export const EngineTypesUsingSQL = [
- "MYSQL",
- "CLICKHOUSE",
- "POSTGRES",
- "SNOWFLAKE",
- "TIDB",
- "SPANNER",
- "OCEANBASE",
-] as const;
-export type SQLDialect = (typeof EngineTypesUsingSQL)[number];
-export const EngineToSQLDialectMap = new Map<Engine, SQLDialect>([
+export type SQLDialect =
+ | "MYSQL"
+ | "CLICKHOUSE"
+ | "POSTGRES"
+ | "SNOWFLAKE"
+ | "TIDB"
+ | "SPANNER"
+ | "OCEANBASE";
+const EngineToSQLDialectMap = new Map<Engine, SQLDialect>([
[Engine.MYSQL, "MYSQL"],
[Engine.CLICKHOUSE, "CLICKHOUSE"],
[Engine.POSTGRES, "POSTGRES"],
@@ -39,27 +33,12 @@ export const languageOfEngineV1 = (engine?: Engine): Language => {
return "sql";
};
-export const dialectOfEngine = (engine = "unknown"): SQLDialect => {
- if (EngineTypesUsingSQL.includes(engine as any)) {
- return engine as SQLDialect;
- }
- // Fallback to MYSQL otherwise
- return "MYSQL";
-};
-
export const dialectOfEngineV1 = (
engine: Engine = Engine.ENGINE_UNSPECIFIED
): SQLDialect => {
return EngineToSQLDialectMap.get(engine) ?? "MYSQL";
};
-export enum SortText {
- DATABASE = "0",
- TABLE = "1",
- COLUMN = "2",
- KEYWORD = "3",
-}
-
export interface SQLEditorConnection {
instance: string; // instance resource name, empty if not connected
database: string; // database resource name, empty if not connected to a database
@@ -68,8 +47,6 @@ export interface SQLEditorConnection {
table?: string;
}
-export const SQLEditorTabConnectionSchemaUnspecified = "-1";
-
export type SQLEditorQueryParams = {
connection: SQLEditorConnection; // the connection snapshot of the query
statement: string; // the statement snapshot of the query
diff --git a/frontend/src/types/sqlEditor/tab.ts b/frontend/src/types/sqlEditor/tab.ts
index be073bdf34..6144042c70 100644
--- a/frontend/src/types/sqlEditor/tab.ts
+++ b/frontend/src/types/sqlEditor/tab.ts
@@ -1,11 +1,9 @@
-import type {
- AdviceOption,
- Selection as MonacoSelection,
-} from "@/components/MonacoEditor";
+import type { Selection as MonacoSelection } from "@/components/MonacoEditor";
import { t } from "@/plugins/i18n";
import { DataSourceType } from "@/types/proto-es/v1/instance_service_pb";
import type { SQLResultSetV1 } from "../v1/sql";
import type { SQLEditorConnection, SQLEditorQueryParams } from "./editor";
+import type { EditorPanelViewState } from "./tabViewState";
export type SQLEditorTabStatus =
| "DIRTY" // edited
@@ -89,8 +87,8 @@ export type SQLEditorTab = {
};
editorState: {
selection: MonacoSelection | null;
- advices: AdviceOption[];
};
+ viewState: EditorPanelViewState;
};
export type CoreSQLEditorTab = Pick<
diff --git a/frontend/src/utils/sqlEditor.ts b/frontend/src/utils/sqlEditor.ts
index 651a5b3552..e82927c441 100644
--- a/frontend/src/utils/sqlEditor.ts
+++ b/frontend/src/utils/sqlEditor.ts
@@ -10,6 +10,7 @@ import type {
} from "@/types";
import {
DEFAULT_SQL_EDITOR_TAB_MODE,
+ defaultViewState,
isValidDatabaseName,
isValidInstanceName,
UNKNOWN_DATABASE_NAME,
@@ -41,12 +42,12 @@ export const defaultSQLEditorTab = (): SQLEditorTab => {
},
editorState: {
selection: null,
- advices: [],
},
+ viewState: defaultViewState(),
};
};
-export const defaultSQLEditorTabTitle = () => {
+const defaultSQLEditorTabTitle = () => {
return dayjs().format("YYYY-MM-DD HH:mm");
};
diff --git a/frontend/src/views/SettingWorkspaceGeneral.vue b/frontend/src/views/SettingWorkspaceGeneral.vue
index 62ab7376e2..83381fb113 100644
--- a/frontend/src/views/SettingWorkspaceGeneral.vue
+++ b/frontend/src/views/SettingWorkspaceGeneral.vue
@@ -41,7 +41,7 @@
<div v-if="allowEdit && isDirty" class="sticky bottom-0 z-10">
<div
- class="flex justify-between w-full py-4 border-block-border bg-white"
+ class="flex justify-between w-full py-4 border-t border-block-border bg-white"
>
<NButton @click.prevent="onRevert">
{{ $t("common.cancel") }}
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx
index 9f91dbdb8e..0093157d1e 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx
@@ -25,7 +25,6 @@ import {
useDatabaseV1Store,
useDBSchemaV1Store,
useSQLEditorTabStore,
- useTabViewStateStore,
} from "@/store";
import {
type ComposedDatabase,
@@ -111,7 +110,6 @@ export const useActions = () => {
view: EditorPanelView;
}) => {
const tabStore = useSQLEditorTabStore();
- const tabViewStateStore = useTabViewStateStore();
let schema = params.schema;
let table = params.table;
@@ -142,7 +140,7 @@ export const useActions = () => {
if (!isSameSQLEditorConnection(tab.connection, clonedTab.connection)) {
return false;
}
- const viewState = tabViewStateStore.getViewState(tab.id);
+ const viewState = tab.viewState;
if (
viewState.view !== params.view ||
(schema && viewState.schema !== schema)
diff --git a/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/SheetTree.vue b/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/SheetTree.vue
index e69cf71365..7535b61366 100644
--- a/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/SheetTree.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/SheetTree.vue
@@ -9,7 +9,7 @@
block-line
block-node
:keyboard="false"
- :draggable="!editingNode && !multiSelectMode"
+ :draggable="props.view !== 'draft' && !editingNode && !multiSelectMode"
:data="treeData"
:multiple="false"
cascade
@@ -83,7 +83,6 @@ import {
pushNotification,
useSQLEditorStore,
useSQLEditorTabStore,
- useTabViewStateStore,
useWorkSheetStore,
} from "@/store";
import { DEBOUNCE_SEARCH_DELAY } from "@/types";
@@ -146,7 +145,6 @@ const {
getFoldersForWorksheet,
} = useSheetContextByView(props.view);
const $dialog = useDialog();
-const { removeViewState } = useTabViewStateStore();
const tabStore = useSQLEditorTabStore();
const {
@@ -380,12 +378,7 @@ const nodeProps = ({ option }: { option: TreeOption }) => {
forceNewTab: e.metaKey || e.ctrlKey,
});
} else {
- const tab = tabStore.draftList.find(
- (draft) => draft.id === node.worksheet?.name
- );
- if (tab) {
- tabStore.addTab(tab);
- }
+ tabStore.setCurrentTabId(node.worksheet.name);
}
} else {
if (expandedKeys.value.has(node.key)) {
@@ -407,8 +400,7 @@ const deleteWorksheets = async (worksheets: string[]) => {
for (const worksheet of worksheets) {
const tab = tabStore.openTabList.find((tab) => tab.worksheet === worksheet);
if (tab) {
- tabStore.closeTab(tab);
- removeViewState(tab.id);
+ tabStore.closeTab(tab.id);
}
}
};
diff --git a/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/TreeNodeSuffix.vue b/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/TreeNodeSuffix.vue
index ffd36ecb46..6c0a4c75ca 100644
--- a/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/TreeNodeSuffix.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/TreeNodeSuffix.vue
@@ -60,18 +60,14 @@ import {
import { NTooltip } from "naive-ui";
import { computed } from "vue";
import { t } from "@/plugins/i18n";
-import {
- useSQLEditorTabStore,
- useTabViewStateStore,
- useUserStore,
- useWorkSheetStore,
-} from "@/store";
+import { useSQLEditorTabStore, useUserStore, useWorkSheetStore } from "@/store";
import { Worksheet_Visibility } from "@/types/proto-es/v1/worksheet_service_pb";
import type {
SheetViewMode,
WorksheetFolderNode,
} from "@/views/sql-editor/Sheet";
import { useSheetContext } from "@/views/sql-editor/Sheet";
+import { useTabListContext } from "@/views/sql-editor/TabList/context";
const props = defineProps<{
node: WorksheetFolderNode;
@@ -86,9 +82,9 @@ const emit = defineEmits<{
const userStore = useUserStore();
const worksheetStore = useWorkSheetStore();
-const { removeViewState } = useTabViewStateStore();
const tabStore = useSQLEditorTabStore();
const { isWorksheetCreator } = useSheetContext();
+const { events } = useTabListContext();
const worksheetLite = computed(() => {
if (!props.node.worksheet) {
@@ -124,15 +120,11 @@ const creatorForSheet = (creator: string) => {
};
const handleDeleteDraft = () => {
- if (props.node.worksheet && props.node.worksheet.name) {
- const draft = tabStore.draftList.find(
- (t) => t.id === props.node.worksheet!.name
- );
- if (draft) {
- tabStore.closeTab(draft);
- tabStore.removeDraft(draft);
+ if (props.node.worksheet?.name) {
+ const tab = tabStore.getTabById(props.node.worksheet?.name);
+ if (tab) {
+ events.emit("close-tab", { tab, index: 0, action: "CLOSE" });
}
- removeViewState(props.node.worksheet.name);
}
};
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/VirtualDataTable.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/VirtualDataTable.vue
index e20a6e3a75..8ef4fbf547 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/VirtualDataTable.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/VirtualDataTable.vue
@@ -15,13 +15,16 @@
<!-- header for the index -->
<th
:key="`${setIndex}-0-index`"
- class="`group relative px-1 py-2 tracking-wider border-x border-block-border dark:border-zinc-500"
+ class="`group relative px-2 py-2 tracking-wider border-x border-block-border dark:border-zinc-500"
v-bind="tableResize.getColumnProps(0)"
>
<!-- Use the max index to calculate the cell width -->
<div
:class="[
'textinfolabel opacity-0',
+ selectionDisabled
+ ? ''
+ : 'ml-2',
]"
>{{ rows.length }}</div>
<div
@@ -34,7 +37,7 @@
<th
v-for="(header, columnIndex) of columns"
:key="`${setIndex}-${columnIndex + 1}-${header.id}`"
- class="group relative px-2 py-2 min-w-8 text-left text-xs font-medium text-gray-500 dark:text-gray-300 tracking-wider border-x border-block-border dark:border-zinc-500"
+ class="group relative px-3 py-2 min-w-8 text-left text-xs font-medium text-gray-500 dark:text-gray-300 tracking-wider border-x border-block-border dark:border-zinc-500"
:class="{
'cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800':
!selectionDisabled,
@@ -122,7 +125,7 @@
class="relative flex items-center pl-3 shrink-0 text-sm dark:text-gray-100 leading-5 whitespace-nowrap break-all border-block-border dark:border-zinc-500 group-even:bg-gray-100/50 dark:group-even:bg-gray-700/50"
:class="{
'border-r': true,
- 'border-b': rowIndex < (rows.length - 1),
+ 'border-b': true,
'bg-accent/10! dark:bg-accent/40!': activeRowIndex === rowIndex,
'bg-accent/20! dark:bg-accent/40!': selectionState.rows.includes(rowIndex)
}"
@@ -166,7 +169,7 @@
class="relative shrink-0 text-sm dark:text-gray-100 leading-5 whitespace-nowrap break-all border-block-border dark:border-zinc-500 group-even:bg-gray-100/50 dark:group-even:bg-gray-700/50"
:class="{
'border-r': columnIndex < (row.item.values.length - 1),
- 'border-b': rowIndex < (rows.length - 1),
+ 'border-b': true,
}"
:data-col-index="columnIndex + 1"
:style="{
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
index 1d67a99499..9f85f38f29 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
@@ -155,7 +155,7 @@
</template>
</div>
- <Drawer v-if="detail" :show="!!detail" @close="detail = undefined">
+ <Drawer v-if="detail && resultSet" :show="!!detail" @close="detail = undefined">
<DetailPanel :result="viewMode === 'SINGLE-RESULT' ? resultSet.results[0] : filteredResults[detail.set]" />
</Drawer>
</NConfigProvider>
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
index 5fb45945f6..ba9308b193 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
@@ -194,21 +194,18 @@
<div
class="w-full flex items-center justify-between text-xs mt-1 gap-x-4 text-control-light"
>
- <div class="flex flex-1 items-center gap-x-2">
+ <div class="flex items-center gap-x-2">
<RichDatabaseName :database="database" />
- <NTooltip :disabled="!isSupported">
- <template #trigger>
- <div
- class="truncate cursor-pointer hover:bg-gray-200"
- @click="copyStatement"
- >
- {{ result.statement }}
- </div>
- </template>
- {{ $t("common.click-to-copy") }}
- </NTooltip>
+ <div class="flex items-center gap-x-1">
+ <EllipsisText
+ :line-clamp="1"
+ >
+ {{ result.statement }}
+ </EllipsisText>
+ <CopyButton :size="'tiny'" :content="result.statement" />
+ </div>
</div>
- <div class="flex items-center shrink-0 gap-x-2">
+ <div class="flex shrink-0 items-center gap-x-2">
<NButton
v-if="showVisualizeButton"
text
@@ -238,7 +235,6 @@
<script lang="ts" setup>
import { create } from "@bufbuild/protobuf";
-import { useClipboard } from "@vueuse/core";
import { isEmpty } from "lodash-es";
import { ArrowDownIcon, ArrowUpIcon, XIcon } from "lucide-vue-next";
import { NButton, NEmpty, NFormItem, NSwitch, NTooltip } from "naive-ui";
@@ -254,14 +250,11 @@ import type {
ExportOption,
} from "@/components/DataExportButton.vue";
import DataExportButton from "@/components/DataExportButton.vue";
-import { RichDatabaseName } from "@/components/v2";
+import EllipsisText from "@/components/EllipsisText.vue";
+import { CopyButton, RichDatabaseName } from "@/components/v2";
import { useExecuteSQL } from "@/composables/useExecuteSQL";
import { DISMISS_PLACEHOLDER } from "@/plugins/ai/components/state";
-import {
- pushNotification,
- useSQLEditorStore,
- useSQLEditorTabStore,
-} from "@/store";
+import { useSQLEditorStore, useSQLEditorTabStore } from "@/store";
import type {
ComposedDatabase,
SQLEditorDatabaseQueryContext,
@@ -339,23 +332,6 @@ const state = reactive<LocalState>({
const dataTableRef =
ref<InstanceType<typeof VirtualDataTable | typeof VirtualDataBlock>>();
-const { copy: copyTextToClipboard, isSupported } = useClipboard({
- legacy: true,
-});
-
-const copyStatement = () => {
- if (!isSupported.value) {
- return;
- }
- copyTextToClipboard(props.result.statement).then(() => {
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.copied"),
- });
- });
-};
-
const { t } = useI18n();
const { dark } = useSQLResultViewContext();
const tabStore = useSQLEditorTabStore();
diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTablesPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTablesPanel.vue
index 23383b5df1..c837e3b9b5 100644
--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTablesPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ExternalTablesPanel/ExternalTablesPanel.vue
@@ -25,7 +25,7 @@
<template v-if="metadata.externalTable">
<div
- class="w-full h-[28px] flex flex-row gap-x-2 justify-between items-center"
+ class="w-full h-7 flex flex-row gap-x-2 justify-between items-center"
>
<div class="flex items-center justify-start">
<NButton text @click="deselect">
diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsPanel.vue
index 977b6809e4..b9e4ecc84d 100644
--- a/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/FunctionsPanel/FunctionsPanel.vue
@@ -2,7 +2,7 @@
<div v-if="metadata?.schema" class="h-full overflow-hidden flex flex-col">
<div
v-show="!metadata.func"
- class="w-full h-[44px] py-2 px-2 border-b flex flex-row gap-x-2 justify-end items-center"
+ class="w-full h-11 py-2 px-2 border-b flex flex-row gap-x-2 justify-end items-center"
>
<SearchBox
v-model:value="state.keyword"
diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/PackagesPanel/PackagesPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/PackagesPanel/PackagesPanel.vue
index 3763ac0330..64595ffac0 100644
--- a/frontend/src/views/sql-editor/EditorPanel/Panels/PackagesPanel/PackagesPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/PackagesPanel/PackagesPanel.vue
@@ -2,7 +2,7 @@
<div v-if="metadata?.schema" class="h-full overflow-hidden flex flex-col">
<div
v-show="!metadata.package"
- class="w-full h-[44px] py-2 px-2 border-b flex flex-row gap-x-2 justify-end items-center"
+ class="w-full h-11 py-2 px-2 border-b flex flex-row gap-x-2 justify-end items-center"
>
<SearchBox
v-model:value="state.keyword"
diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresPanel.vue
index 450a3bbe99..1f4ad4a135 100644
--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ProceduresPanel/ProceduresPanel.vue
@@ -2,7 +2,7 @@
<div v-if="metadata?.schema" class="h-full overflow-hidden flex flex-col">
<div
v-show="!metadata.procedure"
- class="w-full h-[44px] py-2 px-2 border-b flex flex-row gap-x-2 justify-end items-center"
+ class="w-full h-11 py-2 px-2 border-b flex flex-row gap-x-2 justify-end items-center"
>
<SearchBox
v-model:value="state.keyword"
diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/SequencesPanel/SequencesPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/SequencesPanel/SequencesPanel.vue
index faac2aac26..b34ad53bb7 100644
--- a/frontend/src/views/sql-editor/EditorPanel/Panels/SequencesPanel/SequencesPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/SequencesPanel/SequencesPanel.vue
@@ -2,7 +2,7 @@
<div v-if="metadata?.schema" class="h-full overflow-hidden flex flex-col">
<div
v-show="!metadata.func"
- class="w-full h-[44px] py-2 px-2 border-b flex flex-row gap-x-2 justify-end items-center"
+ class="w-full h-11 py-2 px-2 border-b flex flex-row gap-x-2 justify-end items-center"
>
<SearchBox
v-model:value="state.keyword"
diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TableDetail.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TableDetail.vue
index 088b786b0d..7095ef58b6 100644
--- a/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TableDetail.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/TablesPanel/TableDetail.vue
@@ -1,6 +1,6 @@
<template>
<div
- class="w-full h-[28px] flex flex-row gap-x-2 justify-between items-center"
+ class="w-full h-7 flex flex-row gap-x-2 justify-between items-center"
>
<NTabs
v-model:value="state.view"
diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/TriggersPanel/TriggersPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/TriggersPanel/TriggersPanel.vue
index 2dc2c6f8f1..9d4d307ac0 100644
--- a/frontend/src/views/sql-editor/EditorPanel/Panels/TriggersPanel/TriggersPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/TriggersPanel/TriggersPanel.vue
@@ -2,7 +2,7 @@
<div v-if="metadata?.schema" class="h-full overflow-hidden flex flex-col">
<div
v-show="!metadata.trigger"
- class="w-full h-[44px] py-2 px-2 border-b flex flex-row gap-x-2 justify-end items-center"
+ class="w-full h-11 py-2 px-2 border-b flex flex-row gap-x-2 justify-end items-center"
>
<SearchBox
v-model:value="state.keyword"
diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewDetail.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewDetail.vue
index 0d0254e71c..a8ed4f95bf 100644
--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewDetail.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewDetail.vue
@@ -1,6 +1,6 @@
<template>
<div
- class="w-full h-[44px] px-2 py-2 border-b flex flex-row justify-between items-center"
+ class="w-full h-11 px-2 py-2 border-b flex flex-row justify-between items-center"
>
<NTabs
v-model:value="state.mode"
diff --git a/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewsPanel.vue b/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewsPanel.vue
index 25e9ef7465..348bf52de1 100644
--- a/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewsPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/Panels/ViewsPanel/ViewsPanel.vue
@@ -2,7 +2,7 @@
<div v-if="metadata?.schema" class="h-full overflow-hidden flex flex-col">
<div
v-show="!metadata.view"
- class="w-full h-[44px] py-2 px-2 border-b flex flex-row gap-x-2 justify-end items-center"
+ class="w-full h-11 py-2 px-2 border-b flex flex-row gap-x-2 justify-end items-center"
>
<SearchBox
v-model:value="state.keyword"
diff --git a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue
index 58d587ae9f..344734463c 100644
--- a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/SQLEditor.vue
@@ -12,7 +12,6 @@
:language="language"
:dialect="dialect"
:readonly="readonly"
- :advices="advices"
:auto-complete-context="{
instance: instance.name,
database: database.name,
@@ -37,7 +36,6 @@ import { storeToRefs } from "pinia";
import { v1 as uuidv1 } from "uuid";
import { computed, nextTick, onBeforeUnmount, ref, watch } from "vue";
import type {
- AdviceOption,
IStandaloneCodeEditor,
MonacoModule,
Selection as MonacoSelection,
@@ -90,13 +88,6 @@ const AIContext = useAIContext();
const monacoEditorRef = ref<InstanceType<typeof MonacoEditor>>();
const content = computed(() => currentTab.value?.statement ?? "");
-const advices = computed((): AdviceOption[] => {
- const tab = currentTab.value;
- if (!tab) {
- return [];
- }
- return tab.editorState.advices;
-});
const { instance, database } = useConnectionOfCurrentSQLEditorTab();
const language = useInstanceV1EditorLanguage(instance);
const dialect = computed((): SQLDialect => {
@@ -134,7 +125,6 @@ const handleUpdateSelection = (selection: MonacoSelection | null) => {
if (!tab) return;
tabStore.updateCurrentTab({
editorState: {
- ...tab.editorState,
selection,
},
});
diff --git a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue
index 1a5f13d6eb..cfadc00636 100644
--- a/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/StandardPanel/StandardPanel.vue
@@ -72,7 +72,6 @@
</template>
<script lang="ts" setup>
-import { cloneDeep } from "lodash-es";
import { NSplit } from "naive-ui";
import { storeToRefs } from "pinia";
import { computed, defineAsyncComponent, nextTick, ref } from "vue";
@@ -82,14 +81,9 @@ import { AIChatToSQL } from "@/plugins/ai";
import {
useConnectionOfCurrentSQLEditorTab,
useSQLEditorTabStore,
- useTabViewStateStore,
} from "@/store";
import type { SQLEditorQueryParams } from "@/types";
-import {
- defaultSQLEditorTab,
- instanceV1HasReadonlyMode,
- suggestedTabTitleForSQLEditorConnection,
-} from "@/utils";
+import { instanceV1HasReadonlyMode } from "@/utils";
import { useSQLEditorContext } from "../../context";
import {
EditorAction,
@@ -107,7 +101,6 @@ const { currentTab: tab, isDisconnected } = storeToRefs(tabStore);
const { instance } = useConnectionOfCurrentSQLEditorTab();
const { showAIPanel, editorPanelSize, handleEditorPanelResize } =
useSQLEditorContext();
-const { cloneViewState } = useTabViewStateStore();
const sqlEditorRef = ref<InstanceType<typeof SQLEditor>>();
const allowReadonlyMode = computed(() => {
@@ -137,24 +130,9 @@ const handleExecute = ({
newTab: boolean;
}) => {
if (newTab) {
- const fromTab = tabStore.currentTab;
- const clonedTab = defaultSQLEditorTab();
- if (fromTab) {
- clonedTab.connection = cloneDeep(fromTab.connection);
- clonedTab.treeState = cloneDeep(fromTab.treeState);
- }
- clonedTab.title = suggestedTabTitleForSQLEditorConnection(
- clonedTab.connection
- );
- const newTab = tabStore.addTab(clonedTab, /* beside */ true);
- if (fromTab) {
- const vs = cloneViewState(fromTab.id, newTab.id);
- if (vs) {
- vs.view = "CODE";
- vs.detail = {};
- }
- }
- newTab.statement = params.statement;
+ tabStore.cloneTab(tabStore.currentTabId, {
+ statement: params.statement,
+ });
}
nextTick(() => {
diff --git a/frontend/src/views/sql-editor/EditorPanel/context/viewState.tsx b/frontend/src/views/sql-editor/EditorPanel/context/viewState.tsx
index f5070fb751..8385853cae 100644
--- a/frontend/src/views/sql-editor/EditorPanel/context/viewState.tsx
+++ b/frontend/src/views/sql-editor/EditorPanel/context/viewState.tsx
@@ -16,9 +16,9 @@ import { t } from "@/plugins/i18n";
import {
useConnectionOfCurrentSQLEditorTab,
useSQLEditorTabStore,
- useTabViewStateStore,
} from "@/store";
import {
+ defaultViewState,
type EditorPanelView,
type EditorPanelViewState as ViewState,
} from "@/types";
@@ -34,14 +34,12 @@ const KEY = Symbol(
export const provideCurrentTabViewStateContext = () => {
const tabStore = useSQLEditorTabStore();
- const tabViewStateStore = useTabViewStateStore();
const { currentTab: tab } = storeToRefs(tabStore);
const { instance } = useConnectionOfCurrentSQLEditorTab();
const viewState = computed(() => {
- if (!tab.value) return undefined;
- return tabViewStateStore.getViewState(tab.value.id);
+ return tab.value?.viewState;
});
const availableActions = computed(() => {
@@ -119,7 +117,13 @@ export const provideCurrentTabViewStateContext = () => {
const updateViewState = (patch: Partial<ViewState>) => {
if (!tab.value) return;
- tabViewStateStore.updateViewState(tab.value.id, patch);
+ tabStore.updateTab(tab.value.id, {
+ viewState: {
+ ...defaultViewState(),
+ ...tab.value.viewState,
+ ...patch,
+ },
+ });
};
watch(
diff --git a/frontend/src/views/sql-editor/Sheet/context.ts b/frontend/src/views/sql-editor/Sheet/context.ts
index 85a386aa68..02c097e32b 100644
--- a/frontend/src/views/sql-editor/Sheet/context.ts
+++ b/frontend/src/views/sql-editor/Sheet/context.ts
@@ -130,12 +130,14 @@ const useSheetTreeByView = (
case "shared":
return worksheetList.value.map(convertToWorksheetLikeItem);
case "draft":
- return tabStore.draftList.map((tab) => ({
- name: tab.id,
- title: tab.title,
- folders: [],
- type: "draft",
- }));
+ return tabStore.openTabList
+ .filter((tab) => !tab.worksheet)
+ .map((tab) => ({
+ name: tab.id,
+ title: tab.title,
+ folders: [],
+ type: "draft",
+ }));
default:
return [];
}
diff --git a/frontend/src/views/sql-editor/TabList/ContextMenu.vue b/frontend/src/views/sql-editor/TabList/ContextMenu.vue
index 34c5f4ae14..159d0b8114 100644
--- a/frontend/src/views/sql-editor/TabList/ContextMenu.vue
+++ b/frontend/src/views/sql-editor/TabList/ContextMenu.vue
@@ -18,14 +18,12 @@ 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) {
@@ -61,11 +59,8 @@ const options = computed((): DropdownOption[] => {
CLOSE_ALL,
];
- const { tab } = state.value;
- if (
- tab.mode === "WORKSHEET" &&
- tabViewStateStore.getViewState(tab.id).view === "CODE"
- ) {
+ const { mode, viewState } = state.value.tab;
+ if (mode === "WORKSHEET" && viewState.view === "CODE") {
options.push(
{
type: "divider",
diff --git a/frontend/src/views/sql-editor/TabList/TabItem/Label.vue b/frontend/src/views/sql-editor/TabList/TabItem/Label.vue
index 45bc2a3c73..0e4da37733 100644
--- a/frontend/src/views/sql-editor/TabList/TabItem/Label.vue
+++ b/frontend/src/views/sql-editor/TabList/TabItem/Label.vue
@@ -29,11 +29,7 @@ import { create } from "@bufbuild/protobuf";
import { NEllipsis } from "naive-ui";
import { computed, nextTick, reactive, ref, watch } from "vue";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
-import {
- useSQLEditorTabStore,
- useTabViewStateStore,
- useWorkSheetStore,
-} from "@/store";
+import { useSQLEditorTabStore, useWorkSheetStore } from "@/store";
import type { SQLEditorTab } from "@/types";
import { WorksheetSchema } from "@/types/proto-es/v1/worksheet_service_pb";
import { useTabListContext } from "../context";
@@ -54,13 +50,13 @@ 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 readonly = computed(() => {
+ const viewState = props.tab.viewState;
+ return viewState.view !== "CODE";
+});
const isCurrentTab = computed(() => props.tab.id === tabStore.currentTabId);
@@ -78,7 +74,7 @@ const beginEdit = () => {
state.editing = true;
state.title = props.tab.title;
nextTick(() => {
- inputRef.value?.focus();
+ inputRef.value?.select();
});
};
diff --git a/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue b/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue
index d3c468b1ba..9d6256dbc5 100644
--- a/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue
+++ b/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue
@@ -1,6 +1,6 @@
<template>
<div class="opacity-80 flex items-center gap-x-2">
- <PencilLineIcon v-if="!tab.worksheet && viewState.view === 'CODE'" class="w-4 h-4" />
+ <PencilLineIcon v-if="isDraft" class="w-4 h-4" />
<template v-else>
<UsersIcon
v-if="sheet && !isWorksheetCreator(sheet)"
@@ -15,7 +15,7 @@
<script lang="ts" setup>
import { PencilLineIcon, UsersIcon, WrenchIcon } from "lucide-vue-next";
import { computed } from "vue";
-import { useTabViewStateStore, useWorkSheetStore } from "@/store";
+import { useWorkSheetStore } from "@/store";
import type { SQLEditorTab } from "@/types";
import { useSheetContext } from "@/views/sql-editor/Sheet";
import { SheetConnectionIcon } from "../../EditorCommon";
@@ -26,9 +26,14 @@ const props = defineProps<{
const sheetV1Store = useWorkSheetStore();
const { isWorksheetCreator } = useSheetContext();
-const { getViewState } = useTabViewStateStore();
-const viewState = computed(() => getViewState(props.tab.id));
+const isDraft = computed(() => {
+ const { worksheet, viewState } = props.tab;
+ if (worksheet) {
+ return false;
+ }
+ return viewState.view === "CODE";
+});
const sheet = computed(() => {
const { worksheet: sheetName } = props.tab;
diff --git a/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue b/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue
index 8204b3ea35..f97040eaa3 100644
--- a/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue
+++ b/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue
@@ -47,8 +47,8 @@ const icon = computed((): IconType | undefined => {
if (state.hovering) {
return "close";
}
- const { mode, status, worksheet } = props.tab;
- if (mode === "WORKSHEET" && !!worksheet && status === "DIRTY") {
+ const { mode, status } = props.tab;
+ if (mode === "WORKSHEET" && status === "DIRTY") {
return "unsaved";
}
return "close";
diff --git a/frontend/src/views/sql-editor/TabList/TabList.vue b/frontend/src/views/sql-editor/TabList/TabList.vue
index 080618c2fc..55ca3ee0a3 100644
--- a/frontend/src/views/sql-editor/TabList/TabList.vue
+++ b/frontend/src/views/sql-editor/TabList/TabList.vue
@@ -74,13 +74,13 @@ import { useI18n } from "vue-i18n";
import Draggable from "vuedraggable";
import ProfileDropdown from "@/components/ProfileDropdown.vue";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
-import { useSQLEditorTabStore, useTabViewStateStore } from "@/store";
+import { useSQLEditorTabStore } from "@/store";
import type { SQLEditorTab } from "@/types";
import { defer, usePreventBackAndForward } from "@/utils";
import { useSQLEditorContext } from "../context";
import BrandingLogoWrapper from "./BrandingLogoWrapper.vue";
import ContextMenu from "./ContextMenu.vue";
-import { provideTabListContext } from "./context";
+import { useTabListContext } from "./context";
import TabItem from "./TabItem/TabItem.vue";
type LocalState = {
@@ -91,6 +91,7 @@ type LocalState = {
const tabStore = useSQLEditorTabStore();
const editorContext = useSQLEditorContext();
+const context = useTabListContext();
const { t } = useI18n();
const dialog = useDialog();
@@ -102,8 +103,6 @@ const state = reactive<LocalState>({
});
const scrollbarRef = ref<InstanceType<typeof NScrollbar>>();
const tabListRef = ref<InstanceType<typeof Draggable>>();
-const { removeViewState } = useTabViewStateStore();
-const context = provideTabListContext();
const contextMenuRef = ref<InstanceType<typeof ContextMenu>>();
const scrollState = reactive({
@@ -172,9 +171,7 @@ const handleRemoveTab = async (tab: SQLEditorTab, focusWhenConfirm = false) => {
}
function remove() {
- tabStore.closeTab(tab);
- removeViewState(tab.id);
-
+ tabStore.closeTab(tab.id);
nextTick(recalculateScrollState);
}