Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: optimize sql editor tabs (#18182)
ecmadaof4817f41cd69
diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vueindex 569e7ab863..a8056ae58d 100644--- a/frontend/src/components/ProvideSQLEditorContext.vue+++ b/frontend/src/components/ProvideSQLEditorContext.vue@@ -25,6 +25,7 @@ import { computed, nextTick, onMounted, watch } from "vue";import { useI18n } from "vue-i18n";import { useRoute, useRouter } from "vue-router";import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";+import { useRouteChangeGuard } from "@/composables/useRouteChangeGuard";import { ProvideAIContext } from "@/plugins/ai";import {SQL_EDITOR_DATABASE_MODULE,@@ -85,6 +86,17 @@ const {maybeSwitchProject,} = useSQLEditorContext();+useRouteChangeGuard(+ computed(() => {+ return (+ tabStore.tabList.find(+ (tab) => !!tab?.worksheet && tab.status === "DIRTY"+ ) !== undefined+ );+ }),+ `${t("sql-editor.tab.unsaved-worksheet")} ${t("common.leave-without-saving")}`+);+const fallbackToFirstProject = async () => {const { projects } = await projectStore.fetchProjectList({pageSize: getDefaultPagination(),diff --git a/frontend/src/composables/useRouteChangeGuard.ts b/frontend/src/composables/useRouteChangeGuard.tsindex 2ff493c686..b1ea103061 100644--- a/frontend/src/composables/useRouteChangeGuard.ts+++ b/frontend/src/composables/useRouteChangeGuard.ts@@ -3,18 +3,21 @@ import { type Ref } from "vue";import { onBeforeRouteLeave } from "vue-router";import { t } from "@/plugins/i18n";-export const useRouteChangeGuard = (isEditing: Ref<boolean>) => {+export const useRouteChangeGuard = (+ isEditing: Ref<boolean>,+ content?: string+) => {useEventListener("beforeunload", (e) => {if (!isEditing.value) {return;}- e.returnValue = t("common.leave-without-saving");+ e.returnValue = content ?? t("common.leave-without-saving");return e.returnValue;});onBeforeRouteLeave((to, from, next) => {if (isEditing.value) {- if (!window.confirm(t("common.leave-without-saving"))) {+ if (!window.confirm(content ?? t("common.leave-without-saving"))) {return;}}diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex b62d796183..cf29e26ef8 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -2102,7 +2102,8 @@"add-worksheet": "Add worksheet","multi-select": "Multi-select"}- }+ },+ "unsaved-worksheet": "You have unsaved worksheet."},"batch-query": {"batch": "Batch",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex edef88f325..74374028b1 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -2102,7 +2102,8 @@"add-worksheet": "Agregar hoja de trabajo","multi-select": "Selección múltiple"}- }+ },+ "unsaved-worksheet": "Tiene una hoja de trabajo sin guardar."},"batch-query": {"batch": "Lote",diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 5f105bd36a..5eb5e3462c 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -2102,7 +2102,8 @@"add-worksheet": "ワークシートを追加","multi-select": "複数選択"}- }+ },+ "unsaved-worksheet": "保存されていないワークシートがあります。"},"batch-query": {"batch": "バッチ",diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex f44f73c528..a96d3f2265 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -2102,7 +2102,8 @@"add-worksheet": "Thêm bảng tính","multi-select": "Chọn nhiều"}- }+ },+ "unsaved-worksheet": "Bạn có bảng tính chưa lưu."},"batch-query": {"batch": "Hàng loạt",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 2589bb1bce..a056a339cf 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -2102,7 +2102,8 @@"add-worksheet": "添加工作表","multi-select": "多选"}- }+ },+ "unsaved-worksheet": "您有未保存的工作表。"},"batch-query": {"batch": "批量",diff --git a/frontend/src/store/modules/sqlEditor/tab.ts b/frontend/src/store/modules/sqlEditor/tab.tsindex 050516cbbd..5de2907887 100644--- a/frontend/src/store/modules/sqlEditor/tab.ts+++ b/frontend/src/store/modules/sqlEditor/tab.ts@@ -35,7 +35,6 @@ import {type ExtendedTab,useExtendedTabStore,} from "./extendedTab";-import { useTabViewStateStore } from "./tabViewState";import { useWebTerminalStore } from "./webTerminal";const LOCAL_STORAGE_KEY_PREFIX = "bb.sql-editor-tab";@@ -62,7 +61,6 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {// statesconst { fetchExtendedTab, saveExtendedTab, deleteExtendedTab } =useExtendedTabStore();- const tabViewStateStore = useTabViewStateStore();const me = useCurrentUserV1();const userUID = computed(() => extractUserId(me.value.name));@@ -164,7 +162,6 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {// it's a combination of `project` and `tabIdListMapByProject`const tabIdList = computed({get() {- // _maybeInitProject(project.value);return tabIdListMapByProject.value[project.value] ?? [];},set(list) {@@ -175,7 +172,6 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {// it's a combination of `project` and `currentTabIdMapByProject`const currentTabId = computed({get() {- // _maybeInitProject(project.value);return currentTabIdMapByProject.value[project.value] ?? "";},set(id) {@@ -390,20 +386,16 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {isDisconnectedSQLEditorTab(curr) ||isSimilarSQLEditorTab(tab, curr, ignoreMode)) {- curr.connection = tab.connection;- curr.worksheet = tab.worksheet;- curr.mode = tab.mode;- if (- defaultTitle &&- tabViewStateStore.getViewState(curr.id).view === "CODE"- ) {- curr.title = defaultTitle;- }+ updateTab(curr.id, {+ connection: tab.connection,+ worksheet: tab.worksheet,+ mode: tab.mode,+ });return curr;}}const similarNewTab = tabList.value.find(- (tmp) => tmp.status === "NEW" && isSimilarSQLEditorTab(tmp, tab)+ (tmp) => tmp.status === "CLEAN" && isSimilarSQLEditorTab(tmp, tab));if (similarNewTab) {setCurrentTabId(similarNewTab.id);@@ -479,7 +471,7 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {keyForTab(persistent.id),persistent);- const activeTab = tabsById.get(tabId);+ const activeTab = tabsById.get(persistent.id);if (activeTab) {saveExtendedTab(activeTab, extended);}diff --git a/frontend/src/types/sqlEditor/tab.ts b/frontend/src/types/sqlEditor/tab.tsindex 6c96632086..be073bdf34 100644--- a/frontend/src/types/sqlEditor/tab.ts+++ b/frontend/src/types/sqlEditor/tab.ts@@ -8,7 +8,6 @@ import type { SQLResultSetV1 } from "../v1/sql";import type { SQLEditorConnection, SQLEditorQueryParams } from "./editor";export type SQLEditorTabStatus =- | "NEW" // just created and untouched| "DIRTY" // edited| "CLEAN"; // saved to a remote sheetdiff --git a/frontend/src/utils/sqlEditor.ts b/frontend/src/utils/sqlEditor.tsindex 97b7d8a5c9..b1e02d0d29 100644--- a/frontend/src/utils/sqlEditor.ts+++ b/frontend/src/utils/sqlEditor.ts@@ -38,7 +38,7 @@ export const defaultSQLEditorTab = (): SQLEditorTab => {connection: emptySQLEditorConnection(),statement: "",selectedStatement: "",- status: "NEW",+ status: "CLEAN",mode: DEFAULT_SQL_EDITOR_TAB_MODE,worksheet: "",treeState: {diff --git a/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/TreeNodeSuffix.vue b/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/TreeNodeSuffix.vueindex 678e78c17a..444868089a 100644--- a/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/TreeNodeSuffix.vue+++ b/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/TreeNodeSuffix.vue@@ -33,7 +33,7 @@{{ t("common.visibility") }}{{ ": " }}{{ visibilityDisplayName(worksheetLite.visibility) }}</div><div- v-if="!isWorksheetCreator(worksheetLite.creator)"+ v-if="!isWorksheetCreator(worksheetLite)">{{ t("common.creator") }}{{ ": " }}{{ creatorForSheet(worksheetLite.creator) }}</div>@@ -61,7 +61,6 @@ import { NTooltip } from "naive-ui";import { computed } from "vue";import { t } from "@/plugins/i18n";import {- useCurrentUserV1,useSQLEditorTabStore,useTabViewStateStore,useUserStore,@@ -72,6 +71,7 @@ import type {SheetViewMode,WorksheetFolderNode,} from "@/views/sql-editor/Sheet";+import { useSheetContext } from "@/views/sql-editor/Sheet";const props = defineProps<{node: WorksheetFolderNode;@@ -86,9 +86,9 @@ const emit = defineEmits<{const userStore = useUserStore();const worksheetStore = useWorkSheetStore();-const me = useCurrentUserV1();const { removeViewState } = useTabViewStateStore();const tabStore = useSQLEditorTabStore();+const { isWorksheetCreator } = useSheetContext();const worksheetLite = computed(() => {if (!props.node.worksheet) {@@ -123,10 +123,6 @@ const creatorForSheet = (creator: string) => {return userStore.getUserByIdentifier(creator)?.title ?? creator;};-const isWorksheetCreator = (creator: string) => {- return creator === `users/${me.value.email}`;-};-const handleDeleteDraft = () => {if (props.node.worksheet && props.node.worksheet.name) {const draft = tabStore.tabList.find(diff --git a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vueindex 9b88a85f6f..721c8ad21f 100644--- a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue+++ b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue@@ -268,7 +268,7 @@ const allowSave = computed(() => {return true;}}- if (tab.status === "NEW" || tab.status === "CLEAN") {+ if (tab.status === "CLEAN") {return false;}if (!tab.connection.database) {@@ -281,7 +281,7 @@ const allowSave = computed(() => {const allowShare = computed(() => {const tab = currentTab.value;if (!tab) return false;- if (tab.status === "NEW" || tab.status === "DIRTY") return false;+ if (tab.status === "DIRTY") return false;if (isEmptyStatement.value) return false;if (isDisconnected.value) return false;if (tab.worksheet) {diff --git a/frontend/src/views/sql-editor/EditorCommon/SheetConnectionIcon.vue b/frontend/src/views/sql-editor/EditorCommon/SheetConnectionIcon.vueindex b788b1f704..312dc36cf4 100644--- a/frontend/src/views/sql-editor/EditorCommon/SheetConnectionIcon.vue+++ b/frontend/src/views/sql-editor/EditorCommon/SheetConnectionIcon.vue@@ -1,8 +1,6 @@<template>- <div class="inline-flex items-center justify-center">- <EngineIcon v-if="instance" :engine="instance.engine" />- <UnlinkIcon v-else class="w-3.5 h-3.5 text-control opacity-50" />- </div>+ <EngineIcon v-if="instance" :engine="instance.engine" />+ <UnlinkIcon v-else /></template><script setup lang="ts">diff --git a/frontend/src/views/sql-editor/Sheet/context.ts b/frontend/src/views/sql-editor/Sheet/context.tsindex 75caf72b6a..97c5195a94 100644--- a/frontend/src/views/sql-editor/Sheet/context.ts+++ b/frontend/src/views/sql-editor/Sheet/context.ts@@ -346,7 +346,7 @@ export type SheetContext = {expandedKeys: Ref<Set<string>>;selectedKeys: Ref<string[]>;editingNode: Ref<{ node: WorksheetFolderNode; rawLabel: string } | undefined>;- isWorksheetCreator: (worksheet: Worksheet) => boolean;+ isWorksheetCreator: (worksheet: { creator: string }) => boolean;batchUpdateWorksheetFolders: (worksheets: { name: string; folders: string[] }[]) => Promise<void>;@@ -445,7 +445,7 @@ export const provideSheetContext = () => {);const selectedKeys = ref<string[]>([]);- const isWorksheetCreator = (worksheet: Worksheet) => {+ const isWorksheetCreator = (worksheet: { creator: string }) => {return worksheet.creator === `users/${me.value.email}`;};@@ -622,6 +622,6 @@ export const addNewSheet = () => {tabStore.addTab({title,connection,- status: "NEW",+ status: "CLEAN",});};diff --git a/frontend/src/views/sql-editor/TabList/TabItem/Label.vue b/frontend/src/views/sql-editor/TabList/TabItem/Label.vueindex a3bb519a1f..45bc2a3c73 100644--- a/frontend/src/views/sql-editor/TabList/TabItem/Label.vue+++ b/frontend/src/views/sql-editor/TabList/TabItem/Label.vue@@ -90,8 +90,11 @@ const confirmEdit = () => {return cancelEdit();}- tab.title = title;- tab.status = "DIRTY";+ tabStore.updateTab(tab.id, {+ title,+ status: "DIRTY",+ });+if (tab.worksheet) {worksheetV1Store.patchWorksheet(@@ -130,20 +133,14 @@ watch(isCurrentTab, (value) => {<style scoped lang="postcss">.label {position: relative;- display: flex;- align-items: center;- white-space: nowrap;min-width: 6rem;- max-width: 12rem;+ max-width: 16rem;overflow: hidden;text-overflow: ellipsis;}.label :deep(.name) {- height: 1.5rem;width: 100%;- display: flex;- align-items: center;font-size: 0.875rem;line-height: 1.25rem;}diff --git a/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue b/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vueindex 6ebc1403b0..a1daced17d 100644--- a/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue+++ b/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue@@ -1,23 +1,23 @@<template>- <SheetConnectionIcon :tab="tab" class="w-4 h-4" />- <UsersIcon- v-if="- sheet?.visibility === Worksheet_Visibility.PROJECT_READ ||- sheet?.visibility === Worksheet_Visibility.PROJECT_WRITE- "- class="w-4 h-4"- />- <template v-if="tab.mode === 'ADMIN'">- <WrenchIcon class="w-4 h-4" />- </template>+ <div class="opacity-80 flex items-center gap-x-2">+ <PencilLineIcon v-if="!tab.worksheet" class="w-4 h-4" />+ <template v-else>+ <UsersIcon+ v-if="sheet && !isWorksheetCreator(sheet)"+ class="w-4 h-4"+ />+ <WrenchIcon v-if="tab.mode === 'ADMIN'" class="w-4 h-4" />+ </template>+ <SheetConnectionIcon :tab="tab" class="w-4 h-4" />+ </div></template><script lang="ts" setup>-import { UsersIcon, WrenchIcon } from "lucide-vue-next";+import { PencilLineIcon, UsersIcon, WrenchIcon } from "lucide-vue-next";import { computed } from "vue";import { useWorkSheetStore } from "@/store";import type { SQLEditorTab } from "@/types";-import { Worksheet_Visibility } from "@/types/proto-es/v1/worksheet_service_pb";+import { useSheetContext } from "@/views/sql-editor/Sheet";import { SheetConnectionIcon } from "../../EditorCommon";const props = defineProps<{@@ -25,6 +25,7 @@ const props = defineProps<{}>();const sheetV1Store = useWorkSheetStore();+const { isWorksheetCreator } = useSheetContext();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.vueindex 811c401b6d..8204b3ea35 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 } = props.tab;- if (mode === "WORKSHEET" && (status === "DIRTY" || status === "NEW")) {+ const { mode, status, worksheet } = props.tab;+ if (mode === "WORKSHEET" && !!worksheet && status === "DIRTY") {return "unsaved";}return "close";diff --git a/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue b/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vueindex 42e6db872d..1d0dd9a8ec 100644--- a/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue+++ b/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue@@ -8,15 +8,12 @@},tab.status.toLowerCase(),]"- :data-status="tab.status"- :data-sheet="tab.worksheet"- :data-connection="JSON.stringify(tab.connection)"@mousedown.left="$emit('select', tab, index)"@mouseenter="state.hovering = true"@mouseleave="state.hovering = false"><div- class="body"+ class="body flex items-center gap-x-2":style="backgroundColorRgb? {@@ -106,7 +103,6 @@ const backgroundColorRgb = computed(() => {display: flex;align-items: center;justify-content: space-between;- column-gap: 0.25rem;padding-left: 0.5rem;padding-right: 0.25rem;border-top-width: 1px;