Skip to content

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

feat(sql-editor): tab experience improvement with "temp" tabs (#2612)

Liu Ji43267ca31329
diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vue
index 7dec24fb88..36f51c3663 100644
--- a/frontend/src/components/ProvideSQLEditorContext.vue
+++ b/frontend/src/components/ProvideSQLEditorContext.vue
@@ -6,7 +6,6 @@
import { uniqBy } from "lodash-es";
import { reactive, onMounted } from "vue";
import { useRoute } from "vue-router";
-import { useSQLEditorConnection } from "@/composables/useSQLEditorConnection";
import {
useCurrentUser,
useDatabaseStore,
@@ -43,7 +42,6 @@ const databaseStore = useDatabaseStore();
const sqlEditorStore = useSQLEditorStore();
const tabStore = useTabStore();
const sheetStore = useSheetStore();
-const { setConnectionContextFromCurrentTab } = useSQLEditorConnection();
const prepareAccessibleConnectionByProject = async () => {
// It will also be called when user logout
@@ -86,28 +84,97 @@ const prepareSQLEditorContext = async () => {
// Will fetch them asynchronously only when a database node opens.
};
-// Get sheetId from query.
-const prepareSheetFromQuery = async () => {
- const sheetId = Number(route.query.sheetId);
- if (!Number.isNaN(sheetId)) {
- const sheet = await sheetStore.fetchSheetById(sheetId);
- tabStore.updateCurrentTab({
- sheetId: sheet.id,
- name: sheet.name,
- statement: sheet.statement,
- isSaved: true,
- connection: {
- ...emptyConnection(),
- projectId: sheet.database?.projectId || DEFAULT_PROJECT_ID,
- instanceId: sheet.database?.instanceId || UNKNOWN_ID,
- databaseId: sheet.databaseId || UNKNOWN_ID,
- },
- });
- setConnectionContextFromCurrentTab();
- useSQLEditorStore().setSQLEditorState({
- sharedSheet: sheet,
+const prepareSheet = async () => {
+ // TODO(Jim): use standard slug format instead of "_" joint format.
+
+ let sheetId = parseInt(route.query.sheetId as string, 10);
+ if (Number.isNaN(sheetId)) {
+ const sheetSlug = (route.params.sheetSlug as string) || "";
+ sheetId = parseInt(sheetSlug.split("_").pop()!, 10);
+ }
+ if (Number.isNaN(sheetId)) {
+ return false;
+ }
+ sqlEditorStore.isFetchingSheet = true;
+ const sheet = await sheetStore.getOrFetchSheetById(sheetId);
+ sqlEditorStore.isFetchingSheet = false;
+ if (sheet.id === UNKNOWN_ID) {
+ return false;
+ }
+
+ const openingSheetTab = tabStore.tabList.find(
+ (tab) => tab.sheetId === sheet.id
+ );
+ if (openingSheetTab) {
+ // Switch to a sheet tab if it's open already.
+ tabStore.setCurrentTabId(openingSheetTab.id);
+ } else {
+ // Open the sheet in a "temp" tab otherwise.
+ tabStore.selectOrAddTempTab();
+ }
+ tabStore.updateCurrentTab({
+ sheetId: sheet.id,
+ name: sheet.name,
+ statement: sheet.statement,
+ isSaved: true,
+ connection: {
+ ...emptyConnection(),
+ projectId: sheet.database?.projectId || DEFAULT_PROJECT_ID,
+ instanceId: sheet.database?.instanceId || UNKNOWN_ID,
+ databaseId: sheet.databaseId || UNKNOWN_ID,
+ },
+ });
+
+ // TODO(Jim): remove this after refactor `sharedSheet`
+ useSQLEditorStore().setSQLEditorState({
+ sharedSheet: sheet,
+ });
+
+ return true;
+};
+
+const prepareConnectionSlug = async () => {
+ // TODO(Jim): use standard slug format instead of "_" joint format.
+
+ const connectionSlug = (route.params.connectionSlug as string) || "";
+ // [instanceName, instanceId, databaseName, databaseId]
+ const parts = connectionSlug.split("_");
+ const instanceId = parseInt(parts[1], 10);
+ const databaseId = parseInt(parts[3], 10);
+ if (Number.isNaN(instanceId) || Number.isNaN(databaseId)) {
+ return false;
+ }
+
+ tabStore.selectOrAddTempTab();
+ const connection =
+ await sqlEditorStore.fetchConnectionByInstanceIdAndDatabaseId({
+ instanceId,
+ databaseId,
});
+ tabStore.updateCurrentTab({
+ connection,
+ });
+ return true;
+};
+
+// Get sheetId from query.
+const setConnectionFromQuery = async () => {
+ // Priority:
+ // 1. sheetId in query
+ // 2. idFromSlug in sheetSlug
+ // 3. instanceId and databaseId in connectionSlug
+ // 4. disconnected
+
+ if (await prepareSheet()) {
+ return;
+ }
+
+ if (await prepareConnectionSlug()) {
+ return;
}
+
+ tabStore.selectOrAddTempTab();
+ // Keep disconnected otherwise
};
onMounted(async () => {
@@ -116,7 +183,7 @@ onMounted(async () => {
await prepareSQLEditorContext();
sqlEditorStore.setConnectionContext({ isLoadingTree: false });
- await prepareSheetFromQuery();
+ await setConnectionFromQuery();
await sqlEditorStore.fetchQueryHistoryList();
await useDebugStore().fetchDebug();
});
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index f5781565ba..d743b619d2 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -38,7 +38,6 @@ import Signup from "../views/auth/Signup.vue";
import DashboardSidebar from "../views/DashboardSidebar.vue";
import Home from "../views/Home.vue";
import {
- useTabStore,
hasFeature,
useVCSStore,
useProjectWebhookStore,
@@ -919,7 +918,6 @@ router.beforeEach((to, from, next) => {
const environmentStore = useEnvironmentStore();
const instanceStore = useInstanceStore();
const issueStore = useIssueStore();
- const tabStore = useTabStore();
const routerStore = useRouterStore();
const projectWebhookStore = useProjectWebhookStore();
const projectStore = useProjectStore();
@@ -1324,6 +1322,7 @@ router.beforeEach((to, from, next) => {
}
if (connectionSlug) {
+ // TODO(Jim): use standard slug format instead of "_" joint format.
const [, instanceId, , databaseId] = connectionSlug.split("_");
useSQLEditorStore()
.fetchConnectionByInstanceIdAndDatabaseId({
@@ -1333,16 +1332,11 @@ router.beforeEach((to, from, next) => {
.then(() => {
// for sharing the sheet to others
if (sheetSlug) {
+ // TODO(Jim): use standard slug format instead of "_" joint format.
const [_, sheetId] = sheetSlug.split("_");
useSheetStore()
.fetchSheetById(Number(sheetId))
.then((sheet: Sheet) => {
- tabStore.updateCurrentTab({
- name: sheet.name,
- statement: sheet.statement,
- isSaved: true,
- sheetId: sheet.id,
- });
useSQLEditorStore().setSQLEditorState({
sharedSheet: sheet,
});
diff --git a/frontend/src/store/modules/database.ts b/frontend/src/store/modules/database.ts
index 0d41749ecf..d47923c5c5 100644
--- a/frontend/src/store/modules/database.ts
+++ b/frontend/src/store/modules/database.ts
@@ -372,6 +372,13 @@ export const useDatabaseStore = defineStore("database", {
return database;
},
+ async getOrFetchDatabaseById(databaseId: DatabaseId) {
+ const storedDatabase = this.getDatabaseById(databaseId);
+ if (storedDatabase.id !== UNKNOWN_ID) {
+ return storedDatabase;
+ }
+ return this.fetchDatabaseById(databaseId);
+ },
async createDatabase(newDatabase: DatabaseCreate) {
const data = (
await axios.post(`/api/database`, {
diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.ts
index 0546c4a295..6f377d86f2 100644
--- a/frontend/src/store/modules/instance.ts
+++ b/frontend/src/store/modules/instance.ts
@@ -287,6 +287,13 @@ export const useInstanceStore = defineStore("instance", {
});
return instance;
},
+ async getOrFetchInstanceById(instanceId: InstanceId) {
+ const storedInstance = this.getInstanceById(instanceId);
+ if (storedInstance.id !== UNKNOWN_ID) {
+ return storedInstance;
+ }
+ return this.fetchInstanceById(instanceId);
+ },
async createInstance(newInstance: InstanceCreate) {
const data = (
await axios.post(
diff --git a/frontend/src/store/modules/sheet.ts b/frontend/src/store/modules/sheet.ts
index b48ae0f95b..e44fb66e11 100644
--- a/frontend/src/store/modules/sheet.ts
+++ b/frontend/src/store/modules/sheet.ts
@@ -268,6 +268,13 @@ export const useSheetStore = defineStore("sheet", {
return sheet;
},
+ async getOrFetchSheetById(sheetId: SheetId) {
+ const storedSheet = this.sheetById.get(sheetId);
+ if (storedSheet && storedSheet.id !== UNKNOWN_ID) {
+ return storedSheet;
+ }
+ return this.fetchSheetById(sheetId);
+ },
async patchSheetById(sheetPatch: SheetPatch): Promise<Sheet> {
const resData = (
await axios.patch(`/api/sheet/${sheetPatch.id}`, {
diff --git a/frontend/src/store/modules/sqlEditor.ts b/frontend/src/store/modules/sqlEditor.ts
index c48231c188..6ea0b3db0d 100644
--- a/frontend/src/store/modules/sqlEditor.ts
+++ b/frontend/src/store/modules/sqlEditor.ts
@@ -13,6 +13,7 @@ import {
Sheet,
unknown,
InstanceId,
+ Connection,
} from "@/types";
import { useActivityStore } from "./activity";
import { useDatabaseStore } from "./database";
@@ -119,21 +120,19 @@ export const useSQLEditorStore = defineStore("sqlEditor", {
}: {
instanceId: InstanceId;
databaseId: DatabaseId;
- }) {
+ }): Promise<Connection> {
const [database] = await Promise.all([
- useDatabaseStore().fetchDatabaseById(databaseId),
- useInstanceStore().fetchInstanceById(instanceId),
- useTableStore().fetchTableListByDatabaseId(databaseId),
+ useDatabaseStore().getOrFetchDatabaseById(databaseId),
+ useInstanceStore().getOrFetchInstanceById(instanceId),
+ useTableStore().getOrFetchTableListByDatabaseId(databaseId),
]);
- useTabStore().updateCurrentTab({
- connection: {
- ...emptyConnection(),
- projectId: database.project.id,
- instanceId,
- databaseId,
- },
- });
+ return {
+ ...emptyConnection(),
+ projectId: database.project.id,
+ instanceId,
+ databaseId,
+ };
},
async fetchQueryHistoryList() {
this.setIsFetchingQueryHistory(true);
diff --git a/frontend/src/store/modules/tab.ts b/frontend/src/store/modules/tab.ts
index d1f421bd2c..978826ec0c 100644
--- a/frontend/src/store/modules/tab.ts
+++ b/frontend/src/store/modules/tab.ts
@@ -1,6 +1,6 @@
import { defineStore } from "pinia";
import { TabInfo, AnyTabInfo, TabState, UNKNOWN_ID } from "@/types";
-import { getDefaultTab, INITIAL_TAB } from "@/utils";
+import { getDefaultTab, INITIAL_TAB, isTempTab } from "@/utils";
import { useInstanceStore } from "./instance";
export const useTabStore = defineStore("tab", {
@@ -14,9 +14,6 @@ export const useTabStore = defineStore("tab", {
const tab = state.tabList.find((tab) => tab.id === state.currentTabId);
return tab ?? getDefaultTab();
},
- hasTabs(state: TabState): boolean {
- return state.tabList.length > 0;
- },
isDisconnected(): boolean {
const { instanceId, databaseId } = this.currentTab.connection;
if (instanceId === UNKNOWN_ID) {
@@ -57,5 +54,13 @@ export const useTabStore = defineStore("tab", {
setCurrentTabId(payload: string) {
this.currentTabId = payload;
},
+ selectOrAddTempTab() {
+ const tempTab = this.tabList.find(isTempTab);
+ if (tempTab) {
+ this.setCurrentTabId(tempTab.id);
+ } else {
+ this.addTab();
+ }
+ },
},
});
diff --git a/frontend/src/store/modules/table.ts b/frontend/src/store/modules/table.ts
index 459eb2bbb8..b8368dfbc3 100644
--- a/frontend/src/store/modules/table.ts
+++ b/frontend/src/store/modules/table.ts
@@ -142,5 +142,13 @@ export const useTableStore = defineStore("table", {
this.setTableListByDatabaseId({ databaseId, tableList });
return tableList;
},
+
+ async getOrFetchTableListByDatabaseId(databaseId: DatabaseId) {
+ const storedList = this.tableListByDatabaseId.get(databaseId);
+ if (storedList) {
+ return storedList;
+ }
+ return this.fetchTableListByDatabaseId(databaseId);
+ },
},
});
diff --git a/frontend/src/utils/tab.ts b/frontend/src/utils/tab.ts
index fbdd719994..97f45d4cdb 100644
--- a/frontend/src/utils/tab.ts
+++ b/frontend/src/utils/tab.ts
@@ -28,3 +28,10 @@ export const getDefaultTab = (): TabInfo => {
};
export const INITIAL_TAB = getDefaultTab();
+
+export const isTempTab = (tab: TabInfo): boolean => {
+ if (tab.sheetId) return false;
+ if (!tab.isSaved) return false;
+ if (tab.statement) return false;
+ return true;
+};
diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
index af76574c2d..05b5d48966 100644
--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
@@ -166,10 +166,16 @@ const setConnection = (option: ConnectionAtom) => {
conn.tableId = option.id;
}
+ if (tabStore.currentTab.sheetId) {
+ // We won't mutate a saved sheet's connection.
+ // So we'll set connection in a temp or new tab.
+ tabStore.selectOrAddTempTab();
+ }
tabStore.updateCurrentTab({
connection: conn,
});
+ // TODO(Jim): move the URL sync logic to <ProvideSQLEditorContext>
if (conn.instanceId !== UNKNOWN_ID && conn.databaseId !== UNKNOWN_ID) {
const database = useDatabaseStore().getDatabaseById(
conn.databaseId,
diff --git a/frontend/src/views/sql-editor/AsidePanel/QueryHistoryContainer.vue b/frontend/src/views/sql-editor/AsidePanel/QueryHistoryContainer.vue
index 70c6cb8536..fcbcc70604 100644
--- a/frontend/src/views/sql-editor/AsidePanel/QueryHistoryContainer.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/QueryHistoryContainer.vue
@@ -191,7 +191,8 @@ const handleActionBtnOutsideClick = () => {
};
const handleQueryHistoryClick = async (queryHistory: QueryHistory) => {
- tabStore.addTab({
+ // Changing SQL statement is quite harmless, so we just update the current tab.
+ tabStore.updateCurrentTab({
statement: queryHistory.statement,
selectedStatement: "",
});
diff --git a/frontend/src/views/sql-editor/AsidePanel/SheetContainer.vue b/frontend/src/views/sql-editor/AsidePanel/SheetContainer.vue
deleted file mode 100644
index d1042ac7d2..0000000000
--- a/frontend/src/views/sql-editor/AsidePanel/SheetContainer.vue
+++ /dev/null
@@ -1,263 +0,0 @@
-<!-- eslint-disable vue/no-v-html -->
-<template>
- <div
- class="relative p-2 space-y-2 w-full h-full flex flex-col justify-start items-start"
- >
- <div class="w-full">
- <NInput
- v-model:value="state.search"
- :placeholder="$t('sql-editor.search-sheets')"
- >
- <template #prefix>
- <heroicons-outline:search class="h-5 w-5 text-gray-300" />
- </template>
- </NInput>
- </div>
- <div class="w-full flex flex-col justify-start items-start overflow-y-auto">
- <div
- v-for="sheet in sheetList"
- :key="sheet.id"
- class="w-full px-1 pr-2 py-2 border-b flex flex-col justify-start items-start cursor-pointer"
- :class="`${
- tabStore.currentTab.sheetId === sheet.id
- ? 'bg-gray-100 rounded border-b-0'
- : ''
- }`"
- @click="handleSheetClick(sheet)"
- >
- <div class="pb-1 w-full flex flex-row justify-between items-center">
- <div
- class="w-full mr-2"
- @dblclick="handleEditSheet(sheet.id, sheet.name)"
- >
- <input
- v-if="state.editingSheetId === sheet.id"
- ref="queryNameInputerRef"
- v-model="state.currentSheetName"
- type="text"
- class="rounded px-2 py-0 text-sm w-full"
- @blur="handleSheetNameChanged"
- @keyup.enter="handleSheetNameChanged"
- @keyup.esc="handleCancelEdit"
- />
- <span v-else class="text-sm" v-html="sheet.formatedName"></span>
- </div>
- <NDropdown
- trigger="click"
- :options="actionDropdownOptions"
- @select="(key: string) => handleActionBtnClick(key, sheet)"
- @clickoutside="handleActionBtnOutsideClick"
- >
- <NButton text @click.stop>
- <template #icon>
- <heroicons-outline:dots-horizontal
- class="h-4 w-4 text-gray-500 flex-shrink-0"
- />
- </template>
- </NButton>
- </NDropdown>
- </div>
- <p
- class="max-w-full text-gray-400 break-words font-mono truncate"
- style="font-size: 10px"
- v-html="sheet.formatedStatement"
- ></p>
- </div>
- </div>
-
- <div
- v-show="notifyMessage"
- class="absolute w-full h-full flex justify-center items-center transition-all bg-transparent"
- >
- {{ notifyMessage }}
- </div>
-
- <div
- v-show="isLoading && sheetList.length === 0"
- class="absolute w-full h-full flex justify-center items-center"
- >
- <BBSpin :title="$t('common.loading')" />
- </div>
- </div>
-</template>
-
-<script lang="ts" setup>
-import { escape } from "lodash-es";
-import { computed, reactive, ref, nextTick } from "vue";
-import { useI18n } from "vue-i18n";
-import { useDialog } from "naive-ui";
-
-import { useTabStore, useSQLEditorStore, useSheetStore } from "@/store";
-import { Sheet, UNKNOWN_ID } from "@/types";
-import { getHighlightHTMLByKeyWords } from "@/utils";
-import { useSQLEditorConnection } from "@/composables/useSQLEditorConnection";
-
-interface State {
- search: string;
- currentSheetName: string;
- editingSheetId: number | null;
- currentActionSheet: Sheet | null;
-}
-
-const { t } = useI18n();
-const { setConnectionContextFromCurrentTab } = useSQLEditorConnection();
-const dialog = useDialog();
-const tabStore = useTabStore();
-const sqlEditorStore = useSQLEditorStore();
-const sheetStore = useSheetStore();
-
-const isLoading = computed(() => sqlEditorStore.isFetchingSheet);
-
-const state = reactive<State>({
- search: "",
- currentSheetName: "",
- editingSheetId: null,
- currentActionSheet: null,
-});
-
-const queryNameInputerRef = ref<HTMLInputElement>();
-
-const sheetList = computed(() => {
- const filterSheetList =
- sqlEditorStore.sharedSheet.id !== UNKNOWN_ID
- ? [...sheetStore.sheetList, sqlEditorStore.sharedSheet]
- : sheetStore.sheetList;
- const tempData =
- filterSheetList && filterSheetList.length > 0
- ? filterSheetList.filter((sheet) => {
- let t = false;
-
- if (sheet.name.includes(state.search)) {
- t = true;
- }
- if (sheet.statement.includes(state.search)) {
- t = true;
- }
-
- return t;
- })
- : [];
-
- return tempData.map((sheet) => {
- return {
- ...sheet,
- formatedName: state.search
- ? getHighlightHTMLByKeyWords(escape(sheet.name), escape(state.search))
- : escape(sheet.name),
- formatedStatement: state.search
- ? getHighlightHTMLByKeyWords(
- escape(sheet.statement),
- escape(state.search)
- )
- : escape(sheet.statement),
- };
- });
-});
-
-const notifyMessage = computed(() => {
- if (isLoading.value) {
- return "";
- }
- if (sheetStore.sheetList.length === null) {
- return t("sql-editor.no-sheet-found");
- }
-
- return "";
-});
-
-const actionDropdownOptions = computed(() => [
- {
- label: t("common.delete"),
- key: "delete",
- },
-]);
-
-const handleEditSheet = (id: number, name: string) => {
- state.editingSheetId = id;
- state.currentSheetName = name;
- nextTick(() => {
- queryNameInputerRef.value?.focus();
- });
-};
-
-const handleCancelEdit = () => {
- state.editingSheetId = null;
- state.currentSheetName = "";
-};
-
-const handleSheetNameChanged = () => {
- if (state.editingSheetId) {
- sheetStore.patchSheetById({
- id: state.editingSheetId,
- name: state.currentSheetName,
- });
-
- if (tabStore.currentTab.sheetId === state.editingSheetId) {
- tabStore.updateCurrentTab({
- name: state.currentSheetName,
- });
- }
- handleCancelEdit();
- }
-};
-
-const handleDeleteSheet = () => {
- if (state.currentActionSheet) {
- sheetStore.deleteSheetById(state.currentActionSheet.id);
-
- if (tabStore.currentTab.sheetId === state.currentActionSheet.id) {
- tabStore.updateCurrentTab({
- sheetId: undefined,
- });
- }
- }
-};
-
-const handleActionBtnClick = (key: string, sheet: Sheet) => {
- state.currentActionSheet = sheet;
-
- if (key === "delete") {
- const $dialog = dialog.create({
- title: t("sql-editor.hint-tips.confirm-to-delete-this-sheet"),
- type: "info",
- onPositiveClick() {
- handleDeleteSheet();
- $dialog.destroy();
- },
- async onNegativeClick() {
- state.currentActionSheet = null;
- $dialog.destroy();
- },
- negativeText: t("common.cancel"),
- positiveText: t("common.confirm"),
- showIcon: false,
- });
- }
-};
-
-const handleActionBtnOutsideClick = () => {
- state.currentActionSheet = null;
-};
-
-const handleSheetClick = async (sheet: Sheet) => {
- if (tabStore.currentTab.sheetId !== sheet.id) {
- // open opened tab first
- for (const tab of tabStore.tabList) {
- if (tab.sheetId === sheet.id) {
- tabStore.setCurrentTabId(tab.id);
- setConnectionContextFromCurrentTab();
- return;
- }
- }
-
- // otherwise, add new tab
- tabStore.addTab({
- name: sheet.name,
- statement: sheet.statement,
- selectedStatement: "",
- sheetId: sheet.id,
- });
- setConnectionContextFromCurrentTab();
- }
-};
-</script>
diff --git a/frontend/src/views/sql-editor/EditorPanel/SharePopover.vue b/frontend/src/views/sql-editor/EditorPanel/SharePopover.vue
index dedec69ef3..f902025e54 100644
--- a/frontend/src/views/sql-editor/EditorPanel/SharePopover.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/SharePopover.vue
@@ -171,6 +171,8 @@ const handleChangeAccess = (option: AccessOption) => {
const sheetSlug = `${slug(tabStore.currentTab.name)}_${
tabStore.currentTab.sheetId
}`;
+
+// TODO(Jim): use standard slug format instead of "_" joint format.
const sharedTabLink = ref(
`${window.location.origin}/sql-editor/${connectionSlug.value}/${sheetSlug}`
);
diff --git a/frontend/src/views/sql-editor/SQLEditorPage.vue b/frontend/src/views/sql-editor/SQLEditorPage.vue
index 9f7a106cbc..11d65ae45f 100644
--- a/frontend/src/views/sql-editor/SQLEditorPage.vue
+++ b/frontend/src/views/sql-editor/SQLEditorPage.vue
@@ -5,20 +5,21 @@
<Pane size="20" min-size="20" max-size="30">
<AsidePanel />
</Pane>
- <Pane size="80">
- <template v-if="hasTabs">
- <Splitpanes horizontal class="default-theme">
- <Pane :size="isDisconnected ? 100 : 60">
- <EditorPanel />
- </Pane>
- <Pane :size="isDisconnected ? 0 : 40">
- <TablePanel />
- </Pane>
- </Splitpanes>
- </template>
- <template v-else>
- <GettingStarted />
- </template>
+ <Pane size="80" class="relative">
+ <Splitpanes horizontal class="default-theme">
+ <Pane :size="isDisconnected ? 100 : 60">
+ <EditorPanel />
+ </Pane>
+ <Pane :size="isDisconnected ? 0 : 40">
+ <TablePanel />
+ </Pane>
+ </Splitpanes>
+ <div
+ v-if="isFetchingSheet"
+ class="flex items-center justify-center absolute inset-0 bg-white/50 z-20"
+ >
+ <BBSpin />
+ </div>
</Pane>
</Splitpanes>
</div>
@@ -26,19 +27,19 @@
<script lang="ts" setup>
import { computed } from "vue";
-import { useTabStore } from "@/store";
+import { useSQLEditorStore, useTabStore } from "@/store";
import AsidePanel from "./AsidePanel/AsidePanel.vue";
import EditorPanel from "./EditorPanel/EditorPanel.vue";
import TabListContainer from "./TabListContainer.vue";
import TablePanel from "./TablePanel/TablePanel.vue";
-import GettingStarted from "./GettingStarted.vue";
import { Splitpanes, Pane } from "splitpanes";
import "splitpanes/dist/splitpanes.css";
const tabStore = useTabStore();
+const sqlEditorStore = useSQLEditorStore();
-const hasTabs = computed(() => tabStore.hasTabs);
const isDisconnected = computed(() => tabStore.isDisconnected);
+const isFetchingSheet = computed(() => sqlEditorStore.isFetchingSheet);
</script>
<style>
diff --git a/frontend/src/views/sql-editor/TabListContainer.vue b/frontend/src/views/sql-editor/TabListContainer.vue
index e2c0313b3a..10364e2f88 100644
--- a/frontend/src/views/sql-editor/TabListContainer.vue
+++ b/frontend/src/views/sql-editor/TabListContainer.vue
@@ -51,7 +51,7 @@
v-if="sheetOfTab(tab).visibility === 'PUBLIC'"
class="w-4 h-4"
/>
- <span>{{ tab.name }}</span>
+ <span :class="isTempTab(tab) && 'italic'">{{ tab.name }}</span>
</span>
</div>
<template v-if="enterTabId === tab.id && tabStore.tabList.length > 1">
@@ -120,16 +120,14 @@ import { ref, reactive, nextTick, computed, onMounted, onUnmounted } from "vue";
import { debounce } from "lodash-es";
import { useI18n } from "vue-i18n";
import { useDialog } from "naive-ui";
-
import { pushNotification, useTabStore, useSheetStore } from "@/store";
import { TabInfo, unknown } from "@/types";
-import { useSQLEditorConnection } from "@/composables/useSQLEditorConnection";
+import { isTempTab } from "@/utils";
const tabStore = useTabStore();
const sheetStore = useSheetStore();
const { t } = useI18n();
-const { setConnectionContextFromCurrentTab } = useSQLEditorConnection();
const dialog = useDialog();
const enterTabId = ref("");
@@ -139,7 +137,7 @@ const labelState = reactive({
currentLabelName: "",
editingTabId: "",
});
-const labelInputRef = ref<HTMLInputElement>();
+const labelInputRef = ref<HTMLInputElement | HTMLInputElement[]>();
const sheetOfTab = (tab: TabInfo) => {
const { sheetId } = tab;
@@ -192,7 +190,10 @@ const handleEditLabel = (tab: TabInfo) => {
labelState.editingTabId = tab.id;
labelState.currentLabelName = tab.name;
nextTick(() => {
- labelInputRef.value?.focus();
+ const inputElem = Array.isArray(labelInputRef.value)
+ ? labelInputRef.value[0]
+ : labelInputRef.value;
+ inputElem?.focus();
});
};
@@ -228,7 +229,6 @@ const handleCancelChangeLabel = () => {
const handleSelectTab = async (tab: TabInfo) => {
tabStore.setCurrentTabId(tab.id);
- setConnectionContextFromCurrentTab();
};
const handleAddTab = () => {
tabStore.addTab();
@@ -269,7 +269,6 @@ const handleRemoveTab = async (tab: TabInfo) => {
};
const handleSelectTabFromPopselect = (tabId: string) => {
tabStore.setCurrentTabId(tabId);
- setConnectionContextFromCurrentTab();
};
const handleScollTabList = debounce((e: WheelEvent) => {
@@ -278,12 +277,6 @@ const handleScollTabList = debounce((e: WheelEvent) => {
console.log(e.offsetX);
}, 333);
-onMounted(async () => {
- if (!tabStore.hasTabs) {
- handleAddTab();
- }
-});
-
// add listener to confirm confrim if close the tab.
onMounted(() => {
window.onbeforeunload = () => {