Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Move updating data source to data source detail page.
天舟40b4f34614ab
diff --git a/frontend/src/store/modules/dataSource.ts b/frontend/src/store/modules/dataSource.tsindex 9063ac3b1e..004b8328c0 100644--- a/frontend/src/store/modules/dataSource.ts+++ b/frontend/src/store/modules/dataSource.ts@@ -6,7 +6,6 @@ import {DataSourceMember,DataSourceMemberId,DataSourceState,- DataSourceType,InstanceId,ResourceObject,ResourceIdentifier,@@ -49,7 +48,6 @@ function convertMember(const state: () => DataSourceState = () => ({dataSourceListByInstanceId: new Map(),- dataSourceById: new Map(),memberListById: new Map(),});@@ -75,9 +73,32 @@ const getters = {},dataSourceById: (state: DataSourceState) => (- dataSourceId: DataSourceId+ dataSourceId: DataSourceId,+ instanceId?: InstanceId): DataSource | undefined => {- return state.dataSourceById.get(dataSourceId);+ let dataSource = undefined;+ if (instanceId) {+ const list = state.dataSourceListByInstanceId.get(instanceId) || [];+ dataSource = list.find((item) => item.id == dataSourceId);+ } else {+ for (let [_, list] of state.dataSourceListByInstanceId) {+ dataSource = list.find((item) => item.id == dataSourceId);+ if (dataSource) {+ break;+ }+ }+ }+ if (dataSource) {+ return dataSource;+ }+ return {+ id: "-1",+ instanceId: "-1",+ name: "<<Unknown data source>>",+ createdTs: 0,+ lastUpdatedTs: 0,+ type: "RO",+ };},memberListById: (state: DataSourceState) => (@@ -118,10 +139,11 @@ const actions = {).data.data);- commit("setDataSourceById", {- dataSourceId,+ commit("upsertDataSourceInListByInstanceId", {+ instanceId,dataSource,});+return dataSource;},@@ -143,9 +165,9 @@ const actions = {).data.data);- commit("appendDataSourceByInstanceId", {- dataSource: createdDataSource,+ commit("upsertDataSourceInListByInstanceId", {instanceId,+ dataSource: createdDataSource,});return createdDataSource;@@ -176,14 +198,9 @@ const actions = {).data.data);- commit("setDataSourceById", {- instanceId: instanceId,- updatedDataSource,- });-- commit("replaceDataSourceInListByInstanceId", {- instanceId: instanceId,- updatedDataSource,+ commit("upsertDataSourceInListByInstanceId", {+ instanceId,+ dataSource: updatedDataSource,});return updatedDataSource;@@ -200,11 +217,6 @@ const actions = {`/api/instance/${instanceId}/datasource/${dataSourceId}`);- commit("setDataSourceById", {- dataSourceId: dataSourceId,- dataSource: null,- });-commit("deleteDataSourceInListById", dataSourceId);},@@ -265,20 +277,7 @@ const mutations = {state.dataSourceListByInstanceId.set(instanceId, dataSourceList);},- setDataSourceById(- state: DataSourceState,- {- dataSourceId,- dataSource,- }: {- dataSourceId: DataSourceId;- dataSource: DataSource;- }- ) {- state.dataSourceById.set(dataSourceId, dataSource);- },-- appendDataSourceByInstanceId(+ upsertDataSourceInListByInstanceId(state: DataSourceState,{instanceId,@@ -290,30 +289,14 @@ const mutations = {) {const list = state.dataSourceListByInstanceId.get(instanceId);if (list) {- list.push(dataSource);- } else {- state.dataSourceListByInstanceId.set(instanceId, [dataSource]);- }- },-- replaceDataSourceInListByInstanceId(- state: DataSourceState,- {- instanceId,- updatedDataSource,- }: {- instanceId: InstanceId;- updatedDataSource: DataSource;- }- ) {- const list = state.dataSourceListByInstanceId.get(instanceId);- if (list) {- const i = list.findIndex(- (item: DataSource) => item.id == updatedDataSource.id- );+ const i = list.findIndex((item: DataSource) => item.id == dataSource.id);if (i != -1) {- list[i] = updatedDataSource;+ list[i] = dataSource;+ } else {+ list.push(dataSource);}+ } else {+ state.dataSourceListByInstanceId.set(instanceId, [dataSource]);}},diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.tsindex 9cd65d5fe6..0e32ef02ad 100644--- a/frontend/src/types/bytebase.ts+++ b/frontend/src/types/bytebase.ts@@ -380,7 +380,6 @@ export interface InstanceState {export interface DataSourceState {dataSourceListByInstanceId: Map<InstanceId, DataSource[]>;- dataSourceById: Map<DataSourceId, DataSource>;memberListById: Map<DataSourceId, DataSourceMember[]>;}diff --git a/frontend/src/views/DataSourceDetail.vue b/frontend/src/views/DataSourceDetail.vueindex 13e5a97759..9b7c697562 100644--- a/frontend/src/views/DataSourceDetail.vue+++ b/frontend/src/views/DataSourceDetail.vue@@ -35,14 +35,28 @@<div class="flex items-center"><div><div class="flex items-center">- <h1 class="text-xl font-bold leading-7 text-main truncate">+ <input+ v-if="state.editing"+ required+ ref="editNameTextField"+ id="name"+ name="name"+ type="text"+ class="textfield my-0.5 w-full"+ v-model="state.editingDataSource.name"+ />+ <!-- Padding value is to prevent flickering when switching between edit/non-edit mode -->+ <h1+ v-else+ class="pt-2 pb-2.5 text-xl font-bold leading-6 text-main truncate"+ >{{ dataSource.name }}</h1></div><dl class="flex flex-col mt-2 sm:flex-row sm:flex-wrap"><dt class="sr-only">RoleType</dt><dd- class="flex items-center text-sm text-control-light font-medium sm:mr-6"+ class="flex items-center text-sm text-control-light font-medium sm:mr-4"><!-- Heroicon name: solid/pencil --><svg@@ -71,11 +85,13 @@clip-rule="evenodd"></path></svg>- <span v-data-source-type>{{ dataSource.type }}</span>+ <span v-data-source-type class="text-control">{{+ dataSource.type+ }}</span></dd><dt class="sr-only">Instance</dt><dd- class="flex items-center text-sm text-control-light font-medium sm:mr-6"+ class="flex items-center text-sm text-control-light font-medium sm:mr-4"><!-- Heroicon name: solid/database --><svg@@ -104,7 +120,7 @@</dd><dt class="sr-only">Environment</dt><dd- class="flex items-center text-sm text-control-light font-medium sm:mr-6"+ class="flex items-center text-sm text-control-light font-medium"><!-- Heroicon name: solid/globle-alt --><svg@@ -128,7 +144,40 @@</div></div><div class="mt-6 flex space-x-3 md:mt-0 md:ml-4">- <button type="button" class="btn-normal" @click.prevent="editUser">+ <template v-if="state.editing">+ <button+ type="button"+ class="btn-normal"+ @click.prevent="cancelEdit"+ >+ Cancel+ </button>+ <button+ type="button"+ class="btn-normal"+ :disabled="!allowSave"+ @click.prevent="saveEdit"+ >+ <!-- Heroicon name: solid/save -->+ <svg+ class="-ml-1 mr-2 h-5 w-5 text-control-light"+ fill="currentColor"+ viewBox="0 0 20 20"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="M7.707 10.293a1 1 0 10-1.414 1.414l3 3a1 1 0 001.414 0l3-3a1 1 0 00-1.414-1.414L11 11.586V6h5a2 2 0 012 2v7a2 2 0 01-2 2H4a2 2 0 01-2-2V8a2 2 0 012-2h5v5.586l-1.293-1.293zM9 4a1 1 0 012 0v2H9V4z"+ ></path>+ </svg>+ <span>Save</span>+ </button>+ </template>+ <button+ v-else+ type="button"+ class="btn-normal"+ @click.prevent="editDataSource"+ ><!-- Heroicon name: solid/pencil --><svgclass="-ml-1 mr-2 h-5 w-5 text-control-light"@@ -145,22 +194,93 @@</div></div>- <div class="mt-6">+ <form class="mt-6"><div class="max-w-6xl mx-auto px-4"><!-- Description list --><div class="max-w-5xl mx-auto px-4 mb-6"><dl class="grid grid-cols-1 gap-x-4 gap-y-8 sm:grid-cols-2"><div class="sm:col-span-1">- <dt class="text-sm font-medium text-control-light">Username</dt>+ <dt class="text-sm font-medium text-control-light">+ Username<span v-if="state.editing" class="text-red-600"+ >*</span+ >+ </dt><dd class="mt-1 text-sm text-main">- {{ dataSource.username }}+ <input+ v-if="state.editing"+ required+ id="username"+ type="text"+ class="textfield"+ v-model="state.editingDataSource.username"+ />+ <template v-else>+ {{ dataSource.username }}+ </template></dd></div><div class="sm:col-span-1">- <dt class="text-sm font-medium text-control-light">Password</dt>+ <div class="flex items-center space-x-1">+ <dt class="text-sm font-medium text-control-light">+ Password+ </dt>+ <button+ class="btn-icon"+ @click.prevent="state.showPassword = !state.showPassword"+ >+ <svg+ v-if="state.showPassword"+ class="w-5 h-5"+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"+ ></path>+ </svg>+ <svg+ v-else+ class="w-5 h-5"+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"+ ></path>+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"+ ></path>+ </svg>+ </button>+ </div><dd class="mt-1 text-sm text-main">- {{ dataSource.password }}+ <input+ v-if="state.editing"+ required+ autocomplete="off"+ id="password"+ :type="state.showPassword ? 'text' : 'password'"+ class="textfield"+ v-model="state.editingDataSource.password"+ />+ <template v-else-if="state.showPassword">+ {{ dataSource.password }}+ </template>+ <template v-else> ****** </template></dd></div></dl>@@ -171,16 +291,25 @@:dataSourceId="dataSource.id"/></div>- </div>+ </form></main></div></template><script lang="ts">-import { computed } from "vue";+import { computed, nextTick, reactive, ref } from "vue";import { useStore } from "vuex";+import cloneDeep from "lodash-es/cloneDeep";+import isEqual from "lodash-es/isEqual";import DataSourceMemberTable from "../components/DataSourceMemberTable.vue";import { idFromSlug } from "../utils";+import { DataSource } from "../types";++interface LocalState {+ editing: boolean;+ showPassword: boolean;+ editingDataSource?: DataSource;+}export default {name: "DataSourceDetail",@@ -196,10 +325,17 @@ export default {},components: { DataSourceMemberTable },setup(props, ctx) {+ const editNameTextField = ref();+const store = useStore();const instanceId = idFromSlug(props.instanceSlug);const dataSourceId = idFromSlug(props.dataSourceSlug);+ const state = reactive<LocalState>({+ editing: false,+ showPassword: false,+ });+const dataSource = computed(() => {return store.getters["dataSource/dataSourceById"](dataSourceId,@@ -222,10 +358,50 @@ export default {return "* (All databases)";});+ const allowSave = computed(() => {+ return (+ state.editingDataSource!.name &&+ !isEqual(dataSource.value, state.editingDataSource)+ );+ });++ const editDataSource = () => {+ state.editingDataSource = cloneDeep(dataSource.value);+ state.editing = true;++ nextTick(() => editNameTextField.value.focus());+ };++ const cancelEdit = () => {+ state.editingDataSource = undefined;+ state.editing = false;+ };++ const saveEdit = () => {+ store+ .dispatch("dataSource/patchDataSource", {+ instanceId,+ dataSource: state.editingDataSource,+ })+ .then(() => {+ state.editingDataSource = undefined;+ state.editing = false;+ })+ .catch((error) => {+ console.log(error);+ });+ };+return {+ editNameTextField,+ state,dataSource,instance,databaseName,+ allowSave,+ editDataSource,+ cancelEdit,+ saveEdit,};},};diff --git a/frontend/src/views/InstanceDetail.vue b/frontend/src/views/InstanceDetail.vueindex a6fee14500..1a53268de2 100644--- a/frontend/src/views/InstanceDetail.vue+++ b/frontend/src/views/InstanceDetail.vue@@ -13,7 +13,7 @@ input[type="number"] {</style><template>- <form class="px-4 space-y-6 divide-y divide-control-border">+ <form class="px-4 space-y-6"><!-- Instance Name --><div class="grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-6"><div class="sm:col-span-2">@@ -118,7 +118,7 @@ input[type="number"] {</div></div><!-- Read/Write Datasource Info -->- <div class="pt-6">+ <div v-if="state.new" class="py-6 border-t border-b divide-control-border"><div class="flex justify-between"><div><h3 class="text-lg leading-6 font-medium text-gray-900">@@ -174,7 +174,7 @@ input[type="number"] {><svgv-if="state.showPassword"- class="w-7 h-7"+ class="w-6 h-6"fill="none"stroke="currentColor"viewBox="0 0 24 24"@@ -189,7 +189,7 @@ input[type="number"] {</svg><svgv-else- class="w-7 h-7"+ class="w-6 h-6"fill="none"stroke="currentColor"viewBox="0 0 24 24"@@ -217,7 +217,7 @@ input[type="number"] {<!-- Action Button Group --><div><!-- Create button group -->- <div v-if="state.new" class="flex justify-end pt-5">+ <div v-if="state.new" class="flex justify-end"><buttontype="button"class="btn-normal py-2 px-4"@@ -234,7 +234,7 @@ input[type="number"] {</button></div><!-- Update button group -->- <div v-else class="flex justify-between pt-5">+ <div v-else class="flex justify-between"><buttontype="button"class="btn-danger py-2 px-4"@@ -242,27 +242,21 @@ input[type="number"] {>Delete</button>- <div>- <button- type="button"- class="btn-normal py-2 px-4"- @click.prevent="cancel"- >- Cancel- </button>- <button- type="button"- class="btn-primary ml-3 inline-flex justify-center py-2 px-4"- :disabled="!valueChanged"- @click.prevent="doUpdate(state.instance, state.adminDataSource)"- >- Update- </button>- </div>+ <button+ type="button"+ class="btn-primary ml-3 inline-flex justify-center py-2 px-4"+ :disabled="!valueChanged"+ @click.prevent="doUpdate(state.instance)"+ >+ Update+ </button></div></div>- <div v-if="!state.new" class="pt-6 space-y-4">+ <div+ v-if="!state.new"+ class="py-6 space-y-4 border-t divide-control-border"+ ><DataSourceTable :instance="state.instance" /></div></form>@@ -318,7 +312,6 @@ interface LocalState {new: boolean;originalInstance?: Instance;instance?: Instance | InstanceNew;- originalAdminDataSource?: DataSource;adminDataSource?: DataSource | DataSourceNew;showDeleteModal: boolean;showCancelModal: boolean;@@ -375,14 +368,6 @@ export default {state.instance = cloneDeep(state.originalInstance);};- const assignAdminDataSource = (dataSource: DataSource | DataSourceNew) => {- if (!state.new) {- state.originalAdminDataSource = dataSource as DataSource;- }- // Make hard copy since we are going to make equal comparsion to determine the update button enable state.- state.adminDataSource = cloneDeep(state.originalAdminDataSource);- };-const updateInstance = (field: string, value: string) => {(state.instance as any)[field] = value;};@@ -418,25 +403,10 @@ export default {assignInstance(store.getters["instance/instanceById"](idFromSlug(props.instanceSlug)));-- // On the other hand, we need to fetch data source remotely first and- // because the operation is async, we need to have a init object to avoid- // adding v-if="state.adminDataSource" guard- assignAdminDataSource(cloneDeep(INIT_DATA_SOURCE));- const dataSource = store.getters[- "dataSource/adminDataSourceByInstanceId"- ](idFromSlug(props.instanceSlug));- if (dataSource) {- assignAdminDataSource(dataSource);- }}const valueChanged = computed(() => {- return (- state.new ||- !isEqual(state.originalInstance, state.instance) ||- !isEqual(state.originalAdminDataSource, state.adminDataSource)- );+ return state.new || !isEqual(state.originalInstance, state.instance);});const goBack = () => {@@ -485,34 +455,20 @@ export default {});};- const doUpdate = (- updatedInstance: Instance,- updatedAdminDataSource: DataSource- ) => {+ const doUpdate = (updatedInstance: Instance) => {store.dispatch("instance/patchInstance", updatedInstance).then((instance) => {assignInstance(instance);- store- .dispatch("dataSource/patchDataSource", {- instanceId: updatedInstance.id,- dataSource: updatedAdminDataSource,- })- .then((dataSource) => {- assignAdminDataSource(dataSource);- store.dispatch("notification/pushNotification", {- module: "bytebase",- style: "SUCCESS",- title: `Successfully updated instance '${updatedInstance.name}'.`,- });- router.push({- name: "workspace.instance",- });- })- .catch((error) => {- console.log(error);- });+ store.dispatch("notification/pushNotification", {+ module: "bytebase",+ style: "SUCCESS",+ title: `Successfully updated instance '${updatedInstance.name}'.`,+ });+ router.push({+ name: "workspace.instance",+ });}).catch((error) => {console.log(error);@@ -521,28 +477,18 @@ export default {const doDelete = () => {store- .dispatch("dataSource/deleteDataSourceById", {- id: state.originalAdminDataSource!.id,- instanceId: state.originalInstance!.id,- })+ .dispatch("instance/deleteInstanceById", state.originalInstance!.id).then(() => {- store- .dispatch("instance/deleteInstanceById", state.originalInstance!.id)- .then(() => {- store.dispatch("notification/pushNotification", {- module: "bytebase",- style: "SUCCESS",- title: `Successfully deleted instance '${- state.originalInstance!.name- }'.`,- });- router.push({- name: "workspace.instance",- });- })- .catch((error) => {- console.log(error);- });+ store.dispatch("notification/pushNotification", {+ module: "bytebase",+ style: "SUCCESS",+ title: `Successfully deleted instance '${+ state.originalInstance!.name+ }'.`,+ });+ router.push({+ name: "workspace.instance",+ });}).catch((error) => {console.log(error);