Skip to content

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

chore: fix code position display (#16948)

boojack6050b3ead2e6
diff --git a/frontend/src/components/Plan/components/ChecksView/ChecksView.vue b/frontend/src/components/Plan/components/ChecksView/ChecksView.vue
index 3e1a117563..ae594c7fa7 100644
--- a/frontend/src/components/Plan/components/ChecksView/ChecksView.vue
+++ b/frontend/src/components/Plan/components/ChecksView/ChecksView.vue
@@ -1,7 +1,7 @@
<template>
<div class="flex-1 flex flex-col pt-2 pb-4">
<!-- Header with filters -->
- <div class="flex items-center justify-between px-4 py-2">
+ <div class="flex items-center justify-between px-4">
<div class="flex items-center gap-4">
<!-- Check result summary with icons -->
<div class="flex items-center gap-3">
@@ -117,50 +117,26 @@
<!-- Results for this check run -->
<div class="space-y-2 pl-8">
- <div
+ <CheckResultItem
v-for="(result, idx) in getFilteredResults(checkRun)"
:key="idx"
- class="flex items-start gap-3 px-3 py-2 border rounded-lg bg-gray-50"
- >
- <component
- :is="getStatusIcon(result.status)"
- class="w-5 h-5 flex-shrink-0"
- :class="getStatusColor(result.status)"
- />
-
- <div class="flex-1 min-w-0 space-y-1">
- <div class="text-sm font-medium text-main">
- {{ getResultTitle(result) }}
- </div>
- <div v-if="result.content" class="text-sm text-control">
- {{ result.content }}
- </div>
- <div
- v-if="
- result.report.case === 'sqlReviewReport' &&
- result.report.value.line > 0
- "
- class="text-sm mt-1"
- >
- Line {{ result.report.value.line }}, Column
- {{ result.report.value.column }}
- </div>
- <div
- v-else-if="result.report.case === 'sqlSummaryReport'"
- class="text-sm mt-1 flex items-center gap-1"
- >
- <NTag size="small" round>
- {{ $t("task.check-type.affected-rows.self") }}
- </NTag>
- <span>{{ result.report.value.affectedRows }}</span>
- <span class="text-control opacity-80"
- >({{
- $t("task.check-type.affected-rows.description")
- }})</span
- >
- </div>
- </div>
- </div>
+ :status="getCheckResultStatus(result.status)"
+ :title="result.title"
+ :content="result.content"
+ :code="result.code"
+ :report-type="result.report?.case"
+ :position="
+ result.report?.case === 'sqlReviewReport' &&
+ result.report.value.startPosition
+ ? result.report.value.startPosition
+ : undefined
+ "
+ :affected-rows="
+ result.report?.case === 'sqlSummaryReport'
+ ? result.report.value.affectedRows
+ : undefined
+ "
+ />
</div>
</div>
</div>
@@ -179,20 +155,18 @@ import {
ShieldIcon,
SearchCodeIcon,
} from "lucide-vue-next";
-import { NTag } from "naive-ui";
import { computed, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import { BBSpin } from "@/bbkit";
-import { getRuleLocalization } from "@/types";
import {
PlanCheckRun_Result_Status,
PlanCheckRun_Type,
type PlanCheckRun,
- type PlanCheckRun_Result,
} from "@/types/proto-es/v1/plan_service_pb";
import { humanizeTs } from "@/utils";
import { usePlanContext } from "../../logic/context";
import { useResourcePoller } from "../../logic/poller";
+import CheckResultItem from "../common/CheckResultItem.vue";
import DatabaseDisplay from "../common/DatabaseDisplay.vue";
const props = defineProps<{
@@ -291,32 +265,6 @@ const getCheckTypeLabel = (type: PlanCheckRun_Type) => {
}
};
-const getStatusIcon = (status: PlanCheckRun_Result_Status) => {
- switch (status) {
- case PlanCheckRun_Result_Status.ERROR:
- return XCircleIcon;
- case PlanCheckRun_Result_Status.WARNING:
- return AlertCircleIcon;
- case PlanCheckRun_Result_Status.SUCCESS:
- return CheckCircleIcon;
- default:
- return CheckCircleIcon;
- }
-};
-
-const getStatusColor = (status: PlanCheckRun_Result_Status) => {
- switch (status) {
- case PlanCheckRun_Result_Status.ERROR:
- return "text-error";
- case PlanCheckRun_Result_Status.WARNING:
- return "text-warning";
- case PlanCheckRun_Result_Status.SUCCESS:
- return "text-success";
- default:
- return "text-control";
- }
-};
-
const formatTime = (timestamp: Timestamp | undefined): string => {
if (!timestamp) return "";
return humanizeTs(
@@ -324,27 +272,18 @@ const formatTime = (timestamp: Timestamp | undefined): string => {
);
};
-const messageWithCode = (message: string, code: number | undefined): string => {
- if (code !== undefined && code !== 0) {
- return `${message} #${code}`;
- }
- return message;
-};
-
-const getResultTitle = (result: PlanCheckRun_Result): string => {
- let title = result.title;
- if (title === "OK" || title === "Syntax error") {
- return title;
- }
- // Only apply SQL review localization if this is a SQL review report
- if (result.report?.case === "sqlReviewReport") {
- // Convert dots to hyphens in the rule key to match the expected format
- const normalizedKey = title.replace(/\./g, "-");
- // Use getRuleLocalization to get the title
- const localization = getRuleLocalization(normalizedKey);
- title = localization.title;
+const getCheckResultStatus = (
+ status: PlanCheckRun_Result_Status
+): "SUCCESS" | "WARNING" | "ERROR" => {
+ switch (status) {
+ case PlanCheckRun_Result_Status.ERROR:
+ return "ERROR";
+ case PlanCheckRun_Result_Status.WARNING:
+ return "WARNING";
+ case PlanCheckRun_Result_Status.SUCCESS:
+ return "SUCCESS";
+ default:
+ return "SUCCESS";
}
- // Add error code if present
- return messageWithCode(title, result.code);
};
</script>
diff --git a/frontend/src/components/Plan/components/SQLCheckV1Section/SQLCheckV1Section.vue b/frontend/src/components/Plan/components/SQLCheckV1Section/SQLCheckV1Section.vue
index dbba788db7..0631149035 100644
--- a/frontend/src/components/Plan/components/SQLCheckV1Section/SQLCheckV1Section.vue
+++ b/frontend/src/components/Plan/components/SQLCheckV1Section/SQLCheckV1Section.vue
@@ -72,44 +72,65 @@
class="w-[40rem] max-w-[100vw] relative"
>
<div class="w-full h-full flex flex-col">
- <!-- Drawer Content -->
- <div v-if="drawerAdvices.length > 0" class="w-full space-y-2">
+ <!-- Status Tabs Header -->
+ <div class="flex items-center gap-3">
<div
- v-for="(advice, idx) in drawerAdvices"
- :key="idx"
- class="space-y-1 p-3 border rounded-lg bg-gray-50"
+ v-if="summary.error > 0"
+ class="flex items-center gap-1 px-2 py-1 cursor-pointer"
+ :class="[
+ selectedStatus === 'ERROR' && 'bg-gray-100 rounded-lg',
+ 'text-lg text-error',
+ ]"
+ @click="selectedStatus = 'ERROR'"
>
- <div class="flex items-start justify-between">
- <div class="text-sm font-medium text-main">
- {{ getAdviceTitle(advice) }}
- </div>
- <component
- :is="getStatusIcon(advice.status)"
- class="w-4 h-4 flex-shrink-0"
- :class="getStatusColor(advice.status)"
- />
- </div>
-
- <!-- Target Database -->
- <DatabaseDisplay :database="advice.target" />
-
- <!-- Advice Content -->
- <div v-if="advice.content" class="text-xs text-control-light">
- {{ advice.content }}
- </div>
-
- <!-- Location Info -->
- <div
- v-if="advice.startPosition && advice.startPosition.line > 0"
- class="text-xs text-control-lighter"
- >
- Line {{ advice.startPosition.line }}, Column
- {{ advice.startPosition.column }}
- </div>
+ <XCircleIcon class="w-6 h-6" />
+ <span>{{ $t("common.error") }}</span>
+ <span class="font-semibold">{{ summary.error }}</span>
+ </div>
+ <div
+ v-if="summary.warning > 0"
+ class="flex items-center gap-1 px-2 py-1 cursor-pointer"
+ :class="[
+ selectedStatus === 'WARNING' && 'bg-gray-100 rounded-lg',
+ 'text-lg text-warning',
+ ]"
+ @click="selectedStatus = 'WARNING'"
+ >
+ <AlertCircleIcon class="w-6 h-6" />
+ <span>{{ $t("common.warning") }}</span>
+ <span class="font-semibold">{{ summary.warning }}</span>
+ </div>
+ <div
+ v-if="summary.success > 0"
+ class="flex items-center gap-1 px-2 py-1 cursor-pointer"
+ :class="[
+ selectedStatus === 'SUCCESS' && 'bg-gray-100 rounded-lg',
+ 'text-lg text-success',
+ ]"
+ @click="selectedStatus = 'SUCCESS'"
+ >
+ <CheckCircleIcon class="w-6 h-6" />
+ <span>{{ $t("common.success") }}</span>
+ <span class="font-semibold">{{ summary.success }}</span>
</div>
</div>
- <div v-else class="w-full text-center py-8 text-control-light">
- No check results
+
+ <!-- Drawer Content -->
+ <div class="flex-1 overflow-y-auto py-4">
+ <div v-if="drawerAdvices.length > 0" class="space-y-2">
+ <CheckResultItem
+ v-for="(advice, idx) in drawerAdvices"
+ :key="idx"
+ :status="getCheckResultStatus(advice.status)"
+ :title="advice.title"
+ :content="advice.content"
+ :position="advice.startPosition"
+ :report-type="'sqlReviewReport'"
+ />
+ </div>
+ <div v-else class="text-center py-8 text-control-light">
+ {{ $t("common.no-data") }}
+ </div>
</div>
</div>
</DrawerContent>
@@ -132,7 +153,6 @@ import Drawer from "@/components/v2/Container/Drawer.vue";
import DrawerContent from "@/components/v2/Container/DrawerContent.vue";
import { releaseServiceClientConnect } from "@/grpcweb";
import { projectNamePrefix } from "@/store";
-import { getRuleLocalization, ruleTemplateMapV2 } from "@/types";
import { Plan_ChangeDatabaseConfig_Type } from "@/types/proto-es/v1/plan_service_pb";
import {
CheckReleaseRequestSchema,
@@ -151,7 +171,7 @@ import {
import { usePlanContext } from "../../logic/context";
import { targetsForSpec } from "../../logic/plan";
import { useSelectedSpec } from "../SpecDetailView/context";
-import DatabaseDisplay from "../common/DatabaseDisplay.vue";
+import CheckResultItem from "../common/CheckResultItem.vue";
const { plan } = usePlanContext();
const selectedSpec = useSelectedSpec();
@@ -288,20 +308,6 @@ const openDrawer = (status: "ERROR" | "WARNING" | "SUCCESS") => {
drawerVisible.value = true;
};
-const getStatusIcon = (status: Advice_Status | string) => {
- if (status === Advice_Status.ERROR || status === "ERROR") return XCircleIcon;
- if (status === Advice_Status.WARNING || status === "WARNING")
- return AlertCircleIcon;
- return CheckCircleIcon;
-};
-
-const getStatusColor = (status: Advice_Status | string) => {
- if (status === Advice_Status.ERROR || status === "ERROR") return "text-error";
- if (status === Advice_Status.WARNING || status === "WARNING")
- return "text-warning";
- return "text-success";
-};
-
watch(
() => selectedSpec.value.id,
() => {
@@ -314,24 +320,18 @@ watch(
}
);
-const getAdviceTitle = (advice: Advice): string => {
- let title = advice.title;
- const rule = getRuleTemplateByType(advice.title);
- if (rule) {
- const ruleLocalization = getRuleLocalization(rule.type, rule.engine);
- if (ruleLocalization.title) {
- title = ruleLocalization.title;
- }
- }
- return title;
-};
-
-const getRuleTemplateByType = (type: string) => {
- for (const mapByType of ruleTemplateMapV2.values()) {
- if (mapByType.has(type)) {
- return mapByType.get(type);
- }
+const getCheckResultStatus = (
+ status: Advice_Status
+): "SUCCESS" | "WARNING" | "ERROR" => {
+ switch (status) {
+ case Advice_Status.ERROR:
+ return "ERROR";
+ case Advice_Status.WARNING:
+ return "WARNING";
+ case Advice_Status.SUCCESS:
+ return "SUCCESS";
+ default:
+ return "SUCCESS";
}
- return;
};
</script>
diff --git a/frontend/src/components/Plan/components/StatementSection/useSQLAdviceMarkers.ts b/frontend/src/components/Plan/components/StatementSection/useSQLAdviceMarkers.ts
index 757c395b47..8f6c8f90bf 100644
--- a/frontend/src/components/Plan/components/StatementSection/useSQLAdviceMarkers.ts
+++ b/frontend/src/components/Plan/components/StatementSection/useSQLAdviceMarkers.ts
@@ -64,16 +64,17 @@ const getLatestAdviceOptions = (planCheckRuns: PlanCheckRun[]) => {
)
.filter(
(result) =>
- result.report?.case === "sqlReviewReport" &&
- result.report.value.line !== undefined
+ result.report.case === "sqlReviewReport" &&
+ result.report.value.startPosition
)
.map<AdviceOption>((result) => {
const sqlReviewReport =
- result.report?.case === "sqlReviewReport"
+ result.report.case === "sqlReviewReport"
? result.report.value
: undefined;
- const line = sqlReviewReport!.line;
- const column = sqlReviewReport?.column ?? Number.MAX_SAFE_INTEGER;
+ const line = sqlReviewReport?.startPosition?.line ?? 0;
+ const column =
+ sqlReviewReport?.startPosition?.column ?? Number.MAX_SAFE_INTEGER;
const code = result.code;
return {
severity:
diff --git a/frontend/src/components/Plan/components/common/CheckResultItem.vue b/frontend/src/components/Plan/components/common/CheckResultItem.vue
new file mode 100644
index 0000000000..891d642e11
--- /dev/null
+++ b/frontend/src/components/Plan/components/common/CheckResultItem.vue
@@ -0,0 +1,129 @@
+<template>
+ <div class="flex items-start gap-3 px-3 py-2 border rounded-lg bg-gray-50">
+ <component
+ :is="statusIcon"
+ class="w-5 h-5 flex-shrink-0"
+ :class="statusColor"
+ />
+
+ <div class="flex-1 min-w-0 space-y-1">
+ <div class="text-sm font-medium text-main">
+ {{ displayTitle }}
+ </div>
+ <div v-if="content" class="text-sm text-control">
+ {{ content }}
+ </div>
+ <div v-if="position" class="text-sm mt-1 text-control-light">
+ Line {{ position.line + 1 }}, Column {{ position.column + 1 }}
+ </div>
+ <div
+ v-if="affectedRows !== undefined"
+ class="text-sm mt-1 flex items-center gap-1"
+ >
+ <NTag size="small" round>
+ {{ $t("task.check-type.affected-rows.self") }}
+ </NTag>
+ <span>{{ affectedRows }}</span>
+ <span class="text-control opacity-80"
+ >({{ $t("task.check-type.affected-rows.description") }})</span
+ >
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { CheckCircleIcon, AlertCircleIcon, XCircleIcon } from "lucide-vue-next";
+import { NTag } from "naive-ui";
+import { computed } from "vue";
+import { getRuleLocalization, ruleTemplateMapV2 } from "@/types";
+
+export interface CheckResultPosition {
+ line: number;
+ column: number;
+}
+
+const props = defineProps<{
+ status: "SUCCESS" | "WARNING" | "ERROR";
+ title: string;
+ content?: string;
+ position?: CheckResultPosition;
+ affectedRows?: number;
+ code?: number;
+ reportType?: "sqlReviewReport" | "sqlSummaryReport" | string;
+}>();
+
+const statusIcon = computed(() => {
+ switch (props.status) {
+ case "ERROR":
+ return XCircleIcon;
+ case "WARNING":
+ return AlertCircleIcon;
+ case "SUCCESS":
+ return CheckCircleIcon;
+ default:
+ return CheckCircleIcon;
+ }
+});
+
+const statusColor = computed(() => {
+ switch (props.status) {
+ case "ERROR":
+ return "text-error";
+ case "WARNING":
+ return "text-warning";
+ case "SUCCESS":
+ return "text-success";
+ default:
+ return "text-control";
+ }
+});
+
+const getRuleTemplateByType = (type: string) => {
+ for (const mapByType of ruleTemplateMapV2.values()) {
+ if (mapByType.has(type)) {
+ return mapByType.get(type);
+ }
+ }
+ return;
+};
+
+const messageWithCode = (message: string, code: number | undefined): string => {
+ if (code !== undefined && code !== 0) {
+ return `${message} #${code}`;
+ }
+ return message;
+};
+
+const displayTitle = computed(() => {
+ let title = props.title;
+
+ // Skip localization for certain titles
+ if (title === "OK" || title === "Syntax error") {
+ return messageWithCode(title, props.code);
+ }
+
+ // Only apply SQL review localization if this is a SQL review report
+ if (props.reportType === "sqlReviewReport") {
+ // Convert dots to hyphens in the rule key to match the expected format
+ const normalizedKey = title.replace(/\./g, "-");
+ // Try to get rule template and localization
+ const rule = getRuleTemplateByType(props.title);
+ if (rule) {
+ const ruleLocalization = getRuleLocalization(rule.type, rule.engine);
+ if (ruleLocalization.title) {
+ title = ruleLocalization.title;
+ }
+ } else {
+ // Fallback to direct localization lookup
+ const localization = getRuleLocalization(normalizedKey);
+ if (localization.title) {
+ title = localization.title;
+ }
+ }
+ }
+
+ // Add error code if present
+ return messageWithCode(title, props.code);
+});
+</script>