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(database-group): polish database match display (#20524)
boojack9363b4f9a851
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 932c958bb6..817d3f3e30 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -776,10 +776,12 @@"self": "Condition"},"delete-group": "Delete the database group {{name}}",- "matched-database": "Matched database",+ "load-database-failed": "Failed to load databases",+ "matched-databases": "Matched databases","no-matched-databases": "No matched databases","select": "Select database group",- "unmatched-database": "Unmatched database"+ "unmatched-databases": "Unmatched databases",+ "unmatched-databases-preview": "Preview"},"db": {"catalog": {diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex e1626045c2..9edab391ad 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -776,10 +776,12 @@"self": "Condición"},"delete-group": "Eliminar el grupo de bases de datos {{name}}",- "matched-database": "Base de datos coincidente",+ "load-database-failed": "Error al cargar bases de datos",+ "matched-databases": "Bases de datos coincidentes","no-matched-databases": "No hay bases de datos coincidentes","select": "Seleccionar grupo de bases de datos",- "unmatched-database": "Base de datos no coincidente"+ "unmatched-databases": "Bases de datos no coincidentes",+ "unmatched-databases-preview": "Vista previa"},"db": {"catalog": {diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 2eceb11b94..fca0783276 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -776,10 +776,12 @@"self": "条件"},"delete-group": "データベースグループ {{name}} を削除",- "matched-database": "一致したデータベース",+ "load-database-failed": "データベースの読み込みに失敗しました",+ "matched-databases": "一致したデータベース","no-matched-databases": "一致するデータベースがありません","select": "データベースグループを選択",- "unmatched-database": "一致しないデータベース"+ "unmatched-databases": "一致しないデータベース",+ "unmatched-databases-preview": "プレビュー"},"db": {"catalog": {diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex 6ff71cedfb..174d18ee37 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -776,10 +776,12 @@"self": "Điều kiện"},"delete-group": "Xóa nhóm cơ sở dữ liệu {{name}}",- "matched-database": "Cơ sở dữ liệu khớp",+ "load-database-failed": "Không tải được cơ sở dữ liệu",+ "matched-databases": "Cơ sở dữ liệu khớp","no-matched-databases": "Không có cơ sở dữ liệu khớp","select": "Chọn nhóm cơ sở dữ liệu",- "unmatched-database": "Cơ sở dữ liệu không khớp"+ "unmatched-databases": "Cơ sở dữ liệu không khớp",+ "unmatched-databases-preview": "Xem trước"},"db": {"catalog": {diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 6589e226c8..3a7403c4fe 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -776,10 +776,12 @@"self": "条件"},"delete-group": "删除数据库分组 {{name}}",- "matched-database": "匹配的数据库",+ "load-database-failed": "加载数据库失败",+ "matched-databases": "匹配的数据库","no-matched-databases": "没有匹配的数据库","select": "选择数据库分组",- "unmatched-database": "未匹配的数据库"+ "unmatched-databases": "未匹配的数据库",+ "unmatched-databases-preview": "预览"},"db": {"catalog": {diff --git a/frontend/src/react/components/DatabaseTargetDisplay.test.tsx b/frontend/src/react/components/DatabaseTargetDisplay.test.tsxnew file mode 100644index 0000000000..bcb71dc273--- /dev/null+++ b/frontend/src/react/components/DatabaseTargetDisplay.test.tsx@@ -0,0 +1,195 @@+import { act } from "react";+import { createRoot } from "react-dom/client";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { Engine } from "@/types/proto-es/v1/common_pb";+import { DatabaseTargetDisplay } from "./DatabaseTargetDisplay";++(+ globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }+).IS_REACT_ACT_ENVIRONMENT = true;++const mocks = vi.hoisted(() => ({+ databasesByName: {} as Record<string, unknown>,+ environmentList: [] as unknown[],+ getEnvironmentByName: vi.fn(),+}));++vi.mock("@/react/components/EngineIcon", () => ({+ EngineIcon: ({+ className,+ engine,+ }: {+ className?: string;+ engine: Engine;+ }) => (+ <span className={className} data-testid="engine-icon">+ {Engine[engine]}+ </span>+ ),+}));++vi.mock("@/react/lib/utils", () => ({+ cn: (...classes: Array<string | false | null | undefined>) =>+ classes.filter(Boolean).join(" "),+}));++vi.mock("@/react/stores/app", () => {+ const getState = () => ({+ databasesByName: mocks.databasesByName,+ environmentList: mocks.environmentList,+ getEnvironmentByName: mocks.getEnvironmentByName,+ });+ const useAppStore = <T,>(+ selector: (state: ReturnType<typeof getState>) => T+ ) => selector(getState());+ useAppStore.getState = getState;+ return { useAppStore };+});++vi.mock("@/types", () => ({+ isValidDatabaseName: (name: string) => name.includes("/databases/"),+}));++vi.mock("@/types/v1/database", () => ({+ unknownDatabase: () => ({ name: "", instanceResource: { title: "" } }),+}));++vi.mock("@/utils", () => ({+ extractDatabaseResourceName: (name: string) => ({+ databaseName: name.split("/databases/")[1] ?? name,+ }),+ getInstanceResource: (database: {+ instanceResource?: { engine: Engine; title: string };+ }) => database.instanceResource,+}));++describe("DatabaseTargetDisplay", () => {+ let container: HTMLDivElement;+ let root: ReturnType<typeof createRoot>;++ beforeEach(() => {+ container = document.createElement("div");+ document.body.append(container);+ root = createRoot(container);+ mocks.databasesByName = {+ "projects/p/instances/prod/databases/app": {+ name: "projects/p/instances/prod/databases/app",+ effectiveEnvironment: "environments/prod",+ instanceResource: {+ engine: Engine.POSTGRES,+ title: "prod-instance",+ },+ },+ };+ mocks.getEnvironmentByName.mockReturnValue({+ name: "environments/prod",+ title: "Production",+ });+ });++ afterEach(() => {+ act(() => {+ root.unmount();+ });+ container.remove();+ vi.clearAllMocks();+ });++ it("renders a database target with engine, environment, instance, and database name", () => {+ act(() => {+ root.render(+ <DatabaseTargetDisplay+ showEnvironment+ target="projects/p/instances/prod/databases/app"+ />+ );+ });++ expect(container.textContent).toContain("POSTGRES");+ expect(container.textContent).toContain("Production");+ expect(container.textContent).toContain("prod-instance");+ expect(container.textContent).toContain("app");+ });++ it("applies stable truncation priority across environment, instance, and database name", () => {+ act(() => {+ root.render(+ <DatabaseTargetDisplay+ showEnvironment+ target="projects/p/instances/prod/databases/app"+ />+ );+ });++ const rootElement = container.firstElementChild;+ const environment = Array.from(container.querySelectorAll("span")).find(+ (element) => element.textContent === "Production"+ );+ const instance = Array.from(container.querySelectorAll("span")).find(+ (element) => element.textContent === "prod-instance"+ );+ const database = Array.from(container.querySelectorAll("span")).find(+ (element) => element.textContent === "app"+ );++ expect(rootElement?.className).toContain("inline-flex");+ expect(rootElement?.className).toContain("max-w-full");+ expect(rootElement?.getAttribute("title")).toBe(+ "Production / prod-instance / app"+ );+ expect(environment?.className).toContain("max-w-24");+ expect(instance?.className).toContain("max-w-40");+ expect(database?.className).toContain("flex-1");+ expect(database?.className).toContain("min-w-12");+ });++ it("can hide optional database metadata", () => {+ act(() => {+ root.render(+ <DatabaseTargetDisplay+ showEngine={false}+ showEnvironment={false}+ showInstance={false}+ target="projects/p/instances/prod/databases/app"+ />+ );+ });++ expect(container.textContent).not.toContain("POSTGRES");+ expect(container.textContent).not.toContain("Production");+ expect(container.textContent).not.toContain("prod-instance");+ expect(container.textContent).toContain("app");+ });++ it("supports a medium size for task target rows", () => {+ act(() => {+ root.render(+ <DatabaseTargetDisplay+ showEnvironment+ size="md"+ target="projects/p/instances/prod/databases/app"+ />+ );+ });++ const rootElement = container.firstElementChild;+ const engineIcon = container.querySelector('[data-testid="engine-icon"]');+ const database = Array.from(container.querySelectorAll("span")).find(+ (element) => element.textContent === "app"+ );++ expect(rootElement?.className).toContain("text-base");+ expect(engineIcon?.className).toContain("h-5");+ expect(database?.className).toContain("min-w-16");+ });++ it("falls back to the raw target when the target is not a database", () => {+ act(() => {+ root.render(+ <DatabaseTargetDisplay target="projects/p/databaseGroups/prod" />+ );+ });++ expect(container.textContent).toContain("projects/p/databaseGroups/prod");+ });+});diff --git a/frontend/src/react/components/DatabaseTargetDisplay.tsx b/frontend/src/react/components/DatabaseTargetDisplay.tsxnew file mode 100644index 0000000000..f8262bb7b5--- /dev/null+++ b/frontend/src/react/components/DatabaseTargetDisplay.tsx@@ -0,0 +1,143 @@+import { ChevronRight } from "lucide-react";+import { useMemo } from "react";+import { EngineIcon } from "@/react/components/EngineIcon";+import { cn } from "@/react/lib/utils";+import { useAppStore } from "@/react/stores/app";+import { isValidDatabaseName } from "@/types";+import { unknownDatabase } from "@/types/v1/database";+import { extractDatabaseResourceName, getInstanceResource } from "@/utils";++type DatabaseTargetDisplaySize = "sm" | "md";++const sizeClasses: Record<+ DatabaseTargetDisplaySize,+ {+ database: string;+ environment: string;+ icon: string;+ instance: string;+ root: string;+ separator: string;+ }+> = {+ sm: {+ database: "min-w-12",+ environment: "max-w-24",+ icon: "h-4 w-4",+ instance: "max-w-40",+ root: "text-sm",+ separator: "h-4 w-4",+ },+ md: {+ database: "min-w-16",+ environment: "max-w-28",+ icon: "h-5 w-5",+ instance: "max-w-48",+ root: "text-base",+ separator: "h-5 w-5",+ },+};++export function DatabaseTargetDisplay({+ className,+ showEngine = true,+ showEnvironment = false,+ showInstance = true,+ size = "sm",+ target,+}: {+ className?: string;+ showEngine?: boolean;+ showEnvironment?: boolean;+ showInstance?: boolean;+ size?: DatabaseTargetDisplaySize;+ target: string;+}) {+ const databasesByName = useAppStore((s) => s.databasesByName);+ const environmentList = useAppStore((s) => s.environmentList);+ const classes = sizeClasses[size];++ const database = databasesByName[target] ?? unknownDatabase();+ const environmentName =+ database.effectiveEnvironment ??+ database.instanceResource?.environment ??+ "";+ const environment = useMemo(+ () =>+ environmentName+ ? useAppStore.getState().getEnvironmentByName(environmentName)+ : undefined,+ [environmentList, environmentName]+ );++ if (!isValidDatabaseName(target)) {+ return (+ <span+ className={cn(+ "truncate text-control-placeholder",+ classes.root,+ className+ )}+ >+ {target}+ </span>+ );+ }++ const instance = getInstanceResource(database);+ const { databaseName } = extractDatabaseResourceName(target);+ const shouldShowSeparator = showInstance && Boolean(instance.title);+ const title = [+ showEnvironment ? environment?.title : undefined,+ showInstance ? instance.title : undefined,+ databaseName,+ ]+ .filter(Boolean)+ .join(" / ");++ return (+ <div+ className={cn(+ "inline-flex max-w-full min-w-0 items-center",+ classes.root,+ className+ )}+ title={title}+ >+ {showEngine && (+ <EngineIcon+ engine={instance.engine}+ className={cn("mr-1 shrink-0", classes.icon)}+ />+ )}+ {showEnvironment && environment?.title && (+ <span+ className={cn(+ "mr-1 min-w-0 shrink truncate text-control-placeholder",+ classes.environment+ )}+ >+ {environment.title}+ </span>+ )}+ {showInstance && instance.title && (+ <span+ className={cn(+ "min-w-0 shrink-[2] truncate text-control-light",+ classes.instance+ )}+ >+ {instance.title}+ </span>+ )}+ {shouldShowSeparator && (+ <ChevronRight+ className={cn("shrink-0 text-control-light/80", classes.separator)}+ />+ )}+ <span className={cn("flex-1 truncate text-control", classes.database)}>+ {databaseName}+ </span>+ </div>+ );+}diff --git a/frontend/src/react/components/MatchedDatabaseView.test.tsx b/frontend/src/react/components/MatchedDatabaseView.test.tsxnew file mode 100644index 0000000000..28b04b40ac--- /dev/null+++ b/frontend/src/react/components/MatchedDatabaseView.test.tsx@@ -0,0 +1,196 @@+import { act } from "react";+import { createRoot } from "react-dom/client";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { Engine } from "@/types/proto-es/v1/common_pb";+import { MatchedDatabaseView } from "./MatchedDatabaseView";++(+ globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }+).IS_REACT_ACT_ENVIRONMENT = true;++const mocks = vi.hoisted(() => ({+ batchGetOrFetchDatabases: vi.fn(),+ databasesByName: {} as Record<string, unknown>,+ fetchDatabases: vi.fn(),+ getDatabaseByName: vi.fn(),+ getEnvironmentByName: vi.fn(),+}));++vi.mock("react-i18next", () => ({+ useTranslation: () => ({+ t: (key: string, params?: Record<string, unknown>) =>+ params?.n !== undefined ? `${key}:${params.n}` : key,+ }),+}));++vi.mock("@/plugins/cel", () => ({+ validateSimpleExpr: () => true,+}));++vi.mock("@/react/components/EngineIcon", () => ({+ EngineIcon: ({+ className,+ engine,+ }: {+ className?: string;+ engine: Engine;+ }) => (+ <span className={className} data-testid="engine-icon">+ {Engine[engine]}+ </span>+ ),+}));++vi.mock("@/react/lib/utils", () => ({+ cn: (...classes: Array<string | false | null | undefined>) =>+ classes.filter(Boolean).join(" "),+}));++vi.mock("@/react/stores/app", () => {+ const getState = () => ({+ batchGetOrFetchDatabases: mocks.batchGetOrFetchDatabases,+ databasesByName: mocks.databasesByName,+ environmentList: [],+ fetchDatabases: mocks.fetchDatabases,+ getDatabaseByName: mocks.getDatabaseByName,+ getEnvironmentByName: mocks.getEnvironmentByName,+ });+ const useAppStore = <T,>(+ selector: (state: ReturnType<typeof getState>) => T+ ) => selector(getState());+ useAppStore.getState = getState;+ return { useAppStore };+});++vi.mock("@/types", () => ({+ DEBOUNCE_SEARCH_DELAY: 0,+ isValidDatabaseName: (name: string) => name.includes("/databases/"),+}));++vi.mock("@/types/v1/database", () => ({+ unknownDatabase: () => ({ name: "", instanceResource: { title: "" } }),+}));++vi.mock("@/utils", () => ({+ extractDatabaseResourceName: (name: string) => ({+ databaseName: name.split("/databases/")[1] ?? name,+ }),+ getDefaultPagination: () => 2,+ getDatabaseEnvironment: (database: { effectiveEnvironment?: string }) => ({+ title: database.effectiveEnvironment?.includes("prod")+ ? "Production"+ : "Staging",+ }),+ getInstanceResource: (database: {+ instanceResource?: { engine: Engine; title: string };+ }) => database.instanceResource,+}));++const matchedDatabase = {+ name: "projects/p/instances/prod/databases/app",+ effectiveEnvironment: "environments/prod",+ instanceResource: {+ engine: Engine.POSTGRES,+ title: "prod-instance",+ },+};++const unmatchedDatabase = {+ name: "projects/p/instances/staging/databases/app_staging",+ effectiveEnvironment: "environments/staging",+ instanceResource: {+ engine: Engine.MYSQL,+ title: "staging-instance",+ },+};++async function flush() {+ await act(async () => {+ vi.runOnlyPendingTimers();+ await Promise.resolve();+ await Promise.resolve();+ });+}++describe("MatchedDatabaseView", () => {+ let container: HTMLDivElement;+ let root: ReturnType<typeof createRoot>;++ beforeEach(() => {+ vi.useFakeTimers();+ container = document.createElement("div");+ document.body.append(container);+ root = createRoot(container);++ mocks.databasesByName = {+ [matchedDatabase.name]: matchedDatabase,+ [unmatchedDatabase.name]: unmatchedDatabase,+ };+ mocks.batchGetOrFetchDatabases.mockResolvedValue(undefined);+ mocks.getDatabaseByName.mockImplementation(+ (name: string) => mocks.databasesByName[name] ?? { name: "" }+ );+ mocks.fetchDatabases.mockResolvedValue({+ databases: [matchedDatabase, unmatchedDatabase],+ nextPageToken: "next",+ });+ mocks.getEnvironmentByName.mockImplementation((name: string) => ({+ name,+ title: name.includes("prod") ? "Production" : "Staging",+ }));+ });++ afterEach(() => {+ act(() => {+ root.unmount();+ });+ container.remove();+ vi.useRealTimers();+ vi.clearAllMocks();+ });++ it("renders matched and unmatched databases with engine, environment, instance, and database name", async () => {+ act(() => {+ root.render(+ <MatchedDatabaseView+ expr={{} as never}+ matchedDatabaseNames={[matchedDatabase.name]}+ project="projects/p"+ />+ );+ });+ await flush();++ expect(container.textContent).toContain("database-group.matched-databases");+ expect(container.textContent).toContain("1");+ expect(container.textContent).toContain("POSTGRES");+ expect(container.textContent).toContain("Production");+ expect(container.textContent).toContain("prod-instance");+ expect(container.textContent).toContain("app");+ expect(container.textContent).toContain(+ "database-group.unmatched-databases"+ );+ expect(container.textContent).toContain("MYSQL");+ expect(container.textContent).toContain("Staging");+ expect(container.textContent).toContain("staging-instance");+ expect(container.textContent).toContain("app_staging");+ });++ it("labels unmatched databases as a preview while more project pages remain", async () => {+ act(() => {+ root.render(+ <MatchedDatabaseView+ expr={{} as never}+ matchedDatabaseNames={[matchedDatabase.name]}+ project="projects/p"+ />+ );+ });+ await flush();++ expect(container.textContent).toContain(+ "database-group.unmatched-databases-preview"+ );+ expect(container.textContent).not.toContain("database-group.n-unmatched");+ });+});diff --git a/frontend/src/react/components/MatchedDatabaseView.tsx b/frontend/src/react/components/MatchedDatabaseView.tsxindex 3bc40bdc3f..90a5f793b8 100644--- a/frontend/src/react/components/MatchedDatabaseView.tsx+++ b/frontend/src/react/components/MatchedDatabaseView.tsx@@ -1,15 +1,13 @@+import { ChevronRight } from "lucide-react";import { useCallback, useEffect, useMemo, useRef, useState } from "react";import { useTranslation } from "react-i18next";import type { ConditionGroupExpr } from "@/plugins/cel";import { validateSimpleExpr } from "@/plugins/cel";+import { DatabaseTargetDisplay } from "@/react/components/DatabaseTargetDisplay";import { useAppStore } from "@/react/stores/app";import { DEBOUNCE_SEARCH_DELAY, isValidDatabaseName } from "@/types";import type { Database } from "@/types/proto-es/v1/database_service_pb";-import {- getDatabaseEnvironment,- getDefaultPagination,- getInstanceResource,-} from "@/utils";+import { getDefaultPagination } from "@/utils";interface MatchedDatabaseViewProps {project: string;@@ -19,6 +17,7 @@ interface MatchedDatabaseViewProps {interface SectionState {databases: Database[];+ error?: string;loading: boolean;}@@ -71,7 +70,7 @@ export function MatchedDatabaseView({const slice = names.slice(currentToken, next);if (slice.length === 0) return;- setMatchedDbs((prev) => ({ ...prev, loading: true }));+ setMatchedDbs((prev) => ({ ...prev, error: undefined, loading: true }));try {await useAppStore.getState().batchGetOrFetchDatabases(slice);const newDbs = slice@@ -82,8 +81,12 @@ export function MatchedDatabaseView({loading: false,});setMatchedToken(next);- } catch {- setMatchedDbs((prev) => ({ ...prev, loading: false }));+ } catch (error) {+ setMatchedDbs((prev) => ({+ ...prev,+ error: error instanceof Error ? error.message : String(error),+ loading: false,+ }));}},[pageSize]@@ -92,7 +95,11 @@ export function MatchedDatabaseView({const loadMoreUnmatched = useCallback(async (token: string, currentDbs: Database[]) => {const names = matchedNamesRef.current;- setUnmatchedDbs((prev) => ({ ...prev, loading: true }));+ setUnmatchedDbs((prev) => ({+ ...prev,+ error: undefined,+ loading: true,+ }));try {let unmatched: Database[] = [];let pageToken = token;@@ -117,8 +124,12 @@ export function MatchedDatabaseView({loading: false,});setUnmatchedToken(pageToken);- } catch {- setUnmatchedDbs((prev) => ({ ...prev, loading: false }));+ } catch (error) {+ setUnmatchedDbs((prev) => ({+ ...prev,+ error: error instanceof Error ? error.message : String(error),+ loading: false,+ }));}},[pageSize, project]@@ -164,7 +175,11 @@ export function MatchedDatabaseView({.map((n) => useAppStore.getState().getDatabaseByName(n)).filter((db) => isValidDatabaseName(db.name));}- setMatchedDbs({ databases: newMatchedDbs, loading: false });+ setMatchedDbs({+ databases: newMatchedDbs,+ error: undefined,+ loading: false,+ });setMatchedToken(matchedNext);// Load unmatched@@ -188,7 +203,11 @@ export function MatchedDatabaseView({const validUnmatched = unmatchedList.filter((db) =>isValidDatabaseName(db.name));- setUnmatchedDbs({ databases: validUnmatched, loading: false });+ setUnmatchedDbs({+ databases: validUnmatched,+ error: undefined,+ loading: false,+ });setUnmatchedToken(pageToken);// Auto-expand sections that have data@@ -214,21 +233,24 @@ export function MatchedDatabaseView({() => [{name: "matched",- title: t("database-group.matched-database"),+ title: t("database-group.matched-databases"),databases: matchedDbs.databases,+ error: matchedDbs.error,sectionLoading: matchedDbs.loading,- total: matchedNames.length,- showTotal: true,+ totalLabel: String(matchedNames.length),hasMore: hasMoreMatched,onLoadMore: () => loadMoreMatched(matchedToken, matchedDbs.databases),},{name: "unmatched",- title: t("database-group.unmatched-database"),+ title: t("database-group.unmatched-databases"),databases: unmatchedDbs.databases,+ error: unmatchedDbs.error,sectionLoading: unmatchedDbs.loading,hasMore: hasMoreUnmatched,- showTotal: false,+ totalLabel: hasMoreUnmatched+ ? t("database-group.unmatched-databases-preview")+ : String(unmatchedDbs.databases.length),onLoadMore: () =>loadMoreUnmatched(unmatchedToken, unmatchedDbs.databases),},@@ -283,7 +305,7 @@ export function MatchedDatabaseView({</p>)}- <div className="border p-2 rounded-sm">+ <div className="border rounded-sm overflow-hidden">{sections.map((section) => {const isExpanded = expandedSections.has(section.name);const isEmpty = section.databases.length === 0;@@ -292,7 +314,7 @@ export function MatchedDatabaseView({<div key={section.name}><buttontype="button"- className={`w-full flex items-center justify-between py-2 px-1 text-left text-sm ${+ className={`w-full flex items-center justify-between py-2 px-2 text-left text-sm border-b border-control-border/60 last:border-b-0 ${isEmpty? "cursor-default text-control-placeholder": "cursor-pointer hover:bg-control-bg"@@ -301,58 +323,46 @@ export function MatchedDatabaseView({onClick={() => toggleSection(section.name)}><div className="flex items-center gap-x-1">- <svg+ <ChevronRightclassName={`size-4 transition-transform ${isExpanded ? "rotate-90" : ""} ${isEmpty ? "text-control-border" : ""}`}- fill="none"- viewBox="0 0 24 24"- stroke="currentColor"- strokeWidth={2}- >- <path- strokeLinecap="round"- strokeLinejoin="round"- d="M9 5l7 7-7 7"- />- </svg>+ /><span>{section.title}</span></div>- {section.showTotal && (+ {section.totalLabel && (<span className="text-control-light text-xs">- {section.total}+ {section.totalLabel}</span>)}</button>{isExpanded && !isEmpty && (- <div className="flex flex-col gap-y-2 w-full max-h-48 overflow-y-auto">- <div>+ <div className="flex flex-col gap-y-2 w-full max-h-48 overflow-y-auto border-b border-control-border/60 last:border-b-0">+ <div className="p-1">{section.databases.map((database) => {- const instance = getInstanceResource(database);- const env = getDatabaseEnvironment(database);- const dbName = database.name.split("/").pop();-return (<divkey={database.name}- className="w-full flex flex-row justify-between items-center px-2 py-1 gap-x-2"+ className="w-full min-w-0 rounded-xs px-2 py-1.5 hover:bg-control-bg">- <span className="truncate">{dbName}</span>- <div className="flex-1 flex flex-row justify-end items-center shrink-0">- <span className="text-sm">{instance.title}</span>- <span className="ml-1 text-sm text-control-placeholder max-w-31 truncate">- {env.title}- </span>- </div>+ <DatabaseTargetDisplay+ showEnvironment+ target={database.name}+ /></div>);})}</div>+ {section.error && (+ <div className="mx-2 rounded-sm border border-error bg-error/10 px-2 py-1 text-sm text-error">+ {t("database-group.load-database-failed")}+ </div>+ )}{section.hasMore && (<buttontype="button"- className="self-start px-2 py-1 text-sm text-accent hover:text-accent/80 disabled:opacity-50"+ className="self-start px-2 pb-2 text-sm text-accent hover:text-accent/80 disabled:opacity-50"disabled={section.sectionLoading}onClick={section.onLoadMore}>diff --git a/frontend/src/react/pages/project/plan-detail/components/PlanTargetDisplay.tsx b/frontend/src/react/pages/project/plan-detail/components/PlanTargetDisplay.tsxindex 715aefd4c5..161f78dd55 100644--- a/frontend/src/react/pages/project/plan-detail/components/PlanTargetDisplay.tsx+++ b/frontend/src/react/pages/project/plan-detail/components/PlanTargetDisplay.tsx@@ -1,143 +1 @@-import { ChevronRight } from "lucide-react";-import { useMemo } from "react";-import { EngineIcon } from "@/react/components/EngineIcon";-import { cn } from "@/react/lib/utils";-import { useAppStore } from "@/react/stores/app";-import { isValidDatabaseName } from "@/types";-import { unknownDatabase } from "@/types/v1/database";-import { extractDatabaseResourceName, getInstanceResource } from "@/utils";--type PlanTargetDisplaySize = "sm" | "md";--const sizeClasses: Record<- PlanTargetDisplaySize,- {- database: string;- environment: string;- icon: string;- instance: string;- root: string;- separator: string;- }-> = {- sm: {- database: "min-w-12",- environment: "max-w-24",- icon: "h-4 w-4",- instance: "max-w-40",- root: "text-sm",- separator: "h-4 w-4",- },- md: {- database: "min-w-16",- environment: "max-w-28",- icon: "h-5 w-5",- instance: "max-w-48",- root: "text-base",- separator: "h-5 w-5",- },-};--export function PlanTargetDisplay({- className,- showEngine = true,- showEnvironment = false,- showInstance = true,- size = "sm",- target,-}: {- className?: string;- showEngine?: boolean;- showEnvironment?: boolean;- showInstance?: boolean;- size?: PlanTargetDisplaySize;- target: string;-}) {- const databasesByName = useAppStore((s) => s.databasesByName);- const environmentList = useAppStore((s) => s.environmentList);- const classes = sizeClasses[size];-- const database = databasesByName[target] ?? unknownDatabase();- const environmentName =- database.effectiveEnvironment ??- database.instanceResource?.environment ??- "";- const environment = useMemo(- () =>- environmentName- ? useAppStore.getState().getEnvironmentByName(environmentName)- : undefined,- [environmentList, environmentName]- );-- if (!isValidDatabaseName(target)) {- return (- <span- className={cn(- "truncate text-control-placeholder",- classes.root,- className- )}- >- {target}- </span>- );- }-- const instance = getInstanceResource(database);- const { databaseName } = extractDatabaseResourceName(target);- const shouldShowSeparator = showInstance && Boolean(instance.title);- const title = [- showEnvironment ? environment?.title : undefined,- showInstance ? instance.title : undefined,- databaseName,- ]- .filter(Boolean)- .join(" / ");-- return (- <div- className={cn(- "inline-flex max-w-full min-w-0 items-center",- classes.root,- className- )}- title={title}- >- {showEngine && (- <EngineIcon- engine={instance.engine}- className={cn("mr-1 shrink-0", classes.icon)}- />- )}- {showEnvironment && environment?.title && (- <span- className={cn(- "mr-1 min-w-0 shrink truncate text-control-placeholder",- classes.environment- )}- >- {environment.title}- </span>- )}- {showInstance && instance.title && (- <span- className={cn(- "min-w-0 shrink-[2] truncate text-control-light",- classes.instance- )}- >- {instance.title}- </span>- )}- {shouldShowSeparator && (- <ChevronRight- className={cn("shrink-0 text-control-light/80", classes.separator)}- />- )}- <span className={cn("flex-1 truncate text-control", classes.database)}>- {databaseName}- </span>- </div>- );-}+export { DatabaseTargetDisplay as PlanTargetDisplay } from "@/react/components/DatabaseTargetDisplay";