Skip to content

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

feat(frontend): refactor instance datasource section and support multiple data sources (#7379)

Liu Jie0a7716824d6
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/CreateReadOnlyDataSourceTips.vue b/frontend/src/components/InstanceForm/DataSourceSection/CreateReadOnlyDataSourceTips.vue
new file mode 100644
index 0000000000..59d887ad55
--- /dev/null
+++ b/frontend/src/components/InstanceForm/DataSourceSection/CreateReadOnlyDataSourceTips.vue
@@ -0,0 +1,31 @@
+<template>
+ <div
+ v-if="!isCreating && !hasReadOnlyDataSource && allowEdit"
+ class="mt-2 flex flex-row justify-start items-center bg-yellow-50 border-none rounded-lg p-2 px-3"
+ >
+ <heroicons-outline:exclamation
+ class="h-6 w-6 text-yellow-400 flex-shrink-0 mr-1"
+ />
+ <span class="text-yellow-800 text-sm">
+ {{ $t("instance.no-read-only-data-source-warn") }}
+ </span>
+ <button
+ type="button"
+ class="btn-normal ml-4 text-sm"
+ @click.prevent="$emit('add-readonly-datasource')"
+ >
+ {{ $t("common.create") }}
+ </button>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { useInstanceFormContext } from "../context";
+
+defineEmits<{
+ (event: "add-readonly-datasource"): void;
+}>();
+
+const { isCreating, allowEdit, hasReadOnlyDataSource } =
+ useInstanceFormContext();
+</script>
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue
new file mode 100644
index 0000000000..4a4d7337c5
--- /dev/null
+++ b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue
@@ -0,0 +1,332 @@
+<template>
+ <!-- eslint-disable vue/no-mutating-props -->
+ <template v-if="basicInfo.engine !== Engine.SPANNER">
+ <CreateDataSourceExample
+ class-name="sm:col-span-3 border-none mt-2"
+ :create-instance-flag="isCreating"
+ :engine="basicInfo.engine"
+ :data-source-type="dataSource.type"
+ />
+ <div class="mt-2 sm:col-span-1 sm:col-start-1">
+ <label for="username" class="textlabel block">
+ {{ $t("common.username") }}
+ </label>
+ <!-- For mysql, username can be empty indicating anonymous user.
+ But it's a very bad practice to use anonymous user for admin operation,
+ thus we make it REQUIRED here.-->
+ <input
+ id="username"
+ v-model="dataSource.username"
+ name="username"
+ type="text"
+ class="textfield mt-1 w-full"
+ :disabled="!allowEdit"
+ :placeholder="
+ basicInfo.engine === Engine.CLICKHOUSE ? $t('common.default') : ''
+ "
+ />
+ </div>
+ <div 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">
+ {{ $t("common.password") }}
+ </label>
+ <BBCheckbox
+ v-if="!isCreating && allowUsingEmptyPassword"
+ :title="$t('common.empty')"
+ :value="dataSource.useEmptyPassword"
+ :disabled="!allowEdit"
+ @toggle="toggleUseEmptyPassword"
+ />
+ </div>
+ <input
+ id="password"
+ name="password"
+ type="text"
+ class="textfield mt-1 w-full"
+ autocomplete="off"
+ :placeholder="
+ dataSource.useEmptyPassword
+ ? $t('instance.no-password')
+ : $t('instance.password-write-only')
+ "
+ :disabled="!allowEdit || dataSource.useEmptyPassword"
+ :value="dataSource.useEmptyPassword ? '' : dataSource.updatedPassword"
+ @input="dataSource.updatedPassword = trimInputValue($event.target)"
+ />
+ </div>
+ </template>
+ <SpannerCredentialInput
+ v-else
+ v-model:value="dataSource.updatedPassword"
+ :write-only="!isCreating"
+ class="mt-2 sm:col-span-3 sm:col-start-1"
+ />
+
+ <template v-if="basicInfo.engine === Engine.ORACLE">
+ <OracleSIDAndServiceNameInput
+ v-model:sid="dataSource.sid"
+ v-model:service-name="dataSource.serviceName"
+ :allow-edit="allowEdit"
+ />
+ </template>
+
+ <template v-if="showAuthenticationDatabase">
+ <div class="sm:col-span-1 sm:col-start-1">
+ <div class="flex flex-row items-center space-x-2">
+ <label for="authenticationDatabase" class="textlabel block">
+ {{ $t("instance.authentication-database") }}
+ </label>
+ </div>
+ <input
+ id="authenticationDatabase"
+ name="authenticationDatabase"
+ type="text"
+ class="textfield mt-1 w-full"
+ autocomplete="off"
+ placeholder="admin"
+ :value="dataSource.authenticationDatabase"
+ @input="
+ dataSource.authenticationDatabase = trimInputValue($event.target)
+ "
+ />
+ </div>
+ </template>
+
+ <template
+ v-if="
+ dataSource.type === DataSourceType.READ_ONLY &&
+ (hasReadonlyReplicaHost || hasReadonlyReplicaPort)
+ "
+ >
+ <div
+ v-if="hasReadonlyReplicaHost"
+ class="mt-2 sm:col-span-1 sm:col-start-1"
+ >
+ <div class="flex flex-row items-center space-x-2">
+ <label for="host" class="textlabel block">
+ {{ $t("data-source.read-replica-host") }}
+ </label>
+ </div>
+ <input
+ id="host"
+ name="host"
+ type="text"
+ class="textfield mt-1 w-full"
+ autocomplete="off"
+ :value="dataSource.host"
+ @input="handleHostInput"
+ />
+ </div>
+
+ <div
+ v-if="hasReadonlyReplicaPort"
+ class="mt-2 sm:col-span-1 sm:col-start-1"
+ >
+ <div class="flex flex-row items-center space-x-2">
+ <label for="port" class="textlabel block">
+ {{ $t("data-source.read-replica-port") }}
+ </label>
+ </div>
+ <input
+ id="port"
+ name="port"
+ type="text"
+ class="textfield mt-1 w-full"
+ autocomplete="off"
+ :value="dataSource.port"
+ @input="handlePortInput"
+ />
+ </div>
+ </template>
+
+ <div v-if="showDatabase" class="mt-2 sm:col-span-1 sm:col-start-1">
+ <label for="database" class="textlabel block">
+ {{ $t("common.database") }}
+ </label>
+ <input
+ id="database"
+ v-model="dataSource.database"
+ name="database"
+ type="text"
+ class="textfield mt-1 w-full"
+ :disabled="!allowEdit"
+ :placeholder="$t('common.database')"
+ />
+ </div>
+
+ <div v-if="showSSL" class="mt-2 sm:col-span-3 sm:col-start-1">
+ <div class="flex flex-row items-center">
+ <label for="ssl" class="textlabel block">
+ {{ $t("data-source.ssl-connection") }}
+ </label>
+ </div>
+ <template v-if="dataSource.pendingCreate">
+ <SslCertificateForm :value="dataSource" @change="handleSSLChange" />
+ </template>
+ <template v-else>
+ <template v-if="dataSource.updateSsl">
+ <SslCertificateForm :value="dataSource" @change="handleSSLChange" />
+ </template>
+ <template v-else>
+ <button
+ class="btn-normal mt-2"
+ :disabled="!allowEdit"
+ @click.prevent="handleEditSSL"
+ >
+ {{ $t("common.edit") }} - {{ $t("common.write-only") }}
+ </button>
+ </template>
+ </template>
+ </div>
+
+ <div v-if="showSSH" class="mt-2 sm:col-span-3 sm:col-start-1">
+ <div class="flex flex-row items-center gap-x-1">
+ <label for="ssh" class="textlabel block">
+ {{ $t("data-source.ssh-connection") }}
+ </label>
+ <FeatureBadge
+ feature="bb.feature.instance-ssh-connection"
+ :instance="instance"
+ />
+ </div>
+ <template v-if="dataSource.pendingCreate">
+ <SshConnectionForm
+ :value="dataSource"
+ :instance="instance"
+ @change="handleSSHChange"
+ />
+ </template>
+ <template v-else>
+ <template v-if="dataSource.updateSsh">
+ <SshConnectionForm
+ :value="dataSource"
+ :instance="instance"
+ @change="handleSSHChange"
+ />
+ </template>
+ <template v-else>
+ <button
+ class="btn-normal mt-2"
+ :disabled="!allowEdit"
+ @click.prevent="handleEditSSH"
+ >
+ {{ $t("common.edit") }} - {{ $t("common.write-only") }}
+ </button>
+ </template>
+ </template>
+ </div>
+</template>
+
+<script setup lang="ts">
+/* eslint-disable vue/no-mutating-props */
+import { Engine } from "@/types/proto/v1/common";
+import { DataSource, DataSourceType } from "@/types/proto/v1/instance_service";
+import { EditDataSource } from "../common";
+import { useInstanceFormContext } from "../context";
+import { useInstanceSpecs } from "../specs";
+import { DataSourceOptions } from "@/types";
+
+const props = defineProps<{
+ dataSource: EditDataSource;
+}>();
+const {
+ instance,
+ isCreating,
+ allowEdit,
+ basicInfo,
+ adminDataSource,
+ hasReadonlyReplicaFeature,
+ showReadOnlyDataSourceFeatureModal,
+} = useInstanceFormContext();
+
+const {
+ showDatabase,
+ showSSL,
+ showSSH,
+ allowUsingEmptyPassword,
+ showAuthenticationDatabase,
+ hasReadonlyReplicaHost,
+ hasReadonlyReplicaPort,
+} = useInstanceSpecs();
+
+const toggleUseEmptyPassword = (on: boolean) => {
+ const ds = props.dataSource;
+ ds.useEmptyPassword = on;
+ if (on) {
+ ds.updatedPassword = "";
+ }
+};
+const handleHostInput = (event: Event) => {
+ const ds = props.dataSource;
+ if (ds.type === DataSourceType.READ_ONLY) {
+ if (!hasReadonlyReplicaFeature.value) {
+ if (ds.host || ds.port) {
+ ds.host = adminDataSource.value.host;
+ ds.port = adminDataSource.value.port;
+ showReadOnlyDataSourceFeatureModal.value = true;
+ return;
+ }
+ }
+ }
+ ds.host = trimInputValue(event.target);
+};
+
+const handlePortInput = (event: Event) => {
+ const ds = props.dataSource;
+ if (ds.type === DataSourceType.READ_ONLY) {
+ if (!hasReadonlyReplicaFeature.value) {
+ if (ds.host || ds.port) {
+ ds.host = adminDataSource.value.host;
+ ds.port = adminDataSource.value.port;
+ showReadOnlyDataSourceFeatureModal.value = true;
+ return;
+ }
+ }
+ }
+ ds.port = trimInputValue(event.target);
+};
+const handleEditSSL = () => {
+ const ds = props.dataSource;
+ ds.sslCa = "";
+ ds.sslCert = "";
+ ds.sslKey = "";
+ ds.updateSsl = true;
+};
+
+const handleEditSSH = () => {
+ const ds = props.dataSource;
+ if (!ds) return;
+ ds.sshHost = "";
+ ds.sshPort = "";
+ ds.sshUser = "";
+ ds.sshPassword = "";
+ ds.sshPrivateKey = "";
+ ds.updateSsh = true;
+};
+
+const handleSSLChange = (
+ value: Partial<Pick<DataSource, "sslCa" | "sslCert" | "sslKey">>
+) => {
+ const ds = props.dataSource;
+ Object.assign(ds, value);
+ ds.updateSsl = true;
+};
+
+const handleSSHChange = (
+ value: Partial<
+ Pick<
+ DataSourceOptions,
+ "sshHost" | "sshPort" | "sshUser" | "sshPassword" | "sshPrivateKey"
+ >
+ >
+) => {
+ const ds = props.dataSource;
+ Object.assign(ds, value);
+ ds.updateSsh = true;
+};
+
+const trimInputValue = (target: Event["target"]) => {
+ return ((target as HTMLInputElement)?.value ?? "").trim();
+};
+</script>
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceSection.vue b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceSection.vue
new file mode 100644
index 0000000000..59cdd62c6a
--- /dev/null
+++ b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceSection.vue
@@ -0,0 +1,51 @@
+<template>
+ <CreateReadOnlyDataSourceTips
+ @add-readonly-datasource="handleCreateRODataSource"
+ />
+
+ <div class="mt-2 grid grid-cols-1 gap-y-2 gap-x-4 border-none sm:grid-cols-3">
+ <DataSourceTabs
+ class="sm:col-span-3"
+ @add-readonly-datasource="handleCreateRODataSource"
+ />
+
+ <DataSourceForm v-if="editingDataSource" :data-source="editingDataSource" />
+ </div>
+</template>
+
+<script setup lang="ts">
+import { DataSourceType } from "@/types/proto/v1/instance_service";
+import { Engine } from "@/types/proto/v1/common";
+import { useInstanceFormContext } from "../context";
+import CreateReadOnlyDataSourceTips from "./CreateReadOnlyDataSourceTips.vue";
+import DataSourceTabs from "./DataSourceTabs.vue";
+import DataSourceForm from "./DataSourceForm.vue";
+import { wrapEditDataSource } from "../common";
+
+const {
+ isCreating,
+ dataSourceEditState,
+ editingDataSource,
+ adminDataSource,
+ basicInfo,
+} = useInstanceFormContext();
+
+const handleCreateRODataSource = () => {
+ if (isCreating.value) {
+ return;
+ }
+
+ const ds = {
+ ...wrapEditDataSource(undefined /* create new empty DS */),
+ type: DataSourceType.READ_ONLY,
+ host: adminDataSource.value.host,
+ port: adminDataSource.value.port,
+ database: adminDataSource.value.database,
+ };
+ if (basicInfo.value.engine === Engine.SPANNER) {
+ ds.host = adminDataSource.value.host;
+ }
+ dataSourceEditState.value.dataSources.push(ds);
+ dataSourceEditState.value.editingDataSourceId = ds.id;
+};
+</script>
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceTabs.vue b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceTabs.vue
new file mode 100644
index 0000000000..0cba60855a
--- /dev/null
+++ b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceTabs.vue
@@ -0,0 +1,125 @@
+<template>
+ <NTabs
+ v-if="!isCreating"
+ ref="tabsRef"
+ v-model:value="dataSourceEditState.editingDataSourceId"
+ type="line"
+ justify-content="start"
+ tab-style="margin-right: 2rem;"
+ >
+ <NTab :name="adminDataSource.id">
+ {{ $t("common.admin") }}
+ </NTab>
+ <NTab v-for="ds in readOnlyDataSourceList" :key="ds.id" :name="ds.id">
+ <span>{{ $t("common.read-only") }}</span>
+ <BBButtonConfirm
+ v-if="hasReadOnlyDataSource"
+ class="ml-1"
+ :style="'DELETE'"
+ :disabled="!allowEdit"
+ :require-confirm="!ds.pendingCreate"
+ :ok-text="$t('common.delete')"
+ :confirm-title="$t('data-source.delete-read-only-data-source') + '?'"
+ @confirm="handleDeleteDataSource(ds)"
+ />
+ </NTab>
+ <NTab
+ v-if="!hasReadOnlyDataSource"
+ name="placeholder-read-only-data-source"
+ :disabled="true"
+ >
+ <span>{{ $t("common.read-only") }}</span>
+ </NTab>
+ <NTab v-if="allowEdit" name="placeholder-add-data-source" :disabled="true">
+ <NButton
+ quaternary
+ size="small"
+ style="--n-padding: 0 4px"
+ @click.stop="$emit('add-readonly-datasource')"
+ >
+ <template #icon>
+ <heroicons:plus />
+ </template>
+ </NButton>
+ </NTab>
+ </NTabs>
+</template>
+
+<script setup lang="ts">
+import { computed, nextTick, ref, watch } from "vue";
+import { NTabs, NTab, TabsInst, NButton } from "naive-ui";
+
+import { DataSourceType } from "@/types/proto/v1/instance_service";
+import { BBButtonConfirm } from "@/bbkit";
+import { useInstanceFormContext } from "../context";
+import { EditDataSource } from "../common";
+import { pullAt } from "lodash-es";
+import { useInstanceV1Store } from "@/store";
+
+defineEmits<{
+ (event: "add-readonly-datasource"): void;
+}>();
+
+const tabsRef = ref<TabsInst>();
+const {
+ instance,
+ isCreating,
+ allowEdit,
+ dataSourceEditState,
+ adminDataSource,
+ hasReadOnlyDataSource,
+} = useInstanceFormContext();
+
+const readOnlyDataSourceList = computed(() => {
+ return dataSourceEditState.value.dataSources.filter(
+ (ds) => ds.type === DataSourceType.READ_ONLY
+ );
+});
+
+const handleDeleteDataSource = async (ds: EditDataSource) => {
+ const removeLocalEditDataSource = (ds: EditDataSource) => {
+ const { dataSources, editingDataSourceId } = dataSourceEditState.value;
+ if (ds.id !== editingDataSourceId) {
+ return;
+ }
+ const index = dataSources.findIndex((d) => d.id === ds.id);
+ if (index >= 0) {
+ pullAt(dataSources, index);
+ }
+ const siblingIndex = Math.min(index, dataSources.length - 1);
+ const siblingDataSource = dataSources[siblingIndex];
+ dataSourceEditState.value.editingDataSourceId = siblingDataSource?.id;
+ };
+
+ if (instance.value && !ds.pendingCreate) {
+ // Remove via API
+ await useInstanceV1Store().deleteDataSource(instance.value, ds);
+ }
+
+ removeLocalEditDataSource(ds);
+
+ // if (!readonlyDataSource.value) {
+ // return;
+ // }
+ // if (readonlyDataSource.value.pendingCreate) {
+ // // TODO: state.currentDataSourceType = DataSourceType.ADMIN;
+ // readonlyDataSource.value = undefined;
+ // } else {
+ // const { instance } = props;
+ // if (!instance) return;
+ // const ds = getDataSourceByType(instance, DataSourceType.READ_ONLY);
+ // if (!ds) return;
+ // const updated = await instanceV1Store.deleteDataSource(instance, ds);
+ // // TODO: state.currentDataSourceType = DataSourceType.ADMIN;
+ // await updateEditState(updated);
+ // }
+};
+
+watch(
+ () => dataSourceEditState.value.editingDataSourceId,
+ async () => {
+ await nextTick();
+ tabsRef.value?.syncBarPosition();
+ }
+);
+</script>
diff --git a/frontend/src/components/InstanceForm/OracleSIDAndServiceNameInput.vue b/frontend/src/components/InstanceForm/DataSourceSection/OracleSIDAndServiceNameInput.vue
similarity index 100%
rename from frontend/src/components/InstanceForm/OracleSIDAndServiceNameInput.vue
rename to frontend/src/components/InstanceForm/DataSourceSection/OracleSIDAndServiceNameInput.vue
diff --git a/frontend/src/components/InstanceForm/SpannerCredentialInput.vue b/frontend/src/components/InstanceForm/DataSourceSection/SpannerCredentialInput.vue
similarity index 94%
rename from frontend/src/components/InstanceForm/SpannerCredentialInput.vue
rename to frontend/src/components/InstanceForm/DataSourceSection/SpannerCredentialInput.vue
index 5be2348005..6df4d4512a 100644
--- a/frontend/src/components/InstanceForm/SpannerCredentialInput.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/SpannerCredentialInput.vue
@@ -28,7 +28,7 @@
<script lang="ts" setup>
import { computed } from "vue";
import { useI18n } from "vue-i18n";
-import DroppableTextarea from "../misc/DroppableTextarea.vue";
+import DroppableTextarea from "@/components/misc/DroppableTextarea.vue";
const props = withDefaults(
defineProps<{
diff --git a/frontend/src/components/InstanceForm/SshConnectionForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue
similarity index 98%
rename from frontend/src/components/InstanceForm/SshConnectionForm.vue
rename to frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue
index d3b7da5793..ad79f504e9 100644
--- a/frontend/src/components/InstanceForm/SshConnectionForm.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue
@@ -108,8 +108,8 @@ import { useI18n } from "vue-i18n";
import { cloneDeep } from "lodash-es";
import { Instance } from "@/types/proto/v1/instance_service";
-import DroppableTextarea from "../misc/DroppableTextarea.vue";
import { useSubscriptionV1Store } from "@/store";
+import DroppableTextarea from "@/components/misc/DroppableTextarea.vue";
const SshTypes = ["NONE", "TUNNEL", "TUNNEL+PK"] as const;
diff --git a/frontend/src/components/InstanceForm/SslCertificateForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue
similarity index 98%
rename from frontend/src/components/InstanceForm/SslCertificateForm.vue
rename to frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue
index 0967d754d9..15b5c71136 100644
--- a/frontend/src/components/InstanceForm/SslCertificateForm.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue
@@ -57,8 +57,8 @@ import { NTabs, NTabPane } from "naive-ui";
import { useI18n } from "vue-i18n";
import { cloneDeep } from "lodash-es";
-import DroppableTextarea from "../misc/DroppableTextarea.vue";
import { DataSource } from "@/types/proto/v1/instance_service";
+import DroppableTextarea from "@/components/misc/DroppableTextarea.vue";
const SslTypes = ["NONE", "CA", "CA+KEY+CERT"] as const;
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/index.ts b/frontend/src/components/InstanceForm/DataSourceSection/index.ts
new file mode 100644
index 0000000000..aae2a4922d
--- /dev/null
+++ b/frontend/src/components/InstanceForm/DataSourceSection/index.ts
@@ -0,0 +1,3 @@
+import DataSourceSection from "DataSourceSection.vue";
+
+export default DataSourceSection;
diff --git a/frontend/src/components/InstanceForm/InstanceForm.vue b/frontend/src/components/InstanceForm/InstanceForm.vue
index c14a8bca55..a666f39159 100644
--- a/frontend/src/components/InstanceForm/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm/InstanceForm.vue
@@ -3,7 +3,7 @@
<div class="space-y-6 divide-y divide-block-border">
<div class="divide-y divide-block-border w-[850px]">
<div v-if="isCreating" class="w-full mt-4 mb-6 grid grid-cols-4 gap-2">
- <template v-for="engine in engineList" :key="engine">
+ <template v-for="engine in EngineList" :key="engine">
<div
class="flex relative justify-start p-2 border rounded cursor-pointer hover:bg-control-bg-hover"
:class="
@@ -192,7 +192,7 @@
{{ $t("data-source.connection-string-schema") }}
</label>
<label
- v-for="type in mongodbConnectionStringSchemaList"
+ v-for="type in MongoDBConnectionStringSchemaList"
:key="type"
class="radio h-7"
>
@@ -251,7 +251,7 @@
type="text"
:disabled="!allowEdit"
class="textfield mt-1 w-full"
- :placeholder="snowflakeExtraLinkPlaceHolder"
+ :placeholder="SnowflakeExtraLinkPlaceHolder"
/>
</template>
</div>
@@ -262,292 +262,7 @@
{{ $t("instance.connection-info") }}
</p>
- <div
- v-if="!isCreating && !hasReadOnlyDataSource && allowEdit"
- class="mt-2 flex flex-row justify-start items-center bg-yellow-50 border-none rounded-lg p-2 px-3"
- >
- <heroicons-outline:exclamation
- class="h-6 w-6 text-yellow-400 flex-shrink-0 mr-1"
- />
- <span class="text-yellow-800 text-sm">
- {{ $t("instance.no-read-only-data-source-warn") }}
- </span>
- <button
- type="button"
- class="btn-normal ml-4 text-sm"
- @click.prevent="handleCreateRODataSource"
- >
- {{ $t("common.create") }}
- </button>
- </div>
-
- <div
- class="mt-2 grid grid-cols-1 gap-y-2 gap-x-4 border-none sm:grid-cols-3"
- >
- <NTabs
- v-if="!isCreating"
- v-model:value="state.currentDataSourceType"
- class="sm:col-span-3"
- type="line"
- >
- <NTab :name="DataSourceType.ADMIN">
- {{ $t("common.admin") }}
- </NTab>
- <NTab
- :name="DataSourceType.READ_ONLY"
- class="relative"
- :disabled="!hasReadOnlyDataSource"
- >
- <span>{{ $t("common.read-only") }}</span>
- <BBButtonConfirm
- v-if="hasReadOnlyDataSource"
- :style="'DELETE'"
- class="absolute left-full ml-1"
- :require-confirm="!readonlyDataSource?.pendingCreate"
- :ok-text="$t('common.delete')"
- :confirm-title="
- $t('data-source.delete-read-only-data-source') + '?'
- "
- @confirm="handleDeleteRODataSource"
- />
- </NTab>
- </NTabs>
-
- <template v-if="basicInfo.engine !== Engine.SPANNER">
- <CreateDataSourceExample
- class-name="sm:col-span-3 border-none mt-2"
- :create-instance-flag="isCreating"
- :engine="basicInfo.engine"
- :data-source-type="state.currentDataSourceType"
- />
- <div class="mt-2 sm:col-span-1 sm:col-start-1">
- <label for="username" class="textlabel block">
- {{ $t("common.username") }}
- </label>
- <!-- For mysql, username can be empty indicating anonymous user.
- But it's a very bad practice to use anonymous user for admin operation,
- thus we make it REQUIRED here.-->
- <input
- id="username"
- v-model="currentDataSource.username"
- name="username"
- type="text"
- class="textfield mt-1 w-full"
- :disabled="!allowEdit"
- :placeholder="
- basicInfo.engine === Engine.CLICKHOUSE
- ? $t('common.default')
- : ''
- "
- />
- </div>
- <div 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">
- {{ $t("common.password") }}
- </label>
- <BBCheckbox
- v-if="!isCreating && allowUsingEmptyPassword"
- :title="$t('common.empty')"
- :value="currentDataSource.useEmptyPassword"
- :disabled="!allowEdit"
- @toggle="toggleUseEmptyPassword"
- />
- </div>
- <input
- id="password"
- name="password"
- type="text"
- class="textfield mt-1 w-full"
- autocomplete="off"
- :placeholder="
- currentDataSource.useEmptyPassword
- ? $t('instance.no-password')
- : $t('instance.password-write-only')
- "
- :disabled="!allowEdit || currentDataSource.useEmptyPassword"
- :value="
- currentDataSource.useEmptyPassword
- ? ''
- : currentDataSource.updatedPassword
- "
- @input="
- currentDataSource.updatedPassword = trimInputValue(
- $event.target
- )
- "
- />
- </div>
- </template>
- <SpannerCredentialInput
- v-else
- v-model:value="currentDataSource.updatedPassword"
- :write-only="!isCreating"
- class="mt-2 sm:col-span-3 sm:col-start-1"
- />
-
- <template v-if="basicInfo.engine === Engine.ORACLE">
- <OracleSIDAndServiceNameInput
- v-model:sid="currentDataSource.sid"
- v-model:service-name="currentDataSource.serviceName"
- :allow-edit="allowEdit"
- />
- </template>
-
- <template v-if="showAuthenticationDatabase">
- <div class="sm:col-span-1 sm:col-start-1">
- <div class="flex flex-row items-center space-x-2">
- <label for="authenticationDatabase" class="textlabel block">
- {{ $t("instance.authentication-database") }}
- </label>
- </div>
- <input
- id="authenticationDatabase"
- name="authenticationDatabase"
- type="text"
- class="textfield mt-1 w-full"
- autocomplete="off"
- placeholder="admin"
- :value="currentDataSource.authenticationDatabase"
- @input="
- currentDataSource.authenticationDatabase = trimInputValue(
- $event.target
- )
- "
- />
- </div>
- </template>
-
- <template
- v-if="
- state.currentDataSourceType === DataSourceType.READ_ONLY &&
- (hasReadonlyReplicaHost || hasReadonlyReplicaPort)
- "
- >
- <div
- v-if="hasReadonlyReplicaHost"
- class="mt-2 sm:col-span-1 sm:col-start-1"
- >
- <div class="flex flex-row items-center space-x-2">
- <label for="host" class="textlabel block">
- {{ $t("data-source.read-replica-host") }}
- </label>
- </div>
- <input
- id="host"
- name="host"
- type="text"
- class="textfield mt-1 w-full"
- autocomplete="off"
- :value="currentDataSource.host"
- @input="handleCurrentDataSourceHostInput"
- />
- </div>
-
- <div
- v-if="hasReadonlyReplicaPort"
- class="mt-2 sm:col-span-1 sm:col-start-1"
- >
- <div class="flex flex-row items-center space-x-2">
- <label for="port" class="textlabel block">
- {{ $t("data-source.read-replica-port") }}
- </label>
- </div>
- <input
- id="port"
- name="port"
- type="text"
- class="textfield mt-1 w-full"
- autocomplete="off"
- :value="currentDataSource.port"
- @input="handleCurrentDataSourcePortInput"
- />
- </div>
- </template>
-
- <div v-if="showDatabase" class="mt-2 sm:col-span-1 sm:col-start-1">
- <label for="database" class="textlabel block">
- {{ $t("common.database") }}
- </label>
- <input
- id="database"
- v-model="currentDataSource.database"
- name="database"
- type="text"
- class="textfield mt-1 w-full"
- :disabled="!allowEdit"
- :placeholder="$t('common.database')"
- />
- </div>
-
- <div v-if="showSSL" class="mt-2 sm:col-span-3 sm:col-start-1">
- <div class="flex flex-row items-center">
- <label for="ssl" class="textlabel block">
- {{ $t("data-source.ssl-connection") }}
- </label>
- </div>
- <template v-if="currentDataSource.pendingCreate">
- <SslCertificateForm
- :value="currentDataSource"
- @change="handleCurrentDataSourceSslChange"
- />
- </template>
- <template v-else>
- <template v-if="currentDataSource.updateSsl">
- <SslCertificateForm
- :value="currentDataSource"
- @change="handleCurrentDataSourceSslChange"
- />
- </template>
- <template v-else>
- <button
- class="btn-normal mt-2"
- :disabled="!allowEdit"
- @click.prevent="handleEditSsl"
- >
- {{ $t("common.edit") }} - {{ $t("common.write-only") }}
- </button>
- </template>
- </template>
- </div>
-
- <div v-if="showSSH" class="mt-2 sm:col-span-3 sm:col-start-1">
- <div class="flex flex-row items-center gap-x-1">
- <label for="ssh" class="textlabel block">
- {{ $t("data-source.ssh-connection") }}
- </label>
- <FeatureBadge
- feature="bb.feature.instance-ssh-connection"
- :instance="instance"
- />
- </div>
- <template v-if="currentDataSource.pendingCreate">
- <SshConnectionForm
- :value="currentDataSource"
- :instance="instance"
- @change="handleCurrentDataSourceSshChange"
- />
- </template>
- <template v-else>
- <template v-if="currentDataSource.updateSsh">
- <SshConnectionForm
- :value="currentDataSource"
- :instance="instance"
- @change="handleCurrentDataSourceSshChange"
- />
- </template>
- <template v-else>
- <button
- class="btn-normal mt-2"
- :disabled="!allowEdit"
- @click.prevent="handleEditSsh"
- >
- {{ $t("common.edit") }} - {{ $t("common.write-only") }}
- </button>
- </template>
- </template>
- </div>
- </div>
+ <DataSourceSection />
<BBAttention
v-if="outboundIpList && actuatorStore.isSaaSMode"
@@ -616,9 +331,9 @@
<FeatureModal
feature="bb.feature.read-replica-connection"
- :open="state.showFeatureModal"
+ :open="showReadOnlyDataSourceFeatureModal"
:instance="instance"
- @cancel="state.showFeatureModal = false"
+ @cancel="showReadOnlyDataSourceFeatureModal = false"
/>
<BBAlert
@@ -634,7 +349,15 @@
</template>
<script lang="ts" setup>
-import { computed, reactive, PropType, ref, watch, onMounted } from "vue";
+import {
+ computed,
+ reactive,
+ PropType,
+ ref,
+ watch,
+ onMounted,
+ toRef,
+} from "vue";
import { cloneDeep, isEqual, omit } from "lodash-es";
import { NButton } from "naive-ui";
import { useI18n } from "vue-i18n";
@@ -642,14 +365,10 @@ import { Status } from "nice-grpc-common";
import { useRouter } from "vue-router";
import {
- hasWorkspacePermissionV1,
isDev,
isValidSpannerHost,
extractInstanceResourceName,
engineNameV1,
- instanceV1HasSSL,
- instanceV1HasSSH,
- supportedEngineV1List,
instanceV1Slug,
calcUpdateMask,
} from "@/utils";
@@ -657,15 +376,10 @@ import {
UNKNOWN_ID,
ResourceId,
ValidatedMessage,
- DataSourceOptions,
- emptyDataSource,
- UNKNOWN_INSTANCE_NAME,
- UNKNOWN_ENVIRONMENT_NAME,
unknownEnvironment,
} from "@/types";
import {
pushNotification,
- useCurrentUserV1,
useSettingV1Store,
useActuatorV1Store,
useEnvironmentV1Store,
@@ -673,14 +387,10 @@ import {
useSubscriptionV1Store,
useGracefulRequest,
} from "@/store";
-import { getErrorCode, extractGrpcErrorMessage } from "@/utils/grpcweb";
+import { extractGrpcErrorMessage, getErrorCode } from "@/utils/grpcweb";
import EnvironmentSelect from "@/components/EnvironmentSelect.vue";
import OracleSyncModeInput from "./OracleSyncModeInput.vue";
-import SslCertificateForm from "./SslCertificateForm.vue";
-import SshConnectionForm from "./SshConnectionForm.vue";
import SpannerHostInput from "./SpannerHostInput.vue";
-import SpannerCredentialInput from "./SpannerCredentialInput.vue";
-import OracleSIDAndServiceNameInput from "./OracleSIDAndServiceNameInput.vue";
import { instanceNamePrefix } from "@/store/modules/v1/common";
import { DrawerContent, InstanceV1EngineIcon } from "@/components/v2";
import ResourceIdField from "@/components/v2/Form/ResourceIdField.vue";
@@ -690,9 +400,21 @@ import {
Instance,
InstanceOptions,
} from "@/types/proto/v1/instance_service";
-import { Engine, State } from "@/types/proto/v1/common";
-import { instanceServiceClient } from "@/grpcweb";
+import { Engine } from "@/types/proto/v1/common";
import { PlanType } from "@/types/proto/v1/subscription_service";
+import DataSourceSection from "./DataSourceSection/DataSourceSection.vue";
+import { EditDataSource, extractDataSourceEditState } from "./common";
+import { provideInstanceFormContext } from "./context";
+import {
+ MongoDBConnectionStringSchemaList,
+ SnowflakeExtraLinkPlaceHolder,
+ defaultPortForEngine,
+ EngineIconPath,
+ EngineList,
+} from "./constants";
+import { useInstanceSpecs } from "./specs";
+import { instanceServiceClient } from "@/grpcweb";
+import { extractBasicInfo } from "./common";
const props = defineProps({
instance: {
@@ -720,18 +442,8 @@ const cancel = () => {
emit("dismiss");
};
-interface EditDataSource extends DataSource {
- pendingCreate: boolean;
- updatedPassword: string;
- useEmptyPassword?: boolean;
- updateSsl?: boolean;
- updateSsh?: boolean;
-}
-
-type BasicInfo = Omit<Instance, "dataSources" | "engineVersion">;
-
interface LocalState {
- currentDataSourceType: DataSourceType;
+ editingDataSourceId: string | undefined;
showFeatureModal: boolean;
isTestingConnection: boolean;
isRequesting: boolean;
@@ -743,12 +455,13 @@ const { t } = useI18n();
const router = useRouter();
const instanceV1Store = useInstanceV1Store();
const settingV1Store = useSettingV1Store();
-const currentUserV1 = useCurrentUserV1();
const actuatorStore = useActuatorV1Store();
const subscriptionStore = useSubscriptionV1Store();
const state = reactive<LocalState>({
- currentDataSourceType: DataSourceType.ADMIN,
+ editingDataSourceId: props.instance?.dataSources.find(
+ (ds) => ds.type === DataSourceType.ADMIN
+ )?.id,
showFeatureModal: false,
isTestingConnection: false,
isRequesting: false,
@@ -756,12 +469,27 @@ const state = reactive<LocalState>({
createInstanceWarning: "",
});
-const hasReadonlyReplicaFeature = computed(() => {
- return subscriptionStore.hasInstanceFeature(
- "bb.feature.read-replica-connection",
- props.instance
- );
-});
+const instance = toRef(props, "instance");
+const context = provideInstanceFormContext({ instance });
+const {
+ isCreating,
+ allowEdit,
+ basicInfo,
+ dataSourceEditState,
+ adminDataSource,
+ editingDataSource,
+ hasReadonlyReplicaFeature,
+ showReadOnlyDataSourceFeatureModal,
+} = context;
+const {
+ showDatabase,
+ showSSL,
+ showSSH,
+ isEngineBeta,
+ defaultPort,
+ instanceLink,
+ allowEditPort,
+} = useInstanceSpecs(context);
const availableLicenseCount = computed(() => {
return Math.max(
@@ -778,30 +506,6 @@ const availableLicenseCountText = computed((): string => {
return `${availableLicenseCount.value}`;
});
-const extractBasicInfo = (instance: Instance | undefined): BasicInfo => {
- return {
- uid: instance?.uid ?? String(UNKNOWN_ID),
- name: instance?.name ?? UNKNOWN_INSTANCE_NAME,
- state: instance?.state ?? State.ACTIVE,
- title: instance?.title ?? t("instance.new-instance"),
- engine: instance?.engine ?? Engine.MYSQL,
- externalLink: instance?.externalLink ?? "",
- environment: instance?.environment ?? UNKNOWN_ENVIRONMENT_NAME,
- activation: instance
- ? instance.activation
- : subscriptionStore.currentPlan !== PlanType.FREE &&
- availableLicenseCount.value > 0,
- options: instance?.options
- ? cloneDeep(instance.options)
- : {
- // default to false (Manage based on database, aka CDB + non-CDB)
- schemaTenantMode: false,
- },
- };
-};
-
-const basicInfo = ref<BasicInfo>(extractBasicInfo(props.instance));
-
const environment = computed(() => {
return (
useEnvironmentV1Store().getEnvironmentByName(basicInfo.value.environment) ??
@@ -821,76 +525,6 @@ const resourceId = computed({
});
const resourceIdField = ref<InstanceType<typeof ResourceIdField>>();
-const getDataSourceByType = (
- instance: Instance | undefined,
- type: DataSourceType
-) => {
- return instance?.dataSources.find((ds) => ds.type === type);
-};
-
-const extractAdminDataSource = (
- instance: Instance | undefined
-): EditDataSource => {
- const ds = getDataSourceByType(instance, DataSourceType.ADMIN);
- return {
- ...cloneDeep(ds ?? emptyDataSource()),
- pendingCreate: ds === undefined,
- updatedPassword: "",
- useEmptyPassword: false,
- };
-};
-// We only support one admin data source and one read-only data source.
-const adminDataSource = ref<EditDataSource>(
- extractAdminDataSource(props.instance)
-);
-
-const extractReadOnlyDataSource = (
- instance: Instance | undefined
-): EditDataSource | undefined => {
- const ds = getDataSourceByType(instance, DataSourceType.READ_ONLY);
- if (ds) {
- return {
- ...cloneDeep(ds),
- pendingCreate: ds === undefined,
- updatedPassword: "",
- useEmptyPassword: false,
- };
- }
- return undefined;
-};
-const readonlyDataSource = ref<EditDataSource | undefined>(
- extractReadOnlyDataSource(props.instance)
-);
-
-const getDefaultPort = (engine: Engine) => {
- if (engine === Engine.CLICKHOUSE) {
- return "9000";
- } else if (engine === Engine.POSTGRES) {
- return "5432";
- } else if (engine === Engine.SNOWFLAKE) {
- return "443";
- } else if (engine === Engine.TIDB) {
- return "4000";
- } else if (engine === Engine.MONGODB) {
- return "27017";
- } else if (engine === Engine.REDIS) {
- return "6379";
- } else if (engine === Engine.ORACLE) {
- return "1521";
- } else if (engine === Engine.MSSQL) {
- return "1433";
- } else if (engine === Engine.REDSHIFT) {
- return "5439";
- } else if (engine === Engine.OCEANBASE) {
- return "2883";
- } else if (engine === Engine.DM) {
- return "5236";
- }
- return "3306";
-};
-
-const isCreating = computed(() => props.instance === undefined);
-
onMounted(async () => {
if (isCreating.value) {
adminDataSource.value.host = isDev() ? "127.0.0.1" : "host.docker.internal";
@@ -904,7 +538,7 @@ watch(
() => basicInfo.value.engine,
() => {
if (isCreating.value) {
- adminDataSource.value.port = getDefaultPort(basicInfo.value.engine);
+ adminDataSource.value.port = defaultPortForEngine(basicInfo.value.engine);
}
},
{
@@ -921,10 +555,6 @@ watch(
}
);
-const engineList = computed(() => {
- return supportedEngineV1List();
-});
-
const outboundIpList = computed(() => {
if (!settingV1Store.workspaceProfileSetting) {
return "";
@@ -932,32 +562,10 @@ const outboundIpList = computed(() => {
return settingV1Store.workspaceProfileSetting.outboundIpList.join(",");
});
-const EngineIconPath: Record<number, string> = {
- [Engine.MYSQL]: new URL("@/assets/db-mysql.png", import.meta.url).href,
- [Engine.POSTGRES]: new URL("@/assets/db-postgres.png", import.meta.url).href,
- [Engine.TIDB]: new URL("@/assets/db-tidb.png", import.meta.url).href,
- [Engine.SNOWFLAKE]: new URL("@/assets/db-snowflake.png", import.meta.url)
- .href,
- [Engine.CLICKHOUSE]: new URL("@/assets/db-clickhouse.png", import.meta.url)
- .href,
- [Engine.MONGODB]: new URL("@/assets/db-mongodb.png", import.meta.url).href,
- [Engine.SPANNER]: new URL("@/assets/db-spanner.png", import.meta.url).href,
- [Engine.REDIS]: new URL("@/assets/db-redis.png", import.meta.url).href,
- [Engine.ORACLE]: new URL("@/assets/db-oracle.svg", import.meta.url).href,
- [Engine.DM]: new URL("@/assets/db-dm.png", import.meta.url).href,
- [Engine.MSSQL]: new URL("@/assets/db-mssql.svg", import.meta.url).href,
- [Engine.REDSHIFT]: new URL("@/assets/db-redshift.svg", import.meta.url).href,
- [Engine.MARIADB]: new URL("@/assets/db-mariadb.png", import.meta.url).href,
- [Engine.OCEANBASE]: new URL("@/assets/db-oceanbase.png", import.meta.url)
- .href,
-};
-
-const mongodbConnectionStringSchemaList = ["mongodb://", "mongodb+srv://"];
-
const currentMongoDBConnectionSchema = computed(() => {
return adminDataSource.value.srv === false
- ? mongodbConnectionStringSchemaList[0]
- : mongodbConnectionStringSchemaList[1];
+ ? MongoDBConnectionStringSchemaList[0]
+ : MongoDBConnectionStringSchemaList[1];
});
const allowCreate = computed(() => {
if (basicInfo.value.engine === Engine.SPANNER) {
@@ -976,95 +584,24 @@ const allowCreate = computed(() => {
);
});
-const allowEdit = computed(() => {
- if (isCreating.value) return true;
-
- return (
- props.instance?.state === State.ACTIVE &&
- hasWorkspacePermissionV1(
- "bb.permission.workspace.manage-instance",
- currentUserV1.value.userRole
- )
- );
-});
-
-const allowEditPort = computed(() => {
- // MongoDB doesn't support specify port if using srv record.
- return !(
- basicInfo.value.engine === Engine.MONGODB && currentDataSource.value.srv
- );
-});
-
-const allowUsingEmptyPassword = computed(() => {
- return basicInfo.value.engine !== Engine.SPANNER;
-});
-
const valueChanged = computed(() => {
const original = getOriginalEditState();
const editing = {
basicInfo: basicInfo.value,
- adminDataSource: adminDataSource.value,
- readonlyDataSource: readonlyDataSource.value,
+ dataSources: dataSourceEditState.value.dataSources,
};
return !isEqual(editing, original);
});
-const defaultPort = computed(() => {
- return getDefaultPort(basicInfo.value.engine);
-});
-
-const currentDataSource = computed((): EditDataSource => {
- if (state.currentDataSourceType === DataSourceType.ADMIN) {
- return adminDataSource.value;
- } else if (state.currentDataSourceType === DataSourceType.READ_ONLY) {
- return readonlyDataSource.value!;
- } else {
- throw new Error("Unknown data source type");
- }
-});
-
-const hasReadOnlyDataSource = computed(() => {
- return readonlyDataSource.value !== undefined;
-});
-
-const snowflakeExtraLinkPlaceHolder =
- "https://us-west-1.console.aws.amazon.com/rds/home?region=us-west-1#database:id=mysql-instance-foo;is-cluster=false";
-
-const instanceLink = computed(() => {
- if (basicInfo.value.engine === Engine.SNOWFLAKE) {
- if (adminDataSource.value.host) {
- return `https://${
- adminDataSource.value.host.split("@")[0]
- }.snowflakecomputing.com/console`;
- }
- }
- return basicInfo.value.externalLink ?? "";
-});
-
-const hasReadonlyReplicaHost = computed((): boolean => {
- return basicInfo.value.engine !== Engine.SPANNER;
-});
-
-const hasReadonlyReplicaPort = computed((): boolean => {
- return basicInfo.value.engine !== Engine.SPANNER;
-});
-
-const showDatabase = computed((): boolean => {
- return (
- (basicInfo.value.engine === Engine.POSTGRES ||
- basicInfo.value.engine === Engine.REDSHIFT) &&
- state.currentDataSourceType === DataSourceType.ADMIN
- );
-});
-const showAuthenticationDatabase = computed((): boolean => {
- return basicInfo.value.engine === Engine.MONGODB;
-});
-const showSSL = computed((): boolean => {
- return instanceV1HasSSL(basicInfo.value.engine);
-});
-const showSSH = computed((): boolean => {
- return instanceV1HasSSH(basicInfo.value.engine);
-});
+// const currentDataSource = computed((): EditDataSource => {
+// if (state.currentDataSourceType === DataSourceType.ADMIN) {
+// return adminDataSource.value;
+// } else if (state.currentDataSourceType === DataSourceType.READ_ONLY) {
+// return readonlyDataSource.value!;
+// } else {
+// throw new Error("Unknown data source type");
+// }
+// });
const allowUpdate = computed((): boolean => {
if (!valueChanged.value) {
@@ -1074,20 +611,16 @@ const allowUpdate = computed((): boolean => {
if (!isValidSpannerHost(adminDataSource.value.host)) {
return false;
}
- if (
- readonlyDataSource.value &&
- !isValidSpannerHost(readonlyDataSource.value.host)
- ) {
- return false;
- }
+ // if (
+ // readonlyDataSource.value &&
+ // !isValidSpannerHost(readonlyDataSource.value.host)
+ // ) {
+ // return false;
+ // }
}
return true;
});
-const isEngineBeta = (engine: Engine): boolean => {
- return [Engine.DM].includes(engine);
-};
-
const handleSelectEnvironmentUID = (uid: number | string) => {
const environment = useEnvironmentV1Store().getEnvironmentByUID(String(uid));
basicInfo.value.environment = environment.name;
@@ -1125,136 +658,19 @@ const trimInputValue = (target: Event["target"]) => {
};
const handleMongodbConnectionStringSchemaChange = (event: Event) => {
+ const ds = editingDataSource.value;
+ if (!ds) return;
switch ((event.target as HTMLInputElement).value) {
- case mongodbConnectionStringSchemaList[0]:
- currentDataSource.value.srv = false;
+ case MongoDBConnectionStringSchemaList[0]:
+ ds.srv = false;
break;
- case mongodbConnectionStringSchemaList[1]:
+ case MongoDBConnectionStringSchemaList[1]:
// MongoDB doesn't support specify port if using srv record.
- currentDataSource.value.port = "";
- currentDataSource.value.srv = true;
+ ds.port = "";
+ ds.srv = true;
break;
default:
- currentDataSource.value.srv = false;
- }
-};
-
-const handleCurrentDataSourceHostInput = (event: Event) => {
- if (currentDataSource.value.type === DataSourceType.READ_ONLY) {
- if (!hasReadonlyReplicaFeature.value) {
- if (currentDataSource.value.host || currentDataSource.value.port) {
- currentDataSource.value.host = adminDataSource.value.host;
- currentDataSource.value.port = adminDataSource.value.port;
- state.showFeatureModal = true;
- return;
- }
- }
- }
-
- currentDataSource.value.host = trimInputValue(event.target);
-};
-
-const handleCurrentDataSourcePortInput = (event: Event) => {
- if (currentDataSource.value.type === DataSourceType.READ_ONLY) {
- if (!hasReadonlyReplicaFeature.value) {
- if (currentDataSource.value.host || currentDataSource.value.port) {
- currentDataSource.value.host = adminDataSource.value.host;
- currentDataSource.value.port = adminDataSource.value.port;
- state.showFeatureModal = true;
- return;
- }
- }
- }
-
- currentDataSource.value.port = trimInputValue(event.target);
-};
-
-const toggleUseEmptyPassword = (on: boolean) => {
- currentDataSource.value.useEmptyPassword = on;
- if (on) {
- currentDataSource.value.updatedPassword = "";
- }
-};
-
-const handleEditSsl = () => {
- const curr = currentDataSource.value;
- curr.sslCa = "";
- curr.sslCert = "";
- curr.sslKey = "";
- curr.updateSsl = true;
-};
-
-const handleEditSsh = () => {
- const curr = currentDataSource.value;
- curr.sshHost = "";
- curr.sshPort = "";
- curr.sshUser = "";
- curr.sshPassword = "";
- curr.sshPrivateKey = "";
- curr.updateSsh = true;
-};
-
-const handleCurrentDataSourceSslChange = (
- value: Partial<Pick<DataSource, "sslCa" | "sslCert" | "sslKey">>
-) => {
- Object.assign(currentDataSource.value, value);
- currentDataSource.value.updateSsl = true;
-};
-
-const handleCurrentDataSourceSshChange = (
- value: Partial<
- Pick<
- DataSourceOptions,
- "sshHost" | "sshPort" | "sshUser" | "sshPassword" | "sshPrivateKey"
- >
- >
-) => {
- Object.assign(currentDataSource.value, value);
- currentDataSource.value.updateSsh = true;
-};
-
-const handleCreateRODataSource = () => {
- if (isCreating.value) {
- return;
- }
-
- const tempDataSource: DataSource = {
- ...emptyDataSource(),
- id: "Read-only data source",
- type: DataSourceType.READ_ONLY,
- host: adminDataSource.value.host,
- port: adminDataSource.value.port,
- database: adminDataSource.value.database,
- };
- if (basicInfo.value.engine === Engine.SPANNER) {
- tempDataSource.host = adminDataSource.value.host;
- }
- readonlyDataSource.value = {
- ...tempDataSource,
- pendingCreate: true,
- updatedPassword: "",
- useEmptyPassword: false,
- };
- state.currentDataSourceType = DataSourceType.READ_ONLY;
-};
-
-const handleDeleteRODataSource = async () => {
- if (!readonlyDataSource.value) {
- return;
- }
-
- if (readonlyDataSource.value.pendingCreate) {
- state.currentDataSourceType = DataSourceType.ADMIN;
- readonlyDataSource.value = undefined;
- } else {
- const { instance } = props;
- if (!instance) return;
- const ds = getDataSourceByType(instance, DataSourceType.READ_ONLY);
- if (!ds) return;
-
- const updated = await instanceV1Store.deleteDataSource(instance, ds);
- state.currentDataSourceType = DataSourceType.ADMIN;
- await updateEditState(updated);
+ ds.srv = false;
}
};
@@ -1289,9 +705,20 @@ const validateResourceId = async (
};
const updateEditState = async (instance: Instance) => {
+ console.log("updateEditState");
+
basicInfo.value = extractBasicInfo(instance);
- adminDataSource.value = extractAdminDataSource(instance);
- readonlyDataSource.value = extractReadOnlyDataSource(instance);
+ const updatedEditState = extractDataSourceEditState(instance);
+ dataSourceEditState.value.dataSources = updatedEditState.dataSources;
+ if (
+ updatedEditState.dataSources.findIndex(
+ (ds) => ds.id === dataSourceEditState.value.editingDataSourceId
+ ) < 0
+ ) {
+ // The original selected data source id is no-longer in the latest data source list
+ dataSourceEditState.value.editingDataSourceId =
+ updatedEditState.editingDataSourceId;
+ }
// Backend will sync the schema when connection info changed, so we need to fetch the synced schema here.
instanceV1Store.fetchInstanceRoleListByName(instance.name);
@@ -1360,17 +787,16 @@ const doUpdate = async () => {
if (!instance) {
return;
}
-
if (!checkRODataSourceFeature(instance)) {
- state.showFeatureModal = true;
+ showReadOnlyDataSourceFeatureModal.value = true;
return;
}
-
// When clicking **Update** we may have more than one thing to do (if needed)
// 1. Patch the instance itself.
// 2. Update the admin datasource.
- // 3. Create OR update a read-only data source.
- const maybeUpdateInstance = async () => {
+ // 3. Create OR update read-only data source(s).
+
+ const maybeUpdateInstanceBasicInfo = async () => {
const instancePatch = {
...instance,
...basicInfo.value,
@@ -1416,33 +842,34 @@ const doUpdate = async () => {
const editing = extractDataSourceFromEdit(instance, adminDataSource.value);
return await updateDataSource(editing, original, adminDataSource.value);
};
- const maybeUpsertReadonlyDataSource = async () => {
- if (!readonlyDataSource.value) return;
- const editing = extractDataSourceFromEdit(
- instance,
- readonlyDataSource.value
+ const maybeUpsertReadonlyDataSources = async () => {
+ const readonlyDataSourceList = dataSourceEditState.value.dataSources.filter(
+ (ds) => ds.type === DataSourceType.READ_ONLY
);
- if (readonlyDataSource.value.pendingCreate) {
- return await instanceV1Store.createDataSource(instance, editing);
- } else {
- const original = instance.dataSources.find(
- (ds) => ds.type === DataSourceType.READ_ONLY
- );
- return await updateDataSource(
- editing,
- original,
- readonlyDataSource.value
- );
+ if (readonlyDataSourceList.length === 0) {
+ // Nothing to do
+ return;
+ }
+ // Upsert readonly data sources one by one
+ for (let i = 0; i < readonlyDataSourceList.length; i++) {
+ const editing = readonlyDataSourceList[i];
+ const patch = extractDataSourceFromEdit(instance, editing);
+ if (editing.pendingCreate) {
+ await instanceV1Store.createDataSource(instance, patch);
+ } else {
+ const original = instance.dataSources.find(
+ (ds) => ds.id === editing.id
+ );
+ await updateDataSource(patch, original, editing);
+ }
}
};
-
state.isRequesting = true;
try {
await useGracefulRequest(async () => {
- await maybeUpdateInstance();
+ await maybeUpdateInstanceBasicInfo();
await maybeUpdateAdminDataSource();
- await maybeUpsertReadonlyDataSource();
-
+ await maybeUpsertReadonlyDataSources();
const updatedInstance = instanceV1Store.getInstanceByName(instance.name);
await updateEditState(updatedInstance);
pushNotification({
@@ -1461,6 +888,10 @@ const doUpdate = async () => {
const testConnection = async (
silent = false
): Promise<{ success: boolean; message: string }> => {
+ if (!editingDataSource.value) {
+ throw new Error("should never reach this line");
+ }
+
// In different scenes, we use different methods to test connection.
const ok = () => {
if (!silent) {
@@ -1470,7 +901,6 @@ const testConnection = async (
title: t("instance.successfully-connected-instance"),
});
}
-
state.isTestingConnection = false;
return { success: true, message: "" };
};
@@ -1490,15 +920,13 @@ const testConnection = async (
manualHide: true,
});
}
-
state.isTestingConnection = false;
return { success: false, message: error };
};
-
state.isTestingConnection = true;
if (isCreating.value) {
// When creating new instance, use
- // CreateInstanceRequest.validateOnly = true
+ // adminDataSource + CreateInstanceRequest.validateOnly = true
const instance: Instance = {
...basicInfo.value,
engineVersion: "",
@@ -1527,10 +955,11 @@ const testConnection = async (
} else {
// Editing existed instance.
const instance = props.instance!;
- const ds = extractDataSourceFromEdit(instance, currentDataSource.value);
- if (currentDataSource.value.pendingCreate) {
+ const editingDS = editingDataSource.value;
+ const ds = extractDataSourceFromEdit(instance, editingDS);
+ if (editingDS.pendingCreate) {
// When read-only data source is about to be created, use
- // AddDataSourceRequest.validateOnly = true
+ // editingDataSource + AddDataSourceRequest.validateOnly = true
try {
await instanceServiceClient.addDataSource(
{
@@ -1548,16 +977,15 @@ const testConnection = async (
}
} else {
// When a data source (admin or read-only) has been edited, use
- // UpdateDataSourceRequest.validateOnly = true
+ // editingDataSource + UpdateDataSourceRequest.validateOnly = true
try {
const original = instance.dataSources.find(
- (ds) => ds.type === currentDataSource.value.type
- )!;
- const updateMask = calcDataSourceUpdateMask(
- ds,
- original,
- currentDataSource.value
+ (ds) => ds.id === editingDS.id
);
+ if (!original) {
+ throw new Error("should never reach this line");
+ }
+ const updateMask = calcDataSourceUpdateMask(ds, original, editingDS);
await instanceServiceClient.updateDataSource(
{
instance: instance.name,
@@ -1582,8 +1010,7 @@ const testConnection = async (
const getOriginalEditState = () => {
return {
basicInfo: extractBasicInfo(props.instance),
- adminDataSource: extractAdminDataSource(props.instance),
- readonlyDataSource: extractReadOnlyDataSource(props.instance),
+ dataSources: extractDataSourceEditState(props.instance).dataSources,
};
};
@@ -1668,40 +1095,43 @@ const extractDataSourceFromEdit = (
};
const checkRODataSourceFeature = (instance: Instance) => {
+ // This is to
+ // - Disallow creating any new RO data sources
+ // - Disallow updating any existed RO data sources
+ // if feature is not available.
+
// Early pass if the feature is available.
if (hasReadonlyReplicaFeature.value) {
return true;
}
- // Not editing/creating
- if (!readonlyDataSource.value) {
+ const readonlyDataSourceList = dataSourceEditState.value.dataSources.filter(
+ (ds) => ds.type === DataSourceType.READ_ONLY
+ );
+ if (readonlyDataSourceList.length === 0) {
+ // Not creating or editing any RO data source
return true;
}
- if (readonlyDataSource.value.pendingCreate) {
- // pre-flight feature guard check for creating RO datasource
- return false;
- } else {
- // pre-flight feature guard check for updating RO datasource
- const editing = extractDataSourceFromEdit(
- instance,
- readonlyDataSource.value
- );
- const original = instance.dataSources.find(
- (ds) => ds.type === DataSourceType.READ_ONLY
- );
- if (original) {
- const updateMask = calcDataSourceUpdateMask(
- editing,
- original,
- readonlyDataSource.value
- );
- if (updateMask.length > 0) {
- return false;
+ const checkOne = (ds: EditDataSource) => {
+ if (ds.pendingCreate) {
+ // Disallowed to create any new RO data sources
+ return false;
+ } else {
+ const editing = extractDataSourceFromEdit(instance, ds);
+ const original = instance.dataSources.find((d) => d.id === ds.id);
+ if (original) {
+ const updateMask = calcDataSourceUpdateMask(editing, original, ds);
+ // Disallowed to update any existed RO data source
+ if (updateMask.length > 0) {
+ return false;
+ }
}
}
- }
- return true;
+ return true;
+ };
+ // Need to check all RO data sources
+ return readonlyDataSourceList.every(checkOne);
};
const changeInstanceActivation = async (on: boolean) => {
diff --git a/frontend/src/components/InstanceForm/common.ts b/frontend/src/components/InstanceForm/common.ts
new file mode 100644
index 0000000000..9296e8f797
--- /dev/null
+++ b/frontend/src/components/InstanceForm/common.ts
@@ -0,0 +1,91 @@
+import { cloneDeep, first } from "lodash-es";
+import {
+ DataSource,
+ DataSourceType,
+ Instance,
+} from "@/types/proto/v1/instance_service";
+import { PlanType } from "@/types/proto/v1/subscription_service";
+import { Engine, State } from "@/types/proto/v1/common";
+import { t } from "@/plugins/i18n";
+import {
+ emptyDataSource,
+ UNKNOWN_ENVIRONMENT_NAME,
+ UNKNOWN_ID,
+ UNKNOWN_INSTANCE_NAME,
+} from "@/types";
+import { useInstanceV1Store, useSubscriptionV1Store } from "@/store";
+
+export type BasicInfo = Omit<Instance, "dataSources" | "engineVersion">;
+
+export type EditDataSource = DataSource & {
+ pendingCreate: boolean;
+ updatedPassword: string;
+ useEmptyPassword?: boolean;
+ updateSsl?: boolean;
+ updateSsh?: boolean;
+};
+
+export type DataSourceEditState = {
+ dataSources: EditDataSource[];
+ editingDataSourceId: string | undefined;
+};
+
+export const extractDataSourceEditState = (
+ instance: Instance | undefined
+): DataSourceEditState => {
+ const dataSources: EditDataSource[] = [];
+ instance?.dataSources.forEach((ds) => {
+ dataSources.push(wrapEditDataSource(ds));
+ });
+ const adminDS = dataSources.find((ds) => ds.type === DataSourceType.ADMIN);
+ if (!adminDS) {
+ dataSources.unshift(wrapEditDataSource(undefined));
+ }
+ const editingDataSourceId =
+ dataSources.find((ds) => ds.type === DataSourceType.ADMIN)?.id ??
+ first(dataSources)?.id ??
+ undefined;
+ return {
+ dataSources,
+ editingDataSourceId,
+ };
+};
+
+export const extractBasicInfo = (instance: Instance | undefined): BasicInfo => {
+ const subscriptionStore = useSubscriptionV1Store();
+ const instanceStore = useInstanceV1Store();
+
+ const availableLicenseCount = Math.max(
+ 0,
+ subscriptionStore.instanceLicenseCount - instanceStore.activateInstanceCount
+ );
+
+ return {
+ uid: instance?.uid ?? String(UNKNOWN_ID),
+ name: instance?.name ?? UNKNOWN_INSTANCE_NAME,
+ state: instance?.state ?? State.ACTIVE,
+ title: instance?.title ?? t("instance.new-instance"),
+ engine: instance?.engine ?? Engine.MYSQL,
+ externalLink: instance?.externalLink ?? "",
+ environment: instance?.environment ?? UNKNOWN_ENVIRONMENT_NAME,
+ activation: instance
+ ? instance.activation
+ : subscriptionStore.currentPlan !== PlanType.FREE &&
+ availableLicenseCount > 0,
+ options: instance?.options
+ ? cloneDeep(instance.options)
+ : {
+ // default to false (Manage based on database, aka CDB + non-CDB)
+ schemaTenantMode: false,
+ },
+ };
+};
+
+export const wrapEditDataSource = (ds: DataSource | undefined) => {
+ return {
+ ...cloneDeep(ds ?? emptyDataSource()),
+ pendingCreate: ds === undefined,
+ updatedPassword: "",
+ useEmptyPassword: false,
+ };
+};
diff --git a/frontend/src/components/InstanceForm/constants.ts b/frontend/src/components/InstanceForm/constants.ts
new file mode 100644
index 0000000000..25833b8296
--- /dev/null
+++ b/frontend/src/components/InstanceForm/constants.ts
@@ -0,0 +1,62 @@
+import { computed } from "vue";
+import { Engine } from "@/types/proto/v1/common";
+import { supportedEngineV1List } from "@/utils";
+
+export const defaultPortForEngine = (engine: Engine) => {
+ if (engine === Engine.CLICKHOUSE) {
+ return "9000";
+ } else if (engine === Engine.POSTGRES) {
+ return "5432";
+ } else if (engine === Engine.SNOWFLAKE) {
+ return "443";
+ } else if (engine === Engine.TIDB) {
+ return "4000";
+ } else if (engine === Engine.MONGODB) {
+ return "27017";
+ } else if (engine === Engine.REDIS) {
+ return "6379";
+ } else if (engine === Engine.ORACLE) {
+ return "1521";
+ } else if (engine === Engine.MSSQL) {
+ return "1433";
+ } else if (engine === Engine.REDSHIFT) {
+ return "5439";
+ } else if (engine === Engine.OCEANBASE) {
+ return "2883";
+ } else if (engine === Engine.DM) {
+ return "5236";
+ }
+ return "3306";
+};
+
+export const EngineList = computed(() => {
+ return supportedEngineV1List();
+});
+
+export const EngineIconPath: Record<number, string> = {
+ [Engine.MYSQL]: new URL("@/assets/db-mysql.png", import.meta.url).href,
+ [Engine.POSTGRES]: new URL("@/assets/db-postgres.png", import.meta.url).href,
+ [Engine.TIDB]: new URL("@/assets/db-tidb.png", import.meta.url).href,
+ [Engine.SNOWFLAKE]: new URL("@/assets/db-snowflake.png", import.meta.url)
+ .href,
+ [Engine.CLICKHOUSE]: new URL("@/assets/db-clickhouse.png", import.meta.url)
+ .href,
+ [Engine.MONGODB]: new URL("@/assets/db-mongodb.png", import.meta.url).href,
+ [Engine.SPANNER]: new URL("@/assets/db-spanner.png", import.meta.url).href,
+ [Engine.REDIS]: new URL("@/assets/db-redis.png", import.meta.url).href,
+ [Engine.ORACLE]: new URL("@/assets/db-oracle.svg", import.meta.url).href,
+ [Engine.DM]: new URL("@/assets/db-dm.png", import.meta.url).href,
+ [Engine.MSSQL]: new URL("@/assets/db-mssql.svg", import.meta.url).href,
+ [Engine.REDSHIFT]: new URL("@/assets/db-redshift.svg", import.meta.url).href,
+ [Engine.MARIADB]: new URL("@/assets/db-mariadb.png", import.meta.url).href,
+ [Engine.OCEANBASE]: new URL("@/assets/db-oceanbase.png", import.meta.url)
+ .href,
+};
+
+export const MongoDBConnectionStringSchemaList = [
+ "mongodb://",
+ "mongodb+srv://",
+];
+
+export const SnowflakeExtraLinkPlaceHolder =
+ "https://us-west-1.console.aws.amazon.com/rds/home?region=us-west-1#database:id=mysql-instance-foo;is-cluster=false";
diff --git a/frontend/src/components/InstanceForm/context.ts b/frontend/src/components/InstanceForm/context.ts
new file mode 100644
index 0000000000..c85007767f
--- /dev/null
+++ b/frontend/src/components/InstanceForm/context.ts
@@ -0,0 +1,107 @@
+import {
+ type InjectionKey,
+ type Ref,
+ provide,
+ inject,
+ computed,
+ ref,
+ ComputedRef,
+} from "vue";
+import { useCurrentUserV1, useSubscriptionV1Store } from "@/store";
+import { State } from "@/types/proto/v1/common";
+import { DataSourceType, Instance } from "@/types/proto/v1/instance_service";
+import { hasWorkspacePermissionV1 } from "@/utils";
+import {
+ BasicInfo,
+ DataSourceEditState,
+ EditDataSource,
+ extractBasicInfo,
+ extractDataSourceEditState,
+} from "./common";
+
+export type InstanceFormContext = {
+ instance: Ref<Instance | undefined>;
+ isCreating: Ref<boolean>;
+ allowEdit: Ref<boolean>;
+ basicInfo: Ref<BasicInfo>;
+ dataSourceEditState: Ref<DataSourceEditState>;
+ hasReadonlyReplicaFeature: ComputedRef<boolean>;
+ showReadOnlyDataSourceFeatureModal: Ref<boolean>;
+
+ // derived states
+ adminDataSource: ComputedRef<EditDataSource>;
+ editingDataSource: ComputedRef<EditDataSource | undefined>;
+ hasReadOnlyDataSource: ComputedRef<boolean>;
+};
+
+const KEY = Symbol(
+ "bb.workspace.instance-form"
+) as InjectionKey<InstanceFormContext>;
+
+export const provideInstanceFormContext = (
+ baseContext: Pick<InstanceFormContext, "instance">
+) => {
+ const me = useCurrentUserV1();
+ const { instance } = baseContext;
+ const isCreating = computed(() => instance.value === undefined);
+ const allowEdit = computed(() => {
+ if (isCreating.value) return true;
+
+ return (
+ instance.value?.state === State.ACTIVE &&
+ hasWorkspacePermissionV1(
+ "bb.permission.workspace.manage-instance",
+ me.value.userRole
+ )
+ );
+ });
+ const basicInfo = ref(extractBasicInfo(instance.value));
+ const dataSourceEditState = ref(extractDataSourceEditState(instance.value));
+
+ const adminDataSource = computed(() => {
+ return dataSourceEditState.value.dataSources.find(
+ (ds) => ds.type === DataSourceType.ADMIN
+ )!;
+ });
+ const editingDataSource = computed(() => {
+ const { dataSources, editingDataSourceId } = dataSourceEditState.value;
+ if (editingDataSourceId === undefined) return undefined;
+ return dataSources.find((ds) => ds.id === editingDataSourceId);
+ });
+ const hasReadOnlyDataSource = computed(() => {
+ return (
+ dataSourceEditState.value.dataSources.filter(
+ (ds) => ds.type === DataSourceType.READ_ONLY
+ ).length > 0
+ );
+ });
+
+ const hasReadonlyReplicaFeature = computed(() => {
+ return useSubscriptionV1Store().hasInstanceFeature(
+ "bb.feature.read-replica-connection",
+ instance.value
+ );
+ });
+
+ const showReadOnlyDataSourceFeatureModal = ref(false);
+
+ const context: InstanceFormContext = {
+ ...baseContext,
+ isCreating,
+ allowEdit,
+ basicInfo,
+ dataSourceEditState,
+ adminDataSource,
+ editingDataSource,
+ hasReadOnlyDataSource,
+ hasReadonlyReplicaFeature,
+ showReadOnlyDataSourceFeatureModal,
+ };
+ provide(KEY, context);
+
+ return context;
+};
+
+export const useInstanceFormContext = () => {
+ return inject(KEY)!;
+};
diff --git a/frontend/src/components/InstanceForm/specs.ts b/frontend/src/components/InstanceForm/specs.ts
new file mode 100644
index 0000000000..3eeb4f4ab9
--- /dev/null
+++ b/frontend/src/components/InstanceForm/specs.ts
@@ -0,0 +1,79 @@
+import { computed } from "vue";
+
+import { Engine } from "@/types/proto/v1/common";
+import { instanceV1HasSSH, instanceV1HasSSL } from "@/utils";
+import { InstanceFormContext, useInstanceFormContext } from "./context";
+import { defaultPortForEngine } from "./constants";
+
+export const useInstanceSpecs = (
+ context: InstanceFormContext | undefined = undefined
+) => {
+ if (!context) {
+ context = useInstanceFormContext();
+ }
+ const { basicInfo, adminDataSource, editingDataSource } = context;
+
+ const showDatabase = computed((): boolean => {
+ return (
+ (basicInfo.value.engine === Engine.POSTGRES ||
+ basicInfo.value.engine === Engine.REDSHIFT) &&
+ false
+ // TODO: state.currentDataSourceType === DataSourceType.ADMIN
+ );
+ });
+ const showSSL = computed((): boolean => {
+ return instanceV1HasSSL(basicInfo.value.engine);
+ });
+ const showSSH = computed((): boolean => {
+ return instanceV1HasSSH(basicInfo.value.engine);
+ });
+ const isEngineBeta = (engine: Engine): boolean => {
+ return [Engine.DM].includes(engine);
+ };
+ const defaultPort = computed(() => {
+ return defaultPortForEngine(basicInfo.value.engine);
+ });
+ const instanceLink = computed(() => {
+ if (basicInfo.value.engine === Engine.SNOWFLAKE) {
+ if (adminDataSource.value.host) {
+ return `https://${
+ adminDataSource.value.host.split("@")[0]
+ }.snowflakecomputing.com/console`;
+ }
+ }
+ return basicInfo.value.externalLink ?? "";
+ });
+ const allowEditPort = computed(() => {
+ // MongoDB doesn't support specify port if using srv record.
+ return !(
+ basicInfo.value.engine === Engine.MONGODB && editingDataSource.value?.srv
+ );
+ });
+
+ const allowUsingEmptyPassword = computed(() => {
+ return basicInfo.value.engine !== Engine.SPANNER;
+ });
+ const showAuthenticationDatabase = computed((): boolean => {
+ return basicInfo.value.engine === Engine.MONGODB;
+ });
+ const hasReadonlyReplicaHost = computed((): boolean => {
+ return basicInfo.value.engine !== Engine.SPANNER;
+ });
+ const hasReadonlyReplicaPort = computed((): boolean => {
+ return basicInfo.value.engine !== Engine.SPANNER;
+ });
+
+ return {
+ showDatabase,
+ showSSL,
+ showSSH,
+ isEngineBeta,
+ defaultPort,
+ instanceLink,
+ allowEditPort,
+ allowUsingEmptyPassword,
+ showAuthenticationDatabase,
+ hasReadonlyReplicaHost,
+ hasReadonlyReplicaPort,
+ };
+};
diff --git a/frontend/src/types/v1/dataSource.ts b/frontend/src/types/v1/dataSource.ts
index 6324a6dbcb..84aa5132a5 100644
--- a/frontend/src/types/v1/dataSource.ts
+++ b/frontend/src/types/v1/dataSource.ts
@@ -1,8 +1,10 @@
+import { v4 as uuidv4 } from "uuid";
import { DataSource, DataSourceType } from "../proto/v1/instance_service";
export const emptyDataSource = () => {
return DataSource.fromJSON({
type: DataSourceType.ADMIN,
+ id: uuidv4(),
});
};