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: sql review result panel (#10738)
ecmadaoe345a3c3a353
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vueindex 3f2b8c4f4c..6a7aae4618 100644--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue@@ -93,9 +93,10 @@<script setup lang="ts">import { computed, reactive } from "vue";import { useI18n } from "vue-i18n";-import { databaseForTask, useIssueContext } from "@/components/IssueV1/logic";+import { useRouter } from "vue-router";import { SQLRuleEditDialog } from "@/components/SQLReview/components";import { PayloadValueType } from "@/components/SQLReview/components/RuleConfigComponents";+import { SETTING_ROUTE_WORKSPACE_SQL_REVIEW } from "@/router/dashboard/workspaceSetting";import { useReviewPolicyByEnvironmentName } from "@/store";import {GeneralErrorCode,@@ -112,9 +113,7 @@ import {PlanCheckRun_Result,PlanCheckRun_Result_Status,PlanCheckRun_Status,- Task,} from "@/types/proto/v1/rollout_service";-import { extractEnvironmentResourceName } from "@/utils";import PlanCheckResultDefinitionModal from "./PlanCheckResultDefinitionModal.vue";interface ErrorCodeLink {@@ -142,15 +141,15 @@ type LocalState = {const props = defineProps<{planCheckRun: PlanCheckRun;- task?: Task;+ environment?: string;}>();const { t } = useI18n();+const router = useRouter();const state = reactive<LocalState>({activeRule: undefined,activeResultDefinition: undefined,});-const { issue } = useIssueContext();const statusIconClass = (status: PlanCheckRun_Result_Status) => {switch (status) {@@ -235,8 +234,10 @@ const errorCodeLink = (case SQLReviewPolicyErrorCode.EMPTY_POLICY:return {title: t("sql-review.configure-policy"),- target: "_self",- url: "/setting/sql-review",+ target: "__blank",+ url: router.resolve({+ name: SETTING_ROUTE_WORKSPACE_SQL_REVIEW,+ }).fullPath,};default: {const errorCodeNamespace =@@ -273,14 +274,7 @@ const showCategoryColumn = computed((): boolean =>const reviewPolicy = useReviewPolicyByEnvironmentName(computed(() => {- const task = props.task;- if (!task) {- return String(UNKNOWN_ID);- }- const database = databaseForTask(issue.value, task);- return extractEnvironmentResourceName(- database.effectiveEnvironmentEntity.name- );+ return props.environment || String(UNKNOWN_ID);}));const getActiveRule = (type: RuleType): PreviewSQLReviewRule | undefined => {diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vueindex b3d78e717b..ff8a0d252f 100644--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue@@ -24,7 +24,7 @@<PlanCheckDetailv-if="selectedPlanCheckRun":plan-check-run="selectedPlanCheckRun"- :task="task"+ :environment="environment"/></div></BBModal>@@ -34,13 +34,14 @@import { first, orderBy } from "lodash-es";import { computed, ref, watch } from "vue";import { useI18n } from "vue-i18n";+import { databaseForTask, useIssueContext } from "@/components/IssueV1/logic";import { TabFilter, TabFilterItem } from "@/components/v2";import {PlanCheckRun,PlanCheckRun_Type,Task,} from "@/types/proto/v1/rollout_service";-import { humanizeDate } from "@/utils";+import { humanizeDate, extractEnvironmentResourceName } from "@/utils";import PlanCheckBadgeBar from "./PlanCheckBadgeBar.vue";import PlanCheckDetail from "./PlanCheckDetail.vue";@@ -56,6 +57,7 @@ defineEmits<{}>();const { t } = useI18n();+const { issue } = useIssueContext();const selectedPlanCheckRunList = computed(() => {return orderBy(@@ -97,4 +99,15 @@ const tabItemList = computed(() => {watch(selectedPlanCheckRunList, (list) => {selectedPlanCheckRunUID.value = first(list)?.uid;});++const environment = computed(() => {+ const task = props.task;+ if (!task) {+ return;+ }+ const database = databaseForTask(issue.value, task);+ return extractEnvironmentResourceName(+ database.effectiveEnvironmentEntity.name+ );+});</script>diff --git a/frontend/src/components/SQLCheck/SQLCheckButton.vue b/frontend/src/components/SQLCheck/SQLCheckButton.vueindex 07488fc176..44c03ca04a 100644--- a/frontend/src/components/SQLCheck/SQLCheckButton.vue+++ b/frontend/src/components/SQLCheck/SQLCheckButton.vue@@ -35,7 +35,7 @@<template #link><router-linkv-if="hasManageSQLReviewPolicyPermission"- :to="`/setting/sql-review`"+ :to="{ name: SETTING_ROUTE_WORKSPACE_SQL_REVIEW }"class="ml-1 normal-link underline">{{ $t("common.go-to-configure") }}@@ -64,6 +64,7 @@ import { computed, onUnmounted, ref } from "vue";import { onMounted } from "vue";import { useI18n } from "vue-i18n";import { sqlServiceClient } from "@/grpcweb";+import { SETTING_ROUTE_WORKSPACE_SQL_REVIEW } from "@/router/dashboard/workspaceSetting";import { useCurrentUserV1, usePolicyByParentAndType } from "@/store";import { ComposedDatabase } from "@/types";import { DatabaseMetadata } from "@/types/proto/v1/database_service";diff --git a/frontend/src/components/SQLCheck/SQLCheckDetail.vue b/frontend/src/components/SQLCheck/SQLCheckDetail.vuedeleted file mode 100644index 5a33fb8d26..0000000000--- a/frontend/src/components/SQLCheck/SQLCheckDetail.vue+++ /dev/null@@ -1,244 +0,0 @@-<template>- <div class="space-y-5 divide-y pb-5 px-2">- <div- v-for="(row, i) in tableRows"- :key="i"- class="pt-5 first:pt-2 space-y-2"- >- <div class="flex items-center space-x-3">- <div- class="relative w-5 h-5 flex flex-shrink-0 items-center justify-center rounded-full select-none"- :class="statusIconClass(row.advice.status)"- >- <template v-if="row.advice.status === Advice_Status.SUCCESS">- <heroicons-solid:check class="w-4 h-4" />- </template>- <template v-if="row.advice.status === Advice_Status.WARNING">- <heroicons-outline:exclamation class="h-4 w-4" />- </template>- <template v-else-if="row.advice.status === Advice_Status.ERROR">- <span class="text-white font-medium text-base" aria-hidden="true">- !- </span>- </template>- </div>- <div v-if="showCategoryColumn">- {{ row.category }}- </div>- <div class="font-semibold">{{ row.title }}</div>- </div>- <div class="textinfolabel">- <span>{{ row.content }}</span>- <template v-if="row.advice.detail">- <span- class="ml-1 normal-link"- @click="state.activeResultDefinition = row.advice.detail"- >{{ $t("sql-review.view-definition") }}</span- >- <span class="border-r border-control-border ml-1"></span>- </template>- <template v-if="getActiveRule(row.advice.title as RuleType)">- <span- class="ml-1 normal-link"- @click="setActiveRule(row.advice.title as RuleType)"- >{{ $t("sql-review.rule-detail") }}</span- >- <span class="border-r border-control-border ml-1"></span>- </template>-- <a- v-if="row.link"- class="ml-1 normal-link"- :href="row.link.url"- :target="row.link.target"- >- {{ row.link.title }}- </a>- </div>- </div>- </div>-- <SQLRuleEditDialog- v-if="state.activeRule"- :editable="false"- :rule="state.activeRule.rule"- :payload="state.activeRule.payload"- :disabled="true"- @cancel="state.activeRule = undefined"- />-- <PlanCheckResultDefinitionModal- v-if="state.activeResultDefinition"- :definition="state.activeResultDefinition"- @cancel="state.activeResultDefinition = undefined"- />-</template>--<script setup lang="ts">-import { computed, reactive } from "vue";-import { useI18n } from "vue-i18n";-import { SQLRuleEditDialog } from "@/components/SQLReview/components";-import { PayloadValueType } from "@/components/SQLReview/components/RuleConfigComponents";-import { useReviewPolicyByEnvironmentName } from "@/store";-import {- ComposedDatabase,- GeneralErrorCode,- RuleTemplate,- RuleType,- SQLReviewPolicyErrorCode,- findRuleTemplate,- getRuleLocalization,- ruleTemplateMap,-} from "@/types";-import { Advice, Advice_Status } from "@/types/proto/v1/sql_service";-import { extractEnvironmentResourceName } from "@/utils";--interface ErrorCodeLink {- title: string;- target: string;- url: string;-}--type PreviewSQLReviewRule = {- rule: RuleTemplate;- payload: PayloadValueType[];-};--type TableRow = {- advice: Advice;- category: string;- title: string;- content: string;- link: ErrorCodeLink | undefined;-};--type LocalState = {- activeRule?: PreviewSQLReviewRule;- activeResultDefinition?: string;-};--const props = defineProps<{- database: ComposedDatabase;- advices: Advice[];-}>();--const { t } = useI18n();-const state = reactive<LocalState>({- activeRule: undefined,- activeResultDefinition: undefined,-});--const statusIconClass = (status: Advice_Status) => {- switch (status) {- case Advice_Status.SUCCESS:- return "bg-success text-white";- case Advice_Status.WARNING:- return "bg-warning text-white";- case Advice_Status.ERROR:- return "bg-error text-white";- }-};--const categoryAndTitle = (advice: Advice): [string, string] => {- const code = advice.code;- if (!code) {- return ["", advice.title];- }- if (code === SQLReviewPolicyErrorCode.EMPTY_POLICY) {- const title = messageWithCode(advice.title, code);- return ["", title];- }- const rule = ruleTemplateMap.get(advice.title as RuleType);- if (rule) {- const ruleLocalization = getRuleLocalization(rule.type);- const key = `sql-review.category.${rule.category.toLowerCase()}`;- const category = t(key);- const title = messageWithCode(ruleLocalization.title, code);- return [category, title];- }- return ["", messageWithCode(advice.title, code)];-};--const messageWithCode = (message: string, code: number) => {- return `${message} #${code}`;-};--const errorCodeLink = (advice: Advice): ErrorCodeLink | undefined => {- const code = advice.code;- switch (code) {- case undefined:- return;- case GeneralErrorCode.OK:- return;- case SQLReviewPolicyErrorCode.EMPTY_POLICY:- return {- title: t("sql-review.configure-policy"),- target: "_self",- url: "/setting/sql-review",- };- default: {- const errorCodeNamespace = "advisor";- const domain = "https://www.bytebase.com";- const path = `/docs/reference/error-code/${errorCodeNamespace}/`;- const query = `source=console#${code}`;- const url = `${domain}${path}?${query}`;- return {- title: t("common.view-doc"),- target: "__blank",- url: url,- };- }- }-};--const tableRows = computed(() => {- return props.advices.map<TableRow>((advice) => {- const [category, title] = categoryAndTitle(advice);- const content = advice.content.trim();- const link = errorCodeLink(advice);- return {- advice,- category,- title,- content,- link,- };- });-});--const showCategoryColumn = computed((): boolean =>- tableRows.value.some((row) => row.category !== "")-);--const reviewPolicy = useReviewPolicyByEnvironmentName(- extractEnvironmentResourceName(props.database.effectiveEnvironmentEntity.name)-);-const getActiveRule = (type: RuleType): PreviewSQLReviewRule | undefined => {- const rule = reviewPolicy.value?.ruleList.find((rule) => rule.type === type);- if (!rule) {- return undefined;- }-- const ruleTemplate = findRuleTemplate(type);- if (!ruleTemplate) {- return undefined;- }- ruleTemplate.comment = rule.comment;- const { componentList } = ruleTemplate;- const payload = componentList.reduce<PayloadValueType[]>(- (list, component) => {- list.push(component.payload.value ?? component.payload.default);- return list;- },- []- );-- return {- rule: ruleTemplate,- payload: payload,- };-};-const setActiveRule = (type: RuleType) => {- state.activeRule = getActiveRule(type);-};-</script>diff --git a/frontend/src/components/SQLCheck/SQLCheckPanel.vue b/frontend/src/components/SQLCheck/SQLCheckPanel.vueindex 45716a7a94..a3425a42e8 100644--- a/frontend/src/components/SQLCheck/SQLCheckPanel.vue+++ b/frontend/src/components/SQLCheck/SQLCheckPanel.vue@@ -8,7 +8,10 @@container-class="!pt-0 -mt-px"@close="$emit('close')">- <SQLCheckDetail :database="database" :advices="advices" />+ <PlanCheckDetail+ :plan-check-run="planCheckRun"+ :environment="environment"+ /><divv-if="confirm"@@ -33,11 +36,17 @@ import { NButton } from "naive-ui";import { computed, onMounted } from "vue";import { usePolicyV1Store } from "@/store";import { ComposedDatabase } from "@/types";+import {+ PlanCheckRun,+ PlanCheckRun_Result,+ PlanCheckRun_Result_Status,+ PlanCheckRun_Result_SqlReviewReport,+ PlanCheckRun_Status,+} from "@/types/proto/v1/rollout_service";import { Advice, Advice_Status } from "@/types/proto/v1/sql_service";import { Defer } from "@/utils";-import SQLCheckDetail from "./SQLCheckDetail.vue";-const { advices } = defineProps<{+const { advices, database } = defineProps<{database: ComposedDatabase;advices: Advice[];overrideTitle?: string;@@ -70,4 +79,40 @@ const prepareOrgPolicy = async () => {"policies/RESTRICT_ISSUE_CREATION_FOR_SQL_REVIEW");};++const environment = computed(() => {+ return database.effectiveEnvironmentEntity.name;+});++const planCheckRun = computed((): PlanCheckRun => {+ return PlanCheckRun.fromPartial({+ status: PlanCheckRun_Status.DONE,+ results: advices.map((advice) => {+ let status = PlanCheckRun_Result_Status.STATUS_UNSPECIFIED;+ switch (advice.status) {+ case Advice_Status.SUCCESS:+ status = PlanCheckRun_Result_Status.SUCCESS;+ break;+ case Advice_Status.WARNING:+ status = PlanCheckRun_Result_Status.WARNING;+ break;+ case Advice_Status.ERROR:+ status = PlanCheckRun_Result_Status.ERROR;+ break;+ }+ return PlanCheckRun_Result.fromPartial({+ status,+ title: advice.title,+ code: advice.code,+ content: advice.content,+ sqlReviewReport: PlanCheckRun_Result_SqlReviewReport.fromPartial({+ line: advice.line,+ column: advice.column,+ detail: advice.detail,+ code: advice.code,+ }),+ });+ }),+ });+});</script>