Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(frontend): improve SDL issue display (#5006)
Liu Ji17d5a7a2be90
diff --git a/frontend/src/components/Issue/IssueTaskSDLPanel.vue b/frontend/src/components/Issue/IssueTaskSDLPanel.vueindex 1a3bc1b3af..04373a21d3 100644--- a/frontend/src/components/Issue/IssueTaskSDLPanel.vue+++ b/frontend/src/components/Issue/IssueTaskSDLPanel.vue@@ -1,19 +1,13 @@<template>- <div- class="flex flex-col md:flex-row md:justify-between md:items-center gap-2 md:gap-4"- >+ <div v-if="!hasFeature('bb.feature.sql-review')"><div class="flex space-x-4 flex-1">- <div class="py-2 text-sm font-medium text-control">- {{ $t("common.sql") }}- <button- v-if="!hasFeature('bb.feature.sql-review')"- type="button"- class="ml-1 btn-small py-0.5 inline-flex items-center text-accent"- @click.prevent="state.showFeatureModal = true"- >- 🎈{{ $t("sql-review.unlock-full-feature") }}- </button>- </div>+ <button+ type="button"+ class="btn-small py-0.5 inline-flex items-center text-accent"+ @click.prevent="state.showFeatureModal = true"+ >+ 🎈{{ $t("sql-review.unlock-full-feature") }}+ </button></div></div><div class="w-full">@@ -23,48 +17,72 @@><BBSpin /></div>- <template v-else>- <NTabs- v-if="sdlState.detail"- v-model:value="state.tab"- pane-style="padding-top: 0.25rem"- >- <NTabPane name="diff" :tab="$t('issue.sdl.schema-change')">- <CodeDiff- :old-string="sdlState.detail.previousSDL"- :new-string="sdlState.detail.prettyExpectedSDL"- output-format="side-by-side"- data-label="bb-change-detail-code-diff-block"- /></NTabPane>- <NTabPane- name="statement"- :tab="$t('issue.sdl.generated-ddl-statements')"- >- <MonacoEditor- ref="editorRef"- class="w-full border h-auto max-h-[360px]"- data-label="bb-issue-sql-editor"- :value="sdlState.detail.diffDDL"- :readonly="true"- :auto-focus="false"- language="sql"- @ready="handleMonacoEditorReady"- />- </NTabPane>- <NTabPane name="schema" :tab="$t('issue.sdl.full-schema')">- <MonacoEditor- ref="editorRef"- class="w-full border h-auto max-h-[360px]"- data-label="bb-issue-sql-editor"- :value="sdlState.detail.expectedSDL"- :readonly="true"- :auto-focus="false"- :advices="markers"- language="sql"- @ready="handleMonacoEditorReady"- />- </NTabPane>+ <template v-else-if="sdlState.detail">+ <NTabs v-model:value="state.tab" class="mb-1">+ <NTab name="diff" :disabled="!!sdlState.detail.error">+ <div class="flex items-center gap-x-1">+ {{ $t("issue.sdl.schema-change") }}+ <NTooltip>+ <template #trigger>+ <heroicons:question-mark-circle class="w-4 h-4" />+ </template>+ <div class="whitespace-nowrap">+ <span>{{ $t("issue.sdl.left-schema-may-change") }}</span>+ <LearnMoreLink+ url="https://www.bytebase.com/docs/change-database/state-based-migration?source=console#caveats"+ color="light"+ class="ml-1"+ />+ </div>+ </NTooltip>+ </div>+ </NTab>+ <NTab name="statement" :disabled="!!sdlState.detail.error">+ {{ $t("issue.sdl.generated-ddl-statements") }}+ </NTab>+ <NTab name="schema">+ {{ $t("issue.sdl.full-schema") }}+ </NTab></NTabs>++ <div+ v-if="sdlState.detail.error"+ class="flex text-error gap-x-1 items-start text-sm mb-1"+ >+ <heroicons:exclamation-circle class="w-4 h-4 shrink-0 mt-0.5" />+ <div>{{ sdlState.detail.error }}</div>+ </div>++ <CodeDiff+ v-if="state.tab === 'diff'"+ :old-string="sdlState.detail.previousSDL"+ :new-string="sdlState.detail.prettyExpectedSDL"+ output-format="side-by-side"+ data-label="bb-change-detail-code-diff-block"+ />+ <MonacoEditor+ v-if="state.tab === 'statement'"+ ref="editorRef"+ class="w-full border h-auto max-h-[360px]"+ data-label="bb-issue-sql-editor"+ :value="sdlState.detail.diffDDL"+ :readonly="true"+ :auto-focus="false"+ language="sql"+ @ready="handleMonacoEditorReady"+ />+ <MonacoEditor+ v-if="state.tab === 'schema'"+ ref="editorRef"+ class="w-full border h-auto max-h-[360px]"+ data-label="bb-issue-sql-editor"+ :value="sdlState.detail.expectedSDL"+ :readonly="true"+ :auto-focus="false"+ :advices="markers"+ language="sql"+ @ready="handleMonacoEditorReady"+ /></template></div><FeatureModal@@ -75,22 +93,25 @@</template><script lang="ts" setup>-import { NTabs, NTabPane } from "naive-ui";+import { NTabs, NTab, NTooltip } from "naive-ui";import { reactive, watch, computed, ref } from "vue";import { CodeDiff } from "v-code-diff";+import axios from "axios";+import LearnMoreLink from "@/components/LearnMoreLink.vue";import { hasFeature, useDatabaseStore, useInstanceStore } from "@/store";import { useIssueLogic } from "./logic";import { Task, TaskDatabaseSchemaUpdateSDLPayload, TaskId } from "@/types";import MonacoEditor from "../MonacoEditor";-import axios from "axios";import { sqlClient } from "@/grpcweb";import { convertEngineType } from "@/types";import { useSQLAdviceMarkers } from "./logic/useSQLAdviceMarkers";+import { useSilentRequest } from "@/plugins/silent-request";type TabView = "diff" | "statement" | "schema";type SDLDetail = {+ error: string;previousSDL: string;prettyExpectedSDL: string;expectedSDL: string;@@ -163,9 +184,9 @@ const useSDLState = () => {sourceSchema: previousSDL ?? "",targetSchema: expectedSDL ?? "",});- return data;+ return data ?? "";};- const diffDDL = (await getSchemaDiff()) ?? "";+ const diffDDL = await useSilentRequest(getSchemaDiff);const { currentSchema, expectedSchema } = await sqlClient.pretty({engine: convertEngineType(database.instance.engine),@@ -178,6 +199,7 @@ const useSDLState = () => {}return {+ error: "",previousSDL: currentSchema,prettyExpectedSDL: expectedSchema,expectedSDL,@@ -205,6 +227,7 @@ const useSDLState = () => {throw new Error();}return {+ error: "",previousSDL: history.schemaPrev,prettyExpectedSDL: history.schema,expectedSDL: history.schema,@@ -218,7 +241,7 @@ const useSDLState = () => {() => (selectedTask.value as Task).status,migrationId,],- ([taskId, taskStatus, migrationId]) => {+ async ([taskId, taskStatus, migrationId]) => {const task = selectedTask.value as Task;if (!map.has(taskId)) {map.set(taskId, emptyState(task));@@ -230,13 +253,30 @@ const useSDLState = () => {};try {if (taskStatus === "DONE") {- fetchSDLDetailFromMigrationHistory(task, migrationId).then(finish);+ const detail = await fetchSDLDetailFromMigrationHistory(+ task,+ migrationId+ );+ finish(detail);} else {- fetchOngoingSDLDetail(task).then(finish);+ const detail = await fetchOngoingSDLDetail(task);+ finish(detail);}- } catch {+ } catch (err: any) {// The task has been changed during the fetch// The result is meaningless.+ state.tab = "schema";+ const payload = task.payload as TaskDatabaseSchemaUpdateSDLPayload;+ const message =+ err.response?.data?.message ?? err.details ?? "Internal server error";++ finish({+ error: message,+ diffDDL: "",+ expectedSDL: payload?.statement,+ previousSDL: "",+ prettyExpectedSDL: "",+ });}},{ immediate: true }diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex a23add6d26..ce3b5d0246 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -661,7 +661,8 @@"sdl": {"schema-change": "Schema change","generated-ddl-statements": "Generated DDL statements",- "full-schema": "Full schema"+ "full-schema": "Full schema",+ "left-schema-may-change": "The schema on the left side may change before the issue is applied."}},"alter-schema": {diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex df4a10ffc7..6da85fe6ab 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -659,7 +659,8 @@"sdl": {"schema-change": "Schema 变化","generated-ddl-statements": "生成的 DDL 语句",- "full-schema": "完整 schema"+ "full-schema": "完整 schema",+ "left-schema-may-change": "左边的 schema 在工单执行前可能会发生变化。"}},"alter-schema": {diff --git a/frontend/src/main.ts b/frontend/src/main.tsindex 10ef370bd0..616812a7fa 100644--- a/frontend/src/main.ts+++ b/frontend/src/main.ts@@ -7,6 +7,7 @@ import NaiveUI from "./plugins/naive-ui";import dayjs from "./plugins/dayjs";import highlight from "./plugins/highlight";import mountDemoApp from "./plugins/demo";+import { isSilent } from "./plugins/silent-request";import { router } from "./router";import {pinia,@@ -89,7 +90,7 @@ axios.interceptors.response.use(}}- if (error.response.data.message) {+ if (error.response.data.message && !isSilent()) {pushNotification({module: "bytebase",style: "CRITICAL",@@ -100,7 +101,7 @@ axios.interceptors.response.use(: undefined,});}- } else if (error.code == "ECONNABORTED") {+ } else if (error.code == "ECONNABORTED" && !isSilent()) {pushNotification({module: "bytebase",style: "CRITICAL",diff --git a/frontend/src/plugins/silent-request.ts b/frontend/src/plugins/silent-request.tsnew file mode 100644index 0000000000..dc46abda7f--- /dev/null+++ b/frontend/src/plugins/silent-request.ts@@ -0,0 +1,16 @@+const state = {+ silent: false,+};++export const isSilent = () => {+ return state.silent;+};++// Requests wrapped in useSilentRequest won't be intercepted by our global+// error handling (pushNotifications)+export const useSilentRequest = async <T>(fn: () => Promise<T>): Promise<T> => {+ state.silent = true;+ const result = await fn();+ state.silent = false;+ return result;+};