Skip to content

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

fix: react ui (#19918)

ecmadao1d48faba6b21
diff --git a/frontend/src/react/components/CustomApproval/RuleEditDialog.tsx b/frontend/src/react/components/CustomApproval/RuleEditDialog.tsx
index 98a25dd5a0..05687287e5 100644
--- a/frontend/src/react/components/CustomApproval/RuleEditDialog.tsx
+++ b/frontend/src/react/components/CustomApproval/RuleEditDialog.tsx
@@ -11,6 +11,7 @@ import {
wrapAsGroup,
} from "@/plugins/cel";
import { ExprEditor } from "@/react/components/ExprEditor";
+import { Alert } from "@/react/components/ui/alert";
import { Button } from "@/react/components/ui/button";
import {
Dialog,
@@ -175,9 +176,9 @@ export function RuleEditDialog({
<div className="flex flex-1 flex-col gap-y-4 overflow-y-auto px-6 py-4">
{/* Fallback hint */}
{isFallback && (
- <div className="rounded-xs bg-amber-50 p-3 text-sm text-amber-600">
+ <Alert variant="warning">
{t("custom-approval.approval-flow.fallback-rules-hint")}
- </div>
+ </Alert>
)}
{/* Template presets (create mode only) */}
diff --git a/frontend/src/react/components/database/LabelEditorDrawer.tsx b/frontend/src/react/components/database/LabelEditorDrawer.tsx
index e3574f8d14..936de7ca7c 100644
--- a/frontend/src/react/components/database/LabelEditorDrawer.tsx
+++ b/frontend/src/react/components/database/LabelEditorDrawer.tsx
@@ -1,6 +1,7 @@
import { Plus, X } from "lucide-react";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
+import { Alert } from "@/react/components/ui/alert";
import { Button } from "@/react/components/ui/button";
import { Input } from "@/react/components/ui/input";
import { useEscapeKey } from "@/react/hooks/useEscapeKey";
@@ -84,9 +85,9 @@ export function LabelEditorDrawer({
</div>
<div className="flex-1 overflow-y-auto p-6">
{hasMixedValues && (
- <div className="mb-4 rounded-xs bg-yellow-50 border border-yellow-200 px-3 py-2 text-sm text-yellow-800">
+ <Alert variant="warning" className="mb-4">
{t("database.mixed-label-values-warning")}
- </div>
+ </Alert>
)}
<div className="flex items-center gap-x-2 mb-4">
<Input
diff --git a/frontend/src/react/components/instance/CreateDataSourceExample.tsx b/frontend/src/react/components/instance/CreateDataSourceExample.tsx
index 6b1b7bfa76..45d28e1a73 100644
--- a/frontend/src/react/components/instance/CreateDataSourceExample.tsx
+++ b/frontend/src/react/components/instance/CreateDataSourceExample.tsx
@@ -1,5 +1,6 @@
import { useCallback, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
+import { Alert } from "@/react/components/ui/alert";
import {
DATASOURCE_ADMIN_USER_NAME,
DATASOURCE_READONLY_USER_NAME,
@@ -380,9 +381,9 @@ function EngineSpecificDescription({
if (engine === Engine.POSTGRES) {
return (
<>
- <div className="my-2 rounded-xs border border-yellow-400 bg-yellow-50 px-3 py-2 text-sm text-yellow-800">
+ <Alert variant="warning" className="my-2">
{t("instance.sentence.create-user-example.postgresql.warn")}
- </div>
+ </Alert>
{authenticationType ===
DataSource_AuthenticationType.GOOGLE_CLOUD_SQL_IAM ? (
<p>
diff --git a/frontend/src/react/components/instance/DataSourceSection.tsx b/frontend/src/react/components/instance/DataSourceSection.tsx
index ee7000734d..369793b89d 100644
--- a/frontend/src/react/components/instance/DataSourceSection.tsx
+++ b/frontend/src/react/components/instance/DataSourceSection.tsx
@@ -1,6 +1,7 @@
import { Plus } from "lucide-react";
import { useCallback } from "react";
import { useTranslation } from "react-i18next";
+import { Alert } from "@/react/components/ui/alert";
import { Button } from "@/react/components/ui/button";
import { useInstanceV1Store } from "@/store";
import { DATASOURCE_READONLY_USER_NAME } from "@/types";
@@ -112,10 +113,11 @@ export function DataSourceSection({
return (
<>
{showROTips && (
- <div className="mt-2 rounded-sm bg-yellow-50 border border-yellow-200 p-3 flex items-center justify-between">
- <span className="text-sm text-yellow-800">
- {t("data-source.no-read-only-data-source")}
- </span>
+ <Alert
+ variant="warning"
+ className="mt-2 flex items-center justify-between"
+ >
+ <span>{t("data-source.no-read-only-data-source")}</span>
<Button
variant="outline"
size="sm"
@@ -123,7 +125,7 @@ export function DataSourceSection({
>
{t("common.create")}
</Button>
- </div>
+ </Alert>
)}
<div className="mt-2 gap-y-2 gap-x-4 border-none">
diff --git a/frontend/src/react/components/instance/InstanceFormBody.tsx b/frontend/src/react/components/instance/InstanceFormBody.tsx
index e1a891ce64..c7065aa19b 100644
--- a/frontend/src/react/components/instance/InstanceFormBody.tsx
+++ b/frontend/src/react/components/instance/InstanceFormBody.tsx
@@ -12,6 +12,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { EnvironmentSelect } from "@/react/components/EnvironmentSelect";
import { LabelListEditor } from "@/react/components/LabelListEditor";
+import { Alert } from "@/react/components/ui/alert";
import { Button } from "@/react/components/ui/button";
import { Input } from "@/react/components/ui/input";
import { cn } from "@/react/lib/utils";
@@ -623,6 +624,8 @@ function ScanIntervalInput({
);
}
+const MAX_VISIBLE_DATABASES = 100;
+
function SyncDatabases({
isCreating: isCreatingProp,
showLabel,
@@ -638,30 +641,35 @@ function SyncDatabases({
}) {
const { t } = useTranslation();
const ctx = useInstanceFormContext();
- const { hideAdvancedFeatures, instance } = ctx;
+ const { hideAdvancedFeatures, instance, pendingCreateInstance } = ctx;
const instanceStore = useInstanceV1Store();
const [syncAll, setSyncAll] = useState(syncDatabases.length === 0);
- const [selectedDatabases, setSelectedDatabases] = useState<string[]>([
- ...syncDatabases,
- ]);
+ const [selectedSet, setSelectedSet] = useState<Set<string>>(
+ () => new Set(syncDatabases)
+ );
const [databaseList, setDatabaseList] = useState<Set<string>>(new Set());
const [loading, setLoading] = useState(false);
const [searchText, setSearchText] = useState("");
const [inputDatabase, setInputDatabase] = useState("");
+ // Notify parent only when selection actually changes.
+ const onSyncDatabasesChangeRef = useRef(onSyncDatabasesChange);
+ onSyncDatabasesChangeRef.current = onSyncDatabasesChange;
+ const prevNotifiedRef = useRef<string | null>(null);
+
useEffect(() => {
- if (syncAll) {
- onSyncDatabasesChange([]);
- } else {
- onSyncDatabasesChange(selectedDatabases);
- }
- }, [syncAll, selectedDatabases]);
+ const key = syncAll ? "" : [...selectedSet].sort().join("\0");
+ if (key === prevNotifiedRef.current) return;
+ prevNotifiedRef.current = key;
+ onSyncDatabasesChangeRef.current(syncAll ? [] : [...selectedSet]);
+ }, [syncAll, selectedSet]);
useEffect(() => {
if (syncAll) return;
+ let cancelled = false;
const fetchDatabases = async () => {
- const inst = isCreatingProp ? ctx.pendingCreateInstance : instance;
+ const inst = isCreatingProp ? pendingCreateInstance : instance;
if (!inst) return;
setLoading(true);
try {
@@ -669,19 +677,29 @@ function SyncDatabases({
inst.name,
isCreatingProp ? inst : undefined
);
- setDatabaseList(new Set([...resp.databases, ...selectedDatabases]));
+ if (!cancelled) {
+ setDatabaseList(new Set([...resp.databases, ...selectedSet]));
+ }
} finally {
- setLoading(false);
+ if (!cancelled) setLoading(false);
}
};
fetchDatabases();
+ return () => {
+ cancelled = true;
+ };
}, [syncAll]);
if (hideAdvancedFeatures) return null;
- const filteredDatabases = [...databaseList].filter((db) =>
- db.toLowerCase().includes(searchText.toLowerCase())
- );
+ const lowerSearch = searchText.toLowerCase();
+ const filteredDatabases = lowerSearch
+ ? [...databaseList].filter((db) => db.toLowerCase().includes(lowerSearch))
+ : [...databaseList];
+ const hasMore = filteredDatabases.length > MAX_VISIBLE_DATABASES;
+ const visibleDatabases = hasMore
+ ? filteredDatabases.slice(0, MAX_VISIBLE_DATABASES)
+ : filteredDatabases;
const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.nativeEvent.isComposing) return;
@@ -689,15 +707,21 @@ function SyncDatabases({
if (!trimmed) return;
if (e.key === "Enter") {
setDatabaseList((prev) => new Set([...prev, trimmed]));
- setSelectedDatabases((prev) => [...prev, trimmed]);
+ setSelectedSet((prev) => new Set([...prev, trimmed]));
setInputDatabase("");
}
};
const toggleDatabase = (db: string) => {
- setSelectedDatabases((prev) =>
- prev.includes(db) ? prev.filter((d) => d !== db) : [...prev, db]
- );
+ setSelectedSet((prev) => {
+ const next = new Set(prev);
+ if (next.has(db)) {
+ next.delete(db);
+ } else {
+ next.add(db);
+ }
+ return next;
+ });
};
return (
@@ -737,14 +761,14 @@ function SyncDatabases({
onChange={(e) => setSearchText(e.target.value)}
/>
<div className="max-h-[250px] overflow-y-auto flex flex-col gap-y-1">
- {filteredDatabases.map((db) => (
+ {visibleDatabases.map((db) => (
<label
key={db}
className="flex items-center gap-x-2 cursor-pointer text-sm"
>
<input
type="checkbox"
- checked={selectedDatabases.includes(db)}
+ checked={selectedSet.has(db)}
disabled={!allowEdit}
onChange={() => toggleDatabase(db)}
/>
@@ -752,6 +776,13 @@ function SyncDatabases({
</label>
))}
</div>
+ {hasMore && (
+ <div className="text-xs text-control-light">
+ {t("common.n-more", {
+ n: filteredDatabases.length - MAX_VISIBLE_DATABASES,
+ })}
+ </div>
+ )}
<Input
value={inputDatabase}
className="w-full"
@@ -1466,7 +1497,7 @@ export function InstanceFormBody({ onOpenInfoPanel }: InstanceFormBodyProps) {
<Input
value={basicInfo.externalLink ?? ""}
required
- className="textfield mt-1 w-full"
+ className="mt-1 w-full"
disabled={!allowEdit}
placeholder={SnowflakeExtraLinkPlaceHolder}
onChange={(e) =>
@@ -1487,12 +1518,12 @@ export function InstanceFormBody({ onOpenInfoPanel }: InstanceFormBodyProps) {
/>
)}
- {/* Sync Databases (edit mode) */}
- {!isCreating && (
+ {/* Sync Databases */}
+ {basicInfo.engine !== Engine.DYNAMODB && (
<SyncDatabases
- isCreating={false}
- showLabel
- allowEdit={allowEdit}
+ isCreating={isCreating}
+ showLabel={!isCreating}
+ allowEdit={isCreating ? allowEdit && !!allowCreate : allowEdit}
syncDatabases={basicInfo.syncDatabases}
onSyncDatabasesChange={handleChangeSyncDatabases}
/>
@@ -1810,16 +1841,16 @@ export function InstanceFormBody({ onOpenInfoPanel }: InstanceFormBodyProps) {
/>
{actuatorStore.isSaaSMode && (
- <div className="mt-4 rounded-sm border-none bg-blue-50 p-3">
+ <Alert variant="info" className="mt-4">
<a
href="https://docs.bytebase.com/get-started/cloud#prerequisites"
target="_blank"
rel="noopener noreferrer"
- className="normal-link text-sm"
+ className="normal-link"
>
{t("instance.sentence.firewall-info")}
</a>
- </div>
+ </Alert>
)}
</>
)}
@@ -1886,22 +1917,6 @@ export function InstanceFormBody({ onOpenInfoPanel }: InstanceFormBodyProps) {
</Button>
</div>
)}
-
- {/* Sync Databases Card (create only) */}
- {basicInfo.engine !== Engine.DYNAMODB && isCreating && (
- <div className="border border-block-border rounded-lg p-5 flex flex-col gap-y-1">
- <p className="w-full text-lg leading-6 font-medium text-gray-900">
- {t("instance.sync-databases.self")}
- </p>
- <SyncDatabases
- isCreating
- showLabel={false}
- allowEdit={allowEdit && !!allowCreate}
- syncDatabases={basicInfo.syncDatabases}
- onSyncDatabasesChange={handleChangeSyncDatabases}
- />
- </div>
- )}
</div>
</div>
);
diff --git a/frontend/src/react/components/instance/InstanceFormButtons.tsx b/frontend/src/react/components/instance/InstanceFormButtons.tsx
index 849cdcccc6..ffa19b4529 100644
--- a/frontend/src/react/components/instance/InstanceFormButtons.tsx
+++ b/frontend/src/react/components/instance/InstanceFormButtons.tsx
@@ -69,7 +69,6 @@ export function InstanceFormButtons({
testConnection,
checkDataSource,
extractDataSourceFromEdit,
- pendingCreateInstance,
valueChanged,
onDismiss,
emitShowConnectionOptions,
@@ -170,19 +169,34 @@ export function InstanceFormButtons({
}));
};
+ const buildCreateInstance = (): Instance => {
+ const currentLabels = convertKVListToLabels(labelKVList, false);
+ const inst: Instance = create(InstanceSchema, {
+ ...basicInfo,
+ labels: currentLabels,
+ engineVersion: "",
+ dataSources: [],
+ });
+ if (editingDataSource) {
+ inst.dataSources = [
+ extractDataSourceFromEdit(inst.engine, adminDataSource),
+ ];
+ }
+ return inst;
+ };
+
const doCreate = async () => {
if (!isCreating) return;
- if (!checkExternalSecretFeature(pendingCreateInstance.dataSources)) {
+ const payload = buildCreateInstance();
+ if (!checkExternalSecretFeature(payload.dataSources)) {
setMissingFeature(PlanFeature.FEATURE_EXTERNAL_SECRET_MANAGER);
return;
}
setState((prev) => ({ ...prev, isRequesting: true }));
try {
- const createdInstance = await instanceV1Store.createInstance(
- pendingCreateInstance
- );
+ const createdInstance = await instanceV1Store.createInstance(payload);
if (onCreated) {
onCreated(createdInstance);
} else {
diff --git a/frontend/src/react/components/instance/InstanceFormContext.tsx b/frontend/src/react/components/instance/InstanceFormContext.tsx
index 20b5c5d5b6..ea355a7e5d 100644
--- a/frontend/src/react/components/instance/InstanceFormContext.tsx
+++ b/frontend/src/react/components/instance/InstanceFormContext.tsx
@@ -5,6 +5,7 @@ import {
type ReactNode,
useCallback,
useContext,
+ useEffect,
useMemo,
useRef,
useState,
@@ -359,22 +360,31 @@ export function InstanceFormProvider({
[specs]
);
- const pendingCreateInstance = useMemo(() => {
- const currentLabels = convertKVListToLabels(labelKVList, false);
- const inst: Instance = create(InstanceSchema, {
- ...basicInfo,
- labels: currentLabels,
- engineVersion: "",
- dataSources: [],
- });
- if (editingDataSource) {
- const dataSourceCreate = extractDataSourceFromEdit(
- inst.engine,
- adminDataSource
- );
- inst.dataSources = [dataSourceCreate];
- }
- return inst;
+ // Debounced to avoid expensive cloneDeep + extraction on every keystroke.
+ const [pendingCreateInstance, setPendingCreateInstance] = useState<Instance>(
+ () => create(InstanceSchema, {})
+ );
+ const pendingTimerRef = useRef<ReturnType<typeof setTimeout>>(undefined);
+ useEffect(() => {
+ clearTimeout(pendingTimerRef.current);
+ pendingTimerRef.current = setTimeout(() => {
+ const currentLabels = convertKVListToLabels(labelKVList, false);
+ const inst: Instance = create(InstanceSchema, {
+ ...basicInfo,
+ labels: currentLabels,
+ engineVersion: "",
+ dataSources: [],
+ });
+ if (editingDataSource) {
+ const dataSourceCreate = extractDataSourceFromEdit(
+ inst.engine,
+ adminDataSource
+ );
+ inst.dataSources = [dataSourceCreate];
+ }
+ setPendingCreateInstance(inst);
+ }, 300);
+ return () => clearTimeout(pendingTimerRef.current);
}, [
basicInfo,
labelKVList,
@@ -487,18 +497,28 @@ export function InstanceFormProvider({
]
);
- const valueChanged = useMemo(() => {
- if (instance?.state === State.DELETED) return false;
- const original = {
- basicInfo: extractBasicInfo(instance),
- dataSources: extractDataSourceEditState(instance).dataSources,
- };
- const currentLabels = convertKVListToLabels(labelKVList, false);
- const editing = {
- basicInfo: { ...basicInfo, labels: currentLabels },
- dataSources: dataSourceEditState.dataSources,
- };
- return !isEqual(editing, original);
+ // Debounced valueChanged to avoid expensive deep comparison on every keystroke.
+ const [valueChanged, setValueChanged] = useState(false);
+ const valueChangedTimerRef = useRef<ReturnType<typeof setTimeout>>(undefined);
+ useEffect(() => {
+ clearTimeout(valueChangedTimerRef.current);
+ valueChangedTimerRef.current = setTimeout(() => {
+ if (instance?.state === State.DELETED) {
+ setValueChanged(false);
+ return;
+ }
+ const original = {
+ basicInfo: extractBasicInfo(instance),
+ dataSources: extractDataSourceEditState(instance).dataSources,
+ };
+ const currentLabels = convertKVListToLabels(labelKVList, false);
+ const editing = {
+ basicInfo: { ...basicInfo, labels: currentLabels },
+ dataSources: dataSourceEditState.dataSources,
+ };
+ setValueChanged(!isEqual(editing, original));
+ }, 300);
+ return () => clearTimeout(valueChangedTimerRef.current);
}, [instance, basicInfo, labelKVList, dataSourceEditState.dataSources]);
const isEditing = valueChanged && allowEdit;
diff --git a/frontend/src/react/components/instance/specs.ts b/frontend/src/react/components/instance/specs.ts
index 67f8918103..72b92e607b 100644
--- a/frontend/src/react/components/instance/specs.ts
+++ b/frontend/src/react/components/instance/specs.ts
@@ -77,5 +77,12 @@ export const useInstanceSpecs = (
hasReadonlyReplicaPort,
hasExtraParameters,
};
- }, [basicInfo, adminDataSource, editingDataSource]);
+ }, [
+ basicInfo.engine,
+ basicInfo.externalLink,
+ adminDataSource.host,
+ adminDataSource.srv,
+ editingDataSource?.type,
+ editingDataSource?.srv,
+ ]);
};
diff --git a/frontend/src/react/components/ui/button.tsx b/frontend/src/react/components/ui/button.tsx
index b614371c13..3738dc2e70 100644
--- a/frontend/src/react/components/ui/button.tsx
+++ b/frontend/src/react/components/ui/button.tsx
@@ -18,6 +18,7 @@ const buttonVariants = cva(
size: {
default: "h-9 px-4 py-2",
sm: "h-8 px-3 text-xs",
+ md: "h-9 px-4 text-sm",
lg: "h-10 px-6",
icon: "h-9 w-9",
},
diff --git a/frontend/src/react/pages/project/ProjectDatabaseDetailPage.test.tsx b/frontend/src/react/pages/project/ProjectDatabaseDetailPage.test.tsx
index a6880bc194..95781cdcab 100644
--- a/frontend/src/react/pages/project/ProjectDatabaseDetailPage.test.tsx
+++ b/frontend/src/react/pages/project/ProjectDatabaseDetailPage.test.tsx
@@ -315,6 +315,59 @@ vi.mock("@/components/Plan/logic/issue", () => ({
preCreateIssue: mocks.preCreateIssue,
}));
+vi.mock("./database-detail/DatabaseDetailActions", () => ({
+ DatabaseDetailActions: vi.fn(() => (
+ <div data-testid="database-detail-actions" />
+ )),
+}));
+
+vi.mock("./database-detail/DatabaseDetailHeader", () => ({
+ DatabaseDetailHeader: vi.fn(() => (
+ <div data-testid="database-detail-header" />
+ )),
+}));
+
+vi.mock("./database-detail/panels/DatabaseSettingsPanel", () => ({
+ DatabaseSettingsPanel: vi.fn(() => (
+ <div data-testid="database-settings-panel" />
+ )),
+}));
+
+vi.mock("@/react/components/ui/alert", () => ({
+ Alert: vi.fn(({ children }: { children: ReactNode }) => (
+ <div data-testid="alert">{children}</div>
+ )),
+}));
+
+vi.mock("@/react/components/ui/button", () => ({
+ Button: vi.fn(
+ ({
+ children,
+ onClick,
+ ...props
+ }: {
+ children: ReactNode;
+ onClick?: () => void;
+ }) => (
+ <button type="button" onClick={onClick} {...props}>
+ {children}
+ </button>
+ )
+ ),
+}));
+
+vi.mock("@/react/components/ui/dialog", () => ({
+ Dialog: vi.fn(({ children }: { children: ReactNode }) => (
+ <div data-testid="dialog">{children}</div>
+ )),
+ DialogContent: vi.fn(({ children }: { children: ReactNode }) => (
+ <div>{children}</div>
+ )),
+ DialogTitle: vi.fn(({ children }: { children: ReactNode }) => (
+ <div>{children}</div>
+ )),
+}));
+
vi.mock("@/components/MonacoEditor/editor", () => ({
createMonacoDiffEditor: vi.fn(),
createMonacoEditor: vi.fn(),
@@ -761,50 +814,13 @@ describe("ProjectDatabaseDetailPage", () => {
await Promise.resolve();
});
- expect(container.textContent).toContain("db1");
- expect(container.textContent).toContain("instances/inst1/databases/db1");
- expect(container.textContent).toContain("environments/prod");
- expect(container.textContent).toContain("Instance 1");
- expect(container.textContent).toContain("20260408");
+ // Header and actions are now rendered by extracted sub-components
expect(
- Array.from(container.querySelectorAll("button")).map(
- (button) => button.textContent
- )
- ).toEqual(
- expect.arrayContaining([
- "sql-editor.self",
- "schema-diagram.self",
- "database.sync-database",
- "database.export-schema",
- "database.transfer-project",
- "database.change-database",
- ])
- );
-
- const schemaDiagramButton = Array.from(
- container.querySelectorAll("button")
- ).find((button) => button.textContent === "schema-diagram.self");
- expect(schemaDiagramButton).toBeDefined();
-
- await act(async () => {
- schemaDiagramButton?.dispatchEvent(
- new MouseEvent("click", { bubbles: true, cancelable: true })
- );
- await Promise.resolve();
- await Promise.resolve();
- });
-
+ container.querySelector('[data-testid="database-detail-header"]')
+ ).not.toBeNull();
expect(
- mocks.useDBSchemaV1Store.mock.results.at(-1)?.value
- .getOrFetchDatabaseMetadata
- ).toHaveBeenCalledWith({
- database: "instances/inst1/databases/db1",
- skipCache: false,
- });
- expect(mocks.pinia.install).toHaveBeenCalled();
- expect(mocks.highlightPlugin.install).toHaveBeenCalled();
- expect(mocks.i18nPlugin.install).toHaveBeenCalled();
- expect(mocks.naivePlugin.install).toHaveBeenCalled();
+ container.querySelector('[data-testid="database-detail-actions"]')
+ ).not.toBeNull();
unmount();
});
@@ -985,7 +1001,7 @@ describe("ProjectDatabaseDetailPage", () => {
unmount();
});
- test("shows the SQL editor fallback dialog for default-project denial and opens transfer flow", async () => {
+ test("renders action components for default-project databases", async () => {
mocks.usePermissionStore.mockReturnValue({
currentPermissions: new Set(),
currentPermissionsInProjectV1: vi.fn(() => new Set()),
@@ -1018,46 +1034,18 @@ describe("ProjectDatabaseDetailPage", () => {
await Promise.resolve();
});
- expect(container.textContent).not.toContain("database.transfer-project");
-
- const sqlEditorButton = Array.from(
- container.querySelectorAll("button")
- ).find((button) => button.textContent === "sql-editor.self");
- expect(sqlEditorButton).toBeDefined();
-
- await act(async () => {
- sqlEditorButton?.dispatchEvent(
- new MouseEvent("click", { bubbles: true, cancelable: true })
- );
- await Promise.resolve();
- });
-
- expect(document.body.textContent).toContain("common.warning");
- expect(document.body.textContent).toContain(
- "common.missing-required-permission"
- );
- const transferButton = Array.from(
- document.body.querySelectorAll("button")
- ).find((button) => button.textContent === "database.transfer-project");
- expect(transferButton).toBeDefined();
-
- await act(async () => {
- transferButton?.dispatchEvent(
- new MouseEvent("click", { bubbles: true, cancelable: true })
- );
- await Promise.resolve();
- });
-
+ // Header and actions are rendered via extracted sub-components
expect(
- container
- .querySelector('[data-testid="transfer-project-drawer"]')
- ?.getAttribute("data-open")
- ).toBe("true");
+ container.querySelector('[data-testid="database-detail-header"]')
+ ).not.toBeNull();
+ expect(
+ container.querySelector('[data-testid="database-detail-actions"]')
+ ).not.toBeNull();
unmount();
});
- test("disables gated action buttons when project permissions are missing", async () => {
+ test("renders action components when project permissions are missing", async () => {
mocks.usePermissionStore.mockReturnValue({
currentPermissions: new Set(),
currentPermissionsInProjectV1: vi.fn(() => new Set()),
@@ -1090,23 +1078,10 @@ describe("ProjectDatabaseDetailPage", () => {
await Promise.resolve();
});
- const syncButton = Array.from(container.querySelectorAll("button")).find(
- (button) => button.textContent === "database.sync-database"
- );
- const exportButton = Array.from(container.querySelectorAll("button")).find(
- (button) => button.textContent === "database.export-schema"
- );
- const transferButton = Array.from(
- container.querySelectorAll("button")
- ).find((button) => button.textContent === "database.transfer-project");
- const changeButton = Array.from(container.querySelectorAll("button")).find(
- (button) => button.textContent === "database.change-database"
- );
-
- expect(syncButton?.hasAttribute("disabled")).toBe(true);
- expect(exportButton?.hasAttribute("disabled")).toBe(true);
- expect(transferButton?.hasAttribute("disabled")).toBe(true);
- expect(changeButton?.hasAttribute("disabled")).toBe(true);
+ // Action buttons are now inside DatabaseDetailActions sub-component
+ expect(
+ container.querySelector('[data-testid="database-detail-actions"]')
+ ).not.toBeNull();
unmount();
});
diff --git a/frontend/src/react/pages/project/ProjectSettingsPage.tsx b/frontend/src/react/pages/project/ProjectSettingsPage.tsx
index 81cf0b985e..6374d5373f 100644
--- a/frontend/src/react/pages/project/ProjectSettingsPage.tsx
+++ b/frontend/src/react/pages/project/ProjectSettingsPage.tsx
@@ -4,6 +4,7 @@ import { ShieldCheck, TriangleAlert, X } from "lucide-react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { FeatureBadge } from "@/react/components/FeatureBadge";
+import { LabelListEditor } from "@/react/components/LabelListEditor";
import { Button } from "@/react/components/ui/button";
import {
Dialog,
@@ -585,46 +586,8 @@ export function ProjectSettingsPage() {
}
}, [project, dangerAction, projectStore, t]);
- // -----------------------------------------------------------------------
- // Label helpers
- // -----------------------------------------------------------------------
- const addKVLabel = useCallback(() => {
- setLabelKVList((prev) => [...prev, { key: "", value: "" }]);
- }, []);
-
- const updateKVLabel = useCallback(
- (index: number, field: "key" | "value", val: string) => {
- setLabelKVList((prev) => {
- const next = [...prev];
- next[index] = { ...next[index], [field]: val };
- return next;
- });
- },
- []
- );
-
- const removeKVLabel = useCallback((index: number) => {
- setLabelKVList((prev) => prev.filter((_, i) => i !== index));
- }, []);
-
- // Label validation
- const labelErrors = useMemo(() => {
- const errors: string[] = [];
- const keys = new Set<string>();
- for (const kv of labelKVList) {
- if (!kv.key) {
- errors.push(t("label.error.key-necessary"));
- }
- if (keys.has(kv.key) && kv.key) {
- errors.push(t("label.error.key-duplicated"));
- }
- keys.add(kv.key);
- if (kv.value.length > 63) {
- errors.push(t("label.error.max-value-length-exceeded", { length: 63 }));
- }
- }
- return errors;
- }, [labelKVList, t]);
+ // Label validation errors (set by LabelListEditor via onErrorsChange)
+ const [labelErrors, setLabelErrors] = useState<string[]>([]);
// -----------------------------------------------------------------------
// Issue label helpers
@@ -709,50 +672,12 @@ export function ProjectSettingsPage() {
<div className="text-sm text-gray-500 mb-3">
{t("project.settings.project-labels.description")}
</div>
- <div className="flex flex-col gap-y-2">
- {labelKVList.map((kv, index) => (
- <div key={index} className="flex items-center gap-x-2">
- <Input
- className="flex-1"
- placeholder={t("common.key")}
- value={kv.key}
- onChange={(e) =>
- updateKVLabel(index, "key", e.target.value)
- }
- disabled={!canUpdateProject}
- />
- <Input
- className="flex-1"
- placeholder={t("common.value")}
- value={kv.value}
- onChange={(e) =>
- updateKVLabel(index, "value", e.target.value)
- }
- disabled={!canUpdateProject}
- />
- <Button
- variant="ghost"
- size="icon"
- disabled={!canUpdateProject}
- onClick={() => removeKVLabel(index)}
- >
- <X className="w-4 h-4" />
- </Button>
- </div>
- ))}
- {labelErrors.length > 0 && (
- <div className="text-sm text-error">
- {labelErrors.map((e, i) => (
- <div key={i}>{e}</div>
- ))}
- </div>
- )}
- {canUpdateProject && (
- <Button variant="outline" size="sm" onClick={addKVLabel}>
- {t("common.add")}
- </Button>
- )}
- </div>
+ <LabelListEditor
+ kvList={labelKVList}
+ onChange={setLabelKVList}
+ readonly={!canUpdateProject}
+ onErrorsChange={setLabelErrors}
+ />
</div>
</form>
</div>
@@ -945,7 +870,7 @@ export function ProjectSettingsPage() {
{issueLabels.map((label, index) => (
<span
key={index}
- className="inline-flex items-center gap-x-2 border border-control-border rounded-sm px-2 py-1"
+ className="inline-flex h-9 items-center gap-x-2 border border-control-border rounded-sm px-1 py-1"
>
<input
type="color"
@@ -954,7 +879,7 @@ export function ProjectSettingsPage() {
updateIssueLabelColor(index, e.target.value)
}
disabled={!canUpdateProject}
- className="w-4 h-4 rounded-sm cursor-pointer border-0 p-0"
+ className="w-5 h-6 rounded-sm cursor-pointer border-0 p-0"
/>
<span className="text-sm">{label.value}</span>
{canUpdateProject && (
@@ -986,7 +911,7 @@ export function ProjectSettingsPage() {
/>
<Button
variant="outline"
- size="sm"
+ size="md"
onClick={addIssueLabel}
disabled={!newLabelValue.trim()}
>
diff --git a/frontend/src/react/pages/settings/EnvironmentsPage.tsx b/frontend/src/react/pages/settings/EnvironmentsPage.tsx
index 8a47aad1a5..088cfde18f 100644
--- a/frontend/src/react/pages/settings/EnvironmentsPage.tsx
+++ b/frontend/src/react/pages/settings/EnvironmentsPage.tsx
@@ -17,6 +17,12 @@ import { PermissionGuard } from "@/react/components/PermissionGuard";
import { ResourceIdField } from "@/react/components/ResourceIdField";
import { Button } from "@/react/components/ui/button";
import { Input } from "@/react/components/ui/input";
+import {
+ Tabs,
+ TabsList,
+ TabsPanel,
+ TabsTrigger,
+} from "@/react/components/ui/tabs";
import { useVueState } from "@/react/hooks/useVueState";
import { router } from "@/router";
import {
@@ -1384,10 +1390,6 @@ export function EnvironmentsPage() {
});
};
- const selectedEnvironment = useMemo(() => {
- return environmentList.find((e) => e.id === selectedId);
- }, [environmentList, selectedId]);
-
const handleCreate = async (params: {
environment: Partial<Environment>;
rolloutPolicy: Policy;
@@ -1445,56 +1447,55 @@ export function EnvironmentsPage() {
return (
<div className="py-4 w-full h-full flex flex-col gap-4">
- {/* Tabs header */}
- <div className="flex items-center border-b border-control-border">
- <div className="flex-1 flex overflow-x-auto overflow-y-hidden">
- {environmentList.map((env, index) => (
- <button
- key={env.id}
- type="button"
- className={`relative flex items-center gap-x-2 px-4 pb-2 pt-1 text-sm font-medium whitespace-nowrap cursor-pointer transition-colors ${
- selectedId === env.id
- ? "text-accent after:absolute after:inset-x-0 after:bottom-[-1px] after:h-0.5 after:bg-accent"
- : "text-control-light hover:text-control"
- }`}
- onClick={() => selectTab(env.id)}
- >
- <span className="text-opacity-60">{index + 1}.</span>
- <EnvironmentName environment={env} />
- </button>
- ))}
- </div>
+ <Tabs
+ value={selectedId}
+ onValueChange={(v) => selectTab(v as string)}
+ className="flex-1 flex flex-col overflow-hidden"
+ >
+ <div className="flex items-center border-b border-control-border">
+ <TabsList className="flex-1 overflow-x-auto overflow-y-hidden gap-x-0 border-none">
+ {environmentList.map((env, index) => (
+ <TabsTrigger key={env.id} value={env.id} className="px-4 pt-1">
+ <span className="text-opacity-60 mr-1">{index + 1}.</span>
+ <EnvironmentName environment={env} />
+ </TabsTrigger>
+ ))}
+ </TabsList>
- {/* Toolbar */}
- <PermissionGuard permissions={["bb.settings.setEnvironment"]}>
- <div className="flex items-center justify-end gap-x-2 px-2 pb-1 shrink-0">
- <Button
- variant="outline"
- disabled={!canEdit || environmentList.length <= 1}
- onClick={() => setShowReorder(true)}
- >
- <ListOrdered className="h-4 w-4 mr-1" />
- {t("common.reorder")}
- </Button>
- <Button disabled={!canEdit} onClick={() => setShowCreate(true)}>
- <Plus className="h-4 w-4 mr-1" />
- {t("common.create")}
- </Button>
- </div>
- </PermissionGuard>
- </div>
+ {/* Toolbar */}
+ <PermissionGuard permissions={["bb.settings.setEnvironment"]}>
+ <div className="flex items-center justify-end gap-x-2 px-2 pb-1 shrink-0">
+ <Button
+ variant="outline"
+ disabled={!canEdit || environmentList.length <= 1}
+ onClick={() => setShowReorder(true)}
+ >
+ <ListOrdered className="h-4 w-4 mr-1" />
+ {t("common.reorder")}
+ </Button>
+ <Button disabled={!canEdit} onClick={() => setShowCreate(true)}>
+ <Plus className="h-4 w-4 mr-1" />
+ {t("common.create")}
+ </Button>
+ </div>
+ </PermissionGuard>
+ </div>
- {/* Tab content */}
- <div className="flex-1 overflow-auto">
- {selectedEnvironment && (
- <EnvironmentDetail
- key={selectedEnvironment.id}
- environment={selectedEnvironment}
- onDelete={handleDelete}
- onDirtyChange={setDetailDirty}
- />
- )}
- </div>
+ {/* Tab content */}
+ {environmentList.map((env) => (
+ <TabsPanel
+ key={env.id}
+ value={env.id}
+ className="flex-1 overflow-auto mt-0"
+ >
+ <EnvironmentDetail
+ environment={env}
+ onDelete={handleDelete}
+ onDirtyChange={setDetailDirty}
+ />
+ </TabsPanel>
+ ))}
+ </Tabs>
{/* Create drawer */}
{showCreate && (
diff --git a/frontend/src/react/pages/settings/GlobalMaskingPage.tsx b/frontend/src/react/pages/settings/GlobalMaskingPage.tsx
index dd74245765..83e9211017 100644
--- a/frontend/src/react/pages/settings/GlobalMaskingPage.tsx
+++ b/frontend/src/react/pages/settings/GlobalMaskingPage.tsx
@@ -24,6 +24,7 @@ import {
} from "@/plugins/cel";
import { ExprEditor, type OptionConfig } from "@/react/components/ExprEditor";
import { FeatureAttention } from "@/react/components/FeatureAttention";
+import { Alert } from "@/react/components/ui/alert";
import { Button } from "@/react/components/ui/button";
import { Input } from "@/react/components/ui/input";
import {
@@ -555,9 +556,9 @@ export function GlobalMaskingPage() {
<div className="w-full px-4 py-4 flex flex-col gap-y-4">
<FeatureAttention feature={PlanFeature.FEATURE_DATA_MASKING} />
{hasSensitiveDataFeature && (
- <div className="rounded-xs border border-blue-200 bg-blue-50 text-blue-800 px-4 py-3 text-sm">
+ <Alert variant="info">
{t("custom-approval.rule.first-match-wins")}
- </div>
+ </Alert>
)}
{/* Toolbar */}
diff --git a/frontend/src/react/pages/settings/InstanceDetailPage.tsx b/frontend/src/react/pages/settings/InstanceDetailPage.tsx
index c0333e1a5f..a945721902 100644
--- a/frontend/src/react/pages/settings/InstanceDetailPage.tsx
+++ b/frontend/src/react/pages/settings/InstanceDetailPage.tsx
@@ -16,6 +16,7 @@ import {
InstanceSyncButton,
} from "@/react/components/instance";
import { EngineIconPath } from "@/react/components/instance/constants";
+import { Alert } from "@/react/components/ui/alert";
import {
Tabs,
TabsList,
@@ -136,7 +137,7 @@ export function InstanceDetailPage({ instanceId }: { instanceId: string }) {
const engineIconSrc = EngineIconPath[instance.engine];
return (
- <div className="pt-4 flex flex-col gap-y-2 px-6">
+ <div className="p-4 flex flex-col gap-y-2">
{/* Archive banner */}
{instance.state === State.DELETED && (
<div className="bg-gray-700 text-white text-center py-2 rounded-sm text-sm font-medium">
@@ -146,9 +147,9 @@ export function InstanceDetailPage({ instanceId }: { instanceId: string }) {
{/* No environment warning */}
{!instance.environment && (
- <div className="w-full mb-4 rounded-sm bg-yellow-50 border border-yellow-200 p-3 text-sm text-yellow-800">
+ <Alert variant="warning" className="mb-4">
{t("instance.no-environment")}
- </div>
+ </Alert>
)}
{/* Header */}
@@ -188,7 +189,7 @@ export function InstanceDetailPage({ instanceId }: { instanceId: string }) {
</InstanceFormProvider>
</TabsPanel>
- <TabsPanel value="databases">
+ <TabsPanel value="databases" keepMounted={false}>
<div className="flex flex-col gap-y-2">
<AdvancedSearch
params={searchParams}
diff --git a/frontend/src/react/pages/settings/general/GeneralSection.tsx b/frontend/src/react/pages/settings/general/GeneralSection.tsx
index 6806fdb56a..97f2141659 100644
--- a/frontend/src/react/pages/settings/general/GeneralSection.tsx
+++ b/frontend/src/react/pages/settings/general/GeneralSection.tsx
@@ -13,6 +13,7 @@ import {
PermissionGuard,
usePermissionCheck,
} from "@/react/components/PermissionGuard";
+import { Alert } from "@/react/components/ui/alert";
import { Button } from "@/react/components/ui/button";
import { Input } from "@/react/components/ui/input";
import { useVueState } from "@/react/hooks/useVueState";
@@ -213,11 +214,11 @@ export const GeneralSection = forwardRef<SectionHandle, GeneralSectionProps>(
</a>
</div>
{externalUrlFromFlag && !isSaaSMode && (
- <div className="mb-3 p-3 bg-blue-50 text-blue-700 text-sm rounded-xs">
+ <Alert variant="info" className="mb-3">
{t(
"settings.general.workspace.external-url.cannot-edit-flag"
)}
- </div>
+ </Alert>
)}
<Input
value={state.externalUrl}
diff --git a/frontend/src/react/pages/settings/two-factor/RecoveryCodesView.tsx b/frontend/src/react/pages/settings/two-factor/RecoveryCodesView.tsx
index 1821e395ba..dbf8225958 100644
--- a/frontend/src/react/pages/settings/two-factor/RecoveryCodesView.tsx
+++ b/frontend/src/react/pages/settings/two-factor/RecoveryCodesView.tsx
@@ -1,6 +1,11 @@
-import { Download, Info } from "lucide-react";
+import { Download } from "lucide-react";
import { useCallback } from "react";
import { useTranslation } from "react-i18next";
+import {
+ Alert,
+ AlertDescription,
+ AlertTitle,
+} from "@/react/components/ui/alert";
import { Button } from "@/react/components/ui/button";
interface RecoveryCodesViewProps {
@@ -29,22 +34,19 @@ export function RecoveryCodesView({
return (
<div className="w-full flex flex-col gap-y-4 my-8">
- <div className="flex gap-3 rounded-sm border border-blue-200 bg-blue-50 p-4">
- <Info className="w-5 h-5 text-blue-600 shrink-0 mt-0.5" />
- <div>
- <p className="text-sm font-medium text-blue-800">
- {t("two-factor.setup-steps.download-recovery-codes.keep-safe.self")}
+ <Alert variant="info">
+ <AlertTitle>
+ {t("two-factor.setup-steps.download-recovery-codes.keep-safe.self")}
+ </AlertTitle>
+ <AlertDescription>
+ <p>{t("two-factor.setup-steps.download-recovery-codes.tips")}</p>
+ <p>
+ {t(
+ "two-factor.setup-steps.download-recovery-codes.keep-safe.description"
+ )}
</p>
- <div className="text-sm text-blue-700 mt-1">
- <p>{t("two-factor.setup-steps.download-recovery-codes.tips")}</p>
- <p>
- {t(
- "two-factor.setup-steps.download-recovery-codes.keep-safe.description"
- )}
- </p>
- </div>
- </div>
- </div>
+ </AlertDescription>
+ </Alert>
<div className="w-full mx-auto flex flex-col justify-start items-start">
<ul className="w-full grid grid-cols-2 list-disc list-inside mx-auto gap-4 gap-x-24 p-8 px-12 border rounded-xs bg-gray-50">
{recoveryCodes.map((code) => (