Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(frontend): Spanner UI improvement (#4613)

Liu Jiafa313c2cc96
diff --git a/frontend/src/components/CreateInstanceForm.vue b/frontend/src/components/CreateInstanceForm.vue
index b612b31492..3f0a2886db 100644
--- a/frontend/src/components/CreateInstanceForm.vue
+++ b/frontend/src/components/CreateInstanceForm.vue
@@ -67,54 +67,44 @@
</div>
<div class="sm:col-span-3 sm:col-start-1">
- <label for="host" class="textlabel block">
- <template v-if="state.instance.engine == 'SNOWFLAKE'">
- {{ $t("instance.account-name") }}
- <span style="color: red">*</span>
- </template>
- <template v-else-if="state.instance.engine == 'SPANNER'">
- {{ $t("instance.project-id-and-instance-id") }}
- <span style="color: red">*</span>
- <p class="text-sm text-gray-500 mt-1">
- {{ $t("instance.find-gcp-project-id-and-instance-id") }}
- <a
- href="https://www.bytebase.com/docs/how-to/spanner/how-to-find-project-id-and-instance-id"
- target="_blank"
- class="normal-link inline-flex items-center"
- >
- {{ $t("common.detailed-guide")
- }}<heroicons-outline:external-link class="w-4 h-4 ml-1"
- /></a>
- </p>
- </template>
- <template v-else>
- {{ $t("instance.host-or-socket") }}
- <span style="color: red">*</span>
- </template>
- </label>
- <input
- id="host"
- required
- type="text"
- name="host"
- :placeholder="
- state.instance.engine == 'SNOWFLAKE'
- ? $t('instance.your-snowflake-account-name')
- : state.instance.engine === 'SPANNER'
- ? 'projects/<projectID>/instances/<instanceID>'
- : $t('instance.sentence.host.snowflake')
- "
- class="textfield mt-1 w-full"
- :disabled="!allowEdit"
- :value="state.instance.host"
- @input="handleInstanceHostInput"
+ <template v-if="state.instance.engine !== 'SPANNER'">
+ <label for="host" class="textlabel block">
+ <template v-if="state.instance.engine == 'SNOWFLAKE'">
+ {{ $t("instance.account-name") }}
+ <span style="color: red">*</span>
+ </template>
+ <template v-else>
+ {{ $t("instance.host-or-socket") }}
+ <span style="color: red">*</span>
+ </template>
+ </label>
+ <input
+ id="host"
+ required
+ type="text"
+ name="host"
+ :placeholder="
+ state.instance.engine == 'SNOWFLAKE'
+ ? $t('instance.your-snowflake-account-name')
+ : $t('instance.sentence.host.snowflake')
+ "
+ class="textfield mt-1 w-full"
+ :disabled="!allowEdit"
+ :value="state.instance.host"
+ @input="handleInstanceHostInput"
+ />
+ <div
+ v-if="state.instance.engine == 'SNOWFLAKE'"
+ class="mt-2 textinfolabel"
+ >
+ {{ $t("instance.sentence.proxy.snowflake") }}
+ </div>
+ </template>
+ <SpannerHostInput
+ v-else
+ v-model:host="state.instance.host"
+ :allow-edit="allowEdit"
/>
- <div
- v-if="state.instance.engine == 'SNOWFLAKE'"
- class="mt-2 textinfolabel"
- >
- {{ $t("instance.sentence.proxy.snowflake") }}
- </div>
</div>
<template v-if="state.instance.engine !== 'SPANNER'">
@@ -206,26 +196,13 @@
</div>
</template>
- <div class="sm:col-span-1 sm:col-start-1">
+ <div
+ v-if="state.instance.engine !== 'SPANNER'"
+ class="sm:col-span-1 sm:col-start-1"
+ >
<div class="flex flex-row items-center space-x-2">
<label for="password" class="textlabel block">
- <template v-if="state.instance.engine == 'SPANNER'">
- {{ $t("common.credentials") }}
- <span class="text-red-600">*</span>
- <p class="text-sm text-gray-500 mt-1">
- {{ $t("instance.create-gcp-credentials") }}
- <a
- href="https://www.bytebase.com/docs/how-to/spanner/how-to-create-a-service-account-for-bytebase"
- target="_blank"
- class="normal-link inline-flex items-center"
- >{{ $t("common.detailed-guide") }}
- <heroicons-outline:external-link class="w-4 h-4 ml-1"
- /></a>
- </p>
- </template>
- <template v-else>
- {{ $t("common.password") }}
- </template>
+ {{ $t("common.password") }}
</label>
</div>
<input
@@ -234,16 +211,20 @@
type="text"
class="textfield mt-1 w-full"
autocomplete="off"
- :placeholder="
- state.instance.engine === 'SPANNER'
- ? $t('instance.credentials-write-only')
- : $t('instance.password-write-only')
- "
+ :placeholder="$t('instance.password-write-only')"
:value="state.instance.password"
@input="handleInstancePasswordInput"
/>
</div>
+ <SpannerCredentialInput
+ v-else
+ :value="state.instance.password ?? ''"
+ :write-only="false"
+ class="mt-2 sm:col-span-3 sm:col-start-1"
+ @update:value="(value) => (state.instance.password = value)"
+ />
+
<div v-if="showDatabase" class="sm:col-span-1 sm:col-start-1">
<div class="flex flex-row items-center space-x-2">
<label for="database" class="textlabel block">
@@ -369,7 +350,11 @@ import { computed, reactive, ref, watch } from "vue";
import { useRouter } from "vue-router";
import EnvironmentSelect from "./EnvironmentSelect.vue";
import CreateDataSourceExample from "./CreateDataSourceExample.vue";
-import { SslCertificateForm } from "./InstanceForm";
+import {
+ SpannerHostInput,
+ SpannerCredentialInput,
+ SslCertificateForm,
+} from "./InstanceForm";
import { instanceSlug, isDev } from "../utils";
import {
InstanceCreate,
diff --git a/frontend/src/components/InstanceForm.vue b/frontend/src/components/InstanceForm.vue
index 967bbbf7a1..dd06adab6c 100644
--- a/frontend/src/components/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm.vue
@@ -43,54 +43,45 @@
</div>
<div class="sm:col-span-3 sm:col-start-1">
- <label for="host" class="textlabel block">
- <template v-if="state.instance.engine == 'SNOWFLAKE'">
- {{ $t("instance.account-name") }}
- <span class="text-red-600 mr-2">*</span>
- </template>
- <template v-else-if="state.instance.engine === 'SPANNER'">
- {{ $t("instance.project-id-and-instance-id") }}
- <span style="color: red">*</span>
- <p class="text-sm text-gray-500 mt-1">
- {{ $t("instance.find-gcp-project-id-and-instance-id") }}
- <a
- href="https://www.bytebase.com/docs/how-to/spanner/how-to-find-project-id-and-instance-id"
- target="_blank"
- class="normal-link inline-flex items-center"
- >
- {{ $t("common.detailed-guide")
- }}<heroicons-outline:external-link class="w-4 h-4 ml-1"
- /></a>
- </p>
- </template>
- <template v-else>
- {{ $t("instance.host-or-socket") }}
- <span class="text-red-600 mr-2">*</span>
- </template>
- </label>
- <input
- id="host"
- required
- type="text"
- name="host"
- :placeholder="
- state.instance.engine == 'SNOWFLAKE'
- ? $t('instance.your-snowflake-account-name')
- : state.instance.engine === 'SPANNER'
- ? 'projects/<projectID>/instances/<instanceID>'
- : $t('instance.sentence.host.snowflake')
- "
- class="textfield mt-1 w-full"
- :disabled="!allowEdit"
- :value="adminDataSource.host"
- @input="handleInstanceHostInput"
+ <template v-if="state.instance.engine !== 'SPANNER'">
+ <label for="host" class="textlabel block">
+ <template v-if="state.instance.engine == 'SNOWFLAKE'">
+ {{ $t("instance.account-name") }}
+ <span class="text-red-600 mr-2">*</span>
+ </template>
+ <template v-else>
+ {{ $t("instance.host-or-socket") }}
+ <span class="text-red-600 mr-2">*</span>
+ </template>
+ </label>
+ <input
+ id="host"
+ required
+ type="text"
+ name="host"
+ :placeholder="
+ state.instance.engine == 'SNOWFLAKE'
+ ? $t('instance.your-snowflake-account-name')
+ : $t('instance.sentence.host.snowflake')
+ "
+ class="textfield mt-1 w-full"
+ :disabled="!allowEdit"
+ :value="adminDataSource.host"
+ @input="handleInstanceHostInput"
+ />
+ <div
+ v-if="state.instance.engine == 'SNOWFLAKE'"
+ class="mt-2 textinfolabel"
+ >
+ {{ $t("instance.sentence.proxy.snowflake") }}
+ </div>
+ </template>
+ <SpannerHostInput
+ v-else
+ :host="adminDataSource.host"
+ :allow-edit="allowEdit"
+ @update:host="handleUpdateSpannerHost"
/>
- <div
- v-if="state.instance.engine == 'SNOWFLAKE'"
- class="mt-2 textinfolabel"
- >
- {{ $t("instance.sentence.proxy.snowflake") }}
- </div>
</div>
<template v-if="state.instance.engine !== 'SPANNER'">
<div class="sm:col-span-1">
@@ -240,29 +231,17 @@
</div>
</template>
- <div class="mt-2 sm:col-span-1 sm:col-start-1">
+ <div
+ v-if="state.instance.engine !== 'SPANNER'"
+ class="mt-2 sm:col-span-1 sm:col-start-1"
+ >
<div class="flex flex-row items-center space-x-2">
<label for="password" class="textlabel block">
- <template v-if="state.instance.engine === 'SPANNER'">
- {{ $t("common.credentials") }}
- <span class="text-red-600">*</span>
- <p class="text-sm text-gray-500 mt-1">
- {{ $t("instance.create-gcp-credentials") }}
- <a
- href="https://www.bytebase.com/docs/how-to/spanner/how-to-create-a-service-account-for-bytebase"
- target="_blank"
- class="normal-link inline-flex items-center"
- >{{ $t("common.detailed-guide") }}
- <heroicons-outline:external-link class="w-4 h-4 ml-1"
- /></a>
- </p>
- </template>
- <template v-else>
- {{ $t("common.password") }}
- <span class="text-red-600">*</span>
- </template>
+ {{ $t("common.password") }}
+ <span class="text-red-600">*</span>
</label>
<BBCheckbox
+ v-if="allowUsingEmptyPassword"
:title="$t('common.empty')"
:value="currentDataSource.useEmptyPassword"
@toggle="handleToggleUseEmptyPassword"
@@ -277,8 +256,6 @@
:placeholder="
currentDataSource.useEmptyPassword
? $t('instance.no-password')
- : state.instance.engine === 'SPANNER'
- ? $t('instance.credentials-write-only')
: $t('instance.password-write-only')
"
:disabled="!allowEdit || currentDataSource.useEmptyPassword"
@@ -291,6 +268,14 @@
/>
</div>
+ <SpannerCredentialInput
+ v-else
+ :value="currentDataSource.updatedPassword"
+ :write-only="true"
+ class="mt-2 sm:col-span-3 sm:col-start-1"
+ @update:value="handleUpdateSpannerCredential"
+ />
+
<template v-if="showAuthenticationDatabase">
<div class="sm:col-span-1 sm:col-start-1">
<div class="flex flex-row items-center space-x-2">
@@ -475,7 +460,11 @@ import { cloneDeep, isEqual, omit } from "lodash-es";
import { computed, reactive, PropType } from "vue";
import EnvironmentSelect from "../components/EnvironmentSelect.vue";
import InstanceEngineIcon from "../components/InstanceEngineIcon.vue";
-import { SslCertificateForm } from "./InstanceForm";
+import {
+ SpannerHostInput,
+ SpannerCredentialInput,
+ SslCertificateForm,
+} from "./InstanceForm";
import { clearObject, hasWorkspacePermission } from "../utils";
import {
InstancePatch,
@@ -565,6 +554,10 @@ const allowEdit = computed(() => {
);
});
+const allowUsingEmptyPassword = computed(() => {
+ return state.instance.engine !== "SPANNER";
+});
+
const valueChanged = computed(() => {
return !isEqual(state.instance, state.originalInstance);
});
@@ -661,6 +654,11 @@ const handleInstanceHostInput = (event: Event) => {
updateInstanceDataSource(adminDataSource.value);
};
+const handleUpdateSpannerHost = (host: string) => {
+ adminDataSource.value.host = host;
+ updateInstanceDataSource(adminDataSource.value);
+};
+
const handleInstancePortWheelScroll = (event: MouseEvent) => {
(event.target as HTMLInputElement).blur();
};
@@ -695,6 +693,11 @@ const handleCurrentDataSourcePasswordInput = (event: Event) => {
updateInstanceDataSource(currentDataSource.value);
};
+const handleUpdateSpannerCredential = (credential: string) => {
+ currentDataSource.value.updatedPassword = credential;
+ updateInstanceDataSource(currentDataSource.value);
+};
+
const handleInstanceAuthenticationDatabaseInput = (event: Event) => {
const str = (event.target as HTMLInputElement).value.trim();
currentDataSource.value.options.authenticationDatabase = str;
diff --git a/frontend/src/components/InstanceForm/SpannerCredentialInput.vue b/frontend/src/components/InstanceForm/SpannerCredentialInput.vue
new file mode 100644
index 0000000000..8ae05bb5be
--- /dev/null
+++ b/frontend/src/components/InstanceForm/SpannerCredentialInput.vue
@@ -0,0 +1,54 @@
+<template>
+ <div class="space-y-1 w-full">
+ <div>
+ <span>{{ $t("common.credentials") }}</span>
+ <span class="text-red-600">*</span>
+ </div>
+ <p class="textinfolabel">
+ <span>{{ $t("instance.create-gcp-credentials") }}</span>
+ <a
+ href="https://www.bytebase.com/docs/how-to/spanner/how-to-create-a-service-account-for-bytebase"
+ target="_blank"
+ class="normal-link inline-flex items-center ml-1"
+ >
+ <span>{{ $t("common.detailed-guide") }}</span>
+ <heroicons-outline:external-link class="w-4 h-4 ml-1" />
+ </a>
+ </p>
+ <DroppableTextarea
+ :value="value"
+ :rounded="true"
+ class="block w-full resize-none whitespace-pre-wrap h-24"
+ :placeholder="placeholder"
+ @update:value="(value) => $emit('update:value', value)"
+ />
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { computed } from "vue";
+import { useI18n } from "vue-i18n";
+import DroppableTextarea from "../misc/DroppableTextarea.vue";
+
+const props = withDefaults(
+ defineProps<{
+ value: string;
+ writeOnly?: boolean;
+ }>(),
+ {
+ writeOnly: false,
+ }
+);
+
+defineEmits<{
+ (name: "update:value", value: string): void;
+}>();
+
+const { t } = useI18n();
+
+const placeholder = computed(() => {
+ return props.writeOnly
+ ? t("instance.type-or-paste-credentials-write-only")
+ : t("instance.type-or-paste-credentials");
+});
+</script>
diff --git a/frontend/src/components/InstanceForm/SpannerHostInput.vue b/frontend/src/components/InstanceForm/SpannerHostInput.vue
new file mode 100644
index 0000000000..e203510896
--- /dev/null
+++ b/frontend/src/components/InstanceForm/SpannerHostInput.vue
@@ -0,0 +1,94 @@
+<template>
+ <div class="grid grid-cols-2 gap-x-2 gap-y-1">
+ <div>
+ <label class="textlabel">
+ {{ $t("instance.project-id") }}
+ <span style="color: red">*</span>
+ </label>
+ <input
+ v-model="projectId"
+ required
+ type="text"
+ placeholder="projectId"
+ class="textfield mt-1 w-full"
+ :disabled="!allowEdit"
+ />
+ </div>
+ <div>
+ <label class="textlabel">
+ {{ $t("instance.instance-id") }}
+ <span style="color: red">*</span>
+ </label>
+ <input
+ v-model="instanceId"
+ required
+ type="text"
+ placeholder="instanceId"
+ class="textfield mt-1 w-full"
+ :disabled="!allowEdit"
+ />
+ </div>
+
+ <p class="col-span-2 textinfolabel">
+ {{ $t("instance.find-gcp-project-id-and-instance-id") }}
+ <a
+ href="https://www.bytebase.com/docs/how-to/spanner/how-to-find-project-id-and-instance-id"
+ target="_blank"
+ class="normal-link inline-flex items-center"
+ >
+ {{ $t("common.detailed-guide")
+ }}<heroicons-outline:external-link class="w-4 h-4 ml-1"
+ /></a>
+ </p>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { computed, reactive, watch } from "vue";
+
+const props = defineProps<{
+ host: string;
+ allowEdit: boolean;
+}>();
+
+const emit = defineEmits<{
+ (name: "update:host", host: string): void;
+}>();
+
+const RE =
+ /^projects\/(?<PROJECT_ID>(?:[a-z]|[-.:]|[0-9])*)\/instances\/(?<INSTANCE_ID>(?:[a-z]|[-]|[0-9])*)/;
+
+const state = reactive({
+ host: props.host,
+});
+
+const update = (projectId: string, instanceId: string) => {
+ const host = `projects/${projectId}/instances/${instanceId}`;
+ emit("update:host", host);
+};
+
+const projectId = computed<string>({
+ get() {
+ const match = state.host.match(RE);
+ return match?.groups?.PROJECT_ID ?? "";
+ },
+ set(value) {
+ update(value, instanceId.value);
+ },
+});
+
+const instanceId = computed<string>({
+ get() {
+ const match = state.host.match(RE);
+ return match?.groups?.INSTANCE_ID ?? "";
+ },
+ set(value) {
+ update(projectId.value, value);
+ },
+});
+
+watch(
+ () => props.host,
+ (host) => (state.host = host)
+);
+</script>
diff --git a/frontend/src/components/InstanceForm/index.ts b/frontend/src/components/InstanceForm/index.ts
index be8bd70029..afbdf3661f 100644
--- a/frontend/src/components/InstanceForm/index.ts
+++ b/frontend/src/components/InstanceForm/index.ts
@@ -1,3 +1,5 @@
import SslCertificateForm from "./SslCertificateForm.vue";
+import SpannerHostInput from "./SpannerHostInput.vue";
+import SpannerCredentialInput from "./SpannerCredentialInput.vue";
-export { SslCertificateForm };
+export { SslCertificateForm, SpannerHostInput, SpannerCredentialInput };
diff --git a/frontend/src/components/misc/DroppableTextarea.vue b/frontend/src/components/misc/DroppableTextarea.vue
index f3338baaf8..e049a73524 100644
--- a/frontend/src/components/misc/DroppableTextarea.vue
+++ b/frontend/src/components/misc/DroppableTextarea.vue
@@ -7,13 +7,22 @@
<textarea
v-model="state.value"
class="textarea"
+ :class="[rounded && 'rounded-md']"
:placeholder="placeholder"
v-bind="$attrs"
/>
+ <div
+ v-if="!state.value"
+ class="absolute bottom-2 left-[50%] -translate-x-1/2 pointer-events-none flex flex-col items-center justify-center border border-control-border border-dashed text-xs text-control-placeholder p-2 rounded-md"
+ >
+ Or drag and drop files here.
+ </div>
+
<div
v-if="isOverDropZone || state.reading"
class="absolute inset-0 pointer-events-none flex flex-col items-center justify-center bg-white/50 border border-accent border-dashed"
+ :class="[rounded && 'rounded-md']"
>
<heroicons-outline:arrow-up-tray v-if="isOverDropZone" class="w-8 h-8" />
<BBSpin v-if="state.reading" />
@@ -46,10 +55,12 @@ const props = withDefaults(
value: string | undefined;
placeholder?: string;
maxFileSize?: number; // in MB
+ rounded?: boolean;
}>(),
{
placeholder: undefined,
maxFileSize: 1,
+ rounded: false,
}
);
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 5529b987f5..8c4374281c 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -717,6 +717,8 @@
"name": "Name",
"host-or-socket": "Host or Socket",
"project-id-and-instance-id": "Project ID and instance ID",
+ "project-id": "Project ID",
+ "instance-id": "Instance ID",
"your-snowflake-account-name": "your Snowflake account name",
"port": "Port",
"authentication-database": "Authentication Database",
@@ -763,7 +765,8 @@
}
},
"no-password": "No password",
- "credentials-write-only": "CREDENTIALS - write only",
+ "type-or-paste-credentials": "Type or paste CREDENTIALS",
+ "type-or-paste-credentials-write-only": "Type or paste CREDENTIALS - write only",
"password-write-only": "YOUR_DB_PWD - write only",
"test-connection": "Test Connection",
"ignore-and-create": "Ignore and create",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 5b27a67a5f..c7f31a7dc6 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -717,6 +717,8 @@
"name": "名称",
"host-or-socket": "Host 或 Socket",
"project-id-and-instance-id": "项目 ID 与实例 ID",
+ "project-id": "项目 ID",
+ "instance-id": "实例 ID",
"your-snowflake-account-name": "您的 Snowflake @:{'instance.account'}@:{'instance.name'}",
"port": "端口",
"instance-name": "@:common.instance@:instance.name",
@@ -762,7 +764,8 @@
}
},
"no-password": "无密码",
- "credentials-write-only": "CREDENTIALS - 仅写入",
+ "type-or-paste-credentials": "输入或粘贴 CREDENTIALS",
+ "type-or-paste-credentials-write-only": "输入或粘贴 CREDENTIALS - 仅写入",
"password-write-only": "YOUR_DB_PWD - 仅写入",
"test-connection": "测试连接",
"ignore-and-create": "忽略并创建",