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: unify ChecksView component with prop-driven architecture (#17408)
boojackfd8a3050a796
diff --git a/frontend/src/components/Plan/components/ChecksView/ChecksDrawer.vue b/frontend/src/components/Plan/components/ChecksView/ChecksDrawer.vueindex 11ccd381ed..efb7b5c4ba 100644--- a/frontend/src/components/Plan/components/ChecksView/ChecksDrawer.vue+++ b/frontend/src/components/Plan/components/ChecksView/ChecksDrawer.vue@@ -4,19 +4,39 @@:title="$t('plan.navigator.checks')"class="w-[40rem] max-w-[100vw] relative">- <div class="-mx-6">- <ChecksView class="!py-0" :defaultStatus="status" />- </div>+ <ChecksView+ :default-status="status"+ :plan-check-runs="planCheckRuns"+ :is-loading="isLoading"+ /></DrawerContent></Drawer></template><script setup lang="ts">+import { ref } from "vue";import { Drawer, DrawerContent } from "@/components/v2";import type { PlanCheckRun_Result_Status } from "@/types/proto-es/v1/plan_service_pb";+import { usePlanContext } from "../../logic";+import { useResourcePoller } from "../../logic/poller";import ChecksView from "./ChecksView.vue";defineProps<{status: PlanCheckRun_Result_Status;}>();++const { planCheckRuns } = usePlanContext();+const { refreshResources } = useResourcePoller();++const isLoading = ref(true);++// Load plan check runs on component mount+const loadCheckRuns = async () => {+ isLoading.value = true;+ await refreshResources(["planCheckRuns"], true);+ isLoading.value = false;+};++// Load once when component mounts+loadCheckRuns();</script>diff --git a/frontend/src/components/Plan/components/ChecksView/ChecksView.vue b/frontend/src/components/Plan/components/ChecksView/ChecksView.vueindex afbb7a1c27..ce7ac0c201 100644--- a/frontend/src/components/Plan/components/ChecksView/ChecksView.vue+++ b/frontend/src/components/Plan/components/ChecksView/ChecksView.vue@@ -1,17 +1,40 @@<template>- <div class="flex-1 flex flex-col pt-2 pb-4">- <!-- Header with filters -->- <div class="flex items-center justify-between px-4">+ <div class="flex-1 flex flex-col">+ <!-- Header with status counts -->+ <div class="flex items-center justify-between"><div class="flex items-center gap-4">- <PlanCheckStatusCount- :plan="plan"- :show-label="true"- :clickable="true"- :selected-status="selectedStatus"- size="normal"- class="text-lg"- @click="toggleSelectedStatus($event)"- />+ <div class="flex items-center gap-3" v-if="hasAnyStatus">+ <div+ v-if="statusSummary.error > 0"+ class="flex items-center gap-1 text-error cursor-pointer"+ :class="getItemClass(PlanCheckRun_Result_Status.ERROR)"+ @click="toggleSelectedStatus(PlanCheckRun_Result_Status.ERROR)"+ >+ <XCircleIcon class="w-5 h-5" />+ <span>{{ $t("common.error") }}</span>+ <span>{{ statusSummary.error }}</span>+ </div>+ <div+ v-if="statusSummary.warning > 0"+ class="flex items-center gap-1 text-warning cursor-pointer"+ :class="getItemClass(PlanCheckRun_Result_Status.WARNING)"+ @click="toggleSelectedStatus(PlanCheckRun_Result_Status.WARNING)"+ >+ <AlertCircleIcon class="w-5 h-5" />+ <span>{{ $t("common.warning") }}</span>+ <span>{{ statusSummary.warning }}</span>+ </div>+ <div+ v-if="statusSummary.success > 0"+ class="flex items-center gap-1 text-success cursor-pointer"+ :class="getItemClass(PlanCheckRun_Result_Status.SUCCESS)"+ @click="toggleSelectedStatus(PlanCheckRun_Result_Status.SUCCESS)"+ >+ <CheckCircleIcon class="w-5 h-5" />+ <span>{{ $t("common.success") }}</span>+ <span>{{ statusSummary.success }}</span>+ </div>+ </div></div></div>@@ -40,7 +63,7 @@<divv-for="checkRun in filteredCheckRuns":key="checkRun.name"- class="px-6 py-4"+ class="px-2 py-4"><!-- Check Run Header --><div class="flex items-start justify-between mb-2">@@ -110,9 +133,11 @@ import {ShieldIcon,SearchCodeIcon,CircleQuestionMarkIcon,+ XCircleIcon,+ AlertCircleIcon,} from "lucide-vue-next";import { NTooltip } from "naive-ui";-import { computed, ref, watch } from "vue";+import { computed, ref } from "vue";import { useI18n } from "vue-i18n";import { BBSpin } from "@/bbkit";import {@@ -121,21 +146,16 @@ import {type PlanCheckRun,} from "@/types/proto-es/v1/plan_service_pb";import { humanizeTs } from "@/utils";-import { usePlanContext } from "../../logic";-import { useResourcePoller } from "../../logic/poller";-import PlanCheckStatusCount from "../PlanCheckStatusCount.vue";import CheckResultItem from "../common/CheckResultItem.vue";import DatabaseDisplay from "../common/DatabaseDisplay.vue";const props = defineProps<{defaultStatus?: PlanCheckRun_Result_Status;+ planCheckRuns: PlanCheckRun[];+ isLoading?: boolean;}>();const { t } = useI18n();-const { plan, planCheckRuns } = usePlanContext();-const { refreshResources } = useResourcePoller();--const isLoading = ref(true);const selectedStatus = ref<PlanCheckRun_Result_Status | undefined>(props.defaultStatus@@ -145,8 +165,56 @@ const hasFilters = computed(() => {return selectedStatus.value !== undefined;});+// Calculate status summary from plan check runs+const statusSummary = computed(() => {+ const summary = { error: 0, warning: 0, success: 0 };++ for (const checkRun of props.planCheckRuns) {+ for (const result of checkRun.results) {+ if (result.status === PlanCheckRun_Result_Status.ERROR) {+ summary.error++;+ } else if (result.status === PlanCheckRun_Result_Status.WARNING) {+ summary.warning++;+ } else if (result.status === PlanCheckRun_Result_Status.SUCCESS) {+ summary.success++;+ }+ }+ }++ return summary;+});++const hasAnyStatus = computed(() => {+ return (+ statusSummary.value.error > 0 ||+ statusSummary.value.warning > 0 ||+ statusSummary.value.success > 0+ );+});++const toggleSelectedStatus = (status: PlanCheckRun_Result_Status) => {+ if (selectedStatus.value === status) {+ selectedStatus.value = undefined; // Deselect if already selected+ } else {+ selectedStatus.value = status; // Select the new status+ }+};++const getItemClass = (status: PlanCheckRun_Result_Status) => {+ const classes: string[] = [];++ if (selectedStatus.value === status) {+ classes.push("bg-gray-100 rounded-lg px-2 py-1");+ } else {+ // Add some padding to align with selected items+ classes.push("px-2 py-1");+ }++ return classes;+};+const filteredCheckRuns = computed(() => {- return planCheckRuns.value.filter((checkRun) => {+ return props.planCheckRuns.filter((checkRun) => {// Filter by status - check if any result matches the selected statusif (selectedStatus.value !== undefined) {const hasMatchingResult = checkRun.results.some(@@ -160,24 +228,6 @@ const filteredCheckRuns = computed(() => {});});-watch(- () => props.defaultStatus,- async () => {- isLoading.value = true;- await refreshResources(["planCheckRuns"], true /** force */);- isLoading.value = false;- },- { immediate: true }-);--const toggleSelectedStatus = (status: PlanCheckRun_Result_Status) => {- if (selectedStatus.value === status) {- selectedStatus.value = undefined; // Deselect if already selected- } else {- selectedStatus.value = status; // Select the new status- }-};-const getFilteredResults = (checkRun: PlanCheckRun) => {return checkRun.results.filter((result) => {return (diff --git a/frontend/src/components/Plan/components/SQLCheckV1Section/SQLCheckV1Section.vue b/frontend/src/components/Plan/components/SQLCheckV1Section/SQLCheckV1Section.vueindex 5ca16cc95b..39553790fa 100644--- a/frontend/src/components/Plan/components/SQLCheckV1Section/SQLCheckV1Section.vue+++ b/frontend/src/components/Plan/components/SQLCheckV1Section/SQLCheckV1Section.vue@@ -65,74 +65,17 @@</div></div>- <!-- Status Drawer -->+ <!-- Checks Drawer --><Drawer v-model:show="drawerVisible"><DrawerContent:title="$t('plan.navigator.checks')"class="w-[40rem] max-w-[100vw] relative">- <div class="w-full h-full flex flex-col">- <!-- Status Tabs Header -->- <div class="flex items-center gap-3">- <div- 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'"- >- <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>-- <!-- 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>+ <ChecksView+ :default-status="getDefaultStatus()"+ :plan-check-runs="formattedCheckRuns"+ :is-loading="isRunningChecks"+ /></DrawerContent></Drawer></div>@@ -153,7 +96,16 @@ 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 { Plan_ChangeDatabaseConfig_Type } from "@/types/proto-es/v1/plan_service_pb";+import {+ Plan_ChangeDatabaseConfig_Type,+ PlanCheckRun_Type,+ PlanCheckRun_Status,+ PlanCheckRun_Result_Status,+ type PlanCheckRun,+ type PlanCheckRun_Result,+ PlanCheckRunSchema,+ PlanCheckRun_ResultSchema,+} from "@/types/proto-es/v1/plan_service_pb";import {CheckReleaseRequestSchema,Release_File_Type,@@ -170,8 +122,8 @@ import {} from "@/utils";import { usePlanContext } from "../../logic/context";import { targetsForSpec } from "../../logic/plan";+import ChecksView from "../ChecksView/ChecksView.vue";import { useSelectedSpec } from "../SpecDetailView/context";-import CheckResultItem from "../common/CheckResultItem.vue";const { plan } = usePlanContext();const selectedSpec = useSelectedSpec();@@ -239,18 +191,6 @@ const summary = computed(() => {return result;});-const drawerAdvices = computed(() => {- return allAdvices.value.filter((advice) => {- if (selectedStatus.value === "ERROR") {- return advice.status === Advice_Status.ERROR;- } else if (selectedStatus.value === "WARNING") {- return advice.status === Advice_Status.WARNING;- } else {- return advice.status === Advice_Status.SUCCESS;- }- });-});-const runChecks = async () => {if (!plan.value.name || !selectedSpec.value) return;@@ -308,6 +248,20 @@ const openDrawer = (status: "ERROR" | "WARNING" | "SUCCESS") => {drawerVisible.value = true;};+// Convert string status to PlanCheckRun_Result_Status+const getDefaultStatus = (): PlanCheckRun_Result_Status | undefined => {+ switch (selectedStatus.value) {+ case "ERROR":+ return PlanCheckRun_Result_Status.ERROR;+ case "WARNING":+ return PlanCheckRun_Result_Status.WARNING;+ case "SUCCESS":+ return PlanCheckRun_Result_Status.SUCCESS;+ default:+ return undefined;+ }+};+watch(() => selectedSpec.value.id,() => {@@ -320,18 +274,48 @@ watch(});-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";- }+// Transform CheckReleaseResponse_CheckResult[] to PlanCheckRun[] format+const transformToFormattedCheckRuns = (+ results: CheckReleaseResponse_CheckResult[]+): PlanCheckRun[] => {+ return results.map((result, index) => {+ const planCheckRunResults: PlanCheckRun_Result[] = result.advices.map(+ (advice) => {+ return create(PlanCheckRun_ResultSchema, {+ status:+ advice.status === Advice_Status.ERROR+ ? PlanCheckRun_Result_Status.ERROR+ : advice.status === Advice_Status.WARNING+ ? PlanCheckRun_Result_Status.WARNING+ : PlanCheckRun_Result_Status.SUCCESS,+ title: advice.title,+ content: advice.content,+ code: advice.code,+ report: {+ case: "sqlReviewReport",+ value: {+ startPosition: advice.startPosition,+ line: advice.startPosition ? advice.startPosition.line : 0,+ },+ },+ });+ }+ );++ return create(PlanCheckRunSchema, {+ name: `check-run-${index}`,+ type: PlanCheckRun_Type.DATABASE_STATEMENT_ADVISE,+ status: PlanCheckRun_Status.DONE,+ target: result.target,+ results: planCheckRunResults,+ createTime: { seconds: BigInt(Math.floor(Date.now() / 1000)), nanos: 0 },+ });+ });};++// Format check runs for ChecksView component+const formattedCheckRuns = computed(() => {+ if (!checkResults.value) return [];+ return transformToFormattedCheckRuns(checkResults.value);+});</script>diff --git a/frontend/src/components/Plan/components/common/CheckResultItem.vue b/frontend/src/components/Plan/components/common/CheckResultItem.vueindex 6fb3407025..2fb5597a5a 100644--- a/frontend/src/components/Plan/components/common/CheckResultItem.vue+++ b/frontend/src/components/Plan/components/common/CheckResultItem.vue@@ -96,26 +96,29 @@ const messageWithCode = (message: string, code: number | undefined): string => {};const displayTitle = computed(() => {- let title = props.title;-// Skip localization for certain titles- if (title === "OK" || title === "Syntax error") {- return messageWithCode(title, props.code);+ if (props.title === "OK" || props.title === "Syntax error") {+ return messageWithCode(props.title, props.code);}// Only apply SQL review localization if this is a SQL review reportif (props.reportType === "sqlReviewReport") {- // Try to get rule template and localization+ const code = props.code;+ if (!code) {+ return props.title;+ }+const rule = getRuleTemplateByType(props.title);if (rule) {const ruleLocalization = getRuleLocalization(rule.type, rule.engine);- if (ruleLocalization.title) {- title = ruleLocalization.title;- }+ const title = messageWithCode(ruleLocalization.title, code);+ return title;+ } else if (props.title.startsWith("builtin.")) {+ return messageWithCode(getRuleLocalization(props.title).title, code);}}// Add error code if present- return messageWithCode(title, props.code);+ return messageWithCode(props.title, props.code);});</script>diff --git a/frontend/src/views/project/PlanCheckRunsView.vue b/frontend/src/views/project/PlanCheckRunsView.vuedeleted file mode 100644index 2f2483a5b1..0000000000--- a/frontend/src/views/project/PlanCheckRunsView.vue+++ /dev/null@@ -1,7 +0,0 @@-<template>- <ChecksView />-</template>--<script lang="ts" setup>-import { ChecksView } from "@/components/Plan/components";-</script>