Skip to content

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

chore(sql-editor): UI bug fixes and improvements (#8078)

Liu Ji82d662e3cfbb
diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vue
index 0cd6057d4a..a788d87702 100644
--- a/frontend/src/components/ProvideSQLEditorContext.vue
+++ b/frontend/src/components/ProvideSQLEditorContext.vue
@@ -20,7 +20,6 @@ import {
useEnvironmentV1Store,
useUserStore,
} from "@/store";
-import { getInstanceAndDatabaseId } from "@/store/modules/v1/common";
import { usePolicyV1Store } from "@/store/modules/v1/policy";
import { useSettingV1Store } from "@/store/modules/v1/setting";
import {
@@ -104,7 +103,7 @@ const connectionTreeCache: Record<"instance" | "project", ConnectionAtom[]> = {
const initializeConnectionTree = async () => {
const build = (mode: ConnectionTreeMode): ConnectionAtom[] => {
- if (mode) {
+ if (mode === ConnectionTreeMode.INSTANCE) {
const { databaseList } = connectionTreeStore.tree;
const instanceList = uniqBy(
databaseList.map((db) => db.instanceEntity),
@@ -257,12 +256,11 @@ const prepareSheet = async () => {
let insId = String(UNKNOWN_ID);
let dbId = String(UNKNOWN_ID);
if (sheet.database) {
- const [instanceName, databaseId] = getInstanceAndDatabaseId(sheet.database);
- const ins = await useInstanceV1Store().getOrFetchInstanceByName(
- `instances/${instanceName}`
+ const database = await databaseStore.getOrFetchDatabaseByName(
+ sheet.database
);
- insId = ins.uid;
- dbId = databaseId;
+ insId = database.instanceEntity.uid;
+ dbId = database.uid;
}
tabStore.updateCurrentTab({
diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
index 708b34a55b..1722e259c8 100644
--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
@@ -183,10 +183,24 @@ const dropdownOptions = computed((): DropdownOptionWithConnectionAtom[] => {
// Highlight the current tab's connection node.
const selectedKeys = computed(() => {
const { instanceId, databaseId } = tabStore.currentTab.connection;
+
if (databaseId !== String(UNKNOWN_ID)) {
+ if (selectedDatabaseSchema.value) {
+ const { db, schema, table } = selectedDatabaseSchema.value;
+ if (schema.name) {
+ return [
+ `table-${[db.uid, schema.name, table.name].join(
+ CONNECTION_TREE_DELIMITER
+ )}`,
+ ];
+ } else {
+ return [
+ `table-${[db.uid, table.name].join(CONNECTION_TREE_DELIMITER)}`,
+ ];
+ }
+ }
return [`database-${databaseId}`];
- }
- if (instanceId !== String(UNKNOWN_ID)) {
+ } else if (instanceId !== String(UNKNOWN_ID)) {
return [`instance-${instanceId}`];
}
return [];
@@ -363,6 +377,8 @@ const maybeSelectTable = async (atom: ConnectionAtom) => {
return;
}
selectedDatabaseSchema.value = {
+ db: database,
+ database: databaseMetadata,
schema: schemaMetadata,
table: tableMetadata,
};
@@ -484,13 +500,16 @@ watch(
);
</script>
-<style postcss>
+<style lang="postcss">
.databases-tree .n-tree-node-content {
@apply !pl-0 text-sm;
}
.databases-tree .n-tree-node-wrapper {
padding: 0;
}
+.databases-tree .n-tree-node-indent {
+ width: 0.25rem;
+}
.databases-tree .n-tree-node-content__prefix {
@apply shrink-0 !mr-1;
}
diff --git a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
index cdfc1c53df..c226ed28b6 100644
--- a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
@@ -60,7 +60,7 @@
type="primary"
size="small"
:disabled="!allowSave"
- @click="() => emit('save-sheet')"
+ @click="handleClickSave"
>
<carbon:save class="-ml-1" />
<span class="ml-1">{{ $t("common.save") }}</span>
@@ -120,6 +120,7 @@ import {
import type { ExecuteConfig, ExecuteOption, FeatureType } from "@/types";
import { TabMode, UNKNOWN_ID } from "@/types";
import { formatEngineV1, keyboardShortcutStr } from "@/utils";
+import { useSQLEditorContext } from "../context";
import AdminModeButton from "./AdminModeButton.vue";
import SharePopover from "./SharePopover.vue";
@@ -128,7 +129,6 @@ interface LocalState {
}
const emit = defineEmits<{
- (e: "save-sheet", content?: string): void;
(
e: "execute",
sql: string,
@@ -143,6 +143,7 @@ const tabStore = useTabStore();
const sqlEditorStore = useSQLEditorStore();
const uiStateStore = useUIStateStore();
const webTerminalStore = useWebTerminalStore();
+const { events } = useSQLEditorContext();
const containerRef = ref<HTMLDivElement>();
const { width: containerWidth } = useElementSize(containerRef);
const hasSharedSQLScriptFeature = featureToRef("bb.feature.shared-sql-script");
@@ -241,6 +242,12 @@ const handleClearScreen = () => {
emit("clear-screen");
};
+const handleClickSave = () => {
+ events.emit("save-sheet", {
+ title: tabStore.currentTab.name,
+ });
+};
+
const handleShareButtonClick = () => {
if (!hasSharedSQLScriptFeature.value) {
state.requiredFeatureName = "bb.feature.shared-sql-script";
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue
index ed41b9acfd..0e0aa369db 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/DataTable.vue
@@ -102,6 +102,7 @@
import { ColumnDef, Table } from "@tanstack/vue-table";
import { computed, nextTick, PropType, ref, watch } from "vue";
import { useSubscriptionV1Store } from "@/store";
+import { useSQLResultViewContext } from "../context";
import SensitiveDataIcon from "./SensitiveDataIcon.vue";
import TableCell from "./TableCell.vue";
import useTableColumnWidthLogic from "./useTableResize";
@@ -132,10 +133,6 @@ const props = defineProps({
type: Object as PropType<Table<string[]>>,
required: true,
},
- keyword: {
- type: String,
- default: "",
- },
setIndex: {
type: Number,
default: 0,
@@ -158,6 +155,7 @@ const tableResize = useTableColumnWidthLogic({
});
const data = computed(() => props.data);
+const { keyword } = useSQLResultViewContext();
const hasSensitiveFeature = computed(() => {
return subscriptionStore.hasFeature("bb.feature.sensitive-data");
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue
index 1adf4711f9..ce15f40aa8 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/TableCell.vue
@@ -25,13 +25,13 @@ import { useSQLResultViewContext } from "../context";
const props = defineProps<{
value: unknown;
- keyword?: string;
setIndex: number;
rowIndex: number;
colIndex: number;
}>();
-const { dark, disallowCopyingData, detail } = useSQLResultViewContext();
+const { dark, disallowCopyingData, detail, keyword } =
+ useSQLResultViewContext();
const wrapperRef = ref<HTMLDivElement>();
const truncated = ref(false);
@@ -82,14 +82,14 @@ const html = computed(() => {
return `<br style="min-width: 1rem; display: inline-flex;" />`;
}
- const { keyword } = props;
- if (!keyword) {
+ const kw = keyword.value.trim();
+ if (!kw) {
return escape(str);
}
return getHighlightHTMLByRegExp(
escape(str),
- escape(keyword),
+ escape(kw),
false /* !caseSensitive */
);
});
diff --git a/frontend/src/views/sql-editor/EditorCommon/SaveSheetForm.vue b/frontend/src/views/sql-editor/EditorCommon/SaveSheetForm.vue
index 3c858de478..c15dd93e55 100644
--- a/frontend/src/views/sql-editor/EditorCommon/SaveSheetForm.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/SaveSheetForm.vue
@@ -21,7 +21,7 @@ import { useTabStore } from "@/store";
const emit = defineEmits<{
(e: "close"): void;
- (e: "save-sheet", content: string): void;
+ (e: "confirm", title: string): void;
}>();
const tabStore = useTabStore();
@@ -30,7 +30,7 @@ const sheetTitle = ref(tabStore.currentTab.name);
const sheetNameInputRef = ref();
const handleSaveSheet = () => {
- emit("save-sheet", sheetTitle.value);
+ emit("confirm", sheetTitle.value);
};
nextTick(() => {
diff --git a/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vue b/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vue
index 51eda76684..6cadd38471 100644
--- a/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vue
@@ -4,12 +4,13 @@
:title="$t('sql-editor.save-sheet')"
@close="close"
>
- <SaveSheetForm @close="close" @save-sheet="trySaveSheet" />
+ <SaveSheetForm @close="close" @confirm="doSaveSheet" />
</BBModal>
</template>
<script lang="ts" setup>
import { computed, reactive } from "vue";
+import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import { useDatabaseV1Store, useSheetV1Store, useTabStore } from "@/store";
import { UNKNOWN_ID } from "@/types";
import {
@@ -18,12 +19,9 @@ import {
Sheet_Type,
Sheet,
} from "@/types/proto/v1/sheet_service";
-import {
- extractSheetUID,
- getSuggestedTabNameFromConnection,
- isSimilarDefaultTabName,
-} from "@/utils";
+import { extractSheetUID } from "@/utils";
import { useSheetContext } from "../Sheet";
+import { useSQLEditorContext } from "../context";
import SaveSheetForm from "./SaveSheetForm.vue";
type LocalState = {
@@ -34,6 +32,7 @@ const tabStore = useTabStore();
const databaseStore = useDatabaseV1Store();
const sheetV1Store = useSheetV1Store();
const { events: sheetEvents } = useSheetContext();
+const { events: editorEvents } = useSQLEditorContext();
const state = reactive<LocalState>({
showModal: false,
@@ -55,9 +54,9 @@ const allowSave = computed((): boolean => {
return true;
});
-const doSaveSheet = async (sheetTitle?: string) => {
+const doSaveSheet = async (title: string) => {
const { name, statement, sheetName } = tabStore.currentTab;
- sheetTitle = sheetTitle || name;
+ title = title || name;
const sheetId = Number(extractSheetUID(sheetName ?? ""));
@@ -69,12 +68,12 @@ const doSaveSheet = async (sheetTitle?: string) => {
sheet = await sheetV1Store.patchSheet({
name: sheetName,
database: database.name,
- title: sheetTitle,
+ title: title,
content: new TextEncoder().encode(statement),
});
} else {
sheet = await sheetV1Store.createSheet(database.project, {
- title: sheetTitle,
+ title: title,
content: new TextEncoder().encode(statement),
database: database.name,
visibility: Sheet_Visibility.VISIBILITY_PRIVATE,
@@ -88,52 +87,43 @@ const doSaveSheet = async (sheetTitle?: string) => {
tabStore.updateCurrentTab({
sheetName: sheet.name,
isSaved: true,
- name: sheetTitle,
+ name: title,
});
// Refresh "my" sheet list.
sheetEvents.emit("refresh", { views: ["my"] });
}
+ state.showModal = false;
};
-const needSheetName = (sheetName: string | undefined) => {
+const needSheetTitle = (title: string) => {
const tab = tabStore.currentTab;
if (tab.sheetName) {
// If the sheet is saved, we don't need to show the name popup.
return false;
}
- if (!sheetName) {
- const name = tab.name;
- if (
- name === getSuggestedTabNameFromConnection(tab.connection) ||
- isSimilarDefaultTabName(name)
- ) {
- // The tab is unsaved and its name is still the default one.
- return true;
- }
- }
- return false;
+ return true;
};
-const trySaveSheet = (sheetTitle?: string) => {
+const trySaveSheet = (title: string) => {
if (!allowSave.value) {
return;
}
- if (needSheetName(sheetTitle)) {
+ if (needSheetTitle(title)) {
state.showModal = true;
return;
}
state.showModal = false;
- doSaveSheet(sheetTitle);
+ doSaveSheet(title);
};
const close = () => {
state.showModal = false;
};
-defineExpose({
- trySaveSheet,
+useEmitteryEventListener(editorEvents, "save-sheet", ({ title }) => {
+ trySaveSheet(title);
});
</script>
diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
index 00147e68b7..5549b279a1 100644
--- a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
@@ -1,13 +1,13 @@
<template>
<div class="flex h-full w-full flex-col justify-start items-start">
<template v-if="tab.editMode === 'SQL-EDITOR'">
- <EditorAction @execute="handleExecute" @save-sheet="trySaveSheet" />
+ <EditorAction @execute="handleExecute" />
<ConnectionPathBar />
<SheetForIssueTipsBar />
- <SQLEditor @execute="handleExecute" @save-sheet="trySaveSheet" />
+ <SQLEditor @execute="handleExecute" />
</template>
<AIChatToSQL
@@ -18,12 +18,11 @@
<ExecutingHintModal />
- <SaveSheetModal ref="saveSheetModal" />
+ <SaveSheetModal />
</div>
</template>
<script lang="ts" setup>
-import { ref } from "vue";
import { useExecuteSQL } from "@/composables/useExecuteSQL";
import { AIChatToSQL } from "@/plugins/ai";
import {
@@ -45,7 +44,6 @@ import SQLEditor from "./SQLEditor.vue";
import SheetForIssueTipsBar from "./SheetForIssueTipsBar.vue";
const tabStore = useTabStore();
-const saveSheetModal = ref<InstanceType<typeof SaveSheetModal>>();
const tab = useCurrentTab();
const sqlEditorStore = useSQLEditorStore();
const { showAIChatBox } = useSQLEditorContext();
@@ -60,9 +58,9 @@ const handleExecute = (
executeReadonly(query, config, option);
};
-const trySaveSheet = (sheetName?: string) => {
- saveSheetModal.value?.trySaveSheet(sheetName);
-};
+// const trySaveSheet = (sheetName?: string) => {
+// saveSheetModal.value?.trySaveSheet(sheetName);
+// };
const handleApplyStatement = async (
statement: string,
diff --git a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
index 3b96ad8d1a..904b36b57f 100644
--- a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue
@@ -39,9 +39,9 @@ import {
} from "@/types";
import { TableMetadata } from "@/types/proto/store/database";
import { formatEngineV1, useInstanceV1EditorLanguage } from "@/utils";
+import { useSQLEditorContext } from "../context";
const emit = defineEmits<{
- (e: "save-sheet", content?: string): void;
(
e: "execute",
sql: string,
@@ -56,6 +56,7 @@ const dbSchemaStore = useDBSchemaV1Store();
const sqlEditorStore = useSQLEditorStore();
const sheetAndTabStore = useSheetAndTabStore();
const uiStateStore = useUIStateStore();
+const { events: editorEvents } = useSQLEditorContext();
const editorRef = ref<InstanceType<typeof MonacoEditor>>();
@@ -103,6 +104,9 @@ const handleChange = (value: string) => {
if (isSwitchingTab.value) {
return;
}
+ if (value === tabStore.currentTab.statement) {
+ return;
+ }
tabStore.updateCurrentTab({
statement: value,
isSaved: false,
@@ -116,7 +120,7 @@ const handleChangeSelection = (value: string) => {
};
const handleSaveSheet = () => {
- emit("save-sheet");
+ editorEvents.emit("save-sheet", { title: tabStore.currentTab.name });
};
const handleEditorReady = async () => {
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/HistoryTabPane/HistoryConnectionIcon.vue b/frontend/src/views/sql-editor/SecondarySidebar/HistoryTabPane/HistoryConnectionIcon.vue
new file mode 100644
index 0000000000..2fb7eeb95f
--- /dev/null
+++ b/frontend/src/views/sql-editor/SecondarySidebar/HistoryTabPane/HistoryConnectionIcon.vue
@@ -0,0 +1,24 @@
+<template>
+ <InstanceV1EngineIcon
+ v-if="instance.uid !== String(UNKNOWN_ID)"
+ :instance="instance"
+ :tooltip="false"
+ class="!w-3.5"
+ />
+</template>
+
+<script setup lang="ts">
+import { computed } from "vue";
+import { InstanceV1EngineIcon } from "@/components/v2";
+import { useInstanceV1ByUID } from "@/store";
+import { QueryHistory, UNKNOWN_ID } from "@/types";
+
+const props = defineProps<{
+ queryHistory: QueryHistory;
+}>();
+
+const instanceUID = computed(() => {
+ return String(props.queryHistory.instanceId);
+});
+const { instance } = useInstanceV1ByUID(instanceUID);
+</script>
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/HistoryTabPane/HistoryTabPane.vue b/frontend/src/views/sql-editor/SecondarySidebar/HistoryTabPane/HistoryTabPane.vue
index 2c41bb70d8..542e1371f5 100644
--- a/frontend/src/views/sql-editor/SecondarySidebar/HistoryTabPane/HistoryTabPane.vue
+++ b/frontend/src/views/sql-editor/SecondarySidebar/HistoryTabPane/HistoryTabPane.vue
@@ -25,14 +25,17 @@
<span class="text-xs text-gray-500">
{{ titleOfQueryHistory(history) }}
</span>
- <span
- class="rounded text-gray-500 hover:text-gray-700 hover:bg-gray-200"
- >
- <heroicons-outline:clipboard-document
- class="w-4 h-4"
- @click.stop="handleCopy(history)"
- />
- </span>
+ <div class="flex items-start gap-x-2">
+ <HistoryConnectionIcon :query-history="history" />
+ <span
+ class="rounded text-gray-500 hover:text-gray-700 hover:bg-gray-200"
+ >
+ <heroicons-outline:clipboard-document
+ class="w-4 h-4"
+ @click.stop="handleCopy(history)"
+ />
+ </span>
+ </div>
</div>
<p
class="max-w-full text-xs break-words font-mono line-clamp-3"
@@ -71,6 +74,7 @@ import {
} from "@/store";
import { QueryHistory } from "@/types";
import { getHighlightHTMLByKeyWords } from "@/utils";
+import HistoryConnectionIcon from "./HistoryConnectionIcon.vue";
interface State {
search: string;
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue
index 9bda0135ac..2e1128ffb5 100644
--- a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue
+++ b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue
@@ -23,7 +23,7 @@
@select-table="handleSelectTable"
@alter-schema="emit('alter-schema', $event)"
/>
- <Transition name="slide-up" appear>
+ <Transition name="slide-up">
<TableSchema
v-if="selected"
class="absolute bottom-0 w-full h-[calc(100%-33px)] bg-white"
@@ -79,15 +79,23 @@ const { database } = useDatabaseV1ByUID(computed(() => conn.value.databaseId));
const databaseMetadata = ref<DatabaseMetadata>();
const handleSelectTable = (schema: SchemaMetadata, table: TableMetadata) => {
- selected.value = { schema, table };
+ if (!databaseMetadata.value) return;
+ selected.value = {
+ db: database.value,
+ database: databaseMetadata.value,
+ schema,
+ table,
+ };
};
watch(
() => database.value.name,
- async (name) => {
- selected.value = undefined;
+ async (toName, fromName) => {
+ if (fromName !== undefined) {
+ selected.value = undefined;
+ }
databaseMetadata.value = await dbSchemaStore.getOrFetchDatabaseMetadata(
- name,
+ toName,
/* !skipCache */ false
);
},
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/SheetTabPane/SheetTabPane.vue b/frontend/src/views/sql-editor/SecondarySidebar/SheetTabPane/SheetTabPane.vue
index 7a0db9e7e9..6de63a38fc 100644
--- a/frontend/src/views/sql-editor/SecondarySidebar/SheetTabPane/SheetTabPane.vue
+++ b/frontend/src/views/sql-editor/SecondarySidebar/SheetTabPane/SheetTabPane.vue
@@ -2,9 +2,9 @@
<NTabs
v-model:value="sheetTab"
size="small"
- class="h-full pt-1.5 px-1"
+ class="bb-sql-editor--sheet-tab-pane--tabs h-full pt-1.5 px-1"
pane-style="height: calc(100% - 29px); padding: 0;"
- :tabs-padding="4"
+ justify-content="space-between"
>
<NTabPane name="my" :tab="$t('sheet.mine')">
<SheetList view="my" />
@@ -33,3 +33,16 @@ useEmitteryEventListener(sheetEvents, "add-sheet", () => {
sheetTab.value = "my";
});
</script>
+
+<style lang="postcss">
+.bb-sql-editor--sheet-tab-pane--tabs
+ .n-tabs-nav-scroll-wrapper--shadow-start::before,
+.bb-sql-editor--sheet-tab-pane--tabs
+ .n-tabs-nav-scroll-wrapper--shadow-end::after {
+ @apply hidden;
+}
+
+.bb-sql-editor--sheet-tab-pane--tabs .n-tabs-wrapper {
+ @apply px-1;
+}
+</style>
diff --git a/frontend/src/views/sql-editor/Sheet/context.ts b/frontend/src/views/sql-editor/Sheet/context.ts
index 32227dbc3a..f76e3871a3 100644
--- a/frontend/src/views/sql-editor/Sheet/context.ts
+++ b/frontend/src/views/sql-editor/Sheet/context.ts
@@ -3,11 +3,10 @@ import { InjectionKey, Ref, inject, provide, ref, computed } from "vue";
import { t } from "@/plugins/i18n";
import {
pushNotification,
- useInstanceV1Store,
+ useDatabaseV1Store,
useSheetV1Store,
useTabStore,
} from "@/store";
-import { getInstanceAndDatabaseId } from "@/store/modules/v1/common";
import { AnyTabInfo, UNKNOWN_ID } from "@/types";
import { Sheet } from "@/types/proto/v1/sheet_service";
import {
@@ -143,12 +142,11 @@ export const openSheet = async (sheet: Sheet, forceNewTab = false) => {
let insId = String(UNKNOWN_ID);
let dbId = String(UNKNOWN_ID);
if (sheet.database) {
- const [instanceName, databaseId] = getInstanceAndDatabaseId(sheet.database);
- const ins = useInstanceV1Store().getInstanceByName(
- `instances/${instanceName}`
+ const database = await useDatabaseV1Store().getOrFetchDatabaseByName(
+ sheet.database
);
- insId = ins.uid;
- dbId = databaseId;
+ insId = database.instanceEntity.uid;
+ dbId = database.uid;
}
tabStore.updateCurrentTab({
diff --git a/frontend/src/views/sql-editor/SheetPanel/SheetTable/SheetConnection.vue b/frontend/src/views/sql-editor/SheetPanel/SheetTable/SheetConnection.vue
index 82a14ffa9a..3131338143 100644
--- a/frontend/src/views/sql-editor/SheetPanel/SheetTable/SheetConnection.vue
+++ b/frontend/src/views/sql-editor/SheetPanel/SheetTable/SheetConnection.vue
@@ -39,7 +39,6 @@ import {
import { useDatabaseV1Store } from "@/store";
import { UNKNOWN_ID } from "@/types";
import { Sheet } from "@/types/proto/v1/sheet_service";
-import { extractDatabaseResourceName } from "@/utils";
const props = defineProps<{
sheet: Sheet;
@@ -49,9 +48,7 @@ const databaseStore = useDatabaseV1Store();
const database = computed(() => {
const { sheet } = props;
if (!props.sheet.database) return undefined;
- const db = databaseStore.getDatabaseByUID(
- extractDatabaseResourceName(sheet.database).database
- );
+ const db = databaseStore.getDatabaseByName(sheet.database);
if (db.uid === String(UNKNOWN_ID)) return undefined;
return db;
});
diff --git a/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue b/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue
index ba30195cec..cc9d0ece54 100644
--- a/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue
+++ b/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue
@@ -9,6 +9,10 @@
},
[sheetTypeForTab(tab).toLowerCase()],
]"
+ :data-is-fresh-new="tab.isFreshNew"
+ :data-is-saved="tab.isSaved"
+ :data-is-disconnected="isDisconnectedTab(tab)"
+ :data-sheet-type="sheetTypeForTab(tab)"
@mousedown.left="$emit('select', tab, index)"
@mouseenter="state.hovering = true"
@mouseleave="state.hovering = false"
@@ -28,7 +32,7 @@ import { computed, PropType, reactive } from "vue";
import { useTabStore } from "@/store";
import type { TabInfo } from "@/types";
import { TabMode } from "@/types";
-import { sheetTypeForTab } from "@/utils";
+import { isDisconnectedTab, sheetTypeForTab } from "@/utils";
import AdminLabel from "./AdminLabel.vue";
import Label from "./Label.vue";
import Prefix from "./Prefix.vue";
diff --git a/frontend/src/views/sql-editor/TabList/TabList.vue b/frontend/src/views/sql-editor/TabList/TabList.vue
index b6d2086dc1..df674da07c 100644
--- a/frontend/src/views/sql-editor/TabList/TabList.vue
+++ b/frontend/src/views/sql-editor/TabList/TabList.vue
@@ -61,7 +61,11 @@ import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener
import { useSQLEditorStore, useTabStore } from "@/store";
import type { TabInfo } from "@/types";
import { TabMode } from "@/types";
-import { defer, getSuggestedTabNameFromConnection } from "@/utils";
+import {
+ defer,
+ getSuggestedTabNameFromConnection,
+ sheetTypeForTab,
+} from "@/utils";
import ProfileDropdown from "../ProfileDropdown";
import { useSheetContext } from "../Sheet";
import ContextMenu from "./ContextMenu.vue";
@@ -263,7 +267,7 @@ useEmitteryEventListener(
if (action === "CLOSE_SAVED") {
for (let i = max; i >= 0; i--) {
const tab = tabList[i];
- if (tab.isSaved) {
+ if (sheetTypeForTab(tab) === "CLEAN") {
await remove(tab, i);
}
}
@@ -284,6 +288,6 @@ useEmitteryEventListener(
}
.tab-list {
- @apply flex flex-nowrap overflow-x-auto max-w-full hide-scrollbar;
+ @apply flex flex-nowrap overflow-x-auto max-w-full hide-scrollbar overscroll-none;
}
</style>
diff --git a/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue b/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue
index c29b914cd9..e06a8f8fb7 100644
--- a/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue
+++ b/frontend/src/views/sql-editor/TerminalPanel/CompactSQLEditor.vue
@@ -10,7 +10,6 @@
:options="EDITOR_OPTIONS"
@change="handleChange"
@change-selection="handleChangeSelection"
- @save="handleSaveSheet"
@ready="handleEditorReady"
/>
</div>
@@ -56,7 +55,6 @@ const props = defineProps({
});
const emit = defineEmits<{
- (e: "save-sheet", content?: string): void;
(e: "update:sql", sql: string): void;
(
e: "execute",
@@ -154,10 +152,6 @@ const handleChangeSelection = (value: string) => {
});
};
-const handleSaveSheet = () => {
- emit("save-sheet");
-};
-
const handleEditorReady = async () => {
const monaco = await import("monaco-editor");
const editor = editorRef.value?.editorInstance;
diff --git a/frontend/src/views/sql-editor/context.ts b/frontend/src/views/sql-editor/context.ts
index 3d20a7086c..cfb51cd511 100644
--- a/frontend/src/views/sql-editor/context.ts
+++ b/frontend/src/views/sql-editor/context.ts
@@ -1,18 +1,26 @@
import Emittery from "emittery";
import { InjectionKey, inject, provide, Ref, ref } from "vue";
+import { ComposedDatabase } from "@/types";
import {
+ DatabaseMetadata,
SchemaMetadata,
TableMetadata,
} from "@/types/proto/v1/database_service";
type SQLEditorEvents = Emittery<{
- // nothing by now
+ "save-sheet": { title: string };
}>;
export type SQLEditorContext = {
showAIChatBox: Ref<boolean>;
selectedDatabaseSchema: Ref<
- { schema: SchemaMetadata; table: TableMetadata } | undefined
+ | {
+ db: ComposedDatabase;
+ database: DatabaseMetadata;
+ schema: SchemaMetadata;
+ table: TableMetadata;
+ }
+ | undefined
>;
events: SQLEditorEvents;