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: allow preview when configuring deployment plan (#880)
Liu Jiaf17206cc86c
diff --git a/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vue b/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vuenew file mode 100644index 0000000000..0149a9f9db--- /dev/null+++ b/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vue@@ -0,0 +1,133 @@+<template>+ <div class="space-y-2 w-192 px-1">+ <div+ v-if="databaseListGroupByName.length === 0"+ class="textinfolabel px-10 py-4"+ >+ <i18n-t keypath="project.overview.no-db-prompt" tag="p">+ <template #newDb>+ <span class="text-main">{{ $t("quick-action.new-db") }}</span>+ </template>+ <template #transferInDb>+ <span class="text-main">+ {{ $t("quick-action.transfer-in-db") }}+ </span>+ </template>+ </i18n-t>+ </div>++ <template v-else>+ <div class="flex items-center py-0.5 space-x-2">+ <select+ v-model="state.selectedDatabaseName"+ class="btn-select w-40 disabled:cursor-not-allowed"+ >+ <option disabled>{{ $t("db.select") }}</option>+ <option+ v-for="(group, i) in databaseListGroupByName"+ :key="i"+ :value="group.name"+ >+ {{ group.name }}+ </option>+ </select>++ <YAxisRadioGroup+ v-model:label="state.label"+ :label-list="labelList"+ class="text-sm"+ />+ </div>++ <div v-if="selectedDatabaseGroup">+ <DeployDatabaseTable+ :database-list="selectedDatabaseGroup.list"+ :label="state.label"+ :label-list="labelList"+ :environment-list="environmentList"+ :deployment="deployment"+ />+ </div>+ </template>+ </div>+</template>++<script lang="ts" setup>+import { computed, reactive, watch } from "vue";+import {+ Project,+ DeploymentConfig,+ Environment,+ Database,+ Label,+ LabelKeyType,+} from "@/types";+import { groupBy } from "lodash-es";+import { parseDatabaseNameByTemplate } from "@/utils";+import { DeployDatabaseTable } from "../TenantDatabaseTable";++type DatabaseGroup = {+ name: string;+ list: Database[];+};++const props = defineProps<{+ project: Project;+ deployment: DeploymentConfig;+ environmentList: Environment[];+ databaseList: Database[];+ labelList: Label[];+}>();++const state = reactive({+ label: "bb.environment" as LabelKeyType,+ selectedDatabaseName: undefined as string | undefined,+});++const databaseListGroupByName = computed((): DatabaseGroup[] => {+ const { dbNameTemplate } = props.project;++ if (dbNameTemplate && props.labelList.length === 0) {+ // We can't calculate dbname correctly if labelList hasn't been fetched+ // So return empty array as a fallback+ return [];+ }++ const dict = groupBy(props.databaseList, (db) => {+ if (dbNameTemplate) {+ return parseDatabaseNameByTemplate(+ db.name,+ dbNameTemplate,+ props.labelList+ );+ } else {+ return db.name;+ }+ });+ return Object.keys(dict).map((name) => ({+ name,+ list: dict[name],+ }));+});++watch(+ databaseListGroupByName,+ (groups) => {+ // reset selection when databaseList changed+ if (groups.length > 0) {+ state.selectedDatabaseName = groups[0].name;+ } else {+ state.selectedDatabaseName = undefined;+ }+ },+ { immediate: true }+);++const selectedDatabaseGroup = computed((): DatabaseGroup | undefined => {+ if (!state.selectedDatabaseName) return undefined;++ return databaseListGroupByName.value.find(+ (group) => group.name === state.selectedDatabaseName+ );+});+</script>diff --git a/frontend/src/components/DeploymentConfigTool/SelectorItem.vue b/frontend/src/components/DeploymentConfigTool/SelectorItem.vueindex 083a61d06e..b603265d4a 100644--- a/frontend/src/components/DeploymentConfigTool/SelectorItem.vue+++ b/frontend/src/components/DeploymentConfigTool/SelectorItem.vue@@ -13,6 +13,7 @@v-model:value="selector.operator":options="OPERATORS":disabled="!editable"+ :modifier="lowerCase"class="select operator"/><LabelSelect@@ -41,6 +42,7 @@ import {} from "../../types";import { hidePrefix } from "../../utils";import LabelSelect from "./LabelSelect.vue";+import { lowerCase } from "lodash-es";const OPERATORS: OperatorType[] = ["In", "Exists"];@@ -80,7 +82,7 @@ export default defineComponent({watch(() => props.selector.key, resetValues);watch(() => props.selector.operator, resetValues);- return { OPERATORS, hidePrefix, keys, values };+ return { OPERATORS, hidePrefix, lowerCase, keys, values };},});</script>diff --git a/frontend/src/components/DeploymentConfigTool/index.ts b/frontend/src/components/DeploymentConfigTool/index.tsindex 3a862908f9..7694379b2a 100644--- a/frontend/src/components/DeploymentConfigTool/index.ts+++ b/frontend/src/components/DeploymentConfigTool/index.ts@@ -1,6 +1,7 @@import DeploymentConfigTool from "./DeploymentConfigTool.vue";import DeploymentStage from "./DeploymentStage.vue";+import DeploymentMatrix from "./DeploymentMatrix.vue";export default DeploymentConfigTool;-export { DeploymentConfigTool, DeploymentStage };+export { DeploymentConfigTool, DeploymentStage, DeploymentMatrix };diff --git a/frontend/src/components/ProjectDeploymentConfigPanel.vue b/frontend/src/components/ProjectDeploymentConfigPanel.vueindex 9976bcf5f6..7fbba996de 100644--- a/frontend/src/components/ProjectDeploymentConfigPanel.vue+++ b/frontend/src/components/ProjectDeploymentConfigPanel.vue@@ -52,29 +52,55 @@:label-list="availableLabelList":database-list="databaseList"/>- <div v-if="allowEdit" class="pt-4 flex justify-between items-center">- <button class="btn-normal" @click="addStage">- {{ $t("deployment-config.add-stage") }}- </button>- <NPopover :disabled="!state.error" trigger="hover">- <template #trigger>- <div- class="btn-primary"- :class="- state.error ? 'bg-accent opacity-50 cursor-not-allowed' : ''- "- @click="update"- >- {{ $t("common.update") }}- </div>- </template>+ <div class="pt-4 flex justify-between items-center">+ <div class="flex items-center space-x-2">+ <button v-if="allowEdit" class="btn-normal" @click="addStage">+ {{ $t("deployment-config.add-stage") }}+ </button>- <span v-if="state.error" class="text-red-600">- {{ $t(state.error) }}- </span>- </NPopover>+ <button+ class="btn-normal"+ :disabled="!!state.error"+ @click="state.showPreview = true"+ >+ {{ $t("common.preview") }}+ </button>+ </div>+ <div class="flex items-center space-x-2">+ <NPopover v-if="allowEdit" :disabled="!state.error" trigger="hover">+ <template #trigger>+ <div+ class="btn-primary"+ :class="+ state.error ? 'bg-accent opacity-50 cursor-not-allowed' : ''+ "+ @click="update"+ >+ {{ $t("common.update") }}+ </div>+ </template>++ <span v-if="state.error" class="text-error">+ {{ $t(state.error) }}+ </span>+ </NPopover>+ </div></div></div>++ <BBModal+ v-if="deployment && state.showPreview"+ :title="$t('deployment-config.preview-deployment-config')"+ @close="state.showPreview = false"+ >+ <DeploymentMatrix+ :project="project"+ :deployment="deployment"+ :database-list="databaseList"+ :environment-list="environmentList"+ :label-list="labelList"+ />+ </BBModal></div></template>@@ -103,7 +129,7 @@ import {DeploymentConfigPatch,LabelSelectorRequirement,} from "../types";-import DeploymentConfigTool from "./DeploymentConfigTool";+import DeploymentConfigTool, { DeploymentMatrix } from "./DeploymentConfigTool";import { cloneDeep } from "lodash-es";import { useI18n } from "vue-i18n";import { NPopover } from "naive-ui";@@ -112,11 +138,12 @@ import { generateDefaultSchedule, validateDeploymentConfig } from "../utils";type LocalState = {error: string | undefined;ready: boolean;+ showPreview: boolean;};export default defineComponent({name: "ProjectDeploymentConfigurationPanel",- components: { DeploymentConfigTool, NPopover },+ components: { DeploymentConfigTool, DeploymentMatrix, NPopover },props: {project: {required: true,@@ -135,6 +162,7 @@ export default defineComponent({const state = reactive<LocalState>({ready: false,error: undefined,+ showPreview: false,});const prepareList = () => {diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.ymlindex 899892336a..c8ff9a39ba 100644--- a/frontend/src/locales/en.yml+++ b/frontend/src/locales/en.yml@@ -176,6 +176,7 @@ common:search: Searchwarning: Warningedited: edited+ preview: Previewerror-page:go-back-home: Go back homeanomaly-center: Anomaly Center@@ -1083,12 +1084,13 @@ deployment-config:at-least-one-stage: At least 1 stagestage-name-required: Stage name is requiredat-least-one-selector: At least 1 selector in each stage- env-in-selector-required: '"environment In" is required in each stage'- env-selector-must-has-one-value: '"environment In" must has exactly one value'+ env-in-selector-required: '"Environment in" is required in each stage'+ env-selector-must-has-one-value: '"Environment in" must has exactly one value'key-required: Key is requiredvalues-required: Values are requiredproject-has-no-deployment-config: This project has no deployment config yet. Please {go} first.go-and-config: Go and config+ preview-deployment-config: Preview Deployment Configdatasource:role-type: Role Typesuccessfully-deleted-data-source-name: Successfully deleted data source '{0}'.diff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.ymlindex 3544e05653..350e6cdf58 100644--- a/frontend/src/locales/zh-CN.yml+++ b/frontend/src/locales/zh-CN.yml@@ -176,6 +176,7 @@ common:search: 搜索warning: 警告edited: 编辑于+ preview: 预览error-page:go-back-home: 回到主页anomaly-center: 异常中心@@ -945,12 +946,13 @@ deployment-config:at-least-one-stage: 至少需要 1 个阶段stage-name-required: 需要指定阶段名称at-least-one-selector: 每个阶段至少需要 1 个选择条件- env-in-selector-required: 每个阶段都需要有 "environment In" 选择条件- env-selector-must-has-one-value: '"environment In" 必须有且只有 1 个值'+ env-in-selector-required: 每个阶段都需要有 "Environment in" 选择条件+ env-selector-must-has-one-value: '"Environment in" 必须有且只有 1 个值'key-required: 需要指定 Keyvalues-required: 需要指定值project-has-no-deployment-config: 这个项目还没有部署配置。请先{go}。go-and-config: 去配置+ preview-deployment-config: 预览部署配置datasource:role-type: 权限类型successfully-deleted-data-source-name: 成功删除数据源'{0}'。