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 data source ui (#11615)
ecmadao7933a003dd50
diff --git a/frontend/src/components/CreateDataSourceExample.vue b/frontend/src/components/CreateDataSourceExample.vueindex 78ad372fe8..6f2e2346d4 100644--- a/frontend/src/components/CreateDataSourceExample.vue+++ b/frontend/src/components/CreateDataSourceExample.vue@@ -1,5 +1,9 @@<template>- <div class="w-full flex flex-col justify-start" :class="props.className">+ <div+ v-if="grantStatement"+ class="w-full flex flex-col justify-start"+ :class="props.className"+ ><p class="w-full mt-1 text-sm text-gray-500"><template v-if="isEngineUsingSQL">{{@@ -82,9 +86,12 @@</template><template v-else-if="props.engine === Engine.POSTGRES"><BBAttention- class="mb-1"+ class="my-3"type="warning"- :title="$t('instance.sentence.create-user-example.postgresql.warn')"+ :title="$t('instance.connection-info')"+ :description="+ $t('instance.sentence.create-user-example.postgresql.warn')+ "/><i18n-ttag="p"@@ -125,11 +132,16 @@<!-- TODO(xz): add a "detailed guide" link to docs here --></template><div class="mt-2 flex flex-row">- <span+ <NConfigProviderclass="flex-1 min-w-0 w-full inline-flex items-center px-3 py-2 border border-r border-control-border bg-gray-50 sm:text-sm whitespace-pre-line rounded-l-[3px]"+ :hljs="hljs">- {{ grantStatement(props.engine, props.dataSourceType) }}- </span>+ <NCode+ word-wrap+ :language="languageOfEngineV1(engine)"+ :code="grantStatement"+ />+ </NConfigProvider><buttontabindex="-1"class="-ml-px px-2 py-2 border border-gray-300 text-sm font-medium text-control-light disabled:text-gray-300 bg-gray-50 hover:bg-gray-100 disabled:bg-gray-50 focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-1 disabled:cursor-not-allowed rounded-r-[3px]"@@ -143,7 +155,8 @@</template><script lang="ts" setup>-import type { PropType } from "vue";+import hljs from "highlight.js/lib/core";+import { NCode, NConfigProvider } from "naive-ui";import { reactive, computed } from "vue";import { useI18n } from "vue-i18n";import { pushNotification } from "@/store";@@ -156,24 +169,20 @@ interface LocalState {showCreateUserExample: boolean;}-const props = defineProps({- className: {- type: String,- default: "",- },- createInstanceFlag: {- type: Boolean,- default: false,- },- engine: {- type: Number as PropType<Engine>,- default: Engine.MYSQL,- },- dataSourceType: {- type: Number as PropType<DataSourceType>,- default: DataSourceType.ADMIN,- },-});+const props = withDefaults(+ defineProps<{+ className?: string;+ createInstanceFlag: boolean;+ engine: Engine;+ dataSourceType: DataSourceType;+ }>(),+ {+ className: "",+ createInstanceFlag: false,+ engine: Engine.MYSQL,+ dataSourceType: DataSourceType.ADMIN,+ }+);const { t } = useI18n();@@ -185,12 +194,9 @@ const isEngineUsingSQL = computed(() => {return languageOfEngineV1(props.engine) === "sql";});-const grantStatement = (- engine: Engine,- dataSourceType: DataSourceType-): string => {- if (dataSourceType === DataSourceType.ADMIN) {- switch (engine) {+const grantStatement = computed(() => {+ if (props.dataSourceType === DataSourceType.ADMIN) {+ switch (props.engine) {case Engine.MYSQL:// RELOAD, LOCK TABLES: enables use of explicit LOCK TABLES statements for backups.// REPLICATION CLIENT: enables use of the SHOW MASTER STATUS, SHOW SLAVE STATUS, and SHOW BINARY LOGS statements.@@ -306,7 +312,17 @@ GRANT ALL PRIVILEGES ON PIPE {{PIPE_NAME}} IN DATABASE {{YOUR_DB_NAME}} TO ROLEcase Engine.REDSHIFT:return "CREATE USER bytebase WITH PASSWORD 'YOUR_DB_PWD' CREATEUSER CREATEDB;";case Engine.MONGODB:- return 'use admin;\ndb.createUser({\n\tuser: "bytebase", \n\tpwd: "YOUR_DB_PWD", \n\troles: [\n\t\t{role: "readWriteAnyDatabase", db: "admin"},\n\t\t{role: "dbAdminAnyDatabase", db: "admin"},\n\t\t{role: "userAdminAnyDatabase", db: "admin"}\n\t]\n});';+ return `use admin;+db.createUser({+ user: "bytebase",+ pwd: "YOUR_DB_PWD",+ roles: [+ {role: "readWriteAnyDatabase", db: "admin"},+ {role: "dbAdminAnyDatabase", db: "admin"},+ {role: "userAdminAnyDatabase", db: "admin"}+ ]+});+`;case Engine.SPANNER:return "";case Engine.REDIS:@@ -321,7 +337,7 @@ GRANT ALL PRIVILEGES ON PIPE {{PIPE_NAME}} IN DATABASE {{YOUR_DB_NAME}} TO ROLEreturn "CREATE USER bytebase IDENTIFIED BY 'YOUR_DB_PWD';\nGRANT ALL PRIVILEGES TO bytebase;";}} else {- switch (engine) {+ switch (props.engine) {case Engine.MYSQL:case Engine.TIDB:case Engine.OCEANBASE:@@ -434,14 +450,14 @@ GRANT ALL PRIVILEGES ON PIPE {{PIPE_NAME}} IN DATABASE {{YOUR_DB_NAME}} TO ROLE}}return ""; // fallback-};+});const toggleCreateUserExample = () => {state.showCreateUserExample = !state.showCreateUserExample;};const copyGrantStatement = () => {- toClipboard(grantStatement(props.engine, props.dataSourceType)).then(() => {+ toClipboard(grantStatement.value).then(() => {pushNotification({module: "bytebase",style: "INFO",diff --git a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vueindex 4add774e14..88fd86d99c 100644--- a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue+++ b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue@@ -373,22 +373,20 @@class="ml-1 text-sm"/></div>- <div>- <DroppableTextarea- v-model:value="dataSource.authenticationPrivateKey"- :resizable="false"- class="w-full h-32 whitespace-pre-wrap"- placeholder="-----BEGIN PRIVATE KEY-----+ <DroppableTextarea+ v-model:value="dataSource.authenticationPrivateKey"+ :resizable="false"+ class="w-full h-32 mt-2 whitespace-pre-wrap"+ placeholder="-----BEGIN PRIVATE KEY-----MIIEvQ...-----END PRIVATE KEY-----"- :allow-edit="allowEdit"- />- </div>+ :allow-edit="allowEdit"+ /></div></template><template v-if="showAuthenticationDatabase">- <div class="sm:col-span-3 sm:col-start-1">+ <div class="mt-4 sm:col-span-3 sm:col-start-1"><div class="flex flex-row items-center space-x-2"><label for="authenticationDatabase" class="textlabel block">{{ $t("instance.authentication-database") }}diff --git a/frontend/src/components/InstanceForm/DataSourceSection/OracleSIDAndServiceNameInput.vue b/frontend/src/components/InstanceForm/DataSourceSection/OracleSIDAndServiceNameInput.vueindex dfba1b8ee0..29ab006ad8 100644--- a/frontend/src/components/InstanceForm/DataSourceSection/OracleSIDAndServiceNameInput.vue+++ b/frontend/src/components/InstanceForm/DataSourceSection/OracleSIDAndServiceNameInput.vue@@ -1,5 +1,5 @@<template>- <div class="mt-2 sm:col-span-1 sm:col-start-1">+ <div class="mt-2 sm:col-span-3 sm:col-start-1"><div class="flex items-center gap-x-4"><NRadio:checked="state.mode === 'ServiceName'"diff --git a/frontend/src/components/InstanceForm/DataSourceSection/SpannerCredentialInput.vue b/frontend/src/components/InstanceForm/DataSourceSection/SpannerCredentialInput.vueindex 30875a6698..cd56028d60 100644--- a/frontend/src/components/InstanceForm/DataSourceSection/SpannerCredentialInput.vue+++ b/frontend/src/components/InstanceForm/DataSourceSection/SpannerCredentialInput.vue@@ -19,7 +19,7 @@:value="value":resizable="false":placeholder="placeholder"- class="w-full h-24 whitespace-pre-wrap"+ class="w-full h-24 mt-2 whitespace-pre-wrap"@update:value="$emit('update:value', $event ?? '')"/></div>diff --git a/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vueindex 08b2c9e95a..0bd157a35b 100644--- a/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue+++ b/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue@@ -21,7 +21,7 @@</label><NInputv-model:value="state.value.sshHost"- class="mt-1 w-full"+ class="mt-2 w-full":placeholder="''"/></div>@@ -32,7 +32,7 @@</label><NInputv-model:value="state.value.sshPort"- class="mt-1 w-full"+ class="mt-2 w-full":placeholder="''":allow-input="onlyAllowNumber"/>@@ -42,23 +42,23 @@<divclass="mt-2 grid grid-cols-1 gap-y-2 gap-x-4 border-none sm:grid-cols-3">- <div class="mt-2 sm:col-span-1 sm:col-start-1">+ <div class="mt-2 sm:col-span-3 sm:col-start-1"><label for="sshUser" class="textlabel block">{{ $t("data-source.ssh.user") }}</label><NInputv-model:value="state.value.sshUser"- class="mt-1 w-full"+ class="mt-2 w-full":placeholder="''"/></div>- <div class="mt-2 sm:col-span-1 sm:col-start-1">+ <div class="mt-2 sm:col-span-3 sm:col-start-1"><label for="sshPassword" class="textlabel block">{{ $t("data-source.ssh.password") }}</label><NInputv-model:value="state.value.sshPassword"- class="mt-1 w-full"+ class="mt-2 w-full":placeholder="$t('instance.password-write-only')"/></div>@@ -67,14 +67,14 @@v-if="state.type === 'TUNNEL+PK'"class="mt-4 sm:col-span-3 sm:col-start-1">- <div class="mt-2 sm:col-span-1 sm:col-start-1 flex flex-col gap-y-1">+ <div class="mt-2 sm:col-span-1 sm:col-start-1 flex flex-col"><label for="sshPrivateKey" class="textlabel block">{{ $t("data-source.ssh.ssh-key") }}</label><DroppableTextareav-model:value="state.value.sshPrivateKey":resizable="false"- class="w-full h-24 whitespace-pre-wrap"+ class="w-full h-24 mt-2 whitespace-pre-wrap"/></div></div>diff --git a/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vueindex 0d608195ac..43eb66214f 100644--- a/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue+++ b/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue@@ -11,8 +11,16 @@<span class="textlabel">{{ getSslTypeLabel(type) }}</span></NRadio></NRadioGroup>++ <DroppableTextarea+ v-if="state.type === 'CA'"+ v-model:value="state.value.sslCa"+ :resizable="false"+ class="w-full h-24 mt-4 whitespace-pre-wrap"+ placeholder="Input or drag and drop YOUR_CA_CERTIFICATE"+ /><NTabs- v-if="state.type === 'CA' || state.type === 'CA+KEY+CERT'"+ v-else-if="state.type === 'CA+KEY+CERT'"v-model:value="state.tab"class="mt-2"pane-style="padding-top: 0.25rem"diff --git a/frontend/src/components/InstanceForm/InstanceForm.vue b/frontend/src/components/InstanceForm/InstanceForm.vueindex c7992aa204..f20ddf3463 100644--- a/frontend/src/components/InstanceForm/InstanceForm.vue+++ b/frontend/src/components/InstanceForm/InstanceForm.vue@@ -172,18 +172,18 @@>{{ $t("data-source.connection-string-schema") }}</label>- <div class="flex flex-col gap-y-1 mt-1">+ <NRadioGroup+ :value="currentMongoDBConnectionSchema"+ @update:value="handleMongodbConnectionStringSchemaChange"+ ><NRadiov-for="type in MongoDBConnectionStringSchemaList":key="type"- :checked="type === currentMongoDBConnectionSchema"- @update:checked="- handleMongodbConnectionStringSchemaChange(type, $event)- "+ :value="type"><span class="textlabel">{{ type }}</span></NRadio>- </div>+ </NRadioGroup></div><ScanIntervalInput@@ -337,7 +337,7 @@<script lang="ts" setup>import { cloneDeep, isEqual, omit } from "lodash-es";-import { NButton, NInput, NSwitch } from "naive-ui";+import { NButton, NInput, NSwitch, NRadioGroup, NRadio } from "naive-ui";import { Status } from "nice-grpc-common";import type { PropType } from "vue";import { computed, reactive, ref, watch, onMounted, toRef } from "vue";@@ -622,6 +622,7 @@ const handleSelectEnvironmentUID = (uid: string | undefined) => {// The default host name is 127.0.0.1 or host.docker.internal which is not applicable to Snowflake, so we change// the host name between 127.0.0.1/host.docker.internal and "" if user hasn't changed default yet.const changeInstanceEngine = (engine: Engine) => {+ context.resetDataSource();if (engine === Engine.SNOWFLAKE || engine === Engine.SPANNER) {if (adminDataSource.value.host === "127.0.0.1" ||@@ -658,11 +659,7 @@ const changeMaximumConnections = (maximumConnections: number) => {basicInfo.value.options.maximumConnections = maximumConnections;};-const handleMongodbConnectionStringSchemaChange = (- type: string,- on: boolean-) => {- if (!on) return;+const handleMongodbConnectionStringSchemaChange = (type: string) => {const ds = editingDataSource.value;if (!ds) return;switch (type) {diff --git a/frontend/src/components/InstanceForm/OracleSyncModeInput.vue b/frontend/src/components/InstanceForm/OracleSyncModeInput.vueindex 9ccb33737b..a2e3d02ec8 100644--- a/frontend/src/components/InstanceForm/OracleSyncModeInput.vue+++ b/frontend/src/components/InstanceForm/OracleSyncModeInput.vue@@ -28,7 +28,7 @@</label></div>- <label class="text-xs text-control-light ml-[1.5rem]">+ <label class="text-xs text-control-light"><template v-if="state.mode === 'DATABASE'">{{ $t("instance.sync-mode.database.description") }}</template>diff --git a/frontend/src/components/InstanceForm/context.ts b/frontend/src/components/InstanceForm/context.tsindex 6893b3df0c..f6ce771c8f 100644--- a/frontend/src/components/InstanceForm/context.ts+++ b/frontend/src/components/InstanceForm/context.ts@@ -30,6 +30,7 @@ export type InstanceFormContext = {editingDataSource: ComputedRef<EditDataSource | undefined>;readonlyDataSourceList: ComputedRef<EditDataSource[]>;hasReadOnlyDataSource: ComputedRef<boolean>;+ resetDataSource: () => void;};const KEY = Symbol(@@ -79,6 +80,9 @@ export const provideInstanceFormContext = ();});+ const resetDataSource = () => {+ dataSourceEditState.value = extractDataSourceEditState(instance.value);+ };const missingFeature = ref<FeatureType | undefined>(undefined);const context: InstanceFormContext = {@@ -93,6 +97,7 @@ export const provideInstanceFormContext = (hasReadOnlyDataSource,hasReadonlyReplicaFeature,missingFeature,+ resetDataSource,};provide(KEY, context);