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: delete read-only data source in UI (#2942)
boojack8f4ce1a85303
diff --git a/frontend/src/bbkit/BBButtonConfirm.vue b/frontend/src/bbkit/BBButtonConfirm.vueindex 24750ef558..68a898b30e 100644--- a/frontend/src/bbkit/BBButtonConfirm.vue+++ b/frontend/src/bbkit/BBButtonConfirm.vue@@ -1,7 +1,8 @@<template><button+ v-bind="$attrs"class="btn-icon text-sm"- @click.prevent="+ @click.prevent.stop="() => {if (requireConfirm) {state.showModal = true;diff --git a/frontend/src/components/InstanceForm.vue b/frontend/src/components/InstanceForm.vueindex 443033f45e..35ef6832c9 100644--- a/frontend/src/components/InstanceForm.vue+++ b/frontend/src/components/InstanceForm.vue@@ -148,8 +148,8 @@</p><div- v-if="!hasReadonlyDataSource"- class="flex flex-row justify-start items-center bg-yellow-50 border-none rounded-lg p-2 px-3 mt-0"+ v-if="!hasReadOnlyDataSource"+ class="mt-2 flex flex-row justify-start items-center bg-yellow-50 border-none rounded-lg p-2 px-3"><heroicons-outline:exclamationclass="h-6 w-6 text-yellow-400 flex-shrink-0 mr-1"@@ -176,7 +176,20 @@@update:value="handleDataSourceTypeChange"><NTab name="ADMIN">Admin</NTab>- <NTab name="RO" :disabled="!hasReadonlyDataSource">Read only</NTab>+ <NTab name="RO" class="relative" :disabled="!hasReadOnlyDataSource">+ <span>Read only</span>+ <BBButtonConfirm+ v-if="hasReadOnlyDataSource"+ :style="'DELETE'"+ class="absolute left-full ml-1"+ :require-confirm="currentDataSource.id !== UNKNOWN_ID"+ :ok-text="$t('common.delete')"+ :confirm-title="+ $t('data-source.delete-read-only-data-source') + '?'+ "+ @confirm="handleDeleteReadOnlyDataSource"+ />+ </NTab></NTabs><CreateDataSourceExampleclassName="sm:col-span-3 border-none mt-2"@@ -372,6 +385,7 @@ import {DataSource,UNKNOWN_ID,DataSourceCreate,+ DataSourcePatch,} from "../types";import isEmpty from "lodash-es/isEmpty";import { useI18n } from "vue-i18n";@@ -384,6 +398,7 @@ import {useInstanceStore,useSQLStore,} from "@/store";+import { isNullOrUndefined } from "@/plugins/demo/utils";interface EditDataSource extends DataSource {updatedPassword: string;@@ -476,7 +491,7 @@ const adminDataSource = computed(() => {return temp;});-const hasReadonlyDataSource = computed(() => {+const hasReadOnlyDataSource = computed(() => {for (const ds of state.dataSourceList) {if (ds.type === "RO") {return true;@@ -563,6 +578,28 @@ const handleCurrentDataSourcePortOverrideInput = (event: Event) => {updateInstanceDataSource();};+const handleDeleteReadOnlyDataSource = async () => {+ const dataSource = state.dataSourceList.find(+ (item) => item.type === "RO"+ ) as DataSource;+ if (isNullOrUndefined(dataSource)) {+ return;+ }+ if (dataSource.type !== "RO") {+ return;+ }++ if (dataSource.id !== UNKNOWN_ID) {+ await dataSourceStore.deleteDataSourceById({+ databaseId: dataSource.databaseId,+ dataSourceId: dataSource.id,+ });+ }++ state.currentDataSourceType = "ADMIN";+ await updateInstanceState();+};+const handleEditSsl = (edit: boolean) => {const curr = currentDataSource.value;if (!edit) {@@ -593,18 +630,8 @@ const updateInstanceDataSource = () => {const newValue = {...state.instance.dataSourceList[index],username: curr.username,- hostOverride: curr.hostOverride,- portOverride: curr.portOverride,};- if (!hasFeature("bb.feature.read-replica-connection")) {- if (newValue.hostOverride || newValue.portOverride) {- currentDataSource.value.hostOverride = "";- currentDataSource.value.portOverride = "";- state.showFeatureModal = true;- }- }-if (curr.useEmptyPassword) {// When 'Password: Empty' is checked, we set the password to empty string.newValue.password = "";@@ -626,6 +653,19 @@ const updateInstanceDataSource = () => {delete newValue.sslCert;delete newValue.sslKey;}++ if (curr.type === "RO") {+ if (!hasFeature("bb.feature.read-replica-connection")) {+ if (curr.hostOverride || curr.portOverride) {+ state.dataSourceList[index].hostOverride = "";+ state.dataSourceList[index].portOverride = "";+ newValue.hostOverride = "";+ newValue.portOverride = "";+ state.showFeatureModal = true;+ }+ }+ }+state.instance.dataSourceList[index] = newValue;};@@ -639,12 +679,12 @@ const handleCreateDataSource = (type: DataSourceType) => {username: "",password: "",} as DataSource;- state.instance.dataSourceList.push(tempDataSource);state.dataSourceList.push({...tempDataSource,updatedPassword: "",useEmptyPassword: false,});+ state.instance.dataSourceList = state.dataSourceList;state.currentDataSourceType = type;};@@ -661,11 +701,34 @@ const updateInstance = (field: string, value: string) => {(state.instance as any)[field] = str;};+const updateInstanceState = async () => {+ const instance = await instanceStore.fetchInstanceById(state.instance.id);+ state.originalInstance = instance;+ state.instance = cloneDeep(state.originalInstance);+ state.dataSourceList = instance.dataSourceList.map((dataSource) => {+ return {+ ...cloneDeep(dataSource),+ updatedPassword: "",+ useEmptyPassword: false,+ } as EditDataSource;+ });+ useDatabaseStore().fetchDatabaseListByInstanceId(instance.id);+ useInstanceStore().fetchInstanceUserListById(instance.id);++ const reloadDatabaseAndUser = connectionInfoChanged.value;+ // Backend will sync the schema upon connection info change, so here we try to fetch the synced schema.+ if (reloadDatabaseAndUser) {+ await useDatabaseStore().fetchDatabaseListByInstanceId(instance.id);+ await useInstanceStore().fetchInstanceUserListById(instance.id);+ }++ return instance;+};+const doUpdate = () => {const patchedInstance: InstancePatch = {};let instanceInfoChanged = false;let dataSourceListChanged = false;- const reloadDatabaseAndUser = connectionInfoChanged.value;if (state.instance.name != state.originalInstance.name) {patchedInstance.name = state.instance.name;@@ -727,11 +790,19 @@ const doUpdate = () => {} else if (!isEqual(dataSource, state.originalInstance.dataSourceList[i])) {+ const dataSourcePatch: DataSourcePatch = {+ ...dataSource,+ };+ if (dataSource.type !== "RO") {+ dataSourcePatch.hostOverride = undefined;+ dataSourcePatch.portOverride = undefined;+ }+requests.push(dataSourceStore.patchDataSource({databaseId: dataSource.databaseId,dataSourceId: dataSource.id,- dataSource: { ...dataSource },+ dataSourcePatch: dataSourcePatch,}));}@@ -748,18 +819,8 @@ const doUpdate = () => {}Promise.all(requests).then(() => {- instanceStore- .fetchInstanceById(state.instance.id)+ updateInstanceState().then((instance) => {- state.originalInstance = instance;- state.instance = cloneDeep(state.originalInstance);- state.dataSourceList = instance.dataSourceList.map((dataSource) => {- return {- ...cloneDeep(dataSource),- updatedPassword: "",- useEmptyPassword: false,- } as EditDataSource;- });pushNotification({module: "bytebase",style: "SUCCESS",@@ -767,12 +828,6 @@ const doUpdate = () => {instance.name,]),});-- // Backend will sync the schema upon connection info change, so here we try to fetch the synced schema.- if (reloadDatabaseAndUser) {- useDatabaseStore().fetchDatabaseListByInstanceId(instance.id);- useInstanceStore().fetchInstanceUserListById(instance.id);- }}).finally(() => {state.isUpdating = false;diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 278cfca1cc..bc55a79068 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1235,7 +1235,8 @@},"ssl-connection": "SSL Connection","read-replica-host": "Read-replica Host",- "read-replica-port": "Read-replica Port"+ "read-replica-port": "Read-replica Port",+ "delete-read-only-data-source": "Delete read-only data source"},"setting": {"project": {diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 5ae7c86062..22f6ff865c 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1235,7 +1235,8 @@},"ssl-connection": "SSL 连接","read-replica-host": "只读副本 Host",- "read-replica-port": "只读副本端口"+ "read-replica-port": "只读副本端口",+ "delete-read-only-data-source": "删除只读数据源"},"setting": {"project": {diff --git a/frontend/src/store/modules/dataSource.ts b/frontend/src/store/modules/dataSource.tsindex 39f7d6d489..4e81b50a0c 100644--- a/frontend/src/store/modules/dataSource.ts+++ b/frontend/src/store/modules/dataSource.ts@@ -121,11 +121,11 @@ export const useDataSourceStore = defineStore("dataSource", {async patchDataSource({databaseId,dataSourceId,- dataSource,+ dataSourcePatch,}: {databaseId: DatabaseId;dataSourceId: DataSourceId;- dataSource: DataSourcePatch;+ dataSourcePatch: DataSourcePatch;}) {const data = (await axios.patch(@@ -133,7 +133,7 @@ export const useDataSourceStore = defineStore("dataSource", {{data: {type: "dataSourcePatch",- attributes: dataSource,+ attributes: dataSourcePatch,},})diff --git a/frontend/src/types/dataSource.ts b/frontend/src/types/dataSource.tsindex 900625c276..372427edff 100644--- a/frontend/src/types/dataSource.ts+++ b/frontend/src/types/dataSource.ts@@ -70,8 +70,8 @@ export type DataSourcePatch = {sslCa?: string;sslCert?: string;sslKey?: string;- hostOverride: string;- portOverride: string;+ hostOverride?: string;+ portOverride?: string;};export type DataSourceMember = {