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: refactor database transfer (#9824)
ecmadaof5cb3b5a8092
diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vueindex cced042842..c9b99fe776 100644--- a/frontend/src/components/ProjectDatabasesPanel.vue+++ b/frontend/src/components/ProjectDatabasesPanel.vue@@ -18,6 +18,7 @@<DatabaseOperationsv-if="showDatabaseOperations"+ :project-uid="project.uid":databases="selectedDatabases"/>@@ -81,9 +82,9 @@</template><script lang="ts" setup>-import { reactive, PropType, computed, ref, watchEffect } from "vue";+import { reactive, computed, ref, watchEffect } from "vue";import { usePageMode, usePolicyV1Store } from "@/store";-import { ComposedDatabase, UNKNOWN_ID } from "@/types";+import { ComposedDatabase, ComposedProject, UNKNOWN_ID } from "@/types";import {Policy,PolicyResourceType,@@ -104,12 +105,10 @@ interface LocalState {params: SearchParams;}-const props = defineProps({- databaseList: {- required: true,- type: Object as PropType<ComposedDatabase[]>,- },-});+const props = defineProps<{+ project: ComposedProject;+ databaseList: ComposedDatabase[];+}>();const pageMode = usePageMode();diff --git a/frontend/src/components/TransferDatabaseForm.vue b/frontend/src/components/TransferDatabaseForm.vueindex b6e22167ca..29c1614076 100644--- a/frontend/src/components/TransferDatabaseForm.vue+++ b/frontend/src/components/TransferDatabaseForm.vue@@ -1,33 +1,66 @@<template>- <TransferMultipleDatabaseForm- :target-project="project"- :transfer-source="state.transferSource"- :database-list="filteredDatabaseList"- @dismiss="$emit('dismiss')"- @submit="(databaseList) => transferDatabase(databaseList)"- >- <template #transfer-source-selector>- <TransferSourceSelector- :project="project"- :raw-database-list="rawDatabaseList"- :transfer-source="state.transferSource"- :instance-filter="state.instanceFilter"- :project-filter="state.projectFilter"- :search-text="state.searchText"- @change="state.transferSource = $event"- @select-instance="state.instanceFilter = $event"- @select-project="state.projectFilter = $event"- @search-text-change="state.searchText = $event"- />+ <DrawerContent :title="$t('quick-action.transfer-in-db-title')">+ <div+ class="px-4 w-[calc(100vw-8rem)] lg:w-[60rem] max-w-[calc(100vw-8rem)]"+ >+ <div+ v-if="state.loading"+ class="absolute inset-0 z-10 bg-white/70 flex items-center justify-center"+ >+ <BBSpin />+ </div>+ <div v-else class="space-y-4">+ <TransferSourceSelector+ :project="project"+ :raw-database-list="rawDatabaseList"+ :transfer-source="state.transferSource"+ :instance-filter="state.instanceFilter"+ :project-filter="state.projectFilter"+ :search-text="state.searchText"+ @change="state.transferSource = $event"+ @select-instance="state.instanceFilter = $event"+ @select-project="state.projectFilter = $event"+ @search-text-change="state.searchText = $event"+ />+ <MultipleDatabaseSelector+ v-if="filteredDatabaseList.length > 0"+ v-model:selected-uid-list="state.selectedDatabaseUidList"+ :transfer-source="state.transferSource"+ :database-list="filteredDatabaseList"+ />+ <NoDataPlaceholder v-else />+ </div>+ </div>++ <template #footer>+ <div class="flex-1 flex items-center justify-between">+ <div>+ <div+ v-if="state.selectedDatabaseUidList.length > 0"+ class="textinfolabel"+ >+ {{+ $t("database.selected-n-databases", {+ n: state.selectedDatabaseUidList.length,+ })+ }}+ </div>+ </div>+ <div class="flex items-center gap-x-3">+ <NButton @click.prevent="$emit('dismiss')">+ {{ $t("common.cancel") }}+ </NButton>+ <NButton+ type="primary"+ :disabled="!allowTransfer"+ @click.prevent="transferDatabase"+ >+ {{ $t("common.transfer") }}+ </NButton>+ </div>+ </div></template>- </TransferMultipleDatabaseForm>-- <div- v-if="state.loading"- class="absolute inset-0 z-10 bg-white/70 flex items-center justify-center"- >- <BBSpin />- </div>+ </DrawerContent></template><script lang="ts" setup>@@ -35,7 +68,7 @@ import { cloneDeep } from "lodash-es";import { computed, onBeforeMount, reactive } from "vue";import { toRef } from "vue";import {- TransferMultipleDatabaseForm,+ MultipleDatabaseSelector,TransferSource,TransferSourceSelector,} from "@/components/TransferDatabaseForm";@@ -66,6 +99,7 @@ interface LocalState {projectFilter: Project | undefined;searchText: string;loading: boolean;+ selectedDatabaseUidList: string[];}const props = defineProps({@@ -89,6 +123,7 @@ const state = reactive<LocalState>({projectFilter: undefined,searchText: "",loading: false,+ selectedDatabaseUidList: [],});const hasWorkspaceManageDatabasePermission = useWorkspacePermissionV1("bb.permission.workspace.manage-database"@@ -158,7 +193,12 @@ const filteredDatabaseList = computed(() => {return sortDatabaseV1List(list);});-const transferDatabase = async (databaseList: ComposedDatabase[]) => {+const allowTransfer = computed(() => state.selectedDatabaseUidList.length > 0);++const transferDatabase = async () => {+ const databaseList = state.selectedDatabaseUidList.map((uid) =>+ databaseStore.getDatabaseByUID(uid)+ );const transferOneDatabase = async (database: ComposedDatabase) => {const targetProject = useProjectV1Store().getProjectByUID(props.projectId);const databasePatch = cloneDeep(database);diff --git a/frontend/src/components/TransferDatabaseForm/MultipleDatabaseSelector.vue b/frontend/src/components/TransferDatabaseForm/MultipleDatabaseSelector.vuenew file mode 100644index 0000000000..41dcfc5255--- /dev/null+++ b/frontend/src/components/TransferDatabaseForm/MultipleDatabaseSelector.vue@@ -0,0 +1,281 @@+<template>+ <div class="w-full">+ <!-- Leave some margin space to avoid accidentally clicking the Collaspe when trying to click the selector -->+ <NCollapse+ arrow-placement="left"+ :default-expanded-names="environmentList.map((env) => env.uid)"+ >+ <NCollapseItem+ v-for="{+ environment,+ databaseList: databaseListInEnvironment,+ } in databaseListGroupByEnvironment"+ :key="environment.uid"+ :name="environment.uid"+ >+ <template #header>+ <label class="flex items-center gap-x-2" @click.stop="">+ <input+ type="checkbox"+ class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed focus:ring-accent ml-0.5"+ v-bind="+ getAllSelectionStateForEnvironment(+ environment,+ databaseListInEnvironment+ )+ "+ @click.stop=""+ @input="+ toggleAllDatabasesSelectionForEnvironment(+ environment,+ databaseListInEnvironment,+ ($event.target as HTMLInputElement).checked+ )+ "+ />+ <div>{{ environment.title }}</div>+ <ProductionEnvironmentV1Icon :environment="environment" />+ </label>+ </template>++ <template #header-extra>+ <div class="flex items-center text-xs text-gray-500 mr-2">+ {{+ $t(+ "database.n-selected-m-in-total",+ getSelectionStateSummaryForEnvironment(+ environment,+ databaseListInEnvironment+ )+ )+ }}+ </div>+ </template>++ <BBGrid+ class="relative bg-white border"+ :column-list="gridColumnList"+ :show-header="false"+ :data-source="databaseListInEnvironment"+ row-key="id"+ @click-row="handleClickRow"+ >+ <template #item="{ item: database }: { item: ComposedDatabase }">+ <div class="bb-grid-cell gap-x-2 !pl-[23px]">+ <input+ type="checkbox"+ class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed focus:ring-accent"+ :checked="+ isDatabaseSelectedForEnvironment(+ database.uid,+ environment.uid+ )+ "+ @input="(e: any) => toggleDatabaseIdForEnvironment(database.uid, environment.uid, e.target.checked)"+ @click.stop=""+ />+ <span+ class="font-medium text-main"+ :class="database.syncState !== State.ACTIVE && 'opacity-40'"+ >{{ database.databaseName }}</span+ >+ </div>+ <div v-if="showProjectColumn" class="bb-grid-cell">+ {{ database.projectEntity.title }}+ </div>+ <div class="bb-grid-cell gap-x-1 textinfolabel justify-end">+ <InstanceV1Name+ :instance="database.instanceEntity"+ :link="false"+ />+ </div>+ </template>+ </BBGrid>+ </NCollapseItem>+ </NCollapse>+ </div>+</template>++<script lang="ts" setup>+import { NCollapse, NCollapseItem } from "naive-ui";+import { computed, reactive, watch } from "vue";+import { type BBGridColumn, BBGrid } from "@/bbkit";+import { useEnvironmentV1List } from "@/store";+import { ComposedDatabase } from "@/types";+import { State } from "@/types/proto/v1/common";+import { Environment } from "@/types/proto/v1/environment_service";+import { InstanceV1Name, ProductionEnvironmentV1Icon } from "../v2";+import { TransferSource } from "./utils";++type LocalState = {+ selectedDatabaseUidListForEnvironment: Map<string, Set<string>>;+};++const props = withDefaults(+ defineProps<{+ transferSource: TransferSource;+ databaseList: ComposedDatabase[];+ selectedUidList?: string[];+ }>(),+ {+ selectedUidList: () => [],+ }+);++const emit = defineEmits<{+ (e: "update:selectedUidList", uidList: string[]): void;+}>();++const environmentList = useEnvironmentV1List();++const state = reactive<LocalState>({+ selectedDatabaseUidListForEnvironment: new Map(),+});++const toggleDatabaseIdForEnvironment = (+ databaseId: string,+ environmentId: string,+ selected: boolean+) => {+ const map = state.selectedDatabaseUidListForEnvironment;+ const set = map.get(environmentId) || new Set();+ if (selected) {+ set.add(databaseId);+ } else {+ set.delete(databaseId);+ }+ map.set(environmentId, set);+};++watch(+ () => [props.databaseList, props.selectedUidList],+ (args) => {+ const [databaseList, selectedUidList] = args as [+ ComposedDatabase[],+ string[]+ ];+ for (const uid of selectedUidList) {+ const database = databaseList.find((db) => db.uid === uid);+ if (!database) {+ continue;+ }+ toggleDatabaseIdForEnvironment(+ uid,+ database.effectiveEnvironmentEntity.uid,+ true+ );+ }+ },+ { immediate: true }+);++watch(+ () => state.selectedDatabaseUidListForEnvironment,+ (map) => {+ const list: string[] = [];+ for (const listForEnv of map.values()) {+ list.push(...listForEnv);+ }+ emit("update:selectedUidList", list);+ },+ { deep: true }+);++const showProjectColumn = computed(() => {+ return props.transferSource === "OTHER";+});++const gridColumnList = computed((): BBGridColumn[] => {+ const DB_NAME: BBGridColumn = {+ width: "1fr",+ };+ const PROJECT: BBGridColumn = {+ width: "8rem",+ };+ const INSTANCE: BBGridColumn = {+ width: "20rem",+ };+ return showProjectColumn.value+ ? [DB_NAME, PROJECT, INSTANCE]+ : [DB_NAME, INSTANCE];+});++const databaseListGroupByEnvironment = computed(() => {+ const listByEnv = environmentList.value.map((environment) => {+ const databaseList = props.databaseList.filter(+ (db) => db.effectiveEnvironment === environment.name+ );+ return {+ environment,+ databaseList,+ };+ });++ return listByEnv.filter((group) => group.databaseList.length > 0);+});++watch(+ () => props.transferSource,+ () => {+ // Clear selected database ID list when transferSource changed.+ state.selectedDatabaseUidListForEnvironment.clear();+ }+);++const isDatabaseSelectedForEnvironment = (+ databaseId: string,+ environmentId: string+) => {+ const map = state.selectedDatabaseUidListForEnvironment;+ const set = map.get(environmentId) || new Set();+ return set.has(databaseId);+};++const getAllSelectionStateForEnvironment = (+ environment: Environment,+ databaseList: ComposedDatabase[]+): { checked: boolean; indeterminate: boolean } => {+ const set =+ state.selectedDatabaseUidListForEnvironment.get(environment.uid) ??+ new Set();+ const checked = set.size > 0 && databaseList.every((db) => set.has(db.uid));+ const indeterminate = !checked && databaseList.some((db) => set.has(db.uid));++ return {+ checked,+ indeterminate,+ };+};++const toggleAllDatabasesSelectionForEnvironment = (+ environment: Environment,+ databaseList: ComposedDatabase[],+ on: boolean+) => {+ databaseList.forEach((db) =>+ toggleDatabaseIdForEnvironment(db.uid, environment.uid, on)+ );+};++const getSelectionStateSummaryForEnvironment = (+ environment: Environment,+ databaseList: ComposedDatabase[]+) => {+ const set =+ state.selectedDatabaseUidListForEnvironment.get(environment.uid) ||+ new Set();+ const selected = databaseList.filter((db) => set.has(db.uid)).length;+ const total = databaseList.length;++ return { selected, total };+};++const handleClickRow = (db: ComposedDatabase) => {+ const environment = db.effectiveEnvironmentEntity;+ toggleDatabaseIdForEnvironment(+ db.uid,+ environment.uid,+ !isDatabaseSelectedForEnvironment(db.uid, environment.uid)+ );+};+</script>diff --git a/frontend/src/components/TransferDatabaseForm/TransferMultipleDatabaseForm.vue b/frontend/src/components/TransferDatabaseForm/TransferMultipleDatabaseForm.vuedeleted file mode 100644index 126c09775a..0000000000--- a/frontend/src/components/TransferDatabaseForm/TransferMultipleDatabaseForm.vue+++ /dev/null@@ -1,312 +0,0 @@-<template>- <DrawerContent :title="$t('quick-action.transfer-in-db-title')">- <div- class="px-4 w-[calc(100vw-8rem)] lg:w-[60rem] max-w-[calc(100vw-8rem)]"- >- <slot name="transfer-source-selector" />-- <!-- Leave some margin space to avoid accidentally clicking the Collaspe when trying to click the selector -->- <NCollapse- class="mt-6"- arrow-placement="left"- :default-expanded-names="environmentList.map((env) => env.uid)"- >- <NCollapseItem- v-for="{- environment,- databaseList: databaseListInEnvironment,- } in databaseListGroupByEnvironment"- :key="environment.uid"- :name="environment.uid"- >- <template #header>- <label class="flex items-center gap-x-2" @click.stop="">- <input- type="checkbox"- class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed focus:ring-accent ml-0.5"- v-bind="- getAllSelectionStateForEnvironment(- environment,- databaseListInEnvironment- )- "- @click.stop=""- @input="- toggleAllDatabasesSelectionForEnvironment(- environment,- databaseListInEnvironment,- ($event.target as HTMLInputElement).checked- )- "- />- <div>{{ environment.title }}</div>- <ProductionEnvironmentV1Icon :environment="environment" />- </label>- </template>-- <template #header-extra>- <div class="flex items-center text-xs text-gray-500 mr-2">- {{- $t(- "database.n-selected-m-in-total",- getSelectionStateSummaryForEnvironment(- environment,- databaseListInEnvironment- )- )- }}- </div>- </template>-- <BBGrid- class="relative bg-white border"- :column-list="gridColumnList"- :show-header="false"- :data-source="databaseListInEnvironment"- row-key="id"- @click-row="handleClickRow"- >- <template #item="{ item: database }: { item: ComposedDatabase }">- <div class="bb-grid-cell gap-x-2 !pl-[23px]">- <input- type="checkbox"- class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed focus:ring-accent"- :checked="- isDatabaseSelectedForEnvironment(- database.uid,- environment.uid- )- "- @input="(e: any) => toggleDatabaseIdForEnvironment(database.uid, environment.uid, e.target.checked)"- @click.stop=""- />- <span- class="font-medium text-main"- :class="database.syncState !== State.ACTIVE && 'opacity-40'"- >{{ database.databaseName }}</span- >- </div>- <div v-if="showProjectColumn" class="bb-grid-cell">- {{ database.projectEntity.title }}- </div>- <div class="bb-grid-cell gap-x-1 textinfolabel justify-end">- <InstanceV1Name- :instance="database.instanceEntity"- :link="false"- />- </div>- </template>- </BBGrid>- </NCollapseItem>- </NCollapse>- </div>-- <template #footer>- <div class="flex-1 flex items-center justify-between">- <div>- <div- v-if="combinedSelectedDatabaseUidList.length > 0"- class="textinfolabel"- >- {{- $t("database.selected-n-databases", {- n: combinedSelectedDatabaseUidList.length,- })- }}- </div>- </div>- <div class="flex items-center gap-x-3">- <NButton @click.prevent="$emit('dismiss')">- {{ $t("common.cancel") }}- </NButton>- <NButton- type="primary"- :disabled="!allowTransfer"- @click.prevent="transferDatabase"- >- {{ $t("common.transfer") }}- </NButton>- </div>- </div>- </template>- </DrawerContent>-</template>--<script lang="ts" setup>-import { NButton, NCollapse, NCollapseItem } from "naive-ui";-import { computed, PropType, reactive, watch } from "vue";-import { type BBGridColumn, BBGrid } from "@/bbkit";-import { useDatabaseV1Store, useEnvironmentV1List } from "@/store";-import { ComposedDatabase } from "@/types";-import { State } from "@/types/proto/v1/common";-import { Environment } from "@/types/proto/v1/environment_service";-import {- DrawerContent,- InstanceV1Name,- ProductionEnvironmentV1Icon,-} from "../v2";-import { TransferSource } from "./utils";--type LocalState = {- selectedDatabaseUidListForEnvironment: Map<string, Set<string>>;-};--const props = defineProps({- transferSource: {- type: String as PropType<TransferSource>,- required: true,- },- databaseList: {- type: Array as PropType<ComposedDatabase[]>,- default: () => [],- },-});--const emit = defineEmits<{- (e: "dismiss"): void;- (e: "submit", databaseList: ComposedDatabase[]): void;-}>();--const databaseStore = useDatabaseV1Store();-const environmentList = useEnvironmentV1List();--const state = reactive<LocalState>({- selectedDatabaseUidListForEnvironment: new Map(),-});--const showProjectColumn = computed(() => {- return props.transferSource === "OTHER";-});--const gridColumnList = computed((): BBGridColumn[] => {- const DB_NAME: BBGridColumn = {- width: "1fr",- };- const PROJECT: BBGridColumn = {- width: "8rem",- };- const INSTANCE: BBGridColumn = {- width: "20rem",- };- return showProjectColumn.value- ? [DB_NAME, PROJECT, INSTANCE]- : [DB_NAME, INSTANCE];-});--const databaseListGroupByEnvironment = computed(() => {- const listByEnv = environmentList.value.map((environment) => {- const databaseList = props.databaseList.filter(- (db) => db.effectiveEnvironment === environment.name- );- return {- environment,- databaseList,- };- });-- return listByEnv.filter((group) => group.databaseList.length > 0);-});--watch(- () => props.transferSource,- () => {- // Clear selected database ID list when transferSource changed.- state.selectedDatabaseUidListForEnvironment.clear();- }-);--const combinedSelectedDatabaseUidList = computed(() => {- const list: string[] = [];- for (const listForEnv of state.selectedDatabaseUidListForEnvironment.values()) {- list.push(...listForEnv);- }- return list;-});--const isDatabaseSelectedForEnvironment = (- databaseId: string,- environmentId: string-) => {- const map = state.selectedDatabaseUidListForEnvironment;- const set = map.get(environmentId) || new Set();- return set.has(databaseId);-};--const toggleDatabaseIdForEnvironment = (- databaseId: string,- environmentId: string,- selected: boolean-) => {- const map = state.selectedDatabaseUidListForEnvironment;- const set = map.get(environmentId) || new Set();- if (selected) {- set.add(databaseId);- } else {- set.delete(databaseId);- }- map.set(environmentId, set);-};--const getAllSelectionStateForEnvironment = (- environment: Environment,- databaseList: ComposedDatabase[]-): { checked: boolean; indeterminate: boolean } => {- const set =- state.selectedDatabaseUidListForEnvironment.get(environment.uid) ??- new Set();- const checked = set.size > 0 && databaseList.every((db) => set.has(db.uid));- const indeterminate = !checked && databaseList.some((db) => set.has(db.uid));-- return {- checked,- indeterminate,- };-};--const toggleAllDatabasesSelectionForEnvironment = (- environment: Environment,- databaseList: ComposedDatabase[],- on: boolean-) => {- databaseList.forEach((db) =>- toggleDatabaseIdForEnvironment(db.uid, environment.uid, on)- );-};--const getSelectionStateSummaryForEnvironment = (- environment: Environment,- databaseList: ComposedDatabase[]-) => {- const set =- state.selectedDatabaseUidListForEnvironment.get(environment.uid) ||- new Set();- const selected = databaseList.filter((db) => set.has(db.uid)).length;- const total = databaseList.length;-- return { selected, total };-};--const handleClickRow = (db: ComposedDatabase) => {- const environment = db.effectiveEnvironmentEntity;- toggleDatabaseIdForEnvironment(- db.uid,- environment.uid,- !isDatabaseSelectedForEnvironment(db.uid, environment.uid)- );-};--const allowTransfer = computed(- () => combinedSelectedDatabaseUidList.value.length > 0-);--const transferDatabase = () => {- if (combinedSelectedDatabaseUidList.value.length === 0) return;-- // If a database can be selected, it must be fetched already.- // So it's safe that we won't get <<Unknown database>> here.- const databaseList = combinedSelectedDatabaseUidList.value.map((uid) =>- databaseStore.getDatabaseByUID(uid)- );- emit("submit", databaseList);-};-</script>diff --git a/frontend/src/components/TransferDatabaseForm/TransferSourceSelector.vue b/frontend/src/components/TransferDatabaseForm/TransferSourceSelector.vueindex 4a2c847d1f..424a66d806 100644--- a/frontend/src/components/TransferDatabaseForm/TransferSourceSelector.vue+++ b/frontend/src/components/TransferDatabaseForm/TransferSourceSelector.vue@@ -1,8 +1,5 @@<template><div class="textlabel">- <div v-if="state.transferSource == 'DEFAULT'" class="textinfolabel mb-2">- {{ $t("quick-action.unassigned-db-hint") }}- </div><div class="flex items-center justify-between"><div class="radio-set-row"><template v-if="project.name !== DEFAULT_PROJECT_V1_NAME">@@ -56,6 +53,9 @@/></NInputGroup></div>+ <div v-if="state.transferSource == 'DEFAULT'" class="textinfolabel mt-2">+ {{ $t("quick-action.unassigned-db-hint") }}+ </div></div></template>diff --git a/frontend/src/components/TransferDatabaseForm/index.ts b/frontend/src/components/TransferDatabaseForm/index.tsindex f12607c3ea..22dccdf60a 100644--- a/frontend/src/components/TransferDatabaseForm/index.ts+++ b/frontend/src/components/TransferDatabaseForm/index.ts@@ -1,11 +1,11 @@-import TransferMultipleDatabaseForm from "./TransferMultipleDatabaseForm.vue";+import MultipleDatabaseSelector from "./MultipleDatabaseSelector.vue";import TransferSingleDatabase from "./TransferSingleDatabase.vue";import TransferSourceSelector from "./TransferSourceSelector.vue";export * from "./utils";export {- TransferMultipleDatabaseForm,+ MultipleDatabaseSelector,TransferSourceSelector,TransferSingleDatabase,};diff --git a/frontend/src/components/TransferOutDatabaseForm/TransferOutDatabaseForm.vue b/frontend/src/components/TransferOutDatabaseForm/TransferOutDatabaseForm.vueindex 88d703a4ed..75c4b2e045 100644--- a/frontend/src/components/TransferOutDatabaseForm/TransferOutDatabaseForm.vue+++ b/frontend/src/components/TransferOutDatabaseForm/TransferOutDatabaseForm.vue@@ -1,17 +1,29 @@<template>- <DrawerContent :title="$t('database.transfer-database-from-to')">+ <DrawerContent :title="$t('database.transfer-database-to')"><divclass="w-[calc(100vw-8rem)] lg:w-[60rem] max-w-[calc(100vw-8rem)] h-full flex flex-col gap-y-2">- <div class="flex items-center justify-between gap-x-8">- <div class="flex-1 flex items-center gap-x-2">- <span class="textlabel">- {{ $t("database.transfer.source-project") }}+ <div+ v-if="loading"+ class="absolute inset-0 z-10 bg-white/70 flex items-center justify-center"+ >+ <BBSpin />+ </div>+ <div v-else class="space-y-4">+ <div>+ <span class="text-main">+ {{ $t("database.transfer.select-databases") }}+ <span class="text-red-500">*</span></span>- <ProjectV1Name :project="sourceProject" :link="false" />+ <MultipleDatabaseSelector+ v-model:selected-uid-list="selectedUidList"+ :transfer-source="'OTHER'"+ :database-list="[...databaseList]"+ /></div>- <div class="flex-1 flex items-center gap-x-2">- <span class="textlabel">+ <NDivider class="w-full py-2" />+ <div class="space-y-4">+ <span class="text-main">{{ $t("database.transfer.select-target-project") }}<span class="text-red-500">*</span></span>@@ -19,32 +31,9 @@v-model:project="targetProjectId":allowed-project-role-list="[PresetRoleType.OWNER]":include-default-project="true"- :filter="filterTargetProject"/></div></div>- <NTransfer- ref="transfer"- v-model:value="selectedValueList"- :options="sourceTransferOptions"- :render-source-list="renderSourceList"- :render-target-list="renderTargetList"- :source-filterable="true"- :source-filter-placeholder="$t('common.filter-by-name')"- class="bb-transfer-out-database-transfer"- style="height: 100%"- />- <div- class="absolute top-1/2 left-1/2 -translate-x-1/2 z-10 w-8 h-8 text-control flex items-center justify-center"- >- <heroicons:chevron-right class="w-8 h-8" />- </div>- <div- v-if="loading"- class="absolute inset-0 z-10 bg-white/70 flex items-center justify-center"- >- <BBSpin />- </div></div><template #footer>@@ -73,36 +62,19 @@</template><script setup lang="ts">-import {- NTransfer,- NTree,- TreeOption,- TransferRenderSourceList,- NButton,- NTooltip,-} from "naive-ui";-import { computed, h, ref, toRef } from "vue";+import { NButton, NTooltip, NDivider } from "naive-ui";+import { computed, ref, watch } from "vue";import { useI18n } from "vue-i18n";-import { ProjectV1Name, ProjectSelect, DrawerContent } from "@/components/v2";+import { ProjectSelect, DrawerContent } from "@/components/v2";import {pushNotification,useDatabaseV1Store,- useProjectV1ByUID,useProjectV1Store,} from "@/store";-import { PresetRoleType, UNKNOWN_ID } from "@/types";-import { Project } from "@/types/proto/v1/project_service";-import Label from "./Label.vue";-import {- DatabaseTreeOption,- flattenTreeOptions,- mapTreeOptions,- getDatabaseTreeValue,- isDatabaseTreeValue,-} from "./common";+import { PresetRoleType, ComposedDatabase, UNKNOWN_ID } from "@/types";const props = defineProps<{- projectId: string;+ databaseList: ComposedDatabase[];selectedDatabaseUidList?: string[];}>();@@ -114,22 +86,21 @@ const { t } = useI18n();const projectStore = useProjectV1Store();const databaseStore = useDatabaseV1Store();const loading = ref(false);-const transfer = ref<InstanceType<typeof NTransfer>>();-const databaseList = computed(() => {- const project = projectStore.getProjectByUID(props.projectId);- return databaseStore.databaseListByProject(project.name);-});+const selectedUidList = ref<string[]>(props.selectedDatabaseUidList ?? []);-const selectedValueList = ref<string[]>(- (props.selectedDatabaseUidList ?? []).map(getDatabaseTreeValue)+watch(+ () => props.selectedDatabaseUidList ?? [],+ (list) => (selectedUidList.value = list),+ { immediate: true });+const selectedDatabaseList = computed(() => {- return selectedValueList.value.filter(isDatabaseTreeValue).map((value) => {- const uid = value.split("-").pop()!;+ return selectedUidList.value.map((uid) => {return databaseStore.getDatabaseByUID(uid);});});+const targetProjectId = ref<string>();const targetProject = computed(() => {const id = targetProjectId.value;@@ -137,14 +108,12 @@ const targetProject = computed(() => {return projectStore.getProjectByUID(id);});-const { project: sourceProject } = useProjectV1ByUID(toRef(props, "projectId"));-const validationErrors = computed(() => {const errors: string[] = [];if (!targetProject.value) {errors.push(t("database.transfer.errors.select-target-project"));}- if (selectedDatabaseList.value.length === 0) {+ if (selectedUidList.value.length === 0) {errors.push(t("database.transfer.errors.select-at-least-one-database"));}return errors;@@ -154,113 +123,37 @@ const allowTransfer = computed(() => {return validationErrors.value.length === 0;});-const sourceTreeOptions = computed(() => {- return mapTreeOptions(databaseList.value);-});-const sourceTransferOptions = computed(() => {- return flattenTreeOptions(sourceTreeOptions.value);-});--const renderSourceList: TransferRenderSourceList = ({ onCheck, pattern }) => {- return h(NTree, {- style: "margin: 0 4px;",- keyField: "value",- defaultExpandAll: true,- checkable: true,- selectable: false,- blockLine: true,- checkOnClick: true,- cascade: true,- virtualScroll: true,- data: sourceTreeOptions.value,- renderLabel: ({ option }: { option: TreeOption }) => {- return h(Label, {- option: option as DatabaseTreeOption,- keyword: pattern,- });- },- pattern,- checkedKeys: selectedValueList.value,- showIrrelevantNodes: false,- onUpdateCheckedKeys: (checkedKeys: string[]) => {- onCheck(checkedKeys.filter(isDatabaseTreeValue));- },- });-};--const targetTreeOptions = computed(() => {- return mapTreeOptions(selectedDatabaseList.value);-});-const targetCheckedKeys = computed(() => {- return flattenTreeOptions(targetTreeOptions.value).map(- (option) => option.value- );-});--const renderTargetList: TransferRenderSourceList = ({ onCheck }) => {- return h(NTree, {- key: targetCheckedKeys.value.join(","),- style: "margin: 0 4px;",- keyField: "value",- defaultExpandAll: true,- selectable: false,- blockLine: true,- checkable: true,- checkOnClick: true,- cascade: true,- virtualScroll: true,- data: targetTreeOptions.value,- renderLabel: ({ option }: { option: TreeOption }) => {- return h(Label, {- option: option as DatabaseTreeOption,- });- },- checkedKeys: targetCheckedKeys.value,- onUpdateCheckedKeys: (checkedKeys: string[]) => {- onCheck(checkedKeys.filter(isDatabaseTreeValue));- },- });-};--const filterTargetProject = (project: Project) => {- return project.uid !== props.projectId;-};-const doTransfer = async () => {const target = targetProject.value!;if (!target) return;- const databaseList = selectedDatabaseList.value;+ const databaseList = selectedDatabaseList.value.filter(+ (db) => db.project !== target.name+ );try {loading.value = true;- await useDatabaseV1Store().transferDatabases(- selectedDatabaseList.value,- target.name- );- const displayDatabaseName =- databaseList.length > 1- ? `${databaseList.length} databases`- : `'${databaseList[0].databaseName}'`;- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: `Successfully transferred ${displayDatabaseName} to project '${target.title}'.`,- });+ if (databaseList.length > 0) {+ await useDatabaseV1Store().transferDatabases(+ selectedDatabaseList.value,+ target.name+ );+ const displayDatabaseName =+ databaseList.length > 1+ ? `${databaseList.length} databases`+ : `'${databaseList[0].databaseName}'`;++ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: `Successfully transferred ${displayDatabaseName} to project '${target.title}'.`,+ });+ }+emit("dismiss");} finally {loading.value = false;}};</script>--<style>-.bb-transfer-out-database-transfer {- @apply gap-x-8;-}--.bb-transfer-out-database-transfer .n-transfer-list--target {- border-left: 1px solid var(--n-border-color) !important;-}-</style>diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vueindex f460493d23..1916afa2a5 100644--- a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue+++ b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseOperations.vue@@ -53,6 +53,19 @@@apply="onLabelsApply($event)"/>+ <Drawer+ :show="state.showTransferOutDatabaseForm"+ :auto-focus="true"+ @close="state.showTransferOutDatabaseForm = false"+ >+ <TransferOutDatabaseForm+ :project-id="selectedProjectUid"+ :database-list="props.databases"+ :selected-database-uid-list="selectedDatabaseUidList"+ @dismiss="state.showTransferOutDatabaseForm = false"+ />+ </Drawer>+<BBAlertv-if="state.showUnassignAlert":style="'WARN'"@@ -76,10 +89,12 @@ import {TagIcon,PencilIcon,PenSquareIcon,+ ArrowRightLeftIcon,} from "lucide-vue-next";import { computed, h, VNode, reactive, ref } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";+import { Drawer } from "@/components/v2";import {useCurrentUserV1,useCurrentUserIamPolicy,@@ -115,17 +130,23 @@ interface LocalState {showSchemaEditorModal: boolean;showUnassignAlert: boolean;showLabelEditorDrawer: boolean;+ showTransferOutDatabaseForm: boolean;}-const props = defineProps<{- databases: ComposedDatabase[];-}>();+const props = withDefaults(+ defineProps<{+ databases: ComposedDatabase[];+ projectUid?: string;+ }>(),+ { projectUid: "" }+);const state = reactive<LocalState>({loading: false,showSchemaEditorModal: false,showUnassignAlert: false,showLabelEditorDrawer: false,+ showTransferOutDatabaseForm: false,});const schemaEditorContext = ref<{databaseIdList: string[];@@ -167,6 +188,9 @@ const getDisabledTooltip = (action: string) => {};const selectedProjectUid = computed(() => {+ if (props.projectUid) {+ return props.projectUid;+ }if (selectedProjectNames.value.size !== 1) {return "";}@@ -215,10 +239,7 @@ const databaseSupportAlterSchema = computed(() => {const allowEditSchema = computed(() => {return props.databases.every((db) => {- return (- canEditDatabase(db, "bb.permission.project.change-database") &&- instanceV1HasAlterSchema(db.instanceEntity)- );+ return canEditDatabase(db, "bb.permission.project.change-database");});});@@ -335,6 +356,7 @@ const unAssignDatabases = async () => {return;}try {+ state.loading = true;await useDatabaseV1Store().transferDatabases(assignedDatabases.value,DEFAULT_PROJECT_V1_NAME@@ -355,30 +377,50 @@ const unAssignDatabases = async () => {}};+const operationsInProjectDetail = computed(() => !!props.projectUid);+const actions = computed((): DatabaseAction[] => {const resp: DatabaseAction[] = [];if (!isStandaloneMode.value) {- resp.push({- icon: h(RefreshCcwIcon),- text: t("common.sync"),- disabled: props.databases.length < 1,- click: syncSchema,- tooltip: (action) => getDisabledTooltip(action),- });- resp.push({- icon: h(TagIcon),- text: t("database.edit-labels"),- disabled: !allowEditLabels.value || props.databases.length < 1,- click: () => (state.showLabelEditorDrawer = true),- tooltip: (action) => {- if (!allowEditLabels.value) {- return t("database.batch-action-permission-denied", {- action,- });- }- return getDisabledTooltip(action);+ resp.push(+ {+ icon: h(RefreshCcwIcon),+ text: t("common.sync"),+ disabled: props.databases.length < 1,+ click: syncSchema,+ tooltip: (action) => getDisabledTooltip(action),},- });+ {+ icon: h(TagIcon),+ text: t("database.edit-labels"),+ disabled: !allowEditLabels.value || props.databases.length < 1,+ click: () => (state.showLabelEditorDrawer = true),+ tooltip: (action) => {+ if (!allowEditLabels.value) {+ return t("database.batch-action-permission-denied", {+ action,+ });+ }+ return getDisabledTooltip(action);+ },+ }+ );+ if (!operationsInProjectDetail.value) {+ resp.push({+ icon: h(ArrowRightLeftIcon),+ text: t("database.transfer-project"),+ disabled: !allowTransferProject.value || props.databases.length < 1,+ click: () => (state.showTransferOutDatabaseForm = true),+ tooltip: (action) => {+ if (!allowTransferProject.value) {+ return t("database.batch-action-permission-denied", {+ action,+ });+ }+ return getDisabledTooltip(action);+ },+ });+ }}resp.unshift({@@ -387,6 +429,7 @@ const actions = computed((): DatabaseAction[] => {disabled:!allowChangeData.value ||!selectedProjectUid.value ||+ props.databases.length < 1 ||selectedProjectNames.value.has(DEFAULT_PROJECT_V1_NAME),click: () => generateMultiDb("bb.issue.database.data.update"),tooltip: (action) => {@@ -405,6 +448,7 @@ const actions = computed((): DatabaseAction[] => {!databaseSupportAlterSchema.value ||!allowEditSchema.value ||!selectedProjectUid.value ||+ props.databases.length < 1 ||selectedProjectNames.value.has(DEFAULT_PROJECT_V1_NAME),click: () => generateMultiDb("bb.issue.database.schema.update"),tooltip: (action) => {@@ -421,11 +465,11 @@ const actions = computed((): DatabaseAction[] => {});- if (allowTransferProject.value && assignedDatabases.value.length > 0) {+ if (operationsInProjectDetail.value) {resp.push({icon: h(UnlinkIcon),text: t("database.unassign"),- disabled: false,+ disabled: !allowTransferProject.value || props.databases.length < 1,click: () => (state.showUnassignAlert = true),tooltip: (action) => {if (!allowTransferProject.value) {diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 28517736f2..65ed8373f2 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -792,7 +792,7 @@"self": "MD5 mask","salt": "Salt","salt-label": "Salt is used to generate a hash from the original value."- }+ }},"masking-level": {"self": "Masking Level",@@ -1710,8 +1710,10 @@"select-target-project": "Select target project","select-at-least-one-database": "Select at least one database"},+ "select-databases": "Select databases","select-target-project": "Select target project"},+ "transfer-database-to": "Transfer databases to target project","transfer-database-from-to": "Transfer database from source project to target project","classification": {"self": "Classification"diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex fb5e0ed578..2f6359ee35 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1709,8 +1709,10 @@"select-target-project": "Seleccionar proyecto de destino","select-at-least-one-database": "Seleccione al menos una base de datos"},+ "select-databases": "Seleccionar bases de datos","select-target-project": "Seleccionar proyecto de destino"},+ "transfer-database-to": "Transferir bases de datos al proyecto de destino","transfer-database-from-to": "Transferir la base de datos del proyecto de origen al proyecto de destino","classification": {"self": "Clasificación"diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex c6047cd499..37be50e301 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1705,8 +1705,10 @@"select-target-project": "选择目标项目","select-at-least-one-database": "至少选择一个数据库"},+ "select-databases": "选择数据库","select-target-project": "选择目标项目"},+ "transfer-database-to": "将数据库转移到目标项目","transfer-database-from-to": "将数据库从源项目转移到目标项目","classification": {"self": "分类分级"diff --git a/frontend/src/views/ProjectDetail.vue b/frontend/src/views/ProjectDetail.vueindex b66de27e60..09cb687829 100644--- a/frontend/src/views/ProjectDetail.vue+++ b/frontend/src/views/ProjectDetail.vue@@ -9,7 +9,7 @@<ProjectBranchesPanel id="branches" :project="project" /></template><template v-if="hash === 'databases'">- <ProjectDatabasesPanel :database-list="databaseV1List" />+ <ProjectDatabasesPanel :project="project" :database-list="databaseV1List" /></template><template v-if="hash === 'database-groups'"><ProjectDatabaseGroupPanel :project="project" />diff --git a/frontend/src/views/project/ProjectDatabaseDashboard.vue b/frontend/src/views/project/ProjectDatabaseDashboard.vueindex e8d881d217..6c122c245f 100644--- a/frontend/src/views/project/ProjectDatabaseDashboard.vue+++ b/frontend/src/views/project/ProjectDatabaseDashboard.vue@@ -2,7 +2,7 @@<div v-if="showQuickActionPanel" class="flex-1 pb-4"><QuickActionPanel :quick-action-list="quickActionList" /></div>- <ProjectDatabasesPanel :database-list="databaseV1List" />+ <ProjectDatabasesPanel :project="project" :database-list="databaseV1List" /></template><script lang="ts" setup>