Skip to content

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

refactor(sql-editor): SQL editor sharing feature part Ⅰ (#584)

Yunwei Xiao31e396c231f9
diff --git a/frontend/src/components/MonacoEditor/MonacoEditor.vue b/frontend/src/components/MonacoEditor/MonacoEditor.vue
index 5ea135d1d9..1c372a329b 100644
--- a/frontend/src/components/MonacoEditor/MonacoEditor.vue
+++ b/frontend/src/components/MonacoEditor/MonacoEditor.vue
@@ -19,7 +19,7 @@ import type { editor as Editor } from "monaco-editor";
import { useMonaco } from "./useMonaco";
import {
- EditorSelectorGetters,
+ TabGetters,
SqlDialect,
SqlEditorActions,
SqlEditorState,
@@ -56,8 +56,8 @@ const language = toRef(props, "language");
const { shouldSetContent } = useNamespacedState<SqlEditorState>("sqlEditor", [
"shouldSetContent",
]);
-const { currentTab } = useNamespacedGetters<EditorSelectorGetters>(
- "editorSelector",
+const { currentTab } = useNamespacedGetters<TabGetters>(
+ "tab",
["currentTab"]
);
const { setShouldSetContent } = useNamespacedActions<SqlEditorActions>(
diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.ts
index e2f911865b..c8a890b757 100644
--- a/frontend/src/composables/useExecuteSQL.ts
+++ b/frontend/src/composables/useExecuteSQL.ts
@@ -31,7 +31,7 @@ const useExecuteSQL = () => {
notify("INFO", t("common.tips"), t("sql-editor.can-not-execute-query"));
}
- const currentTab = store.getters["editorSelector/currentTab"];
+ const currentTab = store.getters["tab/currentTab"];
const queryStatement = currentTab.queryStatement;
const selectedStatement = currentTab.selectedStatement;
const sqlStatement = selectedStatement || queryStatement;
diff --git a/frontend/src/store/index.ts b/frontend/src/store/index.ts
index 61215aa067..51f555acde 100644
--- a/frontend/src/store/index.ts
+++ b/frontend/src/store/index.ts
@@ -22,7 +22,7 @@ export const store: Store<any> = createStore({
modules,
plugins: [
createPersistedState({
- paths: ["editorSelector"],
+ paths: ["tab"],
}),
],
strict: !isProd,
diff --git a/frontend/src/store/modules/editorSelector.ts b/frontend/src/store/modules/editorSelector.ts
deleted file mode 100644
index 0ae26410f7..0000000000
--- a/frontend/src/store/modules/editorSelector.ts
+++ /dev/null
@@ -1,117 +0,0 @@
-import dayjs from "dayjs";
-import { v1 as uuidv1 } from "uuid";
-import { TabInfo, AnyTabInfo, EditorSelectorState } from "../../types";
-import * as types from "../mutation-types";
-import { makeActions } from "../actions";
-
-const getDefaultTab = () => {
- return {
- id: uuidv1(),
- label: "Untitled Queries",
- isSaved: false,
- savedAt: dayjs().format("YYYY-MM-DD HH:mm:ss"),
- queryStatement: "",
- selectedStatement: "",
- };
-};
-
-const state: () => EditorSelectorState = () => {
- const defaultTab = getDefaultTab();
-
- return {
- queryTabList: [defaultTab],
- activeTabId: defaultTab.id,
- };
-};
-
-const getters = {
- currentTab(state: EditorSelectorState) {
- const idx = state.queryTabList.findIndex(
- (tab: TabInfo) => tab.id === state.activeTabId
- );
- return (idx === -1 ? {} : state.queryTabList[idx]) as TabInfo;
- },
- hasTabs(state: EditorSelectorState) {
- return state.queryTabList.length > 0;
- },
-};
-
-const mutations = {
- [types.SET_EDITOR_SELECTOR_STATE](
- state: EditorSelectorState,
- payload: Partial<EditorSelectorState>
- ) {
- Object.assign(state, payload);
- },
- [types.ADD_TAB](state: EditorSelectorState, payload: TabInfo) {
- state.queryTabList.push(payload);
- },
- [types.REMOVE_TAB](state: EditorSelectorState, payload: TabInfo) {
- state.queryTabList.splice(state.queryTabList.indexOf(payload), 1);
- },
- [types.UPDATE_TAB](state: EditorSelectorState, payload: TabInfo) {
- const idx = state.queryTabList.findIndex(
- (tab: TabInfo) => tab.id === payload.id
- );
- Object.assign(state.queryTabList[idx], payload);
- },
- [types.UPDATE_ACTIVE_TAB](state: EditorSelectorState, payload: AnyTabInfo) {
- const idx = state.queryTabList.findIndex(
- (tab: TabInfo) => tab.id === state.activeTabId
- );
- Object.assign(state.queryTabList[idx], {
- ...state.queryTabList[idx],
- ...payload,
- });
- },
- [types.SET_ACTIVE_TAB_ID](state: EditorSelectorState, payload: string) {
- state.activeTabId = payload;
- },
-};
-
-type ActionsMap = {
- setEditorSelectorState: typeof mutations.SET_EDITOR_SELECTOR_STATE;
-};
-
-const actions = {
- ...makeActions<ActionsMap>({
- setEditorSelectorState: types.SET_EDITOR_SELECTOR_STATE,
- }),
- addTab({ commit }: any, payload: AnyTabInfo) {
- const newTab = {
- ...getDefaultTab(),
- label: payload.label ? payload.label : `Untitled Queries`,
- isSaved: false,
- savedAt: dayjs().format("YYYY-MM-DD HH:mm:ss"),
- queryStatement: payload.queryStatement || "",
- selectedStatement: payload.selectedStatement || "",
- };
-
- commit(types.SET_EDITOR_SELECTOR_STATE, {
- activeTabId: newTab.id,
- });
- commit(types.ADD_TAB, newTab);
- },
- removeTab({ commit, state, dispatch }: any, payload: TabInfo) {
- commit(types.REMOVE_TAB, payload);
- const tabsLength = state.queryTabList.length;
-
- if (tabsLength > 0) {
- dispatch("setActiveTabId", state.queryTabList[tabsLength - 1].id);
- }
- },
- updateActiveTab({ commit }: any, payload: AnyTabInfo) {
- commit(types.UPDATE_ACTIVE_TAB, payload);
- },
- setActiveTabId({ commit, state }: any, payload: string) {
- commit(types.SET_ACTIVE_TAB_ID, payload);
- },
-};
-
-export default {
- namespaced: true,
- state,
- getters,
- actions,
- mutations,
-};
diff --git a/frontend/src/store/modules/sqlEditor.ts b/frontend/src/store/modules/sqlEditor.ts
index 447dd2c4bd..278222d488 100644
--- a/frontend/src/store/modules/sqlEditor.ts
+++ b/frontend/src/store/modules/sqlEditor.ts
@@ -213,7 +213,7 @@ const actions = {
{ dispatch, state, rootGetters }: any,
payload: Partial<QueryInfo> = {}
) {
- const currentTab = rootGetters["editorSelector/currentTab"];
+ const currentTab = rootGetters["tab/currentTab"];
const res = await dispatch(
"sql/query",
{
@@ -226,7 +226,7 @@ const actions = {
);
dispatch(
- "editorSelector/updateActiveTab",
+ "tab/updateCurrentTab",
{
queryResult: res.data,
},
diff --git a/frontend/src/store/modules/tab.ts b/frontend/src/store/modules/tab.ts
new file mode 100644
index 0000000000..368cb3932e
--- /dev/null
+++ b/frontend/src/store/modules/tab.ts
@@ -0,0 +1,105 @@
+import dayjs from "dayjs";
+import { v1 as uuidv1 } from "uuid";
+import { TabInfo, AnyTabInfo, TabState } from "../../types";
+import * as types from "../mutation-types";
+import { makeActions } from "../actions";
+
+export const getDefaultTab = () => {
+ return {
+ id: uuidv1(),
+ label: "Untitled Queries",
+ isSaved: false,
+ savedAt: dayjs().format("YYYY-MM-DD HH:mm:ss"),
+ queryStatement: "",
+ selectedStatement: "",
+ };
+};
+
+// tab store is the sheet store for frontend
+const state: () => TabState = () => {
+ return {
+ tabList: [],
+ currentTabId: "",
+ };
+};
+
+const getters = {
+ currentTab(state: TabState) {
+ const idx = state.tabList.findIndex(
+ (tab: TabInfo) => tab.id === state.currentTabId
+ );
+ return (idx === -1 ? {} : state.tabList[idx]) as TabInfo;
+ },
+ hasTabs(state: TabState) {
+ return state.tabList.length > 0;
+ },
+};
+
+const mutations = {
+ [types.SET_TAB_STATE](state: TabState, payload: Partial<TabState>) {
+ Object.assign(state, payload);
+ },
+ [types.ADD_TAB](state: TabState, payload: TabInfo) {
+ state.tabList.push(payload);
+ },
+ [types.REMOVE_TAB](state: TabState, payload: TabInfo) {
+ state.tabList.splice(state.tabList.indexOf(payload), 1);
+ },
+ [types.UPDATE_TAB](state: TabState, payload: TabInfo) {
+ const idx = state.tabList.findIndex(
+ (tab: TabInfo) => tab.id === payload.id
+ );
+ Object.assign(state.tabList[idx], payload);
+ },
+ [types.UPDATE_CURRENT_TAB](state: TabState, payload: AnyTabInfo) {
+ const idx = state.tabList.findIndex(
+ (tab: TabInfo) => tab.id === state.currentTabId
+ );
+ Object.assign(state.tabList[idx], {
+ ...state.tabList[idx],
+ ...payload,
+ });
+ },
+ [types.SET_CURRENT_TAB_ID](state: TabState, payload: string) {
+ state.currentTabId = payload;
+ },
+};
+
+type ActionsMap = {
+ setTabState: typeof mutations.SET_TAB_STATE;
+ removeTab: typeof mutations.REMOVE_TAB;
+};
+
+const actions = {
+ ...makeActions<ActionsMap>({
+ setTabState: types.SET_TAB_STATE,
+ removeTab: types.REMOVE_TAB,
+ }),
+ addTab({ commit }: any, payload: AnyTabInfo) {
+ const defaultTab = getDefaultTab();
+
+ const newTab = {
+ ...defaultTab,
+ ...payload,
+ };
+
+ commit(types.SET_TAB_STATE, {
+ currentTabId: newTab.id,
+ });
+ commit(types.ADD_TAB, newTab);
+ },
+ updateCurrentTab({ commit }: any, payload: AnyTabInfo) {
+ commit(types.UPDATE_CURRENT_TAB, payload);
+ },
+ setCurrentTabId({ commit, state }: any, payload: string) {
+ commit(types.SET_CURRENT_TAB_ID, payload);
+ },
+};
+
+export default {
+ namespaced: true,
+ state,
+ getters,
+ actions,
+ mutations,
+};
diff --git a/frontend/src/store/mutation-types.ts b/frontend/src/store/mutation-types.ts
index ac969ab9a3..94437c107c 100644
--- a/frontend/src/store/mutation-types.ts
+++ b/frontend/src/store/mutation-types.ts
@@ -10,9 +10,9 @@ export const SET_SAVED_QUERY_LIST = "SET_SAVED_QUERY_LIST";
export const SET_IS_FETCHING_SAVED_QUERIES = "SET_IS_FETCHING_SAVED_QUERIES";
// Editor Selector mutation types
-export const SET_EDITOR_SELECTOR_STATE = "SET_EDITOR_SELECTOR_STATE";
+export const SET_TAB_STATE = "SET_TAB_STATE";
export const ADD_TAB = "ADD_TAB";
export const REMOVE_TAB = "REMOVE_TAB";
export const UPDATE_TAB = "UPDATE_TAB";
-export const UPDATE_ACTIVE_TAB = "UPDATE_ACTIVE_TAB";
-export const SET_ACTIVE_TAB_ID = "SET_ACTIVE_TAB_ID";
+export const UPDATE_CURRENT_TAB = "UPDATE_CURRENT_TAB";
+export const SET_CURRENT_TAB_ID = "SET_CURRENT_TAB_ID";
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index 0655ff301c..cb15814713 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -36,5 +36,5 @@ export * from "./view";
export * from "./label";
export * from "./deployment";
export * from "./sqlEditor";
-export * from "./editorSelector";
+export * from "./tab";
export * from "./subscription";
diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.ts
index 424e159e7d..78f1513935 100644
--- a/frontend/src/types/store.ts
+++ b/frontend/src/types/store.ts
@@ -44,10 +44,10 @@ import { Table } from "./table";
import { VCS } from "./vcs";
import { Label } from "./label";
import { ConnectionAtom, ConnectionContext } from "./sqlEditor";
-import { TabInfo } from "./editorSelector";
+import { TabInfo } from "./tab";
import instanceStore from "../store/modules/instance";
import sqlEditorStore from "../store/modules/sqlEditor";
-import editorSelectorStore from "../store/modules/editorSelector";
+import tabStore from "../store/modules/tab";
export interface ActuatorState {
serverInfo?: ServerInfo;
@@ -205,13 +205,13 @@ export type SqlEditorGetters = typeof sqlEditorStore.getters;
export type SqlEditorActions = typeof sqlEditorStore.actions;
export type SqlEditorMutations = typeof sqlEditorStore.mutations;
-export interface EditorSelectorState {
- queryTabList: TabInfo[];
- activeTabId: string;
+export interface TabState {
+ tabList: TabInfo[];
+ currentTabId: string;
}
-export type EditorSelectorGetters = typeof editorSelectorStore.getters;
-export type EditorSelectorActions = typeof editorSelectorStore.actions;
-export type EditorSelectorMutations = typeof editorSelectorStore.mutations;
+export type TabGetters = typeof tabStore.getters;
+export type TabActions = typeof tabStore.actions;
+export type TabMutations = typeof tabStore.mutations;
export interface DeploymentState {
deploymentConfigByProjectId: Map<ProjectId, DeploymentConfig>;
diff --git a/frontend/src/types/editorSelector.ts b/frontend/src/types/tab.ts
similarity index 100%
rename from frontend/src/types/editorSelector.ts
rename to frontend/src/types/tab.ts
diff --git a/frontend/src/views/SqlEditor/AsidePanel/QueryHistoryContainer.vue b/frontend/src/views/SqlEditor/AsidePanel/QueryHistoryContainer.vue
index 7c06b51845..b51aa0b7c0 100644
--- a/frontend/src/views/SqlEditor/AsidePanel/QueryHistoryContainer.vue
+++ b/frontend/src/views/SqlEditor/AsidePanel/QueryHistoryContainer.vue
@@ -83,7 +83,7 @@ import {
} from "vuex-composition-helpers";
import {
- EditorSelectorActions,
+ TabActions,
QueryHistory,
SqlEditorActions,
SqlEditorState,
@@ -109,10 +109,7 @@ const { deleteQueryHistory } = useNamespacedActions<SqlEditorActions>(
"sqlEditor",
["deleteQueryHistory"]
);
-const { addTab } = useNamespacedActions<EditorSelectorActions>(
- "editorSelector",
- ["addTab"]
-);
+const { addTab } = useNamespacedActions<TabActions>("tab", ["addTab"]);
const state = reactive<State>({
search: "",
diff --git a/frontend/src/views/SqlEditor/AsidePanel/SavedQueryContainer.vue b/frontend/src/views/SqlEditor/AsidePanel/SavedQueryContainer.vue
index a2836c1b45..e911378d22 100644
--- a/frontend/src/views/SqlEditor/AsidePanel/SavedQueryContainer.vue
+++ b/frontend/src/views/SqlEditor/AsidePanel/SavedQueryContainer.vue
@@ -103,9 +103,9 @@ import {
} from "vuex-composition-helpers";
import {
- EditorSelectorActions,
- EditorSelectorGetters,
- EditorSelectorState,
+ TabActions,
+ TabGetters,
+ TabState,
SavedQuery,
SqlEditorActions,
SqlEditorState,
@@ -128,25 +128,18 @@ const { savedQueryList, isFetchingSavedQueries: isLoading } =
"savedQueryList",
"isFetchingSavedQueries",
]);
-const { queryTabList } = useNamespacedState<EditorSelectorState>(
- "editorSelector",
- ["queryTabList"]
-);
-const { currentTab } = useNamespacedGetters<EditorSelectorGetters>(
- "editorSelector",
- ["currentTab"]
-);
+const { tabList } = useNamespacedState<TabState>("tab", ["tabList"]);
+const { currentTab } = useNamespacedGetters<TabGetters>("tab", ["currentTab"]);
const { deleteSavedQuery, setShouldSetContent, patchSavedQuery } =
useNamespacedActions<SqlEditorActions>("sqlEditor", [
"deleteSavedQuery",
"setShouldSetContent",
"patchSavedQuery",
]);
-const { updateActiveTab, setActiveTabId } =
- useNamespacedActions<EditorSelectorActions>("editorSelector", [
- "updateActiveTab",
- "setActiveTabId",
- ]);
+const { updateCurrentTab, setCurrentTabId } = useNamespacedActions<TabActions>(
+ "tab",
+ ["updateCurrentTab", "setCurrentTabId"]
+);
const state = reactive<State>({
search: "",
@@ -233,7 +226,7 @@ const handleSavedQueryNameChanged = () => {
});
if (currentTab.value.currentQueryId === state.editingSavedQueryId) {
- updateActiveTab({
+ updateCurrentTab({
label: state.currentSavedQueryName,
});
}
@@ -263,7 +256,7 @@ const handleDeleteSavedQuery = () => {
deleteSavedQuery(state.currentActionSavedQuery.id);
if (currentTab.value.currentQueryId === state.currentActionSavedQuery.id) {
- updateActiveTab({
+ updateCurrentTab({
currentQueryId: undefined,
});
}
@@ -273,15 +266,15 @@ const handleDeleteSavedQuery = () => {
const handleSavedQueryClick = (savedQuery: SavedQuery) => {
if (currentTab.value.currentQueryId !== savedQuery.id) {
- for (const tab of queryTabList.value) {
+ for (const tab of tabList.value) {
if (tab.currentQueryId === savedQuery.id) {
- setActiveTabId(tab.id);
+ setCurrentTabId(tab.id);
setShouldSetContent(true);
return;
}
}
- updateActiveTab({
+ updateCurrentTab({
label: savedQuery.name,
queryStatement: savedQuery.statement,
selectedStatement: "",
diff --git a/frontend/src/views/SqlEditor/EditorHeader.vue b/frontend/src/views/SqlEditor/EditorHeader.vue
index 956ec2ac5b..1c8503e27d 100644
--- a/frontend/src/views/SqlEditor/EditorHeader.vue
+++ b/frontend/src/views/SqlEditor/EditorHeader.vue
@@ -3,15 +3,17 @@
<div class="flex items-center">
<div class="flex-shrink-0 w-44">
<router-link to="/" class="select-none" active-class exact-active-class>
- <img class="h-12 w-auto" src="../../assets/logo-full.svg" alt="Bytebase" />
+ <img
+ class="h-12 w-auto"
+ src="../../assets/logo-full.svg"
+ alt="Bytebase"
+ />
</router-link>
</div>
<div class="hidden sm:block">
<div class="ml-6 flex items-baseline space-x-1">
<router-link to="/sql-editor" class="bar-link px-2 py-2 rounded-md">
- {{
- $t("sql-editor.self")
- }}
+ {{ $t("sql-editor.self") }}
</router-link>
</div>
</div>
@@ -25,7 +27,11 @@
></span>
<heroicons-outline:bell class="w-6 h-6" />
</router-link>
- <div v-if="showSwitchPlan" class="cursor-pointer" @click="toggleLocales">
+ <div
+ v-if="showSwitchPlan"
+ class="cursor-pointer"
+ @click="toggleLocales"
+ >
<heroicons-outline:translate class="w-6 h-6" />
</div>
<div class="ml-2">
@@ -57,32 +63,31 @@
-->
<div v-if="state.showMobileMenu" class="block md:hidden">
<router-link to="/project" class="bar-link rounded-md block px-3 py-2">
- {{
- $t("common.projects")
- }}
+ {{ $t("common.projects") }}
</router-link>
<router-link to="/db" class="bar-link rounded-md block px-3 py-2">
- {{
- $t("common.databases")
- }}
+ {{ $t("common.databases") }}
</router-link>
<router-link
v-if="showDBAItem"
to="/instance"
class="bar-link rounded-md block px-3 py-2"
- >{{ $t("common.instances") }}</router-link>
+ >{{ $t("common.instances") }}</router-link
+ >
<router-link
to="/environment"
class="bar-link rounded-md block px-3 py-2"
- >{{ $t("common.environments") }}</router-link>
+ >{{ $t("common.environments") }}</router-link
+ >
<router-link
to="/setting/member"
class="bar-link rounded-md block px-3 py-2"
- >{{ $t("common.settings") }}</router-link>
+ >{{ $t("common.settings") }}</router-link
+ >
</div>
</template>
@@ -95,7 +100,7 @@ import { useLocalStorage } from "@vueuse/core";
import { useStore } from "vuex";
import ProfileDropdown from "../../components/ProfileDropdown.vue";
-import { InboxSummary, PlanType, UNKNOWN_ID } from "../../types";
+import { InboxSummary, UNKNOWN_ID } from "../../types";
import { isDBAOrOwner, isDev } from "../../utils";
interface LocalState {
@@ -116,7 +121,9 @@ export default defineComponent({
const currentUser = computed(() => store.getters["auth/currentUser"]());
- const currentPlan = computed(() => store.getters["subscription/currentPlan"]());
+ const currentPlan = computed(() =>
+ store.getters["subscription/currentPlan"]()
+ );
const showDBAItem = computed((): boolean => {
return (
diff --git a/frontend/src/views/SqlEditor/EditorPanel/EditorAction.vue b/frontend/src/views/SqlEditor/EditorPanel/EditorAction.vue
index b208126f9e..35c6dae451 100644
--- a/frontend/src/views/SqlEditor/EditorPanel/EditorAction.vue
+++ b/frontend/src/views/SqlEditor/EditorPanel/EditorAction.vue
@@ -51,8 +51,8 @@ import {
SqlEditorState,
SqlEditorActions,
ConnectionContext,
- EditorSelectorGetters,
- EditorSelectorActions,
+ TabGetters,
+ TabActions,
} from "../../../types";
import { useExecuteSQL } from "../../../composables/useExecuteSQL";
import { isDev } from "../../../utils";
@@ -62,10 +62,7 @@ const { connectionTree, connectionContext } =
"connectionTree",
"connectionContext",
]);
-const { currentTab } = useNamespacedGetters<EditorSelectorGetters>(
- "editorSelector",
- ["currentTab"]
-);
+const { currentTab } = useNamespacedGetters<TabGetters>("tab", ["currentTab"]);
const {
createSavedQuery,
setConnectionContext,
@@ -77,10 +74,9 @@ const {
"patchSavedQuery",
"checkSavedQueryExistById",
]);
-const { updateActiveTab } = useNamespacedActions<EditorSelectorActions>(
- "editorSelector",
- ["updateActiveTab"]
-);
+const { updateCurrentTab } = useNamespacedActions<TabActions>("tab", [
+ "updateCurrentTab",
+]);
const isEmptyStatement = computed(
() => !currentTab.value || currentTab.value.queryStatement === ""
@@ -156,12 +152,12 @@ const handleSaveQueryBtnClick = async () => {
name: label,
statement: queryStatement,
});
- updateActiveTab({
+ updateCurrentTab({
currentQueryId: newSavedQuery.id,
});
}
- updateActiveTab({
+ updateCurrentTab({
isSaved: true,
});
};
diff --git a/frontend/src/views/SqlEditor/EditorPanel/ExecuteHint.vue b/frontend/src/views/SqlEditor/EditorPanel/ExecuteHint.vue
index 055ef61700..02e300266d 100644
--- a/frontend/src/views/SqlEditor/EditorPanel/ExecuteHint.vue
+++ b/frontend/src/views/SqlEditor/EditorPanel/ExecuteHint.vue
@@ -50,7 +50,7 @@ import {
import type {
SqlEditorState,
SqlEditorGetters,
- EditorSelectorGetters,
+ TabGetters,
} from "../../../types";
import {
parseSQL,
@@ -72,10 +72,7 @@ const { findProjectIdByDatabaseId } = useNamespacedGetters<SqlEditorGetters>(
const { connectionContext } = useNamespacedState<SqlEditorState>("sqlEditor", [
"connectionContext",
]);
-const { currentTab } = useNamespacedGetters<EditorSelectorGetters>(
- "editorSelector",
- ["currentTab"]
-);
+const { currentTab } = useNamespacedGetters<TabGetters>("tab", ["currentTab"]);
const parsedStatement = computed(() => {
const sqlStatement =
diff --git a/frontend/src/views/SqlEditor/EditorPanel/QueryEditor.vue b/frontend/src/views/SqlEditor/EditorPanel/QueryEditor.vue
index f620b5fe4a..730ff5d4e2 100644
--- a/frontend/src/views/SqlEditor/EditorPanel/QueryEditor.vue
+++ b/frontend/src/views/SqlEditor/EditorPanel/QueryEditor.vue
@@ -18,18 +18,18 @@ import {
import { useExecuteSQL } from "../../../composables/useExecuteSQL";
import {
- EditorSelectorActions,
- EditorSelectorGetters,
+ TabActions,
+ TabGetters,
SqlEditorActions,
} from "../../../types";
-const { currentTab } = useNamespacedGetters<EditorSelectorGetters>(
- "editorSelector",
+const { currentTab } = useNamespacedGetters<TabGetters>(
+ "tab",
["currentTab"]
);
-const { updateActiveTab } = useNamespacedActions<EditorSelectorActions>(
- "editorSelector",
- ["updateActiveTab"]
+const { updateCurrentTab } = useNamespacedActions<TabActions>(
+ "tab",
+ ["updateCurrentTab"]
);
const { createSavedQuery, patchSavedQuery, checkSavedQueryExistById } =
useNamespacedActions<SqlEditorActions>("sqlEditor", [
@@ -43,14 +43,14 @@ const { execute } = useExecuteSQL();
const sqlCode = computed(() => currentTab.value.queryStatement);
const handleChange = debounce((value: string) => {
- updateActiveTab({
+ updateCurrentTab({
queryStatement: value,
isSaved: false,
});
}, 300);
const handleChangeSelection = debounce((value: string) => {
- updateActiveTab({
+ updateCurrentTab({
selectedStatement: value,
});
}, 300);
@@ -70,12 +70,12 @@ const handleSave = async (statement: string) => {
name: label,
statement,
});
- updateActiveTab({
+ updateCurrentTab({
currentQueryId: newSavedQuery.id,
});
}
- updateActiveTab({
+ updateCurrentTab({
isSaved: true,
});
};
diff --git a/frontend/src/views/SqlEditor/SqlEditor.vue b/frontend/src/views/SqlEditor/SqlEditor.vue
index 11224f4acd..eb42e0bee8 100644
--- a/frontend/src/views/SqlEditor/SqlEditor.vue
+++ b/frontend/src/views/SqlEditor/SqlEditor.vue
@@ -35,8 +35,8 @@ import GettingStarted from "./GettingStarted.vue";
const store = useStore();
-const hasTabs = computed(() => store.getters["editorSelector/hasTabs"]);
-const paneKey = computed(() => store.getters["editorSelector/currentTab"].id);
+const hasTabs = computed(() => store.getters["tab/hasTabs"]);
+const paneKey = computed(() => store.getters["tab/currentTab"].id);
</script>
<style>
diff --git a/frontend/src/views/SqlEditor/TabListContainer.vue b/frontend/src/views/SqlEditor/TabListContainer.vue
index ef57c3b6b0..38925872a2 100644
--- a/frontend/src/views/SqlEditor/TabListContainer.vue
+++ b/frontend/src/views/SqlEditor/TabListContainer.vue
@@ -11,10 +11,10 @@
@wheel="handleScollTabList"
>
<div
- v-for="tab in queryTabList"
+ v-for="tab in tabList"
:key="tab.id"
class="tag-list-tab"
- :class="{ active: tab.id === activeTabId }"
+ :class="{ active: tab.id === currentTabId }"
:style="scrollState.style"
@click="handleSelectTab(tab)"
@mouseover="enterTabId = tab.id"
@@ -51,7 +51,7 @@
{{ tab.label }}
</span>
</div>
- <template v-if="enterTabId === tab.id && queryTabList.length > 1">
+ <template v-if="enterTabId === tab.id && tabList.length > 1">
<span
class="suffix close hover:bg-gray-200 rounded-sm"
@click.prevent.stop="handleRemoveTab(tab)"
@@ -65,9 +65,7 @@
<carbon:dot-mark class="h-4 w-4" />
</span>
</template>
- <template
- v-else-if="tab.id === activeTabId && queryTabList.length > 1"
- >
+ <template v-else-if="tab.id === currentTabId && tabList.length > 1">
<span
class="suffix close hover:bg-gray-200 rounded-sm"
@click.prevent="handleRemoveTab(tab)"
@@ -94,7 +92,7 @@
<div class="tag-list-more">
<NPopselect
v-model:value="selectedTab"
- :options="tabList"
+ :options="tabListOptions"
trigger="click"
size="medium"
scrollable
@@ -126,28 +124,25 @@ import {
import {
TabInfo,
AnyTabInfo,
- EditorSelectorGetters,
- EditorSelectorState,
- EditorSelectorActions,
+ TabGetters,
+ TabState,
+ TabActions,
SqlEditorActions,
} from "../../types";
import { debounce } from "lodash-es";
-const { currentTab } = useNamespacedGetters<EditorSelectorGetters>(
- "editorSelector",
- ["currentTab"]
-);
+const { currentTab } = useNamespacedGetters<TabGetters>("tab", ["currentTab"]);
-const { activeTabId, queryTabList } = useNamespacedState<EditorSelectorState>(
- "editorSelector",
- ["activeTabId", "queryTabList"]
-);
-const { addTab, removeTab, setActiveTabId, updateActiveTab } =
- useNamespacedActions<EditorSelectorActions>("editorSelector", [
+const { currentTabId, tabList } = useNamespacedState<TabState>("tab", [
+ "currentTabId",
+ "tabList",
+]);
+const { addTab, removeTab, setCurrentTabId, updateCurrentTab } =
+ useNamespacedActions<TabActions>("tab", [
"addTab",
"removeTab",
- "setActiveTabId",
- "updateActiveTab",
+ "setCurrentTabId",
+ "updateCurrentTab",
]);
const { patchSavedQuery, checkSavedQueryExistById } =
useNamespacedActions<SqlEditorActions>("sqlEditor", [
@@ -159,7 +154,7 @@ const store = useStore();
const { t } = useI18n();
const enterTabId = ref("");
-const selectedTab = computed(() => activeTabId.value);
+const selectedTab = computed(() => currentTabId.value);
// edit label state
const labelState = reactive({
isEditingLabel: false,
@@ -169,8 +164,8 @@ const labelState = reactive({
});
const labelInputRef = ref<HTMLInputElement>();
-const tabList = computed(() => {
- return queryTabList.value.map((tab: TabInfo) => {
+const tabListOptions = computed(() => {
+ return tabList.value.map((tab: TabInfo) => {
return {
label: tab.label,
value: tab.id,
@@ -204,7 +199,7 @@ const handleEditLabel = (tab: TabInfo) => {
const handleTryChangeLabel = () => {
if (labelState.currentLabelName !== "") {
labelState.isEditingLabel = false;
- updateActiveTab({
+ updateCurrentTab({
label: labelState.currentLabelName,
});
if (currentTab.value.currentQueryId) {
@@ -229,7 +224,7 @@ const handleTryChangeLabel = () => {
};
const handleCancelChangeLabel = () => {
labelState.currentLabelName = labelState.oldLabelName;
- updateActiveTab({
+ updateCurrentTab({
label: labelState.currentLabelName,
});
if (currentTab.value.currentQueryId) {
@@ -245,14 +240,14 @@ const handleCancelChangeLabel = () => {
};
const handleSelectTab = async (tab: TabInfo) => {
- setActiveTabId(tab.id);
+ setCurrentTabId(tab.id);
if (currentTab.value.currentQueryId) {
const exist = await checkSavedQueryExistById(
currentTab.value.currentQueryId
);
if (!exist) {
- updateActiveTab({
+ updateCurrentTab({
currentQueryId: undefined,
});
}
@@ -273,7 +268,7 @@ const handleRemoveTab = (tab: TabInfo) => {
});
};
const handleSelectTabFromPopselect = (tabId: string) => {
- setActiveTabId(tabId);
+ setCurrentTabId(tabId);
};
const handleScollTabList = debounce((e: WheelEvent) => {
diff --git a/frontend/src/views/SqlEditor/TablePanel/TableView.vue b/frontend/src/views/SqlEditor/TablePanel/TableView.vue
index 2640d87482..402b987b87 100644
--- a/frontend/src/views/SqlEditor/TablePanel/TableView.vue
+++ b/frontend/src/views/SqlEditor/TablePanel/TableView.vue
@@ -69,7 +69,7 @@ import {
useNamespacedState,
} from "vuex-composition-helpers";
-import { EditorSelectorGetters, SqlEditorState } from "../../../types";
+import { TabGetters, SqlEditorState } from "../../../types";
interface State {
search: string;
@@ -81,10 +81,7 @@ const { isExecuting } = useNamespacedState<SqlEditorState>("sqlEditor", [
"isExecuting",
]);
-const { currentTab } = useNamespacedGetters<EditorSelectorGetters>(
- "editorSelector",
- ["currentTab"]
-);
+const { currentTab } = useNamespacedGetters<TabGetters>("tab", ["currentTab"]);
const queryResult = computed(() => currentTab.value.queryResult || []);