Skip to content

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

feat(frontend): display the number of sql review rules (#4307)

Liu Ji3bf7e0be8929
diff --git a/frontend/src/components/SQLReview/SQLReviewPreview.vue b/frontend/src/components/SQLReview/SQLReviewPreview.vue
index 2b4a128362..a0c8d66e58 100644
--- a/frontend/src/components/SQLReview/SQLReviewPreview.vue
+++ b/frontend/src/components/SQLReview/SQLReviewPreview.vue
@@ -13,6 +13,7 @@
:text="environmentName(selectedEnvironment)"
:can-remove="false"
/>
+ <SQLRuleLevelSummary :rule-list="selectedRuleList" />
</div>
<BBAttention
v-else-if="isPreviewStep"
@@ -119,6 +120,7 @@ import {
SchemaRuleEngineType,
} from "@/types";
import { environmentName } from "@/utils";
+import SQLRuleLevelSummary from "./components/SQLRuleLevelSummary.vue";
const props = withDefaults(
defineProps<{
diff --git a/frontend/src/components/SQLReview/components/SQLReviewSidebar.vue b/frontend/src/components/SQLReview/components/SQLReviewSidebar.vue
index 0f784ab5d3..568c8ecce2 100644
--- a/frontend/src/components/SQLReview/components/SQLReviewSidebar.vue
+++ b/frontend/src/components/SQLReview/components/SQLReviewSidebar.vue
@@ -2,11 +2,19 @@
<aside class="hidden lg:block">
<div class="space-y-6">
<h1 class="text-left text-2xl font-semibold">
- {{ $t("sql-review.rules") }}
+ <span>{{ $t("sql-review.rules") }}</span>
+ <span class="ml-1 font-normal text-control-light">
+ ({{ selectedRuleList.length }})
+ </span>
</h1>
<fieldset v-for="(category, index) in categoryList" :key="index">
<div class="block text-sm font-medium text-gray-900">
- {{ $t(`sql-review.category.${category.id.toLowerCase()}`) }}
+ <span>
+ {{ $t(`sql-review.category.${category.id.toLowerCase()}`) }}
+ </span>
+ <span class="ml-0.5 font-normal text-control-light">
+ ({{ category.ruleList.length }})
+ </span>
</div>
<div
v-for="(rule, ruleIndex) in category.ruleList"
diff --git a/frontend/src/components/SQLReview/components/SQLRuleLevelBadge.vue b/frontend/src/components/SQLReview/components/SQLRuleLevelBadge.vue
index 39c38b2492..1ad87483d9 100644
--- a/frontend/src/components/SQLReview/components/SQLRuleLevelBadge.vue
+++ b/frontend/src/components/SQLReview/components/SQLRuleLevelBadge.vue
@@ -1,13 +1,11 @@
<template>
- <BBBadge
- :text="$t(`sql-review.level.${level.toLowerCase()}`)"
- :can-remove="false"
- :style="style"
- />
+ <BBBadge :text="text" :can-remove="false" :style="style" />
</template>
<script lang="ts" setup>
import { PropType, computed } from "vue";
+import { useI18n } from "vue-i18n";
+
import { RuleLevel } from "@/types/sqlReview";
import { BBBadgeStyle } from "@/bbkit/BBBadge.vue";
@@ -16,8 +14,14 @@ const props = defineProps({
required: true,
type: String as PropType<RuleLevel>,
},
+ suffix: {
+ type: String,
+ default: "",
+ },
});
+const { t } = useI18n();
+
const style = computed((): BBBadgeStyle => {
switch (props.level) {
case RuleLevel.ERROR:
@@ -28,4 +32,13 @@ const style = computed((): BBBadgeStyle => {
return "DISABLED";
}
});
+
+const text = computed(() => {
+ const { level, suffix } = props;
+ const parts = [t(`sql-review.level.${level.toLowerCase()}`)];
+ if (suffix) {
+ parts.push(suffix);
+ }
+ return parts.join(" ");
+});
</script>
diff --git a/frontend/src/components/SQLReview/components/SQLRuleLevelSummary.vue b/frontend/src/components/SQLReview/components/SQLRuleLevelSummary.vue
new file mode 100644
index 0000000000..10fc431f5c
--- /dev/null
+++ b/frontend/src/components/SQLReview/components/SQLRuleLevelSummary.vue
@@ -0,0 +1,39 @@
+<template>
+ <div v-if="summary.length > 0" class="inline-flex gap-x-1">
+ <SQLRuleLevelBadge
+ v-for="item in summary"
+ :key="item.level"
+ :level="item.level"
+ :suffix="`(${item.count})`"
+ />
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { groupBy } from "lodash-es";
+import { computed } from "vue";
+
+import { RuleLevel, RuleTemplate } from "@/types";
+import SQLRuleLevelBadge from "./SQLRuleLevelBadge.vue";
+
+const props = withDefaults(
+ defineProps<{
+ ruleList?: RuleTemplate[];
+ }>(),
+ {
+ ruleList: () => [],
+ }
+);
+
+const summary = computed(() => {
+ const groups = groupBy(props.ruleList, (rule) => rule.level);
+
+ return Object.keys(groups).map((level) => {
+ const group = groups[level];
+ return {
+ level: level as RuleLevel,
+ count: group.length,
+ };
+ });
+});
+</script>
diff --git a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
index 3443164168..b858c4777c 100644
--- a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
+++ b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
@@ -63,6 +63,7 @@
>
{{ environmentName(reviewPolicy.environment) }}
</router-link>
+ <SQLRuleLevelSummary :rule-list="filteredSelectedRuleList" />
</div>
<BBAttention
v-else
@@ -138,7 +139,7 @@
<BBTableSearch
ref="searchField"
:placeholder="$t('sql-review.search-rule-name')"
- @change-text="(text) => (state.searchText = text)"
+ @change-text="(text: string) => (state.searchText = text)"
/>
</div>
<SQLReviewPreview
@@ -212,6 +213,7 @@ import {
useSQLReviewStore,
} from "@/store";
import { CategoryFilterItem } from "../components/SQLReview/components/SQLReviewCategoryTabFilter.vue";
+import SQLRuleLevelSummary from "../components/SQLReview/components/SQLRuleLevelSummary.vue";
const props = defineProps({
sqlReviewPolicySlug: {