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): support SQL review checks in new issue CI/CD UI (#7592)
Liu Ji0ae48c6c1899
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBar.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBar.vueindex f39edb38ba..c6cadd2e56 100644--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBar.vue+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckBar.vue@@ -24,6 +24,7 @@:selected-type="selectedType":plan-check-run-list="planCheckRunList":task="task"+ @select-type="selectedType = $event"@close="selectedType = undefined"/></div>diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vueindex aae57a2e72..7496915e36 100644--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckDetail.vue@@ -40,30 +40,74 @@{{ row.title }}</div><div class="bb-grid-cell">- <span>{{ row.checkResult.content }}</span>- <template v-if="row.checkResult.sqlReviewReport?.detail">- <span+ <div>+ <span>{{ row.checkResult.content }}</span>+ <template v-if="row.checkResult.sqlReviewReport?.detail">+ <span+ class="ml-1 normal-link"+ @click="+ state.activeResultDefinition =+ row.checkResult.sqlReviewReport.detail+ "+ >{{ $t("sql-review.view-definition") }}</span+ >+ <span class="border-r border-control-border ml-1"></span>+ </template>+ <template+ v-if="row.checkResult.sqlReviewReport && getActiveRule(row.checkResult.title as RuleType)"+ >+ <span+ class="ml-1 normal-link"+ @click="setActiveRule(row.checkResult.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"- @click="selectDetail(row.checkResult.sqlReviewReport)"- >{{ $t("sql-review.view-definition") }}</span+ :href="row.link.url"+ :target="row.link.target">- <span class="border-r border-control-border ml-1"></span>- </template>- TODO: details+ {{ row.link.title }}+ </a>+ </div></div></template></BBGrid>++ <SQLRuleEditDialog+ v-if="state.activeRule"+ :editable="false"+ :rule="state.activeRule.rule"+ :payload="state.activeRule.payload"+ :disabled="false"+ @cancel="state.activeRule = undefined"+ />++ <PlanCheckResultDefinitionModal+ v-if="state.activeResultDefinition"+ :definition="state.activeResultDefinition"+ @cancel="state.activeResultDefinition = undefined"+ /></template><script setup lang="ts">-import { computed } from "vue";+import { computed, reactive } from "vue";import { useI18n } from "vue-i18n";import { BBGridColumn, BBGridRow, BBGrid } from "@/bbkit";import { LocalizedSQLRuleErrorCodes } from "@/components/Issue/const";+import { databaseForTask, useIssueContext } from "@/components/IssueV1/logic";+import { SQLRuleEditDialog } from "@/components/SQLReview/components";+import { PayloadValueType } from "@/components/SQLReview/components/RuleConfigComponents";+import { useReviewPolicyByEnvironmentId } from "@/store";import {GeneralErrorCode,+ RuleTemplate,RuleType,SQLReviewPolicyErrorCode,+ findRuleTemplate,getRuleLocalization,ruleTemplateMap,} from "@/types";@@ -74,6 +118,7 @@ import {PlanCheckRun_Status,Task,} from "@/types/proto/v1/rollout_service";+import PlanCheckResultDefinitionModal from "./PlanCheckResultDefinitionModal.vue";interface ErrorCodeLink {title: string;@@ -81,10 +126,10 @@ interface ErrorCodeLink {url: string;}-// type PreviewSQLReviewRule = {-// rule: RuleTemplate;-// payload: PayloadValueType[];-// };+type PreviewSQLReviewRule = {+ rule: RuleTemplate;+ payload: PayloadValueType[];+};type TableRow = {checkResult: PlanCheckRun_Result;@@ -93,12 +138,22 @@ type TableRow = {link: ErrorCodeLink | undefined;};+type LocalState = {+ activeRule?: PreviewSQLReviewRule;+ activeResultDefinition?: string;+};+const props = defineProps<{planCheckRun: PlanCheckRun;task: Task;}>();const { t } = useI18n();+const state = reactive<LocalState>({+ activeRule: undefined,+ activeResultDefinition: undefined,+});+const { issue } = useIssueContext();const statusIconClass = (status: PlanCheckRun_Result_Status) => {switch (status) {@@ -115,37 +170,15 @@ const checkResultList = computed((): PlanCheckRun_Result[] => {if (props.planCheckRun.status === PlanCheckRun_Status.DONE) {return props.planCheckRun.results;} else if (props.planCheckRun.status === PlanCheckRun_Status.FAILED) {- // return [- // {- // status: "ERROR",- // title: t("common.error"),- // code: props.planCheckRun.code,- // content: props.planCheckRun.result.detail,- // namespace: "bb.core",- // line: undefined,- // column: undefined,- // },- // ];return [- PlanCheckRun_Result.fromJSON({+ PlanCheckRun_Result.fromPartial({status: PlanCheckRun_Result_Status.ERROR,title: t("common.error"),}),];} else if (props.planCheckRun.status === PlanCheckRun_Status.CANCELED) {- // return [- // {- // status: "WARN",- // title: t("common.canceled"),- // code: props.planCheckRun.code,- // content: "",- // namespace: "bb.core",- // line: undefined,- // column: undefined,- // },- // ];return [- PlanCheckRun_Result.fromJSON({+ PlanCheckRun_Result.fromPartial({status: PlanCheckRun_Result_Status.WARNING,title: t("common.canceled"),}),@@ -158,20 +191,21 @@ const checkResultList = computed((): PlanCheckRun_Result[] => {const categoryAndTitle = (checkResult: PlanCheckRun_Result): [string, string] => {- if (checkResult.code === SQLReviewPolicyErrorCode.EMPTY_POLICY) {- const title = messageWithCode(checkResult.title, checkResult.code);+ const code = checkResult.sqlReviewReport?.code ?? checkResult.code;+ if (code === SQLReviewPolicyErrorCode.EMPTY_POLICY) {+ const title = messageWithCode(checkResult.title, code);return ["", title];}- if (LocalizedSQLRuleErrorCodes.has(checkResult.code)) {+ if (LocalizedSQLRuleErrorCodes.has(code)) {const rule = ruleTemplateMap.get(checkResult.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, checkResult.code);+ const title = messageWithCode(ruleLocalization.title, code);return [category, title];} else {- return ["", messageWithCode(checkResult.title, checkResult.code)];+ return ["", messageWithCode(checkResult.title, code)];}}@@ -185,7 +219,8 @@ const messageWithCode = (message: string, code: number) => {const errorCodeLink = (checkResult: PlanCheckRun_Result): ErrorCodeLink | undefined => {- switch (checkResult.code) {+ const code = checkResult.sqlReviewReport?.code ?? checkResult.code;+ switch (code) {case undefined:return;case GeneralErrorCode.OK:@@ -197,10 +232,12 @@ const errorCodeLink = (url: "/setting/sql-review",};default: {- // const url = `https://www.bytebase.com/docs/reference/error-code/${- // checkResult.namespace === "bb.advisor" ? "advisor" : "core"- // }?source=console#${checkResult.code}`;- const url = "#TODO";+ const errorCodeNamespace =+ checkResult.sqlReviewReport !== undefined ? "advisor" : "core";+ 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",@@ -238,11 +275,11 @@ const COLUMN_LIST = computed(() => {};const TITLE: BBGridColumn = {title: "Title",- width: "12rem",+ width: "minmax(12rem, 1fr)",};const CONTENT: BBGridColumn = {title: "Detail",- width: "1fr",+ width: "2fr",};if (showCategoryColumn.value) {return [STATUS, CATEGORY, TITLE, CONTENT];@@ -250,7 +287,38 @@ const COLUMN_LIST = computed(() => {return [STATUS, TITLE, CONTENT];});-const selectDetail = (args: any) => {- // TODO+const reviewPolicy = useReviewPolicyByEnvironmentId(+ computed(() => {+ const database = databaseForTask(issue.value, props.task);+ return database.effectiveEnvironmentEntity.uid;+ })+);+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/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vueindex eaf55b54c4..20ea9ea7e5 100644--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckPanel.vue@@ -10,6 +10,7 @@:plan-check-run-list="planCheckRunList":selected-type="selectedType":task="task"+ @select-type="$emit('select-type', $event)"/><TabFilterv-if="selectedPlanCheckRunUID"@@ -47,6 +48,7 @@ const props = defineProps<{}>();defineEmits<{+ (event: "select-type", type: PlanCheckRun_Type): void;(event: "close"): void;}>();diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckResultDefinitionModal.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckResultDefinitionModal.vuenew file mode 100644index 0000000000..12c79a14dc--- /dev/null+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckBar/PlanCheckResultDefinitionModal.vue@@ -0,0 +1,33 @@+<template>+ <BBModal :title="$t('sql-review.view-definition')" @close="emit('cancel')">+ <div class="space-y-4 w-[calc(100vw-5rem)] sm:w-[40rem] pb-1">+ <div class="space-y-1">+ <div class="flex flex-col gap-x-2 whitespace-pre-wrap">+ {{ definition }}+ </div>+ </div>+ <div class="mt-4 pt-2 border-t flex justify-end">+ <button+ type="button"+ class="btn-normal py-2 px-4"+ @click.prevent="emit('cancel')"+ >+ {{ $t("common.cancel") }}+ </button>+ </div>+ </div>+ </BBModal>+</template>++<script lang="ts" setup>+defineProps({+ definition: {+ required: true,+ type: String,+ },+});++const emit = defineEmits<{+ (event: "cancel"): void;+}>();+</script>diff --git a/frontend/src/components/IssueV1/components/StatementSection/useSQLAdviceMarkers.ts b/frontend/src/components/IssueV1/components/StatementSection/useSQLAdviceMarkers.tsindex 3aa37b8ca4..85167917fd 100644--- a/frontend/src/components/IssueV1/components/StatementSection/useSQLAdviceMarkers.ts+++ b/frontend/src/components/IssueV1/components/StatementSection/useSQLAdviceMarkers.ts@@ -6,7 +6,7 @@ import {PlanCheckRun_Result_Status,PlanCheckRun_Type,} from "@/types/proto/v1/rollout_service";-import { useIssueContext } from "../../logic";+import { planCheckRunListForTask, useIssueContext } from "../../logic";export const useSQLAdviceMarkers = () => {const { isCreating, issue, selectedTask } = useIssueContext();@@ -14,14 +14,10 @@ export const useSQLAdviceMarkers = () => {if (isCreating.value) return [];const task = selectedTask.value;- const planCheckRunList = issue.value.planCheckRunList.filter((checkRun) => {- task; // TODO: match task and plan- return true;- });+ const planCheckRunList = planCheckRunListForTask(issue.value, task);const types: PlanCheckRun_Type[] = [PlanCheckRun_Type.DATABASE_STATEMENT_ADVISE,- PlanCheckRun_Type.DATABASE_STATEMENT_SYNTAX,];return types.flatMap((type) => {return getLatestAdviceOptions(@@ -46,21 +42,22 @@ const getLatestAdviceOptions = (planCheckRunList: PlanCheckRun[]) => {result.status === PlanCheckRun_Result_Status.ERROR ||result.status === PlanCheckRun_Result_Status.WARNING)- .filter((result) => result.line !== undefined)+ .filter((result) => result.sqlReviewReport?.line !== undefined).map<AdviceOption>((result) => {+ const line = result.sqlReviewReport!.line;+ const column = result.sqlReviewReport?.column ?? Number.MAX_SAFE_INTEGER;+ const code = result.sqlReviewReport?.code ?? result.code;return {severity:result.status === PlanCheckRun_Result_Status.ERROR? "ERROR": "WARNING",message: result.content,- source: `${result.title} (${result.code})`,- startLineNumber: result.line!,- // We don't know the actual column yet, so we show the marker at then end of the line- startColumn: Number.MAX_SAFE_INTEGER,- endLineNumber: result.line!,- // We don't know the actual column yet, so we show the marker at then end of the line- endColumn: Number.MAX_SAFE_INTEGER,+ source: `${result.title} (${code}) L${line}:C${column}`,+ startLineNumber: line,+ endLineNumber: line,+ startColumn: column,+ endColumn: column,};});};