Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: support filter by address (#13414)
ecmadao895af6240981
diff --git a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.tsindex d41f78caed..553014a554 100644--- a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts+++ b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts@@ -1,6 +1,5 @@import type { Ref, VNode } from "vue";import { computed, h, unref } from "vue";-import { useI18n } from "vue-i18n";import { useRoute } from "vue-router";import GitIcon from "@/components/GitIcon.vue";import {@@ -9,6 +8,7 @@ import {RichDatabaseName,EnvironmentV1Name,} from "@/components/v2";+import { t } from "@/plugins/i18n";import {useDatabaseV1Store,useEnvironmentV1List,@@ -33,7 +33,6 @@ export const useCommonSearchScopeOptions = (params: Ref<SearchParams>,supportOptionIdList: MaybeRef<SearchScopeId[]>) => {- const { t } = useI18n();const route = useRoute();const databaseV1Store = useDatabaseV1Store();const environmentStore = useEnvironmentV1Store();@@ -41,7 +40,7 @@ export const useCommonSearchScopeOptions = (const projectList = useProjectV1Store().projectList;const project = computed(() => {- const { projectId } = route.params;+ const { projectId } = route?.params ?? {};if (projectId && typeof projectId === "string") {return `projects/${projectId}`;}diff --git a/frontend/src/components/PasswordSigninForm.vue b/frontend/src/components/PasswordSigninForm.vueindex cb3b0b4868..e9865d6ee0 100644--- a/frontend/src/components/PasswordSigninForm.vue+++ b/frontend/src/components/PasswordSigninForm.vue@@ -107,6 +107,9 @@ const props = withDefaults(showForgotPassword?: boolean;}>(),{+ email: "",+ password: "",+ showPassword: false,showForgotPassword: true,});@@ -116,9 +119,9 @@ const route = useRoute();const authStore = useAuthStore();const state = reactive<LocalState>({- email: props.email || "",- password: props.password || "",- showPassword: props.showPassword || false,+ email: props.email,+ password: props.password,+ showPassword: props.showPassword,isLoading: false,});diff --git a/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue b/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vueindex 25ea10c2d5..8f1fdc6354 100644--- a/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue+++ b/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue@@ -26,14 +26,18 @@</template><script setup lang="tsx">-import { ExternalLinkIcon } from "lucide-vue-next";+import {+ ExternalLinkIcon,+ ChevronDownIcon,+ ChevronUpIcon,+} from "lucide-vue-next";import { NButton, NDataTable, type DataTableColumn } from "naive-ui";-import { computed, reactive } from "vue";+import { computed, reactive, watch } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";import { InstanceV1Name } from "@/components/v2";import type { ComposedInstance } from "@/types";-import { urlfy, hostPortOfInstanceV1 } from "@/utils";+import { urlfy, hostPortOfInstanceV1, hostPortOfDataSource } from "@/utils";import EnvironmentV1Name from "../../EnvironmentV1Name.vue";import InstanceOperations from "./InstanceOperations.vue";@@ -43,6 +47,7 @@ type InstanceDataTableColumn = DataTableColumn<ComposedInstance> & {interface LocalState {selectedInstance: Set<string>;+ dataSourceToggle: Set<string>;processing: boolean;}@@ -54,6 +59,7 @@ const props = withDefaults(showSelection?: boolean;showOperation?: boolean;canAssignLicense?: boolean;+ defaultExpandDataSource?: string[];onClick?: (instance: ComposedInstance, e: MouseEvent) => void;}>(),{@@ -62,6 +68,7 @@ const props = withDefaults(showOperation: true,canAssignLicense: true,onClick: undefined,+ defaultExpandDataSource: () => [],});@@ -69,9 +76,21 @@ const { t } = useI18n();const router = useRouter();const state = reactive<LocalState>({selectedInstance: new Set(),+ dataSourceToggle: new Set(),processing: false,});+watch(+ () => props.defaultExpandDataSource,+ () => {+ state.dataSourceToggle = new Set(props.defaultExpandDataSource);+ },+ {+ immediate: true,+ deep: true,+ }+);+const columnList = computed((): InstanceDataTableColumn[] => {const SELECTION: InstanceDataTableColumn = {type: "selection",@@ -108,7 +127,32 @@ const columnList = computed((): InstanceDataTableColumn[] => {key: "address",title: t("common.address"),resizable: true,- render: (instance) => hostPortOfInstanceV1(instance),+ render: (instance) => {+ return (+ <div class={"flex items-start gap-x-2"}>+ <div>+ {state.dataSourceToggle.has(instance.name)+ ? instance.dataSources.map((ds) => (+ <div>{hostPortOfDataSource(ds)}</div>+ ))+ : hostPortOfInstanceV1(instance)}+ </div>+ {instance.dataSources.length > 1 ? (+ <NButton+ quaternary+ size="tiny"+ onClick={(e) => handleDataSourceToggle(e, instance)}+ >+ {state.dataSourceToggle.has(instance.name) ? (+ <ChevronUpIcon class={"w-4 cursor-pointer"} />+ ) : (+ <ChevronDownIcon class={"w-4 cursor-pointer"} />+ )}+ </NButton>+ ) : null}+ </div>+ );+ },};const EXTERNAL_LINK: InstanceDataTableColumn = {key: "project",@@ -139,6 +183,15 @@ const columnList = computed((): InstanceDataTableColumn[] => {);});+const handleDataSourceToggle = (e: MouseEvent, instance: ComposedInstance) => {+ e.stopPropagation();+ if (state.dataSourceToggle.has(instance.name)) {+ state.dataSourceToggle.delete(instance.name);+ } else {+ state.dataSourceToggle.add(instance.name);+ }+};+const rowProps = (instance: ComposedInstance) => {return {style: "cursor: pointer;",diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 63091d4352..79602d93c7 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1557,6 +1557,14 @@"default-value": "Default (10)","description": "Limiting connection and resource usage is achieved by setting the maximum number of connections to the instance.","max-value": "Maximum {value} connections"+ },+ "advanced-search": {+ "scope": {+ "address": {+ "title": "Address",+ "description": "Filter by address"+ }+ }}},"environment": {diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 33a63cfea5..f56c6f92b3 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1557,6 +1557,14 @@"default-value": "Predeterminado (10)","description": "Limitar la conexión y el uso de recursos se logra estableciendo el número máximo de conexiones a la instancia.","max-value": "Máximo {value} conexiones"+ },+ "advanced-search": {+ "scope": {+ "address": {+ "title": "DIRECCIÓN",+ "description": "Filtrar por dirección"+ }+ }}},"environment": {@@ -3668,4 +3676,4 @@"worksheet": {"self": "Hoja de trabajo"}-}\ No newline at end of file+}diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex e66f594df5..84c2fda2b6 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -1557,6 +1557,14 @@"default-value": "デフォルト (10 接続)","description": "インスタンスの最大接続数を設定して、接続とリソースの使用を制限します。","max-value": "最大接続数 {value}"+ },+ "advanced-search": {+ "scope": {+ "address": {+ "title": "住所",+ "description": "住所でフィルタリング"+ }+ }}},"environment": {@@ -3668,4 +3676,4 @@"worksheet": {"self": "ワークシート"}-}\ No newline at end of file+}diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 9bcd7759e5..27f411b2d6 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1557,6 +1557,14 @@"default-value": "默认 (10 个连接)","description": "通过设置实例的最大连接数来限制连接和资源的使用。","max-value": "最大连接数 {value} 个"+ },+ "advanced-search": {+ "scope": {+ "address": {+ "title": "地址",+ "description": "按地址过滤"+ }+ }}},"environment": {diff --git a/frontend/src/utils/v1/advanced-search/common.ts b/frontend/src/utils/v1/advanced-search/common.tsindex b25a9bdc24..8e3f7f536c 100644--- a/frontend/src/utils/v1/advanced-search/common.ts+++ b/frontend/src/utils/v1/advanced-search/common.ts@@ -28,6 +28,8 @@ export const SearchScopeIdList = ["method","level","actor",+ // instance related search scopes.+ "address",] as const;export type SearchScopeId =diff --git a/frontend/src/utils/v1/instance.ts b/frontend/src/utils/v1/instance.tsindex 8bd200bec9..536b44bb57 100644--- a/frontend/src/utils/v1/instance.ts+++ b/frontend/src/utils/v1/instance.ts@@ -1,6 +1,7 @@import { keyBy, orderBy } from "lodash-es";import { computed, unref } from "vue";import { useI18n } from "vue-i18n";+import { t } from "@/plugins/i18n";import { useEnvironmentV1Store, useSubscriptionV1Store } from "@/store";import type { ComposedInstance, MaybeRef } from "@/types";import { isValidProjectName, languageOfEngineV1 } from "@/types";@@ -10,11 +11,13 @@ import type {Instance,InstanceResource,} from "@/types/proto/v1/instance_service";-import { DataSourceType } from "@/types/proto/v1/instance_service";+import {+ DataSourceType,+ type DataSource,+} from "@/types/proto/v1/instance_service";import { PlanType } from "@/types/proto/v1/subscription_service";export function instanceV1Name(instance: Instance | InstanceResource) {- const { t } = useI18n();const store = useSubscriptionV1Store();let name = instance.title;// instance cannot be deleted and activated at the same time.@@ -52,10 +55,17 @@ export const sortInstanceV1List = ();};-export const hostPortOfInstanceV1 = (instance: Instance | InstanceResource) => {- const ds =- instance.dataSources.find((ds) => ds.type === DataSourceType.ADMIN) ??- instance.dataSources[0];+export const readableDataSourceType = (type: DataSourceType): string => {+ if (type === DataSourceType.ADMIN) {+ return t("data-source.admin");+ } else if (type === DataSourceType.READ_ONLY) {+ return t("data-source.read-only");+ } else {+ return "Unknown";+ }+};++export const hostPortOfDataSource = (ds: DataSource | undefined): string => {if (!ds) {return "";}@@ -66,6 +76,13 @@ export const hostPortOfInstanceV1 = (instance: Instance | InstanceResource) => {return parts.join(":");};+export const hostPortOfInstanceV1 = (instance: Instance | InstanceResource) => {+ const ds =+ instance.dataSources.find((ds) => ds.type === DataSourceType.ADMIN) ??+ instance.dataSources[0];+ return hostPortOfDataSource(ds);+};+// Sort the list to put prod items first.export const sortInstanceV1ListByEnvironmentV1 = <T extends Instance>(list: T[],diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vueindex caa73d63f8..bb620ae1c5 100644--- a/frontend/src/views/InstanceDashboard.vue+++ b/frontend/src/views/InstanceDashboard.vue@@ -17,14 +17,20 @@:loading="!ready":instance-list="filteredInstanceV1List":can-assign-license="subscriptionStore.currentPlan !== PlanType.FREE"+ :default-expand-data-source="state.dataSourceToggle"/></div></template>-<script lang="ts" setup>-import { computed, onMounted, reactive } from "vue";+<script lang="tsx" setup>+import { NTag } from "naive-ui";+import { computed, onMounted, reactive, watch } from "vue";import { useI18n } from "vue-i18n";import AdvancedSearch from "@/components/AdvancedSearch";+import type {+ ScopeOption,+ ValueOption,+} from "@/components/AdvancedSearch/types";import { useCommonSearchScopeOptions } from "@/components/AdvancedSearch/useCommonSearchScopeOptions";import { FeatureAttention } from "@/components/FeatureGuard";import { InstanceV1Table } from "@/components/v2";@@ -35,16 +41,18 @@ import {useInstanceV1List,useInstanceV1Store,} from "@/store";-import { UNKNOWN_ID } from "@/types";import { PlanType } from "@/types/proto/v1/subscription_service";-import type { SearchParams } from "@/utils";import {+ type SearchParams,+ hostPortOfDataSource,+ readableDataSourceType,sortInstanceV1ListByEnvironmentV1,extractEnvironmentResourceName,} from "@/utils";interface LocalState {params: SearchParams;+ dataSourceToggle: string[];}const { t } = useI18n();@@ -59,20 +67,95 @@ const state = reactive<LocalState>({query: "",scopes: [],},+ dataSourceToggle: [],});-const scopeOptions = useCommonSearchScopeOptions(- computed(() => state.params),- ["environment"]-);-const selectedEnvironment = computed(() => {return (- state.params.scopes.find((scope) => scope.id === "environment")?.value ??- `${UNKNOWN_ID}`+ state.params.scopes.find((scope) => scope.id === "environment")?.value ?? ""+ );+});++const selectedAddress = computed(() => {+ return (+ state.params.scopes.find((scope) => scope.id === "address")?.value ?? "");});+watch(+ () => selectedAddress.value,+ (selectedAddress) => {+ if (!selectedAddress) {+ state.dataSourceToggle = [];+ }+ }+);++const addressOptions = computed(() => {+ const addressMap: Map<+ string,+ {+ keywords: string[];+ types: Set<string>;+ }+ > = new Map();++ for (const instance of instanceList.value) {+ for (const ds of instance.dataSources) {+ const host = hostPortOfDataSource(ds);+ if (!host) {+ continue;+ }+ if (!addressMap.has(host)) {+ addressMap.set(host, {+ keywords: [ds.host, ds.port],+ types: new Set(),+ });+ }+ addressMap.get(host)?.types?.add(readableDataSourceType(ds.type));+ }+ }++ const options: ValueOption[] = [];+ for (const [host, item] of addressMap.entries()) {+ options.push({+ value: host,+ keywords: [...item.keywords, ...item.types],+ render: () => {+ return (+ <div class={"flex items-center gap-x-2"}>+ {host}+ <div class={"flex items-center gap-x-1"}>+ {[...item.types].map((type) => (+ <NTag size="small" round>+ {type}+ </NTag>+ ))}+ </div>+ </div>+ );+ },+ });+ }++ return options;+});++const scopeOptions = computed((): ScopeOption[] => {+ return [+ ...useCommonSearchScopeOptions(+ computed(() => state.params),+ ["environment"]+ ).value,+ {+ id: "address",+ title: t("instance.advanced-search.scope.address.title"),+ description: t("instance.advanced-search.scope.address.description"),+ options: addressOptions.value,+ },+ ];+});+onMounted(() => {if (!uiStateStore.getIntroStateByKey("instance.visit")) {uiStateStore.saveIntroStateByKey({@@ -83,20 +166,32 @@ onMounted(() => {});const filteredInstanceV1List = computed(() => {- let list = [...instanceList.value];- if (selectedEnvironment.value !== `${UNKNOWN_ID}`) {- list = list.filter(- (instance) =>- extractEnvironmentResourceName(instance.environment) ===- selectedEnvironment.value- );- }const keyword = state.params.query.trim().toLowerCase();- if (keyword) {- list = list.filter((instance) =>- instance.title.toLowerCase().includes(keyword)- );- }+ const list = instanceList.value.filter((instance) => {+ if (keyword) {+ if (!instance.title.toLowerCase().includes(keyword)) {+ return false;+ }+ }+ if (selectedEnvironment.value) {+ if (+ extractEnvironmentResourceName(instance.environment) !==+ selectedEnvironment.value+ ) {+ return false;+ }+ }+ if (selectedAddress.value) {+ const matched = instance.dataSources.some(+ (ds) => hostPortOfDataSource(ds) === selectedAddress.value+ );+ if (matched) {+ state.dataSourceToggle.push(instance.name);+ }+ return matched;+ }+ return true;+ });return sortInstanceV1ListByEnvironmentV1(list, environmentList.value);});diff --git a/frontend/src/views/sql-editor/EditorCommon/QueryContextSettingPopover.vue b/frontend/src/views/sql-editor/EditorCommon/QueryContextSettingPopover.vueindex 181407aa30..50733bc4b1 100644--- a/frontend/src/views/sql-editor/EditorCommon/QueryContextSettingPopover.vue+++ b/frontend/src/views/sql-editor/EditorCommon/QueryContextSettingPopover.vue@@ -99,6 +99,7 @@ import {DataSourceQueryPolicy_Restriction,PolicyType,} from "@/types/proto/v1/org_policy_service";+import { readableDataSourceType } from "@/utils";import { getAdminDataSourceRestrictionOfDatabase } from "@/utils";import { useSQLEditorContext } from "../context";import QueryModeSelect from "./QueryModeSelect.vue";@@ -190,16 +191,6 @@ const onDataSourceSelected = (dataSourceId?: string) => {});};-const readableDataSourceType = (type: DataSourceType): string => {- if (type === DataSourceType.ADMIN) {- return t("data-source.admin");- } else if (type === DataSourceType.READ_ONLY) {- return t("data-source.read-only");- } else {- return "Unknown";- }-};-watch(() => selectedDataSourceId.value,() => {