Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: optimize SQL review policy (part 2) (#3668)
ecmadao97f61b210943
diff --git a/frontend/src/components/SQLReview/components/SQLReviewCard.vue b/frontend/src/components/SQLReview/components/SQLReviewCard.vueindex 3d159cc8ac..dc24bc9922 100644--- a/frontend/src/components/SQLReview/components/SQLReviewCard.vue+++ b/frontend/src/components/SQLReview/components/SQLReviewCard.vue@@ -14,13 +14,22 @@:style="'DISABLED'"/></div>- <button- type="button"- class="btn-normal py-2 px-4"- @click.prevent="emit('click', reviewPolicy)"- >- {{ $t("common.view") }}- </button>+ <div class="flex gap-x-3">+ <button+ type="button"+ class="btn-normal py-2 px-4"+ @click.prevent="emit('duplicate', reviewPolicy)"+ >+ {{ $t("common.duplicate") }}+ </button>+ <button+ type="button"+ class="btn-primary py-2 px-4"+ @click.prevent="emit('click', reviewPolicy)"+ >+ {{ $t("common.view") }}+ </button>+ </div></div><div class="border-t border-block-border"><dl class="divide-y divide-block-border">@@ -81,5 +90,8 @@ defineProps({type: Object as PropType<SQLReviewPolicy>,},});-const emit = defineEmits(["click"]);+const emit = defineEmits<{+ (event: "click", policy: SQLReviewPolicy): void;+ (event: "duplicate", policy: SQLReviewPolicy): void;+}>();</script>diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex f8d3c1a4a7..cce504a3c0 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1554,11 +1554,13 @@"disabled": "Disabled","no-policy-set": "No SQL review policy","create-policy": "Create policy",+ "duplicate-policy": "Duplicate SQL Review Policy","configure-policy": "Configure policy","search-rule-name": "Search rule name","policy-removed": "Successfully removed the review policy.","policy-created": "Successfully created the review policy.","policy-updated": "Successfully updated the review policy.",+ "policy-duplicated": "Successfully duplicated the review policy.","rules": "Rules","filter": "Filter","no-permission": "Only DBA or Owner has permission to create or update review policy.",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 6de6c00ecd..5050d0bba0 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1554,11 +1554,13 @@"disabled": "已禁用","no-policy-set": "没有 SQL 审核策略","create-policy": "创建审核策略",+ "duplicate-policy": "复制审核策略","configure-policy": "配置审核策略","search-rule-name": "搜索规则名称","policy-removed": "审核策略已删除","policy-created": "审核策略已创建","policy-updated": "审核策略已更新",+ "policy-duplicated": "审核策略已复制","rules": "规则","filter": "筛选","no-permission": "仅 DBA 或所有者有权限创建或更新审核策略。",diff --git a/frontend/src/views/SettingWorkspaceSQLReview.vue b/frontend/src/views/SettingWorkspaceSQLReview.vueindex 9ba08e4f71..21cadaadbe 100644--- a/frontend/src/views/SettingWorkspaceSQLReview.vue+++ b/frontend/src/views/SettingWorkspaceSQLReview.vue@@ -28,17 +28,103 @@</button></div><template v-for="review in store.reviewPolicyList" :key="review.id">- <SQLReviewCard :review-policy="review" @click="onClick" />+ <SQLReviewCard+ :review-policy="review"+ @click="onClick"+ @duplicate="onDuplicate"+ /></template></div><template v-else><SQLReviewEmptyView @create="goToCreationView" /></template></div>+ <BBModal+ v-if="state.showDuplicateModal && state.duplicatePolicy"+ :title="$t('sql-review.duplicate-policy')"+ @close="state.showDuplicateModal = false"+ >+ <div class="min-w-0 md:min-w-400">+ <div class="mt-2">+ <label class="textlabel">+ {{ $t("sql-review.create.basic-info.display-name") }}+ <span style="color: red">*</span>+ </label>+ <p class="mt-1 textinfolabel">+ {{ $t("sql-review.create.basic-info.display-name-label") }}+ </p>+ <BBTextField+ class="mt-2 w-full"+ :placeholder="+ $t('sql-review.create.basic-info.display-name-placeholder')+ "+ :value="state.duplicatePolicy.name"+ @input="onNameChange"+ />+ </div>+ <div class="mt-5">+ <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"+ />+ <div class="flex flex-wrap gap-x-3 px-1">+ <div+ v-for="env in availableEnvironmentList"+ :key="env.id"+ class="flex items-center"+ >+ <input+ :id="`${env.id}`"+ type="radio"+ :value="env.id"+ :checked="env.id === state.duplicatePolicy.environment?.id"+ class="text-accent disabled:text-accent-disabled cursor-pointer focus:ring-accent"+ @change="onEnvChange(env)"+ />+ <label+ :for="`${env.id}`"+ class="ml-2 items-center cursor-pointer text-sm"+ >+ {{ environmentName(env) }}+ </label>+ </div>+ </div>+ </div>+ <div class="mt-7 flex justify-end space-x-3">+ <button+ type="button"+ class="btn-normal"+ @click.prevent="state.showDuplicateModal = false"+ >+ {{ $t("common.cancel") }}+ </button>+ <button+ type="button"+ class="btn-primary"+ :disabled="duplicateButtonDisabled"+ @click.prevent="duplicatePolicy"+ >+ {{ $t("common.duplicate") }}+ </button>+ </div>+ </div>+ </BBModal></template><script lang="ts" setup>-import { computed, watchEffect } from "vue";+import { computed, reactive, watchEffect } from "vue";import { useRouter } from "vue-router";import { useI18n } from "vue-i18n";import {@@ -46,9 +132,23 @@ import {useSQLReviewStore,useCurrentUser,featureToRef,+ useEnvironmentList,} from "@/store";-import { SQLReviewPolicy } from "@/types/sqlReview";-import { hasWorkspacePermission, sqlReviewPolicySlug } from "@/utils";+import { unknown, UNKNOWN_ID, SQLReviewPolicy, Environment } from "@/types";+import {+ environmentName,+ hasWorkspacePermission,+ sqlReviewPolicySlug,+} from "@/utils";++interface LocalState {+ showDuplicateModal: boolean;+ duplicatePolicy?: SQLReviewPolicy;+}++const state = reactive<LocalState>({+ showDuplicateModal: false,+});const router = useRouter();const store = useSQLReviewStore();@@ -91,4 +191,75 @@ const onClick = (review: SQLReviewPolicy) => {},});};++const onDuplicate = (policy: SQLReviewPolicy) => {+ state.showDuplicateModal = true;+ state.duplicatePolicy = {+ ...policy,+ environment: unknown("ENVIRONMENT") as Environment,+ };+};++const onNameChange = (event: Event) => {+ if (!state.duplicatePolicy) {+ return;+ }+ state.duplicatePolicy.name = (event.target as HTMLInputElement).value;+};++const onEnvChange = (env: Environment) => {+ if (!state.duplicatePolicy) {+ return;+ }+ state.duplicatePolicy.environment = env;+};++const availableEnvironmentList = computed((): Environment[] => {+ const environmentList = useEnvironmentList(["NORMAL"]);++ const filteredList = store.availableEnvironments(+ environmentList.value,+ undefined // undefined means we don't know the policy id, this shoud be a create action.+ );++ return filteredList;+});++const duplicateButtonDisabled = computed((): boolean => {+ if (!state.duplicatePolicy) {+ return true;+ }++ if (!state.duplicatePolicy.name) {+ return true;+ }++ if (state.duplicatePolicy.environment.id === UNKNOWN_ID) {+ return true;+ }++ return false;+});++const duplicatePolicy = () => {+ if (!state.duplicatePolicy || duplicateButtonDisabled.value) {+ return;+ }++ store+ .addReviewPolicy({+ name: state.duplicatePolicy.name,+ ruleList: state.duplicatePolicy.ruleList,+ environmentId: state.duplicatePolicy.environment.id,+ })+ .then(() => {+ state.duplicatePolicy = undefined;+ state.showDuplicateModal = false;+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("sql-review.policy-duplicated"),+ });+ });+};</script>