Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: use v1 selectors in creating database form (#8060)
boojackcf92c074c1da
diff --git a/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue b/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vueindex 7b3356c767..61085b35a2 100644--- a/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue+++ b/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue@@ -6,13 +6,11 @@{{ $t("common.project") }} <span style="color: red">*</span></label><ProjectSelect- id="project"- class="mt-1"- name="project"+ class="mt-1 !w-full"required:disabled="!allowEditProject"- :selected-id="state.projectId"- @select-project-id="selectProject"+ :project="state.projectId"+ @update:project="selectProject"/></div>@@ -21,13 +19,13 @@{{ $t("create-db.new-database-name") }}<span class="text-red-600">*</span></label>- <input- id="databaseName"- v-model="state.databaseName"+ <NInput+ v-model:value="state.databaseName"requiredname="databaseName"type="text"- class="textfield mt-1 w-full"+ class="mt-1 w-full"+ :placeholder="$t('create-db.new-database-name')"/><span v-if="isReservedName" class="text-red-600"><i18n-t keypath="create-db.reserved-db-error">@@ -49,13 +47,12 @@{{ $t("create-db.new-collection-name") }}<span class="text-red-600">*</span></label>- <input- id="tableName"- v-model="state.tableName"+ <NInput+ v-model:value="state.tableName"requiredname="tableName"type="text"- class="textfield mt-1 w-full"+ class="mt-1 w-full"/></div>@@ -63,12 +60,11 @@<label for="name" class="textlabel">{{ $t("create-db.cluster") }}</label>- <input- id="name"- v-model="state.cluster"+ <NInput+ v-model:value="state.cluster"name="cluster"type="text"- class="textfield mt-1 w-full"+ class="mt-1 w-full"/></div>@@ -87,12 +83,12 @@</label><!-- It's default selected to the first env, so we don't need to set `required` here --><EnvironmentSelect- id="environment"- class="mt-1 w-full"+ class="mt-1"+ requiredname="environment":disabled="!allowEditEnvironment"- :selected-id="state.environmentId"- @select-environment-id="selectEnvironment"+ :environment="state.environmentId"+ @update:environment="selectEnvironment"/></div>@@ -108,15 +104,13 @@</div><div class="flex flex-row space-x-2 items-center"><InstanceSelect- id="instance"class="mt-1"name="instance"required:disabled="!allowEditInstance"- :selected-id="state.instanceId"- :environment-id="state.environmentId"+ :instance="state.instanceId":filter="instanceV1HasCreateDatabase"- @select-instance-id="selectInstance"+ @update:instance="selectInstance"/></div></div>@@ -127,13 +121,12 @@<span class="text-red-600">*</span></label><InstanceRoleSelect- id="instance-user"class="mt-1"name="instance-user":instance-id="state.instanceId":role="state.instanceRole":filter="filterInstanceRole"- @select="selectInstanceRole"+ @update:instance-role="selectInstanceRole"/></div>@@ -156,12 +149,11 @@: $t("db.character-set")}}</label>- <input- id="charset"- v-model="state.characterSet"+ <NInput+ v-model:value="state.characterSet"name="charset"type="text"- class="textfield mt-1 w-full"+ class="mt-1 w-full":placeholder="defaultCharsetOfEngineV1(selectedInstance.engine)"/></div>@@ -170,12 +162,11 @@<label for="collation" class="textlabel">{{ $t("db.collation") }}</label>- <input- id="collation"- v-model="state.collation"+ <NInput+ v-model:value="state.collation"name="collation"type="text"- class="textfield mt-1 w-full"+ class="mt-1 w-full":placeholder="defaultCollationOfEngineV1(selectedInstance.engine) || 'default'"@@ -216,15 +207,18 @@<script lang="ts" setup>import { isEmpty } from "lodash-es";+import { NInput } from "naive-ui";import { v4 as uuidv4 } from "uuid";import { computed, reactive, PropType, watchEffect, ref, toRef } from "vue";import { useRouter } from "vue-router";-import EnvironmentSelect from "@/components/EnvironmentSelect.vue";import InstanceRoleSelect from "@/components/InstanceRoleSelect.vue";-import InstanceSelect from "@/components/InstanceSelect.vue";import MemberSelect from "@/components/MemberSelect.vue";-import ProjectSelect from "@/components/ProjectSelect.vue";-import { InstanceV1EngineIcon } from "@/components/v2";+import {+ ProjectSelect,+ EnvironmentSelect,+ InstanceSelect,+ InstanceV1EngineIcon,+} from "@/components/v2";import {experimentalCreateIssueByPlan,hasFeature,@@ -320,6 +314,7 @@ const instanceV1Store = useInstanceV1Store();const router = useRouter();const currentUserV1 = useCurrentUserV1();+const environmentV1Store = useEnvironmentV1Store();const projectV1Store = useProjectV1Store();const developmentUseV1IssueUI = computed(() => {return !!useActuatorV1Store().serverInfo?.developmentUseV2Scheduler;@@ -444,16 +439,15 @@ useDBNameTemplateInputState(project, {labels: toRef(state, "labels"),});-const selectProject = (projectId: string) => {+const selectProject = (projectId: string | undefined) => {state.projectId = projectId;};-const selectEnvironment = (environmentId: string) => {+const selectEnvironment = (environmentId: string | undefined) => {state.environmentId = environmentId;};const selectInstance = (instanceId: string | undefined) => {- if (!instanceId) return;state.instanceId = instanceId;};@@ -499,13 +493,17 @@ const createV1 = async () => {}}- const instance = useInstanceV1Store().getInstanceByUID(String(instanceId));+ const instance = instanceV1Store.getInstanceByUID(String(instanceId));+ const environment = environmentV1Store.getEnvironmentByUID(+ state.environmentId!+ );const specs: Plan_Spec[] = [];const createDatabaseConfig: Plan_CreateDatabaseConfig = {target: instance.name,database: databaseName,table: tableName,labels: state.labels,+ environment: environment.name,characterSet:state.characterSet ||@@ -681,7 +679,7 @@ watchEffect(() => {const { labels } = state;const key = "bb.environment";if (envId) {- const env = useEnvironmentV1Store().getEnvironmentByUID(envId);+ const env = environmentV1Store.getEnvironmentByUID(envId);const resourceId = extractEnvironmentResourceName(env.name);labels[key] = resourceId;} else {diff --git a/frontend/src/components/CreateDatabasePrepForm/DatabaseLabelForm.vue b/frontend/src/components/CreateDatabasePrepForm/DatabaseLabelForm.vueindex 63a98a18f8..60f29482e3 100644--- a/frontend/src/components/CreateDatabasePrepForm/DatabaseLabelForm.vue+++ b/frontend/src/components/CreateDatabasePrepForm/DatabaseLabelForm.vue@@ -12,15 +12,11 @@</label></div><div class="flex flex-col space-y-1">- <BBTextField- :required="item.required"- :force-required="false"+ <NInput:value="getLabelValue(item.label)":placeholder="getLabelPlaceholder(item.label)"class="text-sm"- @input="- setLabelValue(item.label, ($event.target as HTMLInputElement).value)- "+ @input="(value) => setLabelValue(item.label, value)"/></div></div>@@ -29,6 +25,7 @@<script lang="ts" setup>/* eslint-disable vue/no-mutating-props */+import { NInput } from "naive-ui";import { capitalize } from "lodash-es";import { computed, defineComponent } from "vue";import type { Project } from "@/types/proto/v1/project_service";@@ -38,7 +35,6 @@ import {parseLabelListInTemplate,PRESET_LABEL_KEYS,} from "@/utils";-import { BBTextField } from "@/bbkit";const props = defineProps<{project: Project;diff --git a/frontend/src/components/InstanceRoleSelect.vue b/frontend/src/components/InstanceRoleSelect.vueindex 7ea119c758..b4e5b44cf1 100644--- a/frontend/src/components/InstanceRoleSelect.vue+++ b/frontend/src/components/InstanceRoleSelect.vue@@ -1,23 +1,29 @@<template>- <BBSelect- :selected-item="selectedInstanceRole"- :item-list="filteredInstanceUserList"+ <NSelect+ v-bind="$attrs"+ :value="role"+ :options="options":placeholder="$t('instance.select-database-user')"- :show-prefix-item="true"- @select-item="handleSelectItem"- >- <template #menuItem="{ item: instance }: { item: InstanceRole }">- {{ instance.roleName }}- </template>- </BBSelect>+ :filter="filterByTitle"+ :filterable="true"+ :virtual-scroll="true"+ :fallback-option="false"+ @update:value="$emit('update:instance-role', $event)"+ /></template><script lang="ts" setup>+import { SelectOption } from "naive-ui";import { PropType, computed, ref, watch } from "vue";import { useInstanceV1Store } from "@/store";import { UNKNOWN_ID } from "@/types";import { InstanceRole } from "@/types/proto/v1/instance_role_service";+interface InstanceRoleSelectOption extends SelectOption {+ value: string;+ instanceRole: InstanceRole;+}+const props = defineProps({role: {type: String,@@ -34,41 +40,43 @@ const props = defineProps({});const emit = defineEmits<{- (event: "select", role: string | undefined): void;+ (event: "update:instance-role", role: string | undefined): void;}>();const instanceV1Store = useInstanceV1Store();-const selectedInstanceRole = ref<InstanceRole>();const instanceRoleList = ref<InstanceRole[]>([]);watch(() => props.instanceId,async () => {- selectedInstanceRole.value = undefined;const instance = instanceV1Store.getInstanceByUID(props.instanceId);instanceRoleList.value = await instanceV1Store.fetchInstanceRoleListByName(instance.name);- emit("select", undefined);+ emit("update:instance-role", undefined);},{ immediate: true });-watch(- () => props.role,- () => {- selectedInstanceRole.value = instanceRoleList.value.find(- (user) => user.name === props.role- );- }-);+const options = computed(() => {+ return filteredInstanceRoleList.value.map<InstanceRoleSelectOption>(+ (instanceRole) => {+ return {+ instanceRole,+ value: instanceRole.name,+ label: instanceRole.roleName,+ };+ }+ );+});-const filteredInstanceUserList = computed(() => {+const filteredInstanceRoleList = computed(() => {if (!props.filter) return instanceRoleList.value;return instanceRoleList.value.filter(props.filter);});-const handleSelectItem = (instanceRole: InstanceRole) => {- emit("select", instanceRole.name);+const filterByTitle = (pattern: string, option: SelectOption) => {+ const { instanceRole } = option as InstanceRoleSelectOption;+ return instanceRole.roleName.toLowerCase().includes(pattern.toLowerCase());};</script>diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vueindex c937399596..818a91420f 100644--- a/frontend/src/components/ProjectDatabasesPanel.vue+++ b/frontend/src/components/ProjectDatabasesPanel.vue@@ -12,6 +12,7 @@</div><NInputGroup style="width: auto"><InstanceSelect+ class="!w-48":instance="state.instance":include-all="true":filter="filterInstance"diff --git a/frontend/src/components/SensitiveData/SensitiveColumnView.vue b/frontend/src/components/SensitiveData/SensitiveColumnView.vueindex 616779d7c2..de27ecc965 100644--- a/frontend/src/components/SensitiveData/SensitiveColumnView.vue+++ b/frontend/src/components/SensitiveData/SensitiveColumnView.vue@@ -19,6 +19,7 @@"/><InstanceSelect+ class="!w-48":instance="state.selectedInstanceUid":include-all="true":environment="environment?.uid"diff --git a/frontend/src/components/SlowQuery/Panel/LogFilter.vue b/frontend/src/components/SlowQuery/Panel/LogFilter.vueindex 6388655ce0..cc26e483ee 100644--- a/frontend/src/components/SlowQuery/Panel/LogFilter.vue+++ b/frontend/src/components/SlowQuery/Panel/LogFilter.vue@@ -34,6 +34,7 @@/><InstanceSelectv-if="filterTypes.includes('instance')"+ class="!w-48":instance="params.instance?.uid ?? String(UNKNOWN_ID)":environment="params.environment?.uid":include-all="true"diff --git a/frontend/src/components/TransferDatabaseForm/TransferSourceSelector.vue b/frontend/src/components/TransferDatabaseForm/TransferSourceSelector.vueindex cb152fdf1b..c38c7b6b9f 100644--- a/frontend/src/components/TransferDatabaseForm/TransferSourceSelector.vue+++ b/frontend/src/components/TransferDatabaseForm/TransferSourceSelector.vue@@ -35,6 +35,7 @@<NInputGroup style="width: auto"><InstanceSelectv-if="state.transferSource == 'DEFAULT'"+ class="!w-48":instance="instanceFilter?.uid ?? String(UNKNOWN_ID)":include-all="true":filter="filterInstance"diff --git a/frontend/src/components/v2/Select/EnvironmentSelect.vue b/frontend/src/components/v2/Select/EnvironmentSelect.vuenew file mode 100644index 0000000000..4118f9b336--- /dev/null+++ b/frontend/src/components/v2/Select/EnvironmentSelect.vue@@ -0,0 +1,91 @@+<template>+ <NSelect+ v-bind="$attrs"+ :value="environment"+ :options="options"+ :placeholder="$t('environment.select')"+ :filterable="true"+ :filter="filterByName"+ @update:value="$emit('update:environment', $event)"+ />+</template>++<script lang="ts" setup>+import { NSelect, SelectOption } from "naive-ui";+import { computed, watchEffect } from "vue";+import { useEnvironmentV1Store, useProjectV1Store } from "@/store";+import { State } from "@/types/proto/v1/common";+import { Environment } from "@/types/proto/v1/environment_service";++interface EnvironmentSelectOption extends SelectOption {+ value: string;+ environment: Environment;+}++const props = withDefaults(+ defineProps<{+ environment: string | undefined;+ includeArchived?: boolean;+ filter?: (environment: Environment, index: number) => boolean;+ }>(),+ {+ includeArchived: false,+ filter: () => true,+ }+);++defineEmits<{+ (event: "update:environment", id: string | undefined): void;+}>();++const projectV1Store = useProjectV1Store();+const environmentV1Store = useEnvironmentV1Store();++const prepare = () => {+ projectV1Store.fetchProjectList(true /* showDeleted */);+};++const rawEnvironmentList = computed(() => {+ const list = environmentV1Store.getEnvironmentList(true /* showDeleted */);+ return list;+});++const combinedEnvironmentList = computed(() => {+ let list = rawEnvironmentList.value.filter((environment) => {+ if (props.includeArchived) return true;+ if (environment.state === State.ACTIVE) return true;+ // ARCHIVED+ if (environment.uid === props.environment) return true;+ return false;+ });++ if (props.filter) {+ list = list.filter(props.filter);+ }++ return list;+});++const options = computed(() => {+ return combinedEnvironmentList.value.map<EnvironmentSelectOption>(+ (environment) => {+ return {+ environment,+ value: environment.uid,+ label: environment.title,+ };+ }+ );+});++const filterByName = (pattern: string, option: SelectOption) => {+ const { environment } = option as EnvironmentSelectOption;+ pattern = pattern.toLowerCase();+ return (+ environment.name.toLowerCase().includes(pattern) ||+ environment.title.toLowerCase().includes(pattern)+ );+};++watchEffect(prepare);+</script>diff --git a/frontend/src/components/v2/Select/InstanceSelect.vue b/frontend/src/components/v2/Select/InstanceSelect.vueindex 727c6804ae..b500d18675 100644--- a/frontend/src/components/v2/Select/InstanceSelect.vue+++ b/frontend/src/components/v2/Select/InstanceSelect.vue@@ -1,5 +1,6 @@<template><NSelect+ v-bind="$attrs":value="instance":options="options":placeholder="$t('instance.select')"@@ -9,7 +10,6 @@:virtual-scroll="true":fallback-option="false"class="bb-instance-select"- style="width: 12rem"@update:value="$emit('update:instance', $event)"/></template>diff --git a/frontend/src/components/v2/Select/ProjectSelect.vue b/frontend/src/components/v2/Select/ProjectSelect.vueindex a6f32485fe..0d6e615fc5 100644--- a/frontend/src/components/v2/Select/ProjectSelect.vue+++ b/frontend/src/components/v2/Select/ProjectSelect.vue@@ -1,5 +1,6 @@<template><NSelect+ v-bind="$attrs":value="project":options="options":placeholder="$t('project.select')"diff --git a/frontend/src/components/v2/Select/index.ts b/frontend/src/components/v2/Select/index.tsindex 8f77fc6b5f..d4b96b623f 100644--- a/frontend/src/components/v2/Select/index.ts+++ b/frontend/src/components/v2/Select/index.ts@@ -1,5 +1,6 @@import AnnouncementLevelSelect from "./AnnouncementLevelSelect.vue";import DatabaseSelect from "./DatabaseSelect.vue";+import EnvironmentSelect from "./EnvironmentSelect.vue";import InstanceSelect from "./InstanceSelect.vue";import ProjectSelect from "./ProjectSelect.vue";import RoleRadioSelect from "./RoleRadioSelect.vue";@@ -10,6 +11,7 @@ export {AnnouncementLevelSelect,InstanceSelect,DatabaseSelect,+ EnvironmentSelect,ProjectSelect,WorkspaceRoleSelect,RoleRadioSelect,diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vueindex ad7047a68d..cb4e1ac306 100644--- a/frontend/src/views/DatabaseDashboard.vue+++ b/frontend/src/views/DatabaseDashboard.vue@@ -31,6 +31,7 @@<NInputGroup style="width: auto"><InstanceSelect+ class="!w-48":instance="state.instanceFilter":include-all="true":environment="selectedEnvironment?.uid"diff --git a/frontend/src/views/ExportCenter/index.vue b/frontend/src/views/ExportCenter/index.vueindex 69aeb76158..e7cb0f89de 100644--- a/frontend/src/views/ExportCenter/index.vue+++ b/frontend/src/views/ExportCenter/index.vue@@ -9,6 +9,7 @@@update:project="changeProjectId"/><InstanceSelect+ class="!w-48":instance="state.filterParams.instance?.uid ?? String(UNKNOWN_ID)":include-all="true"@update:instance="changeInstanceId"