Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: show risk level and affected rows of release check result (#15237)

boojackce1f3698ae59
diff --git a/frontend/src/components/SQLCheck/SQLCheckButton.vue b/frontend/src/components/SQLCheck/SQLCheckButton.vue
index e09d15ea8c..b7a7d7a041 100644
--- a/frontend/src/components/SQLCheck/SQLCheckButton.vue
+++ b/frontend/src/components/SQLCheck/SQLCheckButton.vue
@@ -58,6 +58,8 @@
v-if="filteredAdvices && showDetailPanel"
:database="database"
:advices="filteredAdvices"
+ :affected-rows="checkResult.affectedRows"
+ :risk-level="checkResult.riskLevel"
:confirm="confirmDialog"
:override-title="$t('issue.sql-check.sql-review-violations')"
:show-code-location="showCodeLocation"
@@ -86,6 +88,7 @@ import { useReviewPolicyForDatabase } from "@/store";
import type { ComposedDatabase } from "@/types";
import type { DatabaseMetadata } from "@/types/proto/v1/database_service";
import {
+ CheckReleaseResponse,
Release_File_ChangeType,
ReleaseFileType,
} from "@/types/proto/v1/release_service";
@@ -134,16 +137,19 @@ const SKIP_CHECK_THRESHOLD = 2 * 1024 * 1024;
const isRunning = ref(false);
const showDetailPanel = ref(false);
const allowForceContinue = ref(true);
-const rawAdvices = ref<Advice[]>();
const context = useSQLCheckContext();
const confirmDialog = ref<Defer<boolean>>();
+const checkResult = ref<CheckReleaseResponse>(
+ CheckReleaseResponse.fromPartial({})
+);
const filteredAdvices = computed(() => {
const { adviceFilter } = props;
+ const advices = checkResult.value.results.flatMap((r) => r.advices);
if (!adviceFilter) {
- return rawAdvices.value;
+ return advices;
}
- return rawAdvices.value?.filter(adviceFilter);
+ return advices?.filter(adviceFilter);
});
const reviewPolicy = useReviewPolicyForDatabase(
@@ -216,21 +222,24 @@ const runChecks = async () => {
}
const handleErrors = (errors: string[]) => {
- // Mock the pre-check errors to advices
- rawAdvices.value = errors.map((err) =>
- Advice.fromPartial({
- title: "Pre check",
- status: Advice_Status.WARNING,
- content: err,
- })
- );
+ // Mock the pre-check errors to advices.
+ checkResult.value = CheckReleaseResponse.fromPartial({
+ results: [
+ {
+ advices: errors.map((err) =>
+ Advice.fromPartial({
+ title: "Pre check",
+ status: Advice_Status.WARNING,
+ content: err,
+ })
+ ),
+ },
+ ],
+ });
isRunning.value = false;
};
isRunning.value = true;
- if (!rawAdvices.value) {
- rawAdvices.value = [];
- }
const { statement, errors } = await props.getStatement();
allowForceContinue.value = errors.length === 0;
if (new Blob([statement]).size > SKIP_CHECK_THRESHOLD) {
@@ -240,8 +249,7 @@ const runChecks = async () => {
return handleErrors(errors);
}
try {
- const checkResult = await runCheckInternal(statement);
- rawAdvices.value = checkResult.results.flatMap((r) => r.advices);
+ checkResult.value = await runCheckInternal(statement);
} finally {
isRunning.value = false;
}
diff --git a/frontend/src/components/SQLCheck/SQLCheckPanel.vue b/frontend/src/components/SQLCheck/SQLCheckPanel.vue
index acd7465c79..023075b3ce 100644
--- a/frontend/src/components/SQLCheck/SQLCheckPanel.vue
+++ b/frontend/src/components/SQLCheck/SQLCheckPanel.vue
@@ -6,6 +6,24 @@
container-class="!pt-0 -mt-px"
@close="onClose"
>
+ <div class="w-full flex flex-row gap-2">
+ <NTag round v-if="riskLevelText">
+ <span class="text-gray-400 text-sm mr-1">{{
+ $t("issue.risk-level.self")
+ }}</span>
+ <span class="text-sm font-medium">
+ {{ riskLevelText }}
+ </span>
+ </NTag>
+ <NTag round v-if="riskLevelText || (affectedRows && affectedRows > 0)">
+ <span class="text-gray-400 text-sm mr-1">{{
+ $t("task.check-type.affected-rows.self")
+ }}</span>
+ <span class="text-sm font-medium">
+ {{ affectedRows }}
+ </span>
+ </NTag>
+ </div>
<PlanCheckRunDetail
:plan-check-run="planCheckRun"
:database="database"
@@ -35,8 +53,9 @@
</template>
<script setup lang="ts">
-import { NButton } from "naive-ui";
+import { NButton, NTag } from "naive-ui";
import { computed, watchEffect, ref } from "vue";
+import { useI18n } from "vue-i18n";
import { BBModal } from "@/bbkit";
import PlanCheckRunDetail from "@/components/PlanCheckRun/PlanCheckRunDetail.vue";
import { usePolicyV1Store } from "@/store";
@@ -49,6 +68,7 @@ import {
PlanCheckRun_Result_SqlReviewReport,
PlanCheckRun_Status,
} from "@/types/proto/v1/plan_service";
+import { CheckReleaseResponse_RiskLevel } from "@/types/proto/v1/release_service";
import type { Advice } from "@/types/proto/v1/sql_service";
import { Advice_Status } from "@/types/proto/v1/sql_service";
import type { Defer } from "@/utils";
@@ -57,6 +77,8 @@ const props = withDefaults(
defineProps<{
database: ComposedDatabase;
advices: Advice[];
+ affectedRows?: number;
+ riskLevel?: CheckReleaseResponse_RiskLevel;
overrideTitle?: string;
confirm?: Defer<boolean>;
showCodeLocation?: boolean;
@@ -74,6 +96,7 @@ const emit = defineEmits<{
(event: "close"): void;
}>();
+const { t } = useI18n();
const restrictIssueCreationForSqlReviewPolicy = ref(false);
const policyV1Store = usePolicyV1Store();
@@ -85,6 +108,18 @@ const restrictIssueCreationForSQLReview = computed((): boolean => {
);
});
+const riskLevelText = computed(() => {
+ const { riskLevel } = props;
+ if (riskLevel === CheckReleaseResponse_RiskLevel.LOW) {
+ return t("issue.risk-level.low");
+ } else if (riskLevel === CheckReleaseResponse_RiskLevel.MODERATE) {
+ return t("issue.risk-level.moderate");
+ } else if (riskLevel === CheckReleaseResponse_RiskLevel.HIGH) {
+ return t("issue.risk-level.high");
+ }
+ return "";
+});
+
watchEffect(async () => {
const workspaceLevelPolicy =
await policyV1Store.getOrFetchPolicyByParentAndType({
diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.ts
index c11a5183b2..69fe3d339c 100644
--- a/frontend/src/utils/util.ts
+++ b/frontend/src/utils/util.ts
@@ -167,19 +167,6 @@ export function getIntCookie(name: string): number | undefined {
return undefined;
}
-export function getStringCookie(name: string): string {
- const list = document.cookie.split(";");
- for (let i = 0; i < list.length; i++) {
- const parts = list[i].split("=");
- if (parts[0].trim() == name) {
- // For now, just assumes strings are enclosed by quotes
- return parts.length > 1 ? parts[1].slice(1, -1) : "";
- }
- }
-
- return "";
-}
-
export function getHighlightHTMLByKeyWords(s: string, k: string) {
if (!k) return s;
return s.replaceAll(k, `<b class="text-accent">${k}</b>`);