Skip to content

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

feat(database): promote SQL Editor and add responsive actions (#21438)

p0nyd9e69bf3ddb9
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index fab3c76d89..ae28e02486 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -728,6 +728,7 @@
"mixed-label-values": "mixed values",
"mixed-label-values-warning": "Some of the selected resources have mixed values for the same key. Only edit these key-value pairs if you intend to change them.",
"nullable": "Nullable",
+ "open-sql-editor": "Open SQL Editor",
"partition-tables": "Partition tables",
"partitioned": "Partitioned",
"project-instance-transfer-disabled": "Databases from a project-bound instance cannot be transferred or unassigned.",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index e5ca198d89..00d9cd5d54 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -728,6 +728,7 @@
"mixed-label-values": "valores mixtos",
"mixed-label-values-warning": "Algunos de los recursos seleccionados tienen valores mixtos para la misma clave. Solo edite estos pares clave-valor si tiene la intención de cambiarlos.",
"nullable": "Anulable",
+ "open-sql-editor": "Abrir editor SQL",
"partition-tables": "Tablas de particiones",
"partitioned": "Particionado",
"project-instance-transfer-disabled": "Las bases de datos de una instancia vinculada a un proyecto no se pueden transferir ni desasignar.",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 5761d66495..8d8222ae72 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -728,6 +728,7 @@
"mixed-label-values": "混合値",
"mixed-label-values-warning": "選択されたリソースの一部は、同じキーに対して異なる値を持っています。これらのキーと値のペアを変更する場合にのみ編集してください。",
"nullable": "null も可能",
+ "open-sql-editor": "SQL エディターを開く",
"partition-tables": "パーティションテーブル",
"partitioned": "パーティション",
"project-instance-transfer-disabled": "プロジェクトに紐付けられたインスタンスのデータベースは、移管または割り当て解除できません。",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 8e38914602..43ad5d9e38 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -728,6 +728,7 @@
"mixed-label-values": "giá trị hỗn hợp",
"mixed-label-values-warning": "Một số tài nguyên đã chọn có các giá trị khác nhau cho cùng một khóa. Chỉ chỉnh sửa các cặp khóa-giá trị này nếu bạn muốn thay đổi chúng.",
"nullable": "Có thể null",
+ "open-sql-editor": "Mở trình soạn thảo SQL",
"partition-tables": "Bảng phân vùng",
"partitioned": "Đã phân vùng",
"project-instance-transfer-disabled": "Không thể chuyển hoặc hủy gán cơ sở dữ liệu thuộc phiên bản gắn với dự án.",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 62ceb172cd..a9156aa77a 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -728,6 +728,7 @@
"mixed-label-values": "混合值",
"mixed-label-values-warning": "部分标签拥有不同的值,编辑标签将会批量应用。仅在您打算更改时再编辑这些键值对。",
"nullable": "可为空",
+ "open-sql-editor": "打开 SQL 编辑器",
"partition-tables": "分区表",
"partitioned": "分区",
"project-instance-transfer-disabled": "项目绑定实例中的数据库无法转移或取消分配。",
diff --git a/frontend/src/routes/project/ProjectDatabaseDetailPage.tsx b/frontend/src/routes/project/ProjectDatabaseDetailPage.tsx
index 8afbdde4c6..da203f3c39 100644
--- a/frontend/src/routes/project/ProjectDatabaseDetailPage.tsx
+++ b/frontend/src/routes/project/ProjectDatabaseDetailPage.tsx
@@ -185,8 +185,10 @@ export function ProjectDatabaseDetailPage({
/>
)}
- <div className="flex flex-col items-start gap-y-2 xl:flex-row xl:items-center xl:justify-between xl:gap-x-2">
- <DatabaseDetailHeader database={detail.database} />
+ <div className="flex flex-col items-stretch gap-2 xl:flex-row xl:items-center">
+ <div className="min-w-0 xl:w-1/3">
+ <DatabaseDetailHeader database={detail.database} />
+ </div>
<DatabaseDetailActions
database={detail.database}
isDefaultProject={detail.isDefaultProject}
diff --git a/frontend/src/routes/project/database-detail/DatabaseActionBar.test.tsx b/frontend/src/routes/project/database-detail/DatabaseActionBar.test.tsx
new file mode 100644
index 0000000000..ee1fba5c6d
--- /dev/null
+++ b/frontend/src/routes/project/database-detail/DatabaseActionBar.test.tsx
@@ -0,0 +1,76 @@
+import { act, fireEvent, render, screen } from "@testing-library/react";
+import { Pencil } from "lucide-react";
+import { afterEach, beforeEach, expect, test, vi } from "vitest";
+import { DatabaseActionBar, type DatabaseAction } from "./DatabaseActionBar";
+
+vi.mock("react-i18next", () => ({
+ initReactI18next: { type: "3rdParty", init: () => {} },
+ useTranslation: () => ({ t: (key: string) => key }),
+}));
+
+let availableWidth = 600;
+const resizeCallbacks = new Set<() => void>();
+beforeEach(() => {
+ availableWidth = 600;
+ vi.stubGlobal("ResizeObserver", class {
+ callback: () => void;
+ constructor(callback: () => void) { this.callback = callback; resizeCallbacks.add(callback); }
+ observe() {}
+ unobserve() {}
+ disconnect() { resizeCallbacks.delete(this.callback); }
+ });
+ vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(function (this: HTMLElement) {
+ let width = 0;
+ if (this.classList.contains("relative")) width = availableWidth;
+ else if (this.parentElement?.closest("[inert]")) width = this.textContent === "common.more" ? 60 : 100;
+ else if (this.querySelector("a")) width = 140;
+ return { width, height: 36, top: 0, left: 0, bottom: 36, right: width, x: 0, y: 0, toJSON() {} };
+ });
+});
+afterEach(() => { vi.restoreAllMocks(); vi.unstubAllGlobals(); resizeCallbacks.clear(); });
+
+function resize(width: number) {
+ act(() => { availableWidth = width; for (const callback of resizeCallbacks) callback(); });
+}
+
+test("keeps actions visible when they fit and overflows by priority as space shrinks", async () => {
+ const sync = vi.fn();
+ const exportSchema = vi.fn();
+ const actions: DatabaseAction[] = [
+ { key: "change", label: "Change Database" },
+ { key: "sync", label: "Sync Database", onClick: sync },
+ { key: "export", label: "Export Schema", options: [{ key: "single", label: "Single file", onClick: exportSchema }] },
+ { key: "transfer", label: "Transfer Project", disabled: true },
+ ].map((action) => ({ ...action, icon: Pencil, wrap: (content) => content }));
+ render(<DatabaseActionBar actions={actions} primary={<a href="/sql-editor">Open SQL Editor</a>} />);
+ expect(screen.queryByRole("button", { name: "common.more" })).not.toBeInTheDocument();
+ expect(screen.getByRole("button", { name: "Transfer Project" })).toBeDisabled();
+
+ expect(screen.getAllByRole("button").map((button) => button.textContent)).toEqual([
+ "Transfer Project", "Export Schema", "Sync Database", "Change Database",
+ ]);
+ resize(450);
+ expect(screen.getAllByRole("button").map((button) => button.textContent)).toEqual([
+ "common.more", "Sync Database", "Change Database",
+ ]);
+
+ resize(350);
+ expect(screen.getByRole("button", { name: "Change Database" })).toBeInTheDocument();
+ expect(screen.queryByRole("button", { name: "Sync Database" })).not.toBeInTheDocument();
+ fireEvent.click(screen.getByRole("button", { name: "common.more" }));
+ fireEvent.click(await screen.findByRole("menuitem", { name: "Sync Database" }));
+ expect(sync).toHaveBeenCalledOnce();
+
+ fireEvent.click(screen.getByRole("button", { name: "common.more" }));
+ const exportItem = await screen.findByRole("menuitem", { name: "Export Schema" });
+ fireEvent.click(exportItem);
+ fireEvent.click(await screen.findByRole("menuitem", { name: "Single file" }));
+ expect(exportSchema).toHaveBeenCalledOnce();
+
+ resize(220);
+ expect(screen.queryByRole("button", { name: "Change Database" })).not.toBeInTheDocument();
+ expect(screen.getByRole("link", { name: "Open SQL Editor" })).toBeInTheDocument();
+ resize(600);
+ expect(screen.queryByRole("button", { name: "common.more" })).not.toBeInTheDocument();
+ expect(screen.getByRole("button", { name: "Sync Database" })).toBeInTheDocument();
+});
diff --git a/frontend/src/routes/project/database-detail/DatabaseActionBar.tsx b/frontend/src/routes/project/database-detail/DatabaseActionBar.tsx
new file mode 100644
index 0000000000..ca089cc9bd
--- /dev/null
+++ b/frontend/src/routes/project/database-detail/DatabaseActionBar.tsx
@@ -0,0 +1,191 @@
+import {
+ ChevronDown,
+ ChevronRight,
+ type LucideIcon,
+ MoreHorizontal,
+} from "lucide-react";
+import { type ReactNode, useLayoutEffect, useRef, useState } from "react";
+import { useTranslation } from "react-i18next";
+import { Button, buttonVariants } from "@/components/ui/button";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuSubmenu,
+ DropdownMenuSubmenuContent,
+ DropdownMenuSubmenuTrigger,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
+
+export interface DatabaseAction {
+ key: string;
+ label: string;
+ icon: LucideIcon;
+ disabled?: boolean;
+ onClick?: () => void;
+ options?: { key: string | number; label: string; onClick: () => void }[];
+ wrap: (content: ReactNode) => ReactNode;
+}
+
+export function DatabaseActionBar({
+ actions,
+ primary,
+}: {
+ // Actions are ordered by retention priority, highest first.
+ actions: DatabaseAction[];
+ primary: ReactNode;
+}) {
+ const { t } = useTranslation();
+ const containerRef = useRef<HTMLDivElement>(null);
+ const measureRef = useRef<HTMLDivElement>(null);
+ const primaryRef = useRef<HTMLDivElement>(null);
+ const [visibleCount, setVisibleCount] = useState(actions.length);
+
+ useLayoutEffect(() => {
+ const container = containerRef.current;
+ const measurement = measureRef.current;
+ const primaryElement = primaryRef.current;
+ if (!container || !measurement || !primaryElement) return;
+ const update = () => {
+ const available = container.getBoundingClientRect().width;
+ if (!available) return;
+ const gap = Number.parseFloat(getComputedStyle(container).columnGap) || 8;
+ const widths = Array.from(
+ measurement.children,
+ (child) => child.getBoundingClientRect().width
+ );
+ const moreWidth = widths.pop() ?? 0;
+ const primaryWidth = primaryElement.getBoundingClientRect().width;
+ let count = widths.length;
+ while (count > 0) {
+ const hasOverflow = count < widths.length;
+ const required =
+ primaryWidth +
+ widths.slice(0, count).reduce((sum, width) => sum + width, 0) +
+ (hasOverflow ? moreWidth : 0) +
+ gap * (count + Number(hasOverflow));
+ if (required <= available) break;
+ count--;
+ }
+ setVisibleCount(count);
+ };
+ update();
+ const observer = new ResizeObserver(update);
+ observer.observe(container);
+ observer.observe(primaryElement);
+ for (const child of measurement.children) observer.observe(child);
+ return () => observer.disconnect();
+ }, [actions]);
+
+ const inline = actions.slice(0, visibleCount).reverse();
+ const overflow = actions.slice(visibleCount);
+ return (
+ <div
+ ref={containerRef}
+ className="relative flex min-w-0 flex-1 flex-wrap items-center justify-end gap-2"
+ >
+ <div
+ aria-hidden="true"
+ inert
+ className="pointer-events-none invisible absolute inset-0 overflow-hidden"
+ >
+ <div ref={measureRef} className="flex w-max gap-2">
+ {actions.map(({ key, label, icon: Icon, options }) => (
+ <span
+ key={key}
+ className={buttonVariants({ appearance: "outline" })}
+ >
+ <Icon className="size-4" />
+ {label}
+ {options && <ChevronDown className="size-4" />}
+ </span>
+ ))}
+ <span className={buttonVariants({ appearance: "outline" })}>
+ <MoreHorizontal className="size-4" />
+ {t("common.more")}
+ </span>
+ </div>
+ </div>
+ {overflow.length > 0 && (
+ <DropdownMenu>
+ <DropdownMenuTrigger render={<Button appearance="outline" />}>
+ <MoreHorizontal className="size-4" />
+ {t("common.more")}
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="start">
+ {overflow.map((action) => (
+ <div key={action.key}>
+ {action.wrap(
+ action.options ? (
+ <DropdownMenuSubmenu>
+ <DropdownMenuSubmenuTrigger disabled={action.disabled}>
+ <action.icon className="size-4" />
+ {action.label}
+ <ChevronRight className="size-4" />
+ </DropdownMenuSubmenuTrigger>
+ <DropdownMenuSubmenuContent>
+ {action.options.map((option) => (
+ <DropdownMenuItem
+ key={option.key}
+ onClick={option.onClick}
+ >
+ {option.label}
+ </DropdownMenuItem>
+ ))}
+ </DropdownMenuSubmenuContent>
+ </DropdownMenuSubmenu>
+ ) : (
+ <DropdownMenuItem
+ disabled={action.disabled}
+ onClick={action.onClick}
+ >
+ <action.icon className="size-4" />
+ {action.label}
+ </DropdownMenuItem>
+ )
+ )}
+ </div>
+ ))}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )}
+ {inline.map((action) => (
+ <div key={action.key} className="shrink-0">
+ {action.wrap(
+ action.options ? (
+ <DropdownMenu>
+ <DropdownMenuTrigger
+ render={<Button appearance="outline" />}
+ disabled={action.disabled}
+ >
+ <action.icon className="size-4" />
+ {action.label}
+ <ChevronDown className="size-4" />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent>
+ {action.options.map((option) => (
+ <DropdownMenuItem key={option.key} onClick={option.onClick}>
+ {option.label}
+ </DropdownMenuItem>
+ ))}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ ) : (
+ <Button
+ appearance="outline"
+ disabled={action.disabled}
+ onClick={action.onClick}
+ >
+ <action.icon className="size-4" />
+ {action.label}
+ </Button>
+ )
+ )}
+ </div>
+ ))}
+ <div ref={primaryRef} className="shrink-0">
+ {primary}
+ </div>
+ </div>
+ );
+}
diff --git a/frontend/src/routes/project/database-detail/DatabaseDetailActions.test.tsx b/frontend/src/routes/project/database-detail/DatabaseDetailActions.test.tsx
index 5e6cb70e9c..56c248e871 100644
--- a/frontend/src/routes/project/database-detail/DatabaseDetailActions.test.tsx
+++ b/frontend/src/routes/project/database-detail/DatabaseDetailActions.test.tsx
@@ -31,9 +31,11 @@ vi.mock("@/stores/app", () => ({
vi.mock("@/lib/plan/issue", () => ({ preCreateIssue: vi.fn() }));
vi.mock("./DatabaseExportSchemaButton", () => ({
- DatabaseExportSchemaButton: () => null,
+ useDatabaseSchemaExport: () => ({ exporting: false, options: [], exportSchema: vi.fn() }),
}));
-vi.mock("./DatabaseSyncButton", () => ({ DatabaseSyncButton: () => null }));
+vi.mock("./DatabaseSyncButton", () => ({ useDatabaseSync: () => ({ syncing: false, sync: vi.fn() }) }));
+vi.mock("./DatabaseSQLEditorButton", () => ({ DatabaseSQLEditorButton: () => <a href="/sql-editor">Open SQL Editor</a> }));
+globalThis.ResizeObserver ??= class { observe() {} unobserve() {} disconnect() {} };
import { DatabaseDetailActions } from "./DatabaseDetailActions";
diff --git a/frontend/src/routes/project/database-detail/DatabaseDetailActions.tsx b/frontend/src/routes/project/database-detail/DatabaseDetailActions.tsx
index f28e06cda9..b29c4a6801 100644
--- a/frontend/src/routes/project/database-detail/DatabaseDetailActions.tsx
+++ b/frontend/src/routes/project/database-detail/DatabaseDetailActions.tsx
@@ -1,16 +1,17 @@
-import { ArrowRightLeft, Pencil } from "lucide-react";
-import { useMemo } from "react";
+import { ArrowRightLeft, Download, Pencil, RefreshCw } from "lucide-react";
+import { type ReactNode, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { PermissionGuard } from "@/components/PermissionGuard";
-import { Button } from "@/components/ui/button";
import { useProjectByName } from "@/hooks/useProjectByName";
import { preCreateIssue } from "@/lib/plan/issue";
import { useAppStore } from "@/stores/app";
import type { Permission } from "@/types";
import type { Database } from "@/types/proto-es/v1/database_service_pb";
import { isProjectInstanceDatabase } from "@/utils/v1/database";
-import { DatabaseExportSchemaButton } from "./DatabaseExportSchemaButton";
-import { DatabaseSyncButton } from "./DatabaseSyncButton";
+import { type DatabaseAction, DatabaseActionBar } from "./DatabaseActionBar";
+import { useDatabaseSchemaExport } from "./DatabaseExportSchemaButton";
+import { DatabaseSQLEditorButton } from "./DatabaseSQLEditorButton";
+import { useDatabaseSync } from "./DatabaseSyncButton";
const DATABASE_CHANGE_PERMISSIONS: Permission[] = [
"bb.plans.create",
@@ -67,54 +68,60 @@ export function DatabaseDetailActions({
[hasProjectPermission]
);
+ const { syncing, sync } = useDatabaseSync(database);
+ const { exporting, options, exportSchema } =
+ useDatabaseSchemaExport(database);
+ const guard = (permissions: Permission[]) => (content: ReactNode) => (
+ <PermissionGuard permissions={permissions} project={project}>
+ {content}
+ </PermissionGuard>
+ );
+ const actions: DatabaseAction[] = [];
+ if (!isDefaultProject) {
+ actions.push({
+ key: "change",
+ label: t("database.change-database"),
+ icon: Pencil,
+ disabled: !canChangeDatabase,
+ onClick: () => void preCreateIssue(database.project, [database.name]),
+ wrap: guard(DATABASE_CHANGE_PERMISSIONS),
+ });
+ }
+ actions.push(
+ {
+ key: "sync",
+ label: t("database.sync-database"),
+ icon: RefreshCw,
+ disabled: !canSync || syncing,
+ onClick: () => void sync(),
+ wrap: guard(["bb.databases.sync"]),
+ },
+ {
+ key: "export",
+ label: t("database.export-schema"),
+ icon: Download,
+ disabled: !canExportSchema || exporting,
+ options: options.map((option) => ({
+ ...option,
+ onClick: () => void exportSchema(option.key),
+ })),
+ wrap: guard(["bb.databases.getSchema"]),
+ }
+ );
+ if (!isDefaultProject && !isProjectInstanceDatabase(database)) {
+ actions.push({
+ key: "transfer",
+ label: t("database.transfer-project"),
+ icon: ArrowRightLeft,
+ disabled: !canUpdate,
+ onClick: onOpenTransferProject,
+ wrap: guard(["bb.databases.update"]),
+ });
+ }
return (
- <>
- <div className="flex shrink-0 flex-wrap items-center justify-start gap-x-2 gap-y-2">
- <PermissionGuard permissions={["bb.databases.sync"]} project={project}>
- <DatabaseSyncButton database={database} disabled={!canSync} />
- </PermissionGuard>
- <PermissionGuard
- permissions={["bb.databases.getSchema"]}
- project={project}
- >
- <DatabaseExportSchemaButton
- database={database}
- disabled={!canExportSchema}
- />
- </PermissionGuard>
- {!isDefaultProject && !isProjectInstanceDatabase(database) && (
- <PermissionGuard
- permissions={["bb.databases.update"]}
- project={project}
- >
- <Button
- appearance="outline"
- disabled={!canUpdate}
- onClick={onOpenTransferProject}
- >
- <ArrowRightLeft className="h-4 w-4" />
- {t("database.transfer-project")}
- </Button>
- </PermissionGuard>
- )}
- {!isDefaultProject && (
- <PermissionGuard
- permissions={["bb.plans.create", "bb.sheets.create"]}
- project={project}
- >
- <Button
- appearance="outline"
- disabled={!canChangeDatabase}
- onClick={() =>
- void preCreateIssue(database.project, [database.name])
- }
- >
- <Pencil className="h-4 w-4" />
- {t("database.change-database")}
- </Button>
- </PermissionGuard>
- )}
- </div>
- </>
+ <DatabaseActionBar
+ actions={actions}
+ primary={<DatabaseSQLEditorButton database={database} />}
+ />
);
}
diff --git a/frontend/src/routes/project/database-detail/DatabaseDetailHeader.tsx b/frontend/src/routes/project/database-detail/DatabaseDetailHeader.tsx
index 4c1efe0edd..ed07ee0f51 100644
--- a/frontend/src/routes/project/database-detail/DatabaseDetailHeader.tsx
+++ b/frontend/src/routes/project/database-detail/DatabaseDetailHeader.tsx
@@ -19,7 +19,6 @@ import {
hexToRgb,
} from "@/utils";
import { extractReleaseUID } from "@/utils/v1/release";
-import { DatabaseSQLEditorButton } from "./DatabaseSQLEditorButton";
const extractDatabaseParts = (resource: string) => {
const matches = resource.match(
@@ -155,7 +154,6 @@ export function DatabaseDetailHeader({ database }: { database: Database }) {
<span>{extractReleaseUID(database.release)}</span>
</div>
)}
- <DatabaseSQLEditorButton database={database} />
</div>
</div>
);
diff --git a/frontend/src/routes/project/database-detail/DatabaseExportSchemaButton.tsx b/frontend/src/routes/project/database-detail/DatabaseExportSchemaButton.tsx
index 9f7b381c5e..150f1ae37d 100644
--- a/frontend/src/routes/project/database-detail/DatabaseExportSchemaButton.tsx
+++ b/frontend/src/routes/project/database-detail/DatabaseExportSchemaButton.tsx
@@ -25,16 +25,9 @@ const extractDatabaseName = (resource: string) => {
return matches?.groups?.databaseName ?? "";
};
-export function DatabaseExportSchemaButton({
- database,
- disabled = false,
-}: {
- database: Database;
- disabled?: boolean;
-}) {
+export function useDatabaseSchemaExport(database: Database) {
const { t } = useTranslation();
const [exporting, setExporting] = useState(false);
- const [open, setOpen] = useState(false);
const options = useMemo(
() => [
@@ -53,7 +46,6 @@ export function DatabaseExportSchemaButton({
const handleExport = useCallback(
async (format: GetDatabaseSDLSchemaRequest_SDLFormat) => {
setExporting(true);
- setOpen(false);
try {
const response =
@@ -104,6 +96,20 @@ export function DatabaseExportSchemaButton({
[database, t]
);
+ return { exporting, options, exportSchema: handleExport };
+}
+
+export function DatabaseExportSchemaButton({
+ database,
+ disabled = false,
+}: {
+ database: Database;
+ disabled?: boolean;
+}) {
+ const { t } = useTranslation();
+ const [open, setOpen] = useState(false);
+ const { exporting, options, exportSchema } =
+ useDatabaseSchemaExport(database);
return (
<DropdownMenu open={open} onOpenChange={setOpen}>
<DropdownMenuTrigger
@@ -118,7 +124,10 @@ export function DatabaseExportSchemaButton({
{options.map((option) => (
<DropdownMenuItem
key={option.key}
- onClick={() => void handleExport(option.key)}
+ onClick={() => {
+ setOpen(false);
+ void exportSchema(option.key);
+ }}
>
{option.label}
</DropdownMenuItem>
diff --git a/frontend/src/routes/project/database-detail/DatabaseSQLEditorButton.test.tsx b/frontend/src/routes/project/database-detail/DatabaseSQLEditorButton.test.tsx
index acd3183ef8..c5ef10c95e 100644
--- a/frontend/src/routes/project/database-detail/DatabaseSQLEditorButton.test.tsx
+++ b/frontend/src/routes/project/database-detail/DatabaseSQLEditorButton.test.tsx
@@ -70,7 +70,7 @@ describe("DatabaseSQLEditorButton", () => {
mocks.hasProjectPermission.mockReturnValue(true);
render(<DatabaseSQLEditorButton database={database} />);
- const link = screen.getByRole("link", { name: "sql-editor.self" });
+ const link = screen.getByRole("link", { name: "database.open-sql-editor" });
expect(link).toHaveAttribute("target", "_blank");
expect(link).toHaveAttribute("rel", "noopener noreferrer");
expect(mocks.resolve).toHaveBeenCalledWith({
@@ -90,7 +90,7 @@ describe("DatabaseSQLEditorButton", () => {
test("disables the link when project query access is missing", () => {
render(<DatabaseSQLEditorButton database={database} />);
- const link = screen.getByRole("link", { name: "sql-editor.self" });
+ const link = screen.getByRole("link", { name: "database.open-sql-editor" });
expect(link).toHaveAttribute("aria-disabled", "true");
fireEvent.click(link);
diff --git a/frontend/src/routes/project/database-detail/DatabaseSQLEditorButton.tsx b/frontend/src/routes/project/database-detail/DatabaseSQLEditorButton.tsx
index 728986ee5f..44baffe8cc 100644
--- a/frontend/src/routes/project/database-detail/DatabaseSQLEditorButton.tsx
+++ b/frontend/src/routes/project/database-detail/DatabaseSQLEditorButton.tsx
@@ -1,3 +1,4 @@
+import { useTranslation } from "react-i18next";
import { useCurrentRoute } from "@/app/router";
import { PermissionGuard } from "@/components/PermissionGuard";
import { SQLEditorButton } from "@/components/SQLEditorButton";
@@ -11,22 +12,22 @@ export function DatabaseSQLEditorButton({
database: Database;
disabled?: boolean;
}) {
+ const { t } = useTranslation();
const route = useCurrentRoute();
const project = useProjectByName(database.project);
return (
- <dd className="md:mr-4">
- <PermissionGuard permissions={["bb.sql.select"]} project={project}>
- {({ disabled: permissionDisabled }) => (
- <SQLEditorButton
- database={database}
- disabled={disabled || permissionDisabled}
- openInNewTab={!route.name?.startsWith("sql-editor")}
- appearance="secondary"
- size="sm"
- />
- )}
- </PermissionGuard>
- </dd>
+ <PermissionGuard permissions={["bb.sql.select"]} project={project}>
+ {({ disabled: permissionDisabled }) => (
+ <SQLEditorButton
+ database={database}
+ disabled={disabled || permissionDisabled}
+ openInNewTab={!route.name?.startsWith("sql-editor")}
+ appearance="solid"
+ size="md"
+ label={t("database.open-sql-editor")}
+ />
+ )}
+ </PermissionGuard>
);
}
diff --git a/frontend/src/routes/project/database-detail/DatabaseSyncButton.tsx b/frontend/src/routes/project/database-detail/DatabaseSyncButton.tsx
index bb6985715f..dbb104d942 100644
--- a/frontend/src/routes/project/database-detail/DatabaseSyncButton.tsx
+++ b/frontend/src/routes/project/database-detail/DatabaseSyncButton.tsx
@@ -14,13 +14,7 @@ const extractDatabaseName = (resource: string) => {
return matches?.groups?.databaseName ?? "";
};
-export function DatabaseSyncButton({
- database,
- disabled = false,
-}: {
- database: Database;
- disabled?: boolean;
-}) {
+export function useDatabaseSync(database: Database) {
const { t } = useTranslation();
const getOrFetchDatabaseMetadata = useAppStore(
(s) => s.getOrFetchDatabaseMetadata
@@ -61,13 +55,25 @@ export function DatabaseSyncButton({
}
}, [database, getOrFetchDatabaseMetadata, t]);
+ return { syncing, sync: handleClick };
+}
+
+export function DatabaseSyncButton({
+ database,
+ disabled = false,
+}: {
+ database: Database;
+ disabled?: boolean;
+}) {
+ const { t } = useTranslation();
+ const { syncing, sync } = useDatabaseSync(database);
return (
<Button
appearance="outline"
disabled={disabled || syncing}
- onClick={() => void handleClick()}
+ onClick={() => void sync()}
>
- <RefreshCw className="h-4 w-4" />
+ <RefreshCw className="size-4" />
{t("database.sync-database")}
</Button>
);