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): several minor UI updates for sql review policy configuration (#4903)
Liu Ji1bfcf24d4504
diff --git a/frontend/src/bbkit/BBAlertDialog.vue b/frontend/src/bbkit/BBAlertDialog.vuenew file mode 100644index 0000000000..509ef8712f--- /dev/null+++ b/frontend/src/bbkit/BBAlertDialog.vue@@ -0,0 +1,205 @@+<template>+ <div v-if="state.visible" class="fixed z-10 inset-0 overflow-y-auto">+ <div+ class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0"+ >+ <!--+ Background overlay, show/hide based on modal state.++ Entering: "ease-out duration-300"+ From: "opacity-0"+ To: "opacity-100"+ Leaving: "ease-in duration-200"+ From: "opacity-100"+ To: "opacity-0"+ -->+ <div class="fixed inset-0 transition-opacity" aria-hidden="true">+ <div class="absolute inset-0 bg-gray-500 opacity-75"></div>+ </div>++ <!-- This element is to trick the browser into centering the modal contents. -->+ <span+ class="hidden sm:inline-block sm:align-middle sm:h-screen"+ aria-hidden="true"+ >​</span+ >+ <!--+ Modal panel, show/hide based on modal state.++ Entering: "ease-out duration-300"+ From: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"+ To: "opacity-100 translate-y-0 sm:scale-100"+ Leaving: "ease-in duration-200"+ From: "opacity-100 translate-y-0 sm:scale-100"+ To: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"+ -->+ <div+ class="inline-block align-bottom bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full sm:p-6"+ role="dialog"+ aria-modal="true"+ aria-labelledby="modal-headline"+ >+ <div class="sm:flex sm:flex-col sm:items-start">+ <div class="flex items-start">+ <div+ v-if="style == 'SUCCESS'"+ class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-green-100 sm:mx-0 sm:h-10 sm:w-10"+ >+ <!-- Heroicons name: outline/exclamation -->+ <heroicons-outline:exclamation class="h-6 w-6 text-success" />+ </div>+ <div+ v-else-if="style == 'WARN'"+ class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-yellow-100 sm:mx-0 sm:h-10 sm:w-10"+ >+ <!-- Heroicons name: outline/exclamation -->+ <heroicons-outline:exclamation class="h-6 w-6 text-yellow-600" />+ </div>+ <div+ v-else-if="style == 'CRITICAL'"+ class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10"+ >+ <!-- Heroicons name: outline/exclamation -->+ <heroicons-outline:exclamation class="h-6 w-6 text-red-600" />+ </div>+ <div+ v-else+ class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-blue-100 sm:mx-0 sm:h-10 sm:w-10"+ >+ <!-- Heroicons name: outline/exclamation -->+ <heroicons-outline:exclamation class="h-6 w-6 text-blue-600" />+ </div>+ <h3+ id="modal-headline"+ class="ml-4 flex self-center text-lg leading-6 font-medium text-gray-900"+ >+ {{ $t(title) }}+ </h3>+ </div>+ <div+ v-if="description"+ class="mt-3 text-center sm:mt-0 sm:ml-14 sm:text-left"+ >+ <div class="mt-2">+ <p class="text-gray-500 whitespace-pre-wrap">+ {{ $t(description) }}+ </p>+ </div>+ </div>+ </div>+ <div class="mt-5 flex flex-col space-y-4">+ <div class="flex justify-end">+ <button+ type="button"+ class="btn-normal mt-3 px-4 py-2 sm:mt-0 sm:w-auto"+ data-label="bb-alert-cancel-button"+ :disabled="inProgress"+ @click.prevent="onNegativeClick"+ >+ {{ $t(cancelText) }}+ </button>+ <button+ type="button"+ class="sm:ml-3 inline-flex justify-center w-full rounded-md border border-transparent shadow-sm px-4 py-2 bg-error text-base font-medium text-white focus:outline-none focus-visible:ring-2 focus:ring-offset-2 focus:ring-red-500 sm:w-auto sm:text-sm"+ data-label="bb-alert-ok-button"+ :class="okButtonStyle"+ :disabled="inProgress"+ @click.prevent="onPositiveClick()"+ >+ {{ $t(okText) }}+ </button>+ </div>+ <div v-if="inProgress" class="flex flex-row justify-end items-center">+ <BBSpin />{{ progressText }}+ </div>+ </div>+ </div>+ </div>+ </div>+</template>++<script lang="ts" setup>+import { useEventListener } from "@vueuse/core";+import { withDefaults, computed, reactive } from "vue";+import { BBAlertStyle } from "./types";+import { Defer, defer } from "@/utils";++const props = withDefaults(+ defineProps<{+ style?: BBAlertStyle;+ title: string;+ description?: string;+ okText?: string;+ cancelText?: string;+ inProgress?: boolean;+ progressText?: string;+ onBeforePositiveClick?: () => boolean;+ onBeforeNegativeClick?: () => boolean;+ }>(),+ {+ style: "INFO",+ description: "",+ okText: "bbkit.common.ok",+ cancelText: "bbkit.common.cancel",+ inProgress: false,+ progressText: "",+ onBeforeNegativeClick: undefined,+ onBeforePositiveClick: undefined,+ }+);++const state = reactive({+ visible: false,+ defer: undefined as Defer<boolean> | undefined,+});++const open = () => {+ if (state.defer) {+ state.defer.reject(new Error("duplicated call"));+ }++ state.defer = defer<boolean>();+ state.visible = true;++ return state.defer.promise;+};++const onPositiveClick = () => {+ if (props.onBeforePositiveClick) {+ if (!props.onBeforePositiveClick()) {+ return;+ }+ }++ state.visible = false;+ state.defer?.resolve(true);+};++const onNegativeClick = () => {+ if (props.onBeforeNegativeClick) {+ if (!props.onBeforeNegativeClick()) {+ return;+ }+ }++ state.visible = false;+ state.defer?.resolve(false);+};++defineExpose({ open });++useEventListener(document, "keydown", (e) => {+ if (!props.inProgress && e.code == "Escape") {+ onNegativeClick();+ }+});++const buttonStyleMap: Record<string, string> = {+ INFO: "btn-primary",+ SUCCESS: "btn-success",+ WARN: "btn-primary",+ CRITICAL: "btn-danger",+};++const okButtonStyle = computed(() => buttonStyleMap[props.style]);+</script>diff --git a/frontend/src/bbkit/BBBadge.vue b/frontend/src/bbkit/BBBadge.vueindex 08c047156d..7f6612b467 100644--- a/frontend/src/bbkit/BBBadge.vue+++ b/frontend/src/bbkit/BBBadge.vue@@ -1,5 +1,6 @@<template>- <span+ <component+ :is="link ? 'router-link' : 'span'":class="['inline-flex rounded-full items-center',`bg-${color}-100 text-${color}-800`,@@ -7,6 +8,7 @@size === 'normal' && 'py-0.5 px-2.5 text-sm font-medium',size === 'small' && 'px-[6px] py-[2px] text-xs font-normal',]"+ :to="link"><slot name="default">{{ text }}@@ -23,7 +25,7 @@><heroicons-outline:x class="h-3 w-3" /></button>- </span>+ </component></template><script lang="ts" setup>@@ -39,12 +41,14 @@ const props = withDefaults(canRemove?: boolean;style?: BBBadgeStyle;size?: BBBadgeSize;+ link?: string;}>(),{style: "INFO",text: "",canRemove: true,size: "normal",+ link: "",});diff --git a/frontend/src/bbkit/BBSwitch.vue b/frontend/src/bbkit/BBSwitch.vueindex c4c89848ca..a6ca9d8166 100644--- a/frontend/src/bbkit/BBSwitch.vue+++ b/frontend/src/bbkit/BBSwitch.vue@@ -31,7 +31,7 @@<spanv-if="text"aria-hidden="true"- class="pointer-events-none absolute right-0 top-0 flex items-center justify-center transition ease-in-out duration-200"+ class="pointer-events-none absolute right-0 top-0 flex items-center justify-center transition ease-in-out duration-200 overflow-hidden whitespace-nowrap":class="[`w-${sizes.base}`,`h-${sizes.base}`,@@ -95,7 +95,7 @@ const sizes = computed(() => {text: number; // unit px};const sizeMap: Record<BBSwitchSize, Sizes> = {- normal: { base: 5, cw: 11, ch: 6, text: 9 },+ normal: { base: 5, cw: 11, ch: 6, text: 10 },small: { base: 4, cw: 9, ch: 5, text: 7.5 },};return sizeMap[props.size] ?? sizeMap["normal"];diff --git a/frontend/src/bbkit/index.ts b/frontend/src/bbkit/index.tsindex c081e5ac75..27308e401f 100644--- a/frontend/src/bbkit/index.ts+++ b/frontend/src/bbkit/index.ts@@ -1,4 +1,5 @@import BBAlert from "./BBAlert.vue";+import BBAlertDialog from "./BBAlertDialog.vue";import BBAttention from "./BBAttention.vue";import BBAvatar from "./BBAvatar.vue";import BBTooltipButton from "./BBTooltipButton.vue";@@ -35,6 +36,7 @@ export * from "./types";export {BBAlert,+ BBAlertDialog,BBAttention,BBAvatar,BBTooltipButton,diff --git a/frontend/src/components/EnvironmentForm.vue b/frontend/src/components/EnvironmentForm.vueindex f8c70e0ac9..b10e64ab96 100644--- a/frontend/src/components/EnvironmentForm.vue+++ b/frontend/src/components/EnvironmentForm.vue@@ -204,7 +204,6 @@<BBSwitchv-if="allowEditSQLReviewPolicy"class="mr-2"- size="small":text="true":value="sqlReviewPolicy.rowStatus === 'NORMAL'"@toggle="toggleSQLReviewPolicy"diff --git a/frontend/src/components/SQLReview/SQLReviewCreation.vue b/frontend/src/components/SQLReview/SQLReviewCreation.vueindex 8232b547b5..aee1a5b355 100644--- a/frontend/src/components/SQLReview/SQLReviewCreation.vue+++ b/frontend/src/components/SQLReview/SQLReviewCreation.vue@@ -1,11 +1,10 @@<template><div><BBStepTab- class="":sticky="true":step-item-list="STEP_LIST":allow-next="allowNext"- :finish-title="$t(`common.confirm-and-${policyId ? 'update' : 'add'}`)"+ :finish-title="$t(`common.confirm-and-${policy ? 'update' : 'add'}`)"@try-change-step="tryChangeStep"@try-finish="tryFinishSetup"@cancel="onCancel"@@ -15,9 +14,10 @@:name="state.name":selected-environment="state.selectedEnvironment":available-environment-list="availableEnvironmentList"- :selected-template="state.selectedTemplate"- :is-edit="!!policyId"- class="py-5"+ :selected-template="+ state.pendingApplyTemplate || state.selectedTemplate+ "+ :is-edit="!!policy"@select-template="tryApplyTemplate"@name-change="(val: string) => (state.name = val)"@env-change="(env: Environment) => onEnvChange(env)"@@ -31,29 +31,21 @@/></template></BBStepTab>- <BBAlert- v-if="state.showAlertModal"- style="CRITICAL"+ <BBAlertDialog+ ref="alertDialog"+ :style="'CRITICAL'":ok-text="$t('common.confirm')":title="$t('sql-review.create.configure-rule.confirm-override-title')":description="$t('sql-review.create.configure-rule.confirm-override-description')"- @ok="- () => {- state.showAlertModal = false;- state.ruleUpdated = false;- onTemplateApply(state.pendingApplyTemplate);- }- "- @cancel="state.showAlertModal = false">- </BBAlert>+ </BBAlertDialog></div></template><script lang="ts" setup>-import { reactive, computed, withDefaults } from "vue";+import { reactive, computed, withDefaults, ref } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";import { BBStepTabItem } from "@/bbkit/types";@@ -66,8 +58,9 @@ import {ruleIsAvailableInSubscription,RuleConfigComponent,SQLReviewPolicyTemplate,+ SQLReviewPolicy,} from "@/types";-import { BBStepTab } from "@/bbkit";+import { BBAlertDialog, BBStepTab } from "@/bbkit";import SQLReviewInfo from "./SQLReviewInfo.vue";import SQLReviewConfig from "./SQLReviewConfig.vue";import {@@ -78,6 +71,7 @@ import {useSubscriptionStore,} from "@/store";import { hasWorkspacePermission } from "@/utils";+import { rulesToTemplate } from "./components";interface LocalState {currentStep: number;@@ -92,13 +86,13 @@ interface LocalState {const props = withDefaults(defineProps<{- policyId?: number;+ policy?: SQLReviewPolicy;name?: string;selectedEnvironment?: Environment;selectedRuleList?: RuleTemplate[];}>(),{- policyId: undefined,+ policy: undefined,name: "",selectedEnvironment: undefined,selectedRuleList: () => [],@@ -107,6 +101,7 @@ const props = withDefaults(const emit = defineEmits(["cancel"]);+const alertDialog = ref<InstanceType<typeof BBAlertDialog>>();const { t } = useI18n();const router = useRouter();const store = useSQLReviewStore();@@ -128,7 +123,9 @@ const state = reactive<LocalState>({name: props.name || t("sql-review.create.basic-info.display-name-default"),selectedEnvironment: props.selectedEnvironment,selectedRuleList: [...props.selectedRuleList],- selectedTemplate: undefined,+ selectedTemplate: props.policy+ ? rulesToTemplate(props.policy, false /* withDisabled=false */)+ : undefined,ruleUpdated: false,showAlertModal: false,pendingApplyTemplate: undefined,@@ -166,14 +163,14 @@ const availableEnvironmentList = computed((): Environment[] => {const filteredList = store.availableEnvironments(environmentList.value,- props.policyId+ props.policy?.id);return filteredList;});const onCancel = () => {- if (props.policyId) {+ if (props.policy) {emit("cancel");} else {router.push({@@ -203,6 +200,17 @@ const tryChangeStep = (newStep: number,allowChangeCallback: () => void) => {+ if (oldStep === 0 && newStep === 1) {+ if (state.pendingApplyTemplate) {+ alertDialog.value!.open().then((result) => {+ if (result) {+ onTemplateApply(state.pendingApplyTemplate);+ allowChangeCallback();+ }+ });+ return;+ }+ }state.currentStep = newStep;allowChangeCallback();};@@ -227,10 +235,10 @@ const tryFinishSetup = (allowChangeCallback: () => void) => {),};- if (props.policyId) {+ if (props.policy) {store.updateReviewPolicy({- id: props.policyId,+ id: props.policy.id,...upsert,}).then(() => {@@ -264,8 +272,11 @@ const onEnvChange = (env: Environment) => {};const tryApplyTemplate = (template: SQLReviewPolicyTemplate) => {- if (state.ruleUpdated || props.policyId) {- state.showAlertModal = true;+ if (state.ruleUpdated || props.policy) {+ if (template.id === state.selectedTemplate?.id) {+ state.pendingApplyTemplate = undefined;+ return;+ }state.pendingApplyTemplate = template;return;}diff --git a/frontend/src/components/SQLReview/SQLReviewInfo.vue b/frontend/src/components/SQLReview/SQLReviewInfo.vueindex 01cba00e8c..7233f98b72 100644--- a/frontend/src/components/SQLReview/SQLReviewInfo.vue+++ b/frontend/src/components/SQLReview/SQLReviewInfo.vue@@ -1,5 +1,28 @@<template><div class="space-y-6">+ <div v-if="selectedEnvironment">+ <label class="textlabel">+ {{ $t("sql-review.create.basic-info.environments") }}+ <span style="color: red">*</span>+ </label>+ <p class="mt-1 textinfolabel">+ {{ $t("sql-review.create.basic-info.environments-label") }}+ </p>+ <BBAttention+ v-if="availableEnvironmentList.length === 0"+ class="mt-2"+ :style="'WARN'"+ :title="$t('common.environment')"+ :description="+ $t('sql-review.create.basic-info.no-available-environment-desc')+ "+ />+ <BBTextField+ class="mt-2 w-full"+ :value="environmentName(selectedEnvironment)"+ :disabled="true"+ />+ </div><div><label class="textlabel">{{ $t("sql-review.create.basic-info.display-name") }}@@ -18,109 +41,23 @@/></div><div>- <label class="textlabel">- {{ $t("sql-review.create.basic-info.environments") }}- <span style="color: red">*</span>- </label>- <p class="mt-1 textinfolabel mb-5">- {{ $t("sql-review.create.basic-info.environments-label") }}- </p>- <BBAttention- v-if="availableEnvironmentList.length === 0"- :style="'WARN'"- :title="$t('common.environment')"- :description="- $t('sql-review.create.basic-info.no-available-environment-desc')- "- class="mb-5"+ <SQLReviewTemplateSelector+ :required="true"+ :selected-template="selectedTemplate"+ @select-template="$emit('select-template', $event)"+ @templates-change="onTemplatesChange($event)"/>- <div v-if="!isEdit" class="flex flex-wrap gap-x-3">- <div- v-for="env in environmentList"- :key="env.id"- class="flex items-center"- >- <input- :id="`${env.id}`"- type="radio"- :value="env.id"- :disabled="env.disabled"- :checked="env.id === selectedEnvironment?.id"- class="text-accent disabled:text-accent-disabled focus:ring-accent"- :class="env.disabled ? 'cursor-not-allowed' : 'cursor-pointer'"- @change="$emit('env-change', env)"- />- <label- :for="`${env.id}`"- class="ml-2 items-center text-sm"- :class="- env.disabled- ? 'cursor-not-allowed text-gray-400'- : 'cursor-pointer'- "- >- {{ env.displayName }}- </label>- </div>- </div>- <BBBadge- v-else-if="isEdit && selectedEnvironment"- :text="environmentName(selectedEnvironment)"- :can-remove="false"- />- </div>- <div>- <div v-if="isEdit" class="mt-5">- <div- class="flex cursor-pointer items-center text-indigo-500"- @click="state.openTemplate = !state.openTemplate"- >- <heroicons-solid:chevron-right- class="w-5 h-5 transform transition-all"- :class="state.openTemplate ? 'rotate-90' : ''"- />- <span class="ml-l text-sm font-medium">- {{ $t("sql-review.create.configure-rule.change-template") }}- </span>- </div>-- <template v-if="state.openTemplate">- <SQLReviewTemplateSelector- :required="false"- :selected-template="selectedTemplate"- @select-template="$emit('select-template', $event)"- />- </template>- </div>- <template v-else>- <SQLReviewTemplateSelector- :required="true"- :title="$t('sql-review.create.basic-info.choose-template')"- :selected-template="selectedTemplate"- @select-template="$emit('select-template', $event)"- />- </template></div></div></template><script lang="ts" setup>-import { PropType, reactive, computed } from "vue";-import { useEnvironmentList } from "@/store";+import { PropType } from "vue";import { Environment, SQLReviewPolicyTemplate } from "@/types";import { environmentName } from "@/utils";import { BBTextField } from "@/bbkit";import { SQLReviewTemplateSelector } from "./components";-interface LocalEnvironment extends Environment {- disabled: boolean;- displayName: string;-}--interface LocalState {- openTemplate: boolean;-}-const props = defineProps({name: {required: true,@@ -151,24 +88,16 @@ const emit = defineEmits<{(event: "select-template", template: SQLReviewPolicyTemplate): void;}>();-const state = reactive<LocalState>({- openTemplate: false,-});--const environmentList = computed((): LocalEnvironment[] => {- const environmentList = useEnvironmentList(["NORMAL"]);- const availableIdSet = new Set(- props.availableEnvironmentList.map((env) => env.id)- );-- return environmentList.value.map((env) => ({- ...env,- disabled: !availableIdSet.has(env.id),- displayName: environmentName(env),- }));-});-const onNameChange = (event: Event) => {emit("name-change", (event.target as HTMLInputElement).value);};++const onTemplatesChange = (templates: {+ policy: SQLReviewPolicyTemplate[];+ builtin: SQLReviewPolicyTemplate[];+}) => {+ if (!props.selectedTemplate) {+ emit("select-template", templates.policy[0] ?? templates.builtin[0]);+ }+};</script>diff --git a/frontend/src/components/SQLReview/SQLReviewPolicyTable.vue b/frontend/src/components/SQLReview/SQLReviewPolicyTable.vueindex 26a5fd24a4..ec6b48e4ac 100644--- a/frontend/src/components/SQLReview/SQLReviewPolicyTable.vue+++ b/frontend/src/components/SQLReview/SQLReviewPolicyTable.vue@@ -13,8 +13,10 @@}"><div class="bb-grid-cell">- {{ environment.name }}- <ProductionEnvironmentIcon :environment="environment" />+ <router-link :to="`/environment/${environment.id}`">+ {{ environment.name }}+ <ProductionEnvironmentIcon :environment="environment" />+ </router-link></div><div class="bb-grid-cell"><template v-if="review">@@ -49,7 +51,6 @@</button><BBButtonConfirm- v-if="review.rowStatus === 'ARCHIVED'"class="btn-normal flex justify-center !py-1 !px-3":disabled="!hasPermission":style="'DELETE'"diff --git a/frontend/src/components/SQLReview/components/RuleLevelSwitch.vue b/frontend/src/components/SQLReview/components/RuleLevelSwitch.vueindex c4b0441e94..b228d66761 100644--- a/frontend/src/components/SQLReview/components/RuleLevelSwitch.vue+++ b/frontend/src/components/SQLReview/components/RuleLevelSwitch.vue@@ -41,7 +41,7 @@ defineEmits<{<style lang="postcss" scoped>.button {- @apply relative py-1 w-[4rem] whitespace-nowrap border border-control-border text-control font-medium hover:z-[2];+ @apply relative py-1 w-[4.5rem] whitespace-nowrap border border-control-border text-control font-medium hover:z-[2];@apply disabled:cursor-not-allowed disabled:bg-control-bg disabled:opacity-50;}.button:not(:first-child) {diff --git a/frontend/src/components/SQLReview/components/SQLReviewTemplateSelector.vue b/frontend/src/components/SQLReview/components/SQLReviewTemplateSelector.vueindex 791b044d32..8ca83b0d2f 100644--- a/frontend/src/components/SQLReview/components/SQLReviewTemplateSelector.vue+++ b/frontend/src/components/SQLReview/components/SQLReviewTemplateSelector.vue@@ -1,17 +1,17 @@<template>- <div>- <p v-if="title" class="textlabel">- {{ title }}+ <div class="flex flex-col gap-y-2">+ <p class="textlabel">+ {{ $t("sql-review.create.basic-info.choose-template") }}<span v-if="required" style="color: red">*</span></p><div- class="flex flex-col sm:flex-row justify-start items-center gap-x-10 gap-y-10 mt-4"+ class="flex flex-col sm:flex-row sm:flex-wrap justify-start items-stretch gap-x-10 gap-y-4"><divv-for="template in reviewPolicyTemplateList":key="template.id"- class="relative border border-gray-300 hover:bg-gray-100 rounded-lg p-6 transition-all w-full sm:max-w-xs"+ class="relative border border-gray-300 hover:bg-gray-100 rounded-lg p-6 transition-all w-full h-full sm:max-w-xs":class="isSelectedTemplate(template)? 'bg-gray-100'@@ -43,8 +43,10 @@</div></div>+ <hr />+<div- class="flex flex-col sm:flex-row justify-start items-center gap-x-10 gap-y-10 mt-4"+ class="flex flex-col sm:flex-row sm:flex-wrap justify-start items-stretch gap-x-10 gap-y-4"><divv-for="template in builtInTemplateList"@@ -89,7 +91,7 @@</template><script lang="ts" setup>-import { computed } from "vue";+import { computed, watch } from "vue";import { SQLReviewPolicyTemplate } from "@/types";import { TEMPLATE_LIST as builtInTemplateList, RuleLevel } from "@/types";@@ -111,15 +113,22 @@ const props = withDefaults(});-defineEmits<{+const emit = defineEmits<{(event: "select-template", template: SQLReviewPolicyTemplate): void;+ (+ event: "templates-change",+ templateList: {+ policy: SQLReviewPolicyTemplate[];+ builtin: SQLReviewPolicyTemplate[];+ }+ ): void;}>();const reviewPolicyList = useSQLReviewPolicyList();const reviewPolicyTemplateList = computed(() => {- return reviewPolicyList.value.map((rule) =>- rulesToTemplate(rule, false /* withDisabled=false */)+ return reviewPolicyList.value.map((policy) =>+ rulesToTemplate(policy, false /* withDisabled=false */));});@@ -135,4 +144,15 @@ const enabledRuleCount = (template: SQLReviewPolicyTemplate) => {const getTemplateImage = (id: string) => {return new URL(`../../../assets/${id}.webp`, import.meta.url).href;};++watch(+ reviewPolicyTemplateList,+ () => {+ emit("templates-change", {+ policy: reviewPolicyTemplateList.value,+ builtin: builtInTemplateList,+ });+ },+ { immediate: true }+);</script>diff --git a/frontend/src/components/SQLReview/components/SQLRuleEditDialog.vue b/frontend/src/components/SQLReview/components/SQLRuleEditDialog.vueindex 72bbefa975..df7847792c 100644--- a/frontend/src/components/SQLReview/components/SQLRuleEditDialog.vue+++ b/frontend/src/components/SQLReview/components/SQLRuleEditDialog.vue@@ -17,12 +17,18 @@</a></div></div>- <div v-if="getRuleLocalization(rule.type).description" class="space-y-1">+ <div class="space-y-1"><h3 class="text-lg text-control font-medium">- {{ $t("common.description") }}+ {{ $t("sql-review.rule.active") }}</h3>- <div class="textinfolabel flex items-center gap-x-2">- {{ getRuleLocalization(rule.type).description }}+ <div class="flex items-center gap-x-2 text-sm">+ <BBSwitch+ :class="[!editable && 'pointer-events-none']"+ :disabled="disabled"+ :value="state.level !== RuleLevel.DISABLED"+ size="small"+ @toggle="toggleActivity(rule, $event)"+ /></div></div><div class="space-y-1">@@ -92,6 +98,14 @@@update:value="state.payload[index] = $event"/></div>+ <div v-if="getRuleLocalization(rule.type).description" class="space-y-1">+ <h3 class="text-lg text-control font-medium">+ {{ $t("common.description") }}+ </h3>+ <div class="textinfolabel flex items-center gap-x-2">+ {{ getRuleLocalization(rule.type).description }}+ </div>+ </div><div v-if="editable" class="mt-4 pt-2 border-t flex justify-end"><buttontype="button"@@ -167,6 +181,10 @@ const configTitle = (config: RuleConfigComponent): string => {return t(key);};+const toggleActivity = (rule: RuleTemplate, on: boolean) => {+ state.level = on ? RuleLevel.WARNING : RuleLevel.DISABLED;+};+watch(() => props.payload,() => {diff --git a/frontend/src/components/SQLReview/components/SQLRuleTable.vue b/frontend/src/components/SQLReview/components/SQLRuleTable.vueindex 171e6af89c..7552533a29 100644--- a/frontend/src/components/SQLReview/components/SQLRuleTable.vue+++ b/frontend/src/components/SQLReview/components/SQLRuleTable.vue@@ -59,7 +59,7 @@<heroicons-outline:external-link class="w-4 h-4" /></a></div>- <div class="bb-grid-cell gap-x-1">+ <div class="bb-grid-cell gap-x-2"><RuleEngineIcons :rule="rule" /></div><div class="bb-grid-cell">diff --git a/frontend/src/components/SQLReview/components/utils.ts b/frontend/src/components/SQLReview/components/utils.tsindex 4406750555..9535e3a341 100644--- a/frontend/src/components/SQLReview/components/utils.ts+++ b/frontend/src/components/SQLReview/components/utils.ts@@ -1,5 +1,6 @@import {convertPolicyRuleToRuleTemplate,+ Environment,RuleConfigComponent,RuleLevel,RuleTemplate,@@ -9,6 +10,10 @@ import {} from "@/types";import { PayloadValueType } from "./RuleConfigComponents";+export const templateIdForEnvironment = (environment: Environment): string => {+ return `bb.sql-review.environment-policy.${environment.resourceId}`;+};+export const rulesToTemplate = (review: SQLReviewPolicy,withDisabled = false@@ -51,7 +56,7 @@ export const rulesToTemplate = (}return {- id: `bb.sql-review.environment-policy.${review.environment.resourceId}`,+ id: templateIdForEnvironment(review.environment),review,ruleList: ruleTemplateList,};diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 9dd8d3c9fb..69bd26f625 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -258,7 +258,7 @@"compatibility": "兼容性","connection": "连接","migration-schema": "变更 schema",- "sql-review": "SQL 审查",+ "sql-review": "SQL 审核","earliest-allowed-time": "最早执行时间","ghost-sync": "gh-ost 同步","statement-type": "语句类型",@@ -1772,8 +1772,8 @@"rules": "规则","filter": "筛选","no-permission": "仅 DBA 或所有者有权限创建或更新审核策略。",- "disable": "停用审查策略",- "enable": "开启审查策略",+ "disable": "停用审核策略",+ "enable": "开启审核策略","delete": "删除审核策略","input-then-press-enter": "输入后按下回车来添加","not-available-for-free": "{plan}订阅不能使用该规则",diff --git a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vueindex 29ad95ed4f..bfeb1bc83f 100644--- a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue+++ b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue@@ -8,7 +8,7 @@<SQLReviewCreationv-if="state.editMode"key="sql-review-creation"- :policy-id="reviewPolicy.id"+ :policy="reviewPolicy":name="reviewPolicy.name":selected-environment="reviewPolicy.environment":selected-rule-list="selectedRuleList"@@ -18,8 +18,12 @@<divclass="flex flex-col items-center space-x-2 justify-center md:flex-row">- <div class="flex-1 flex space-x-3 items-center justify-start">- <BBBadge v-if="reviewPolicy.environment" :can-remove="false">+ <div class="flex-1 flex space-x-2 items-center justify-start">+ <BBBadge+ v-if="reviewPolicy.environment"+ :can-remove="false"+ :link="`/environment/${reviewPolicy.environment.id}`"+ >{{ reviewPolicy.environment.name }}<ProductionEnvironmentIcon:environment="reviewPolicy.environment"@@ -37,7 +41,7 @@/></div><BBTextField- class="flex-1 text-3xl py-0.5 font-bold truncate"+ class="flex-1 text-3xl py-0.5 px-0.5 font-bold truncate":disabled="!hasPermission":required="true":focus-on-mount="false"@@ -87,10 +91,9 @@:policy="reviewPolicy":selected-rule-list="filteredRuleList":editable="hasPermission"- class="py-5"/><BBButtonConfirm- v-if="reviewPolicy.rowStatus === 'ARCHIVED' && hasPermission"+ :disabled="!hasPermission":style="'DELETE'":button-text="$t('sql-review.delete')":ok-text="$t('common.delete')"