Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: remove legacy sql editor route (#18391)
ecmadaoeada8d2b08f7
diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vueindex dfb8b3a8dd..e4bb498dd3 100644--- a/frontend/src/components/ProvideSQLEditorContext.vue+++ b/frontend/src/components/ProvideSQLEditorContext.vue@@ -62,10 +62,9 @@ import {getDefaultPagination,getSheetStatement,isDatabaseV1Queryable,+ isSameSQLEditorConnection,isWorksheetReadableV1,- projectNameFromSheetSlug,suggestedTabTitleForSQLEditorConnection,- worksheetNameFromSlug,} from "@/utils";import {type AsidePanelTab,@@ -140,22 +139,19 @@ const initializeProject = async () => {};const connect = (connection: SQLEditorConnection) => {- const currentTab = tabStore.selectOrAddSimilarNewTab(- {- connection,- worksheet: "",- mode: DEFAULT_SQL_EDITOR_TAB_MODE,- },- /* beside */ false,- /* defaultTitle */ suggestedTabTitleForSQLEditorConnection(connection),- /* ignoreMode */ true+ const tabWithSameConnect = tabStore.draftList.find((tab) =>+ isSameSQLEditorConnection(tab.connection, connection));- if (currentTab?.mode === "ADMIN") {- // Don't enter ADMIN mode initially- tabStore.updateCurrentTab({- mode: DEFAULT_SQL_EDITOR_TAB_MODE,- });+ if (tabWithSameConnect) {+ tabStore.addTab(tabWithSameConnect);+ return;}++ tabStore.addTab({+ connection,+ mode: DEFAULT_SQL_EDITOR_TAB_MODE,+ title: suggestedTabTitleForSQLEditorConnection(connection),+ });};const switchWorksheet = async (sheetName: string) => {@@ -210,19 +206,6 @@ const switchWorksheet = async (sheetName: string) => {return true;};-const prepareSheetLegacy = async () => {- const sheetSlug = (route.params.sheetSlug as string) || "";- if (!sheetSlug) {- return false;- }-- const projectName = projectNameFromSheetSlug(sheetSlug);- await maybeSwitchProject(projectName);-- const sheetName = worksheetNameFromSlug(sheetSlug);- return await switchWorksheet(sheetName);-};-const prepareSheet = async () => {const projectId = route.params.project;const sheetId = route.params.sheet;@@ -277,10 +260,6 @@ const initializeConnectionFromQuery = async () => {// 2. instanceId and databaseId in connectionSlug// 3. database in global filter// 4. disconnected-- if (await prepareSheetLegacy()) {- return true;- }if (await prepareSheet()) {return;}diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex 5165e31a2b..e23fee22fc 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -245,19 +245,6 @@ router.beforeEach((to, from, next) => {return;}- // === DYNAMIC ROUTE HANDLING ===-- const routerSlug = routerStore.routeSlug(to);- if (- routerSlug.issueSlug ||- routerSlug.sheetSlug ||- routerSlug.connectionSlug- ) {- // Data fetching is handled by respective components- next();- return;- }-// === FALLBACK ===// Log unexpected route for debuggingdiff --git a/frontend/src/router/sqlEditor.ts b/frontend/src/router/sqlEditor.tsindex 4acf99141f..23ca837d83 100644--- a/frontend/src/router/sqlEditor.ts+++ b/frontend/src/router/sqlEditor.ts@@ -6,8 +6,6 @@ export const SQL_EDITOR_PROJECT_MODULE = "sql-editor.project";export const SQL_EDITOR_INSTANCE_MODULE = "sql-editor.instance";export const SQL_EDITOR_DATABASE_MODULE = "sql-editor.database";export const SQL_EDITOR_WORKSHEET_MODULE = "sql-editor.worksheet";-export const SQL_EDITOR_DETAIL_MODULE_LEGACY = "sql-editor.legacy-detail";-export const SQL_EDITOR_SHARE_MODULE_LEGACY = "sql-editor.legacy-share";const sqlEditorRoutes: RouteRecordRaw[] = [{@@ -45,18 +43,6 @@ const sqlEditorRoutes: RouteRecordRaw[] = [meta: { title: () => "Bytebase SQL Editor" },component: () => import("../views/sql-editor/SQLEditorPage.vue"),},- {- path: ":connectionSlug",- name: SQL_EDITOR_DETAIL_MODULE_LEGACY,- meta: { title: () => "Bytebase SQL Editor" },- component: () => import("../views/sql-editor/SQLEditorPage.vue"),- },- {- path: "sheet/:sheetSlug",- name: SQL_EDITOR_SHARE_MODULE_LEGACY,- meta: { title: () => "Bytebase SQL Editor" },- component: () => import("../views/sql-editor/SQLEditorPage.vue"),- },],},];diff --git a/frontend/src/store/modules/router.ts b/frontend/src/store/modules/router.tsindex 9fdb0031c4..985b46393d 100644--- a/frontend/src/store/modules/router.ts+++ b/frontend/src/store/modules/router.ts@@ -1,6 +1,4 @@import { defineStore } from "pinia";-import type { RouteLocationNormalized } from "vue-router";-import type { RouterSlug } from "@/types";export const useRouterStore = defineStore("router", {// need not to initialize a state since we store everything into localStorage@@ -16,35 +14,5 @@ export const useRouterStore = defineStore("router", {localStorage.setItem("ui.backPath", backPath);return backPath;},- routeSlug(currentRoute: RouteLocationNormalized): RouterSlug {- {- // /sql-editor/sheet/:sheetSlug- // match this route first- const sqlEditorComponents = currentRoute.path.match(- "/sql-editor/sheet/([0-9a-zA-Z_-]+)"- ) || ["/", undefined];-- if (sqlEditorComponents[1]) {- return {- sheetSlug: sqlEditorComponents[1],- };- }- }-- {- // /sql-editor/:connectionSlug- const sqlEditorComponents = currentRoute.path.match(- "/sql-editor/(instances/[0-9a-zA-Z_-]+/databases/[0-9a-zA-Z_-]+)"- ) || ["/", undefined];-- if (sqlEditorComponents[1]) {- return {- connectionSlug: sqlEditorComponents[1],- };- }- }-- return {};- },},});diff --git a/frontend/src/store/modules/sqlEditor/tab.ts b/frontend/src/store/modules/sqlEditor/tab.tsindex ac77532a2c..669ba1e9dd 100644--- a/frontend/src/store/modules/sqlEditor/tab.ts+++ b/frontend/src/store/modules/sqlEditor/tab.ts@@ -4,7 +4,6 @@ import { defineStore, storeToRefs } from "pinia";import { computed, reactive, unref, watch } from "vue";import type {BatchQueryContext,- CoreSQLEditorTab,SQLEditorConnection,SQLEditorDatabaseQueryContext,SQLEditorTab,@@ -18,7 +17,6 @@ import {extractWorksheetConnection,getSheetStatement,isConnectedSQLEditorTab,- isSimilarSQLEditorTab,useDynamicLocalStorage,} from "@/utils";import {@@ -397,50 +395,6 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {currentTabId.value = id;};- // TODO(ed): deprecate- // The similar tab should not consider the worksheet- // What we should do:- // When load the SQL Editor page in the URL like /instances/{instance}/databases/{database},- // get the connection, check if exist opening tab with the same connection- // - exist: set the current tab id- // - not exist: we still have to provide a draft worksheet, but the draft can only exist in the memory, not in the local storage- const selectOrAddSimilarNewTab = (- tab: CoreSQLEditorTab,- beside = false,- defaultTitle?: string,- ignoreMode?: boolean- ) => {- const curr = currentTab.value;- if (curr) {- if (- !isConnectedSQLEditorTab(curr) ||- isSimilarSQLEditorTab(tab, curr, ignoreMode)- ) {- updateTab(curr.id, {- connection: tab.connection,- worksheet: tab.worksheet,- mode: tab.mode,- });- return curr;- }- }- const similarNewTab = openTabList.value.find(- (tmp) => tmp.status === "CLEAN" && isSimilarSQLEditorTab(tmp, tab)- );- if (similarNewTab) {- setCurrentTabId(similarNewTab.id);- return similarNewTab;- } else {- return addTab(- {- ...tab,- title: defaultTitle,- },- beside- );- }- };-watch(() => project.value,() => {@@ -472,7 +426,6 @@ export const useSQLEditorTabStore = defineStore("sqlEditorTab", () => {batchRemoveDatabaseQueryContext,deleteDatabaseQueryContext,setCurrentTabId,- selectOrAddSimilarNewTab,maybeInitProject,isDisconnected,isInBatchMode,diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.tsindex 06c245ea3d..b3ff8f2a34 100644--- a/frontend/src/types/common.ts+++ b/frontend/src/types/common.ts@@ -14,13 +14,6 @@ export const DEBOUNCE_SEARCH_DELAY = 300;export const ENTERPRISE_INQUIRE_LINK ="https://www.bytebase.com/contact-us?source=console";-// Router-export type RouterSlug = {- issueSlug?: string;- connectionSlug?: string;- sheetSlug?: string;-};-// Quick Action Typeexport type Command = {id: CommandId;diff --git a/frontend/src/utils/slug.ts b/frontend/src/utils/slug.tsindex ea7c6046d7..386c349b69 100644--- a/frontend/src/utils/slug.ts+++ b/frontend/src/utils/slug.ts@@ -1,8 +1,6 @@import {getReviewConfigId,- projectNamePrefix,reviewConfigNamePrefix,- worksheetNamePrefix,} from "@/store/modules/v1/common";import type { SQLReviewPolicy } from "../types";import type { IdType } from "../types/id";@@ -26,17 +24,6 @@ export const idFromSlug = (slug: string): string => {return parts[parts.length - 1];};-export function projectNameFromSheetSlug(slug: string): string {- const parts = slug.split("-");- parts.pop();- return `${projectNamePrefix}${parts.join("-")}`;-}--export function worksheetNameFromSlug(slug: string): string {- const parts = slug.split("-");- return `${worksheetNamePrefix}${parts[parts.length - 1]}`;-}-export function sqlReviewPolicySlug(reviewPolicy: SQLReviewPolicy): string {return getReviewConfigId(reviewPolicy.id);}diff --git a/frontend/src/utils/sqlEditor.ts b/frontend/src/utils/sqlEditor.tsindex e7753bc355..651a5b3552 100644--- a/frontend/src/utils/sqlEditor.ts+++ b/frontend/src/utils/sqlEditor.ts@@ -4,7 +4,6 @@ import { v1 as uuidv1 } from "uuid";import { useDatabaseV1Store, usePolicyV1Store } from "@/store";import type {ComposedDatabase,- CoreSQLEditorTab,QueryDataSourceType,SQLEditorConnection,SQLEditorTab,@@ -77,24 +76,13 @@ export const getConnectionForSQLEditorTab = (tab: SQLEditorTab) => {return target;};-const isSameSQLEditorConnection = (+export const isSameSQLEditorConnection = (a: SQLEditorConnection,b: SQLEditorConnection): boolean => {return a.instance === b.instance && a.database === b.database;};-export const isSimilarSQLEditorTab = (- a: CoreSQLEditorTab,- b: CoreSQLEditorTab,- ignoreMode?: boolean-): boolean => {- if (!isSameSQLEditorConnection(a.connection, b.connection)) return false;- if (a.worksheet !== b.worksheet) return false;- if (!ignoreMode && a.mode !== b.mode) return false;- return true;-};-export const suggestedTabTitleForSQLEditorConnection = (conn: SQLEditorConnection) => {diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsxindex 96de110408..9f91dbdb8e 100644--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/actions.tsx@@ -36,6 +36,7 @@ import {languageOfEngineV1,type Position,type SQLEditorConnection,+ type SQLEditorTab,typeToView,} from "@/types";import { Engine } from "@/types/proto-es/v1/common_pb";@@ -51,7 +52,7 @@ import {generateSimpleSelectAllStatement,generateSimpleUpdateStatement,instanceV1HasAlterSchema,- isSimilarSQLEditorTab,+ isSameSQLEditorConnection,sortByDictionary,supportGetStringSchema,} from "@/utils";@@ -104,10 +105,10 @@ export const useActions = () => {};const openNewTab = (params: {- title?: string;+ title: string;schema?: string;table?: string;- view?: EditorPanelView;+ view: EditorPanelView;}) => {const tabStore = useSQLEditorTabStore();const tabViewStateStore = useTabViewStateStore();@@ -124,37 +125,39 @@ export const useActions = () => {}const fromTab = tabStore.currentTab;- const clonedTab = defaultSQLEditorTab();+ const clonedTab: SQLEditorTab = {+ ...defaultSQLEditorTab(),+ status: "CLEAN",+ title: params.title,+ };if (fromTab) {clonedTab.connection = cloneDeep(fromTab.connection);clonedTab.treeState = cloneDeep(fromTab.treeState);}- clonedTab.status = "CLEAN";- clonedTab.title = params.title ?? "";- for (const tab of tabStore.openTabList) {- if (tab.id === fromTab?.id) {- continue;+ const findExistedTab = tabStore.openTabList.find((tab) => {+ if (tab.status !== "CLEAN" || tab.id === fromTab?.id) {+ return false;}- if (!isSimilarSQLEditorTab(clonedTab, tab, false)) {- continue;- }- if (tab.status !== clonedTab.status) {- continue;+ if (!isSameSQLEditorConnection(tab.connection, clonedTab.connection)) {+ return false;}const viewState = tabViewStateStore.getViewState(tab.id);if (viewState.view !== params.view ||(schema && viewState.schema !== schema)) {- continue;+ return false;}- tabStore.setCurrentTabId(tab.id);- return;- }+ return true;+ });- tabStore.addTab(clonedTab);- updateViewState({ view: params.view, schema, table });+ if (findExistedTab) {+ tabStore.setCurrentTabId(findExistedTab.id);+ } else {+ tabStore.addTab(clonedTab);+ updateViewState({ view: params.view, schema, table });+ }};const viewDetail = async (node: TreeNode) => {diff --git a/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue b/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vueindex a1daced17d..d3c468b1ba 100644--- a/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue+++ b/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue@@ -1,6 +1,6 @@<template><div class="opacity-80 flex items-center gap-x-2">- <PencilLineIcon v-if="!tab.worksheet" class="w-4 h-4" />+ <PencilLineIcon v-if="!tab.worksheet && viewState.view === 'CODE'" class="w-4 h-4" /><template v-else><UsersIconv-if="sheet && !isWorksheetCreator(sheet)"@@ -15,7 +15,7 @@<script lang="ts" setup>import { PencilLineIcon, UsersIcon, WrenchIcon } from "lucide-vue-next";import { computed } from "vue";-import { useWorkSheetStore } from "@/store";+import { useTabViewStateStore, useWorkSheetStore } from "@/store";import type { SQLEditorTab } from "@/types";import { useSheetContext } from "@/views/sql-editor/Sheet";import { SheetConnectionIcon } from "../../EditorCommon";@@ -26,6 +26,9 @@ const props = defineProps<{const sheetV1Store = useWorkSheetStore();const { isWorksheetCreator } = useSheetContext();+const { getViewState } = useTabViewStateStore();++const viewState = computed(() => getViewState(props.tab.id));const sheet = computed(() => {const { worksheet: sheetName } = props.tab;