Skip to content

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

chore: some ux fix and optimize (#20604)

ecmadao374002d7c241
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 7612a7d429..3023cd8381 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1660,7 +1660,7 @@
"request-role": {
"disabled-reason": {
"allow-request-role-disabled": "Allow request role is disabled for this project.",
- "can-grant-access-directly": "You already have {{permission}}, so you can grant access directly.",
+ "can-grant-access-directly": "You already have full access to this project, so you can grant access directly.",
"feature-unavailable": "Request role workflow is unavailable on the current plan."
},
"expiration-exceeds-max": "Expiration cannot exceed the workspace limit of {{days}} day(s).",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index ee1abc2afb..ab1228dbf0 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1660,7 +1660,7 @@
"request-role": {
"disabled-reason": {
"allow-request-role-disabled": "La solicitud de roles está deshabilitada para este proyecto.",
- "can-grant-access-directly": "Ya tienes {{permission}}, así que puedes conceder acceso directamente.",
+ "can-grant-access-directly": "Ya tienes acceso completo a este proyecto, así que puedes conceder acceso directamente.",
"feature-unavailable": "El flujo de solicitud de roles no está disponible en el plan actual."
},
"expiration-exceeds-max": "La expiración no puede exceder el límite del espacio de trabajo de {{days}} día(s).",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 7cc6d5f826..ef00459a57 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1660,7 +1660,7 @@
"request-role": {
"disabled-reason": {
"allow-request-role-disabled": "このプロジェクトではロール申請が無効になっています。",
- "can-grant-access-directly": "すでに {{permission}} を持っているため、直接アクセスを付与できます。",
+ "can-grant-access-directly": "このプロジェクトへのフルアクセス権を持っているため、直接アクセスを付与できます。",
"feature-unavailable": "現在のプランではロール申請ワークフローを利用できません。"
},
"expiration-exceeds-max": "有効期限はワークスペースの上限 {{days}} 日を超えることはできません。",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 7581a9865b..06dc132205 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1660,7 +1660,7 @@
"request-role": {
"disabled-reason": {
"allow-request-role-disabled": "Dự án này đã tắt tính năng yêu cầu vai trò.",
- "can-grant-access-directly": "Bạn đã có {{permission}}, nên có thể cấp quyền truy cập trực tiếp.",
+ "can-grant-access-directly": "Bạn đã có toàn quyền truy cập dự án này, nên có thể cấp quyền truy cập trực tiếp.",
"feature-unavailable": "Quy trình yêu cầu vai trò không khả dụng trong gói hiện tại."
},
"expiration-exceeds-max": "Thời gian hết hạn không được vượt quá giới hạn {{days}} ngày của không gian làm việc.",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 0e82f9c7c6..bcbf24388f 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1660,7 +1660,7 @@
"request-role": {
"disabled-reason": {
"allow-request-role-disabled": "此项目未启用申请角色。",
- "can-grant-access-directly": "您已拥有 {{permission}},可以直接授予访问权限。",
+ "can-grant-access-directly": "您已拥有该项目的完整访问权限,可以直接授予访问权限。",
"feature-unavailable": "当前套餐不支持申请角色工作流。"
},
"expiration-exceeds-max": "过期时间不能超过工作空间上限 {{days}} 天。",
diff --git a/frontend/src/react/components/AdvancedSearch.tsx b/frontend/src/react/components/AdvancedSearch.tsx
index e02c6b2545..af532102b9 100644
--- a/frontend/src/react/components/AdvancedSearch.tsx
+++ b/frontend/src/react/components/AdvancedSearch.tsx
@@ -454,9 +454,12 @@ export function AdvancedSearch({
(text: string) => {
setInputText(text);
- if (menuView === "value") {
- // In value mode, input text is used to filter values — don't change mode
- return;
+ if (menuView === "value" && currentScope) {
+ // Stay in value mode only while the input still carries the
+ // "scope:" prefix. Once the user edits the prefix away (or clears
+ // the input), drop back out and re-evaluate the menu below.
+ if (text.startsWith(`${currentScope}:`)) return;
+ setCurrentScope(undefined);
}
// Check if text matches a scope prefix
@@ -471,14 +474,14 @@ export function AdvancedSearch({
// Only show scope menu when input is empty (user is browsing filters).
// When typing non-empty text, treat it as a plain query — don't push scope suggestions.
if (!text.trim()) {
- if (!menuView) setMenuView("scope");
+ setMenuView("scope");
} else {
setMenuView(undefined);
}
emitQuery(text);
},
- [menuView, availableScopeOptions, selectScope, emitQuery]
+ [menuView, currentScope, availableScopeOptions, selectScope, emitQuery]
);
const handleInputClick = useCallback(() => {
diff --git a/frontend/src/react/components/ResourceIdField.tsx b/frontend/src/react/components/ResourceIdField.tsx
index 383b9e749c..c62a2da958 100644
--- a/frontend/src/react/components/ResourceIdField.tsx
+++ b/frontend/src/react/components/ResourceIdField.tsx
@@ -7,6 +7,7 @@ import {
useState,
} from "react";
import { useTranslation } from "react-i18next";
+import { CopyButton } from "@/react/components/ui/copy-button";
import { Input } from "@/react/components/ui/input";
import type { ValidatedMessage } from "@/types";
import { randomString } from "@/utils";
@@ -195,7 +196,10 @@ export const ResourceIdField = forwardRef<
<div className="flex items-center gap-x-1">
{t("resource-id.self", { resource: resourceName })}:
{value ? (
- <span className="text-gray-600 font-medium mr-1">{value}</span>
+ <span className="text-gray-600 font-medium mr-1 inline-flex items-center gap-x-1">
+ {value}
+ {readonly && <CopyButton content={value} />}
+ </span>
) : (
<span className="text-control-placeholder italic">-</span>
)}
diff --git a/frontend/src/react/components/instance/InfoPanel.i18n.test.tsx b/frontend/src/react/components/instance/InfoPanel.i18n.test.tsx
index 33ea61bbe6..235ea7343b 100644
--- a/frontend/src/react/components/instance/InfoPanel.i18n.test.tsx
+++ b/frontend/src/react/components/instance/InfoPanel.i18n.test.tsx
@@ -23,6 +23,12 @@ vi.mock("@/types", () => ({
DATASOURCE_ADMIN_USER_NAME: "bytebase",
}));
+// CopyButton pulls in the app store (and its connect/i18n chain), which isn't
+// available in this minimal render harness. The i18n assertions don't touch it.
+vi.mock("@/react/components/ui/copy-button", () => ({
+ CopyButton: () => null,
+}));
+
const renderIntoContainer = (element: ReactElement) => {
const container = document.createElement("div");
const root = createRoot(container);
diff --git a/frontend/src/react/components/instance/InfoPanel.tsx b/frontend/src/react/components/instance/InfoPanel.tsx
index 7ffba31c18..c082d9377f 100644
--- a/frontend/src/react/components/instance/InfoPanel.tsx
+++ b/frontend/src/react/components/instance/InfoPanel.tsx
@@ -1,8 +1,9 @@
import type { TFunction } from "i18next";
-import { Check, Copy, X } from "lucide-react";
+import { X } from "lucide-react";
import type { ReactNode } from "react";
-import { useCallback, useEffect, useRef, useState } from "react";
+import { useCallback, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
+import { CopyButton } from "@/react/components/ui/copy-button";
import {
Sheet,
SheetBody,
@@ -230,32 +231,3 @@ function getSnippetLinkTitle(t: TFunction, key: InfoSnippetLinkTitleKey) {
const exhaustive: never = key;
return exhaustive;
}
-
-function CopyButton({ content }: { content: string }) {
- const [copied, setCopied] = useState(false);
- const timerRef = useRef<ReturnType<typeof setTimeout>>(undefined);
-
- const handleCopy = useCallback(() => {
- navigator.clipboard.writeText(content);
- setCopied(true);
- clearTimeout(timerRef.current);
- timerRef.current = setTimeout(() => setCopied(false), 2000);
- }, [content]);
-
- useEffect(() => {
- return () => clearTimeout(timerRef.current);
- }, []);
-
- return (
- <button
- className="p-0.5 rounded-xs text-control-light hover:text-main"
- onClick={handleCopy}
- >
- {copied ? (
- <Check className="size-4 text-success" />
- ) : (
- <Copy className="size-4" />
- )}
- </button>
- );
-}
diff --git a/frontend/src/react/components/release/ReleaseFileDetailPanel.tsx b/frontend/src/react/components/release/ReleaseFileDetailPanel.tsx
index 1bfb2ad3e1..0bbf3c552c 100644
--- a/frontend/src/react/components/release/ReleaseFileDetailPanel.tsx
+++ b/frontend/src/react/components/release/ReleaseFileDetailPanel.tsx
@@ -3,64 +3,10 @@ import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { sheetServiceClientConnect } from "@/connect";
import { ReadonlyMonaco } from "@/react/components/monaco/ReadonlyMonaco";
+import { CopyButton } from "@/react/components/ui/copy-button";
import { Separator } from "@/react/components/ui/separator";
-import { pushNotification } from "@/store";
import type { Release_File } from "@/types/proto-es/v1/release_service_pb";
-function execCommandCopy(text: string): boolean {
- const textarea = document.createElement("textarea");
- textarea.value = text;
- textarea.style.position = "fixed";
- textarea.style.opacity = "0";
- document.body.appendChild(textarea);
- textarea.select();
- try {
- return document.execCommand("copy");
- } catch {
- return false;
- } finally {
- document.body.removeChild(textarea);
- }
-}
-
-async function copyToClipboard(text: string): Promise<boolean> {
- if (navigator.clipboard) {
- try {
- await navigator.clipboard.writeText(text);
- return true;
- } catch {
- // fall through to execCommand fallback
- }
- }
- return execCommandCopy(text);
-}
-
-function CopyButton({ content }: { content: string }) {
- const { t } = useTranslation();
- const handleCopy = async () => {
- if (!content) return;
- if (await copyToClipboard(content)) {
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.copied"),
- });
- }
- };
- return (
- <button
- type="button"
- className="text-sm text-control-light transition-colors hover:text-accent disabled:cursor-not-allowed disabled:text-control-light/40"
- title={t("common.copy")}
- aria-label={t("common.copy")}
- disabled={!content}
- onClick={handleCopy}
- >
- {t("common.copy")}
- </button>
- );
-}
-
export interface ReleaseFileDetailPanelProps {
releaseFile: Release_File;
}
diff --git a/frontend/src/react/components/revision/RevisionDetailPanel.tsx b/frontend/src/react/components/revision/RevisionDetailPanel.tsx
index 08ab3174a1..5ea39babef 100644
--- a/frontend/src/react/components/revision/RevisionDetailPanel.tsx
+++ b/frontend/src/react/components/revision/RevisionDetailPanel.tsx
@@ -5,76 +5,13 @@ import { sheetServiceClientConnect } from "@/connect";
import { ReadonlyMonaco } from "@/react/components/monaco";
import { RouterLink } from "@/react/components/RouterLink";
import { TaskRunLogViewer } from "@/react/components/task-run-log";
+import { CopyButton } from "@/react/components/ui/copy-button";
import { useRevisionByName } from "@/react/hooks/useAppState";
import { useAppStore } from "@/react/stores/app";
-import { pushNotification } from "@/store";
import { getTimeForPbTimestampProtoEs } from "@/types";
import { bytesToString, formatAbsoluteDateTime } from "@/utils";
import { extractTaskLink, getRevisionType } from "@/utils/v1/revision";
-interface CopyButtonProps {
- content: string;
-}
-
-function execCommandCopy(text: string): boolean {
- const textarea = document.createElement("textarea");
- textarea.value = text;
- textarea.style.position = "fixed";
- textarea.style.opacity = "0";
- document.body.appendChild(textarea);
- textarea.select();
- try {
- return document.execCommand("copy");
- } catch {
- return false;
- } finally {
- document.body.removeChild(textarea);
- }
-}
-
-async function copyToClipboard(text: string): Promise<boolean> {
- if (navigator.clipboard) {
- try {
- await navigator.clipboard.writeText(text);
- return true;
- } catch {
- // Fall through to execCommand fallback.
- }
- }
- return execCommandCopy(text);
-}
-
-function CopyButton({ content }: CopyButtonProps) {
- const { t } = useTranslation();
-
- const handleCopy = async () => {
- if (!content) {
- return;
- }
-
- if (await copyToClipboard(content)) {
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.copied"),
- });
- }
- };
-
- return (
- <button
- type="button"
- className="text-sm text-control-light transition-colors hover:text-accent disabled:cursor-not-allowed disabled:text-control-light/40"
- title={t("common.copy")}
- aria-label={t("common.copy")}
- disabled={!content}
- onClick={handleCopy}
- >
- {t("common.copy")}
- </button>
- );
-}
-
export interface RevisionDetailPanelProps {
revisionName: string;
}
diff --git a/frontend/src/react/components/ui/copy-button.tsx b/frontend/src/react/components/ui/copy-button.tsx
new file mode 100644
index 0000000000..a6dd854907
--- /dev/null
+++ b/frontend/src/react/components/ui/copy-button.tsx
@@ -0,0 +1,93 @@
+import { Check, Copy } from "lucide-react";
+import { useCallback, useEffect, useRef, useState } from "react";
+import { useTranslation } from "react-i18next";
+import { Button, type ButtonProps } from "@/react/components/ui/button";
+import { Tooltip } from "@/react/components/ui/tooltip";
+import { cn } from "@/react/lib/utils";
+import { useAppStore } from "@/react/stores/app";
+
+// Copy `text` to the clipboard, falling back to the legacy execCommand path
+// when the async Clipboard API is unavailable (e.g. insecure contexts).
+async function writeClipboard(text: string): Promise<boolean> {
+ if (navigator.clipboard) {
+ try {
+ await navigator.clipboard.writeText(text);
+ return true;
+ } catch {
+ // fall through to the execCommand fallback
+ }
+ }
+ const textarea = document.createElement("textarea");
+ textarea.value = text;
+ textarea.style.position = "fixed";
+ textarea.style.opacity = "0";
+ document.body.appendChild(textarea);
+ textarea.select();
+ try {
+ // execCommand is deprecated but remains the only clipboard path in
+ // insecure (http) contexts where navigator.clipboard is unavailable.
+ return document.execCommand("copy"); // NOSONAR
+ } catch {
+ return false;
+ } finally {
+ textarea.remove();
+ }
+}
+
+interface CopyButtonProps {
+ // The text to copy. Pass a function to defer resolution until click.
+ readonly content: string | (() => string);
+ readonly size?: ButtonProps["size"];
+ readonly variant?: ButtonProps["variant"];
+ readonly disabled?: boolean;
+ readonly className?: string;
+}
+
+export function CopyButton({
+ content,
+ size = "xs",
+ variant = "ghost",
+ disabled,
+ className,
+}: CopyButtonProps) {
+ const { t } = useTranslation();
+ const [copied, setCopied] = useState(false);
+ const timerRef = useRef<ReturnType<typeof setTimeout>>(undefined);
+
+ useEffect(() => () => clearTimeout(timerRef.current), []);
+
+ const handleCopy = useCallback(async () => {
+ const text = typeof content === "function" ? content() : content;
+ if (!text) return;
+ const ok = await writeClipboard(text);
+ useAppStore.getState().notify({
+ module: "bytebase",
+ style: ok ? "SUCCESS" : "CRITICAL",
+ title: ok ? t("common.copied") : t("common.copy-failed"),
+ });
+ if (!ok) return;
+ setCopied(true);
+ clearTimeout(timerRef.current);
+ timerRef.current = setTimeout(() => setCopied(false), 2000);
+ }, [content, t]);
+
+ return (
+ <Tooltip content={t("common.copy")}>
+ <Button
+ type="button"
+ variant={variant}
+ size={size}
+ disabled={disabled}
+ onClick={handleCopy}
+ aria-label={t("common.copy")}
+ className={cn("px-1", className)}
+ >
+ {copied ? (
+ <Check className="size-3.5 text-success" />
+ ) : (
+ <Copy className="size-3.5" />
+ )}
+ </Button>
+ </Tooltip>
+ );
+}
diff --git a/frontend/src/react/pages/project/DatabaseChangelogDetailPage.test.tsx b/frontend/src/react/pages/project/DatabaseChangelogDetailPage.test.tsx
index 4f79ee0f68..7c46931452 100644
--- a/frontend/src/react/pages/project/DatabaseChangelogDetailPage.test.tsx
+++ b/frontend/src/react/pages/project/DatabaseChangelogDetailPage.test.tsx
@@ -58,6 +58,7 @@ const mocks = vi.hoisted(() => {
useAppStore: vi.fn(),
getTaskRunLog: vi.fn(),
clipboardWriteText,
+ notify: vi.fn(),
pushNotification: vi.fn(),
ReadonlyMonaco: vi.fn(
({ content, className }: { content: string; className?: string }) => {
@@ -256,6 +257,7 @@ beforeEach(() => {
mocks.getChangelogByName.mockReset();
mocks.useAppStore.mockReset();
mocks.getTaskRunLog.mockReset();
+ mocks.notify.mockReset();
mocks.pushNotification.mockReset();
mocks.ReadonlyMonaco.mockClear();
mocks.ReadonlyDiffMonaco.mockClear();
@@ -309,6 +311,10 @@ beforeEach(() => {
getChangelogByName: mocks.getChangelogByName,
})
);
+ // CopyButton (shared) notifies via useAppStore.getState().notify.
+ Object.assign(mocks.useAppStore, {
+ getState: () => ({ notify: mocks.notify }),
+ });
mocks.getTaskRunLog.mockResolvedValue({
entries: [
{
@@ -511,7 +517,7 @@ describe("DatabaseChangelogDetailPage", () => {
});
expect(mocks.clipboardWriteText).toHaveBeenCalledWith("current schema");
- expect(mocks.pushNotification).toHaveBeenCalledWith({
+ expect(mocks.notify).toHaveBeenCalledWith({
module: "bytebase",
style: "SUCCESS",
title: "common.copied",
diff --git a/frontend/src/react/pages/project/DatabaseChangelogDetailPage.tsx b/frontend/src/react/pages/project/DatabaseChangelogDetailPage.tsx
index 4a9b582e70..a352226634 100644
--- a/frontend/src/react/pages/project/DatabaseChangelogDetailPage.tsx
+++ b/frontend/src/react/pages/project/DatabaseChangelogDetailPage.tsx
@@ -1,12 +1,13 @@
import { create } from "@bufbuild/protobuf";
-import { ArrowUpRight, Check, Copy, LoaderCircle } from "lucide-react";
-import { useCallback, useEffect, useMemo, useState } from "react";
+import { ArrowUpRight, Check, LoaderCircle } from "lucide-react";
+import { useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { rolloutServiceClientConnect } from "@/connect";
import { ReadonlyDiffMonaco, ReadonlyMonaco } from "@/react/components/monaco";
import { RouterLink } from "@/react/components/RouterLink";
import { TaskRunLogViewer } from "@/react/components/task-run-log";
import { Button } from "@/react/components/ui/button";
+import { CopyButton } from "@/react/components/ui/copy-button";
import { Switch } from "@/react/components/ui/switch";
import { router } from "@/react/router";
import {
@@ -16,7 +17,6 @@ import {
PROJECT_V1_ROUTE_SYNC_SCHEMA,
} from "@/react/router/handles";
import { useAppStore } from "@/react/stores/app";
-import { pushNotification } from "@/store";
import { getTimeForPbTimestampProtoEs } from "@/types";
import type { Changelog } from "@/types/proto-es/v1/database_service_pb";
import {
@@ -45,34 +45,6 @@ export interface DatabaseChangelogDetailPageProps {
changelogId: string;
}
-function execCommandCopy(text: string): boolean {
- const textarea = document.createElement("textarea");
- textarea.value = text;
- textarea.style.position = "fixed";
- textarea.style.opacity = "0";
- document.body.appendChild(textarea);
- textarea.select();
- try {
- return document.execCommand("copy");
- } catch {
- return false;
- } finally {
- document.body.removeChild(textarea);
- }
-}
-
-async function copyToClipboard(text: string): Promise<boolean> {
- if (navigator.clipboard?.writeText) {
- try {
- await navigator.clipboard.writeText(text);
- return true;
- } catch {
- // Fall through to execCommand fallback.
- }
- }
- return execCommandCopy(text);
-}
-
function ChangelogStatusIndicator({ status }: { status: Changelog_Status }) {
const { t } = useTranslation();
@@ -152,44 +124,6 @@ async function fetchHasSuccessfulDatabaseSync(
}
}
-function CopyButton({ content }: { content: string }) {
- const { t } = useTranslation();
-
- const handleCopy = useCallback(async () => {
- if (!content) {
- return;
- }
-
- if (await copyToClipboard(content)) {
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.copied"),
- });
- return;
- }
-
- pushNotification({
- module: "bytebase",
- style: "CRITICAL",
- title: t("common.copy-failed"),
- });
- }, [content, t]);
-
- return (
- <Button
- variant="ghost"
- size="sm"
- aria-label={t("common.copy")}
- title={t("common.copy")}
- disabled={!content}
- onClick={handleCopy}
- >
- <Copy className="size-4" />
- </Button>
- );
-}
-
export function DatabaseChangelogDetailPage({
projectId,
instanceId,
@@ -515,7 +449,7 @@ export function DatabaseChangelogDetailPage({
({formattedSchemaSize})
</span>
) : null}
- <CopyButton content={resolvedChangelog.schema} />
+ <CopyButton content={resolvedChangelog.schema} size="sm" />
</p>
<div className="flex items-center justify-between gap-x-2">
diff --git a/frontend/src/react/pages/project/ProjectGitOpsPage.tsx b/frontend/src/react/pages/project/ProjectGitOpsPage.tsx
index 29b65d8777..b2cc567752 100644
--- a/frontend/src/react/pages/project/ProjectGitOpsPage.tsx
+++ b/frontend/src/react/pages/project/ProjectGitOpsPage.tsx
@@ -1,4 +1,4 @@
-import { Check, ChevronDown, ChevronRight, Copy, XCircle } from "lucide-react";
+import { Check, ChevronDown, ChevronRight, XCircle } from "lucide-react";
import { useCallback, useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import gitopsWorkflowImage from "@/assets/gitops-workflow.svg";
@@ -8,6 +8,7 @@ import { RouterLink } from "@/react/components/RouterLink";
import { Alert } from "@/react/components/ui/alert";
import { Button, buttonVariants } from "@/react/components/ui/button";
import { Combobox, type ComboboxOption } from "@/react/components/ui/combobox";
+import { CopyButton } from "@/react/components/ui/copy-button";
import { Switch } from "@/react/components/ui/switch";
import {
Tabs,
@@ -692,60 +693,11 @@ function MissingExternalURLAttention() {
);
}
-function execCommandCopy(text: string): boolean {
- const textarea = document.createElement("textarea");
- textarea.value = text;
- textarea.style.position = "fixed";
- textarea.style.opacity = "0";
- document.body.appendChild(textarea);
- textarea.select();
- try {
- return document.execCommand("copy");
- } catch {
- return false;
- } finally {
- document.body.removeChild(textarea);
- }
-}
-
-async function copyToClipboard(text: string): Promise<boolean> {
- if (navigator.clipboard) {
- try {
- await navigator.clipboard.writeText(text);
- return true;
- } catch {
- // Fall through to execCommand fallback
- }
- }
- return execCommandCopy(text);
-}
-
-function CopyButton({ content }: { content: string }) {
- const [copied, setCopied] = useState(false);
-
- const handleCopy = async () => {
- if (await copyToClipboard(content)) {
- setCopied(true);
- setTimeout(() => setCopied(false), 2000);
- }
- };
-
- return (
- <Button variant="ghost" size="sm" onClick={handleCopy}>
- {copied ? (
- <Check className="h-4 w-4 text-success" />
- ) : (
- <Copy className="h-4 w-4" />
- )}
- </Button>
- );
-}
-
function CodeBlock({ code }: { code: string }) {
return (
<div className="relative rounded-xs p-4 bg-gray-50">
<div className="absolute top-2 right-2 p-2">
- <CopyButton content={code} />
+ <CopyButton content={code} size="sm" />
</div>
<div className="overflow-x-auto pr-12">
<pre className="text-sm font-mono whitespace-pre">{code}</pre>
diff --git a/frontend/src/react/pages/project/ProjectSettingsPage.tsx b/frontend/src/react/pages/project/ProjectSettingsPage.tsx
index 7316058e89..6608fbfb47 100644
--- a/frontend/src/react/pages/project/ProjectSettingsPage.tsx
+++ b/frontend/src/react/pages/project/ProjectSettingsPage.tsx
@@ -6,6 +6,7 @@ import { useTranslation } from "react-i18next";
import { FeatureBadge } from "@/react/components/FeatureBadge";
import { LabelListEditor } from "@/react/components/LabelListEditor";
import { PermissionGuard } from "@/react/components/PermissionGuard";
+import { ResourceIdField } from "@/react/components/ResourceIdField";
import { RouterLink } from "@/react/components/RouterLink";
import { Button } from "@/react/components/ui/button";
import {
@@ -671,8 +672,12 @@ export function ProjectSettingsPage() {
}
required
/>
- <div className="mt-1 text-sm text-control-light">
- {t("common.id")}: {extractProjectResourceName(project.name)}
+ <div className="mt-1">
+ <ResourceIdField
+ readonly
+ value={extractProjectResourceName(project.name)}
+ resourceName={t("common.project")}
+ />
</div>
</div>
diff --git a/frontend/src/react/pages/project/ProjectSyncSchemaPage.tsx b/frontend/src/react/pages/project/ProjectSyncSchemaPage.tsx
index 848d020095..4b9c9647ed 100644
--- a/frontend/src/react/pages/project/ProjectSyncSchemaPage.tsx
+++ b/frontend/src/react/pages/project/ProjectSyncSchemaPage.tsx
@@ -5,7 +5,6 @@ import {
ArrowUp,
ChevronDown,
ChevronLeft,
- Copy,
Maximize2,
Minus,
Plus,
@@ -26,6 +25,7 @@ import {
import { Button } from "@/react/components/ui/button";
import { Checkbox } from "@/react/components/ui/checkbox";
import { Combobox, type ComboboxOption } from "@/react/components/ui/combobox";
+import { CopyButton } from "@/react/components/ui/copy-button";
import {
Dialog,
DialogContent,
@@ -51,7 +51,6 @@ import { cn } from "@/react/lib/utils";
import { router } from "@/react/router";
import { PROJECT_V1_ROUTE_PLAN_DETAIL_SPEC_DETAIL } from "@/react/router/handles";
import { useAppStore } from "@/react/stores/app";
-import { pushNotification } from "@/store";
import { projectNamePrefix } from "@/store/modules/v1/common";
import {
getDateForPbTimestampProtoEs,
@@ -1653,7 +1652,7 @@ function DiffViewPanel({
<div className="w-full flex flex-col justify-start">
<div className="flex flex-row justify-start items-center gap-x-2">
<span>{t("database.sync-schema.synchronize-statements")}</span>
- <CopyButton content={statement} />
+ <CopyButton content={statement} size="sm" />
</div>
<div className="textinfolabel">
{t("database.sync-schema.synchronize-statements-description")}
@@ -1944,33 +1943,6 @@ function MonacoEditorPanel({
return <div ref={containerRef} className="w-full flex-1 border" />;
}
-// ============================================================
-// CopyButton
-// ============================================================
-
-function CopyButton({ content }: { content: string }) {
- const { t } = useTranslation();
-
- const handleCopy = useCallback(async () => {
- try {
- await navigator.clipboard.writeText(content);
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.copied"),
- });
- } catch {
- // ignore
- }
- }, [content, t]);
-
- return (
- <Button variant="ghost" size="sm" onClick={handleCopy}>
- <Copy className="size-4" />
- </Button>
- );
-}
-
// ============================================================
// TargetDatabasesSelectPanel (Drawer)
// ============================================================
diff --git a/frontend/src/react/pages/settings/EnvironmentsPage.tsx b/frontend/src/react/pages/settings/EnvironmentsPage.tsx
index 7901184aa9..9fcb2ee8f9 100644
--- a/frontend/src/react/pages/settings/EnvironmentsPage.tsx
+++ b/frontend/src/react/pages/settings/EnvironmentsPage.tsx
@@ -338,7 +338,7 @@ function RolloutPolicyConfig({
<div className="relative" ref={dropdownRef}>
<Button
variant="outline"
- size="xs"
+ size="sm"
onClick={() => setShowRoleDropdown(!showRoleDropdown)}
>
<Plus className="w-3.5 h-3.5 mr-1" />
diff --git a/frontend/src/react/pages/settings/MCPPage.tsx b/frontend/src/react/pages/settings/MCPPage.tsx
index d9de73a70c..4f9429c3aa 100644
--- a/frontend/src/react/pages/settings/MCPPage.tsx
+++ b/frontend/src/react/pages/settings/MCPPage.tsx
@@ -1,9 +1,9 @@
-import { Check, Copy } from "lucide-react";
-import { useMemo, useState } from "react";
+import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { RouterLink } from "@/react/components/RouterLink";
import { Alert } from "@/react/components/ui/alert";
-import { Button, buttonVariants } from "@/react/components/ui/button";
+import { buttonVariants } from "@/react/components/ui/button";
+import { CopyButton } from "@/react/components/ui/copy-button";
import { Input } from "@/react/components/ui/input";
import {
Tabs,
@@ -128,7 +128,7 @@ export function MCPPage() {
<h3 className="text-base font-medium">
{t("settings.mcp.general-config.title")}
</h3>
- <CopyButton content={generalConfig} />
+ <CopyButton content={generalConfig} size="sm" />
</div>
<p className="text-sm text-control-light">
{t("settings.mcp.setup.add-to-config")}
@@ -169,7 +169,7 @@ export function MCPPage() {
className="flex-1 font-mono"
onClick={(e) => (e.target as HTMLInputElement).select()}
/>
- <CopyButton content={tab.content} />
+ <CopyButton content={tab.content} size="sm" />
</div>
</TabsPanel>
))}
@@ -183,7 +183,7 @@ export function MCPPage() {
<h3 className="text-base font-medium">
{t("settings.mcp.first-prompt.title")}
</h3>
- <CopyButton content={firstPromptExample} />
+ <CopyButton content={firstPromptExample} size="sm" />
</div>
<p className="text-sm text-control-light">
{t("settings.mcp.first-prompt.description")}
@@ -196,27 +196,3 @@ export function MCPPage() {
</div>
);
}
-
-function CopyButton({ content }: { content: string }) {
- const [copied, setCopied] = useState(false);
-
- const handleCopy = async () => {
- try {
- await navigator.clipboard.writeText(content);
- setCopied(true);
- setTimeout(() => setCopied(false), 2000);
- } catch {
- // Clipboard API not available
- }
- };
-
- return (
- <Button variant="ghost" size="sm" onClick={handleCopy}>
- {copied ? (
- <Check className="h-4 w-4 text-success" />
- ) : (
- <Copy className="h-4 w-4" />
- )}
- </Button>
- );
-}
diff --git a/frontend/src/react/pages/settings/MembersPage.tsx b/frontend/src/react/pages/settings/MembersPage.tsx
index ea465f9bfa..4c7ec92349 100644
--- a/frontend/src/react/pages/settings/MembersPage.tsx
+++ b/frontend/src/react/pages/settings/MembersPage.tsx
@@ -92,6 +92,7 @@ import {
ALL_USERS_USER_EMAIL,
type DatabaseResource,
isDefaultProject,
+ type Permission,
PresetRoleType,
userBindingPrefix,
} from "@/types";
@@ -2087,6 +2088,7 @@ export function MembersPage({ projectId }: { projectId?: string }) {
const hasRequestRoleFeature = useAppStore((s) =>
s.hasFeature(PlanFeature.FEATURE_REQUEST_ROLE_WORKFLOW)
);
+ const roleList = useAppStore((state) => state.roleList);
// IAM policy loads are owned by the parent shells: ProjectRouteShell
// loads project IAM on /projects/:projectId/members, and
@@ -2138,6 +2140,23 @@ export function MembersPage({ projectId }: { projectId?: string }) {
hasProjectPermissionV2(project, "bb.projects.setIamPolicy")
: hasWorkspacePermissionV2("bb.workspaces.setIamPolicy");
+ // Whether the current user already holds every PROJECT_OWNER permission
+ // (workspace- or project-scoped). hasProjectPermissionV2 falls back to
+ // workspace permissions, so a single check covers both contexts. Mirrors the
+ // Vue `hasMissingPermission` gate rather than checking `setIamPolicy` alone.
+ // Computed inline (not memoized) so it tracks live IAM policy changes, the
+ // same way canSetIamPolicy above does — the permission check reads
+ // current-user state that isn't captured by [project, roleList] deps.
+ const ownerPermissions = project
+ ? (roleList.find((r) => r.name === PresetRoleType.PROJECT_OWNER)
+ ?.permissions ?? [])
+ : [];
+ const hasFullProjectAccess =
+ !!project &&
+ ownerPermissions.every((permission) =>
+ hasProjectPermissionV2(project, permission as Permission)
+ );
+
const handleRevokeSelected = async () => {
if (
selectedMembers.some(
@@ -2214,10 +2233,10 @@ export function MembersPage({ projectId }: { projectId?: string }) {
projectName,
projectReady: !!project,
allowRequestRole: project?.allowRequestRole ?? false,
- canSetIamPolicy,
+ hasFullProjectAccess,
hasRequestRoleFeature,
}),
- [projectName, project, canSetIamPolicy, hasRequestRoleFeature]
+ [projectName, project, hasFullProjectAccess, hasRequestRoleFeature]
);
const requestRoleDisabledReason = useMemo(() => {
@@ -2233,10 +2252,7 @@ export function MembersPage({ projectId }: { projectId?: string }) {
);
case "can-grant-access-directly":
return t(
- "project.members.request-role.disabled-reason.can-grant-access-directly",
- {
- permission: reason.permission,
- }
+ "project.members.request-role.disabled-reason.can-grant-access-directly"
);
case "feature-unavailable":
return t(
diff --git a/frontend/src/react/pages/settings/requestRoleButton.test.ts b/frontend/src/react/pages/settings/requestRoleButton.test.ts
index e7bef34752..9a2ba9810c 100644
--- a/frontend/src/react/pages/settings/requestRoleButton.test.ts
+++ b/frontend/src/react/pages/settings/requestRoleButton.test.ts
@@ -6,7 +6,7 @@ describe("getRequestRoleButtonState", () => {
projectName: "projects/demo",
projectReady: true,
allowRequestRole: true,
- canSetIamPolicy: false,
+ hasFullProjectAccess: false,
hasRequestRoleFeature: true,
} as const;
@@ -49,17 +49,16 @@ describe("getRequestRoleButtonState", () => {
});
});
- test("shows a disabled button when the user can grant access directly", () => {
+ test("shows a disabled button when the user already has full project access", () => {
expect(
getRequestRoleButtonState({
...base,
- canSetIamPolicy: true,
+ hasFullProjectAccess: true,
})
).toEqual({
visible: true,
disabledReason: {
kind: "can-grant-access-directly",
- permission: "bb.projects.setIamPolicy",
},
});
});
diff --git a/frontend/src/react/pages/settings/requestRoleButton.ts b/frontend/src/react/pages/settings/requestRoleButton.ts
index f3548296bc..e2b14c43b1 100644
--- a/frontend/src/react/pages/settings/requestRoleButton.ts
+++ b/frontend/src/react/pages/settings/requestRoleButton.ts
@@ -14,7 +14,6 @@ export type RequestRoleButtonDisabledReason =
}
| {
kind: "can-grant-access-directly";
- permission: Permission;
}
| {
kind: "feature-unavailable";
@@ -24,7 +23,11 @@ interface RequestRoleButtonStateArgs {
readonly projectName?: string;
readonly projectReady: boolean;
readonly allowRequestRole: boolean;
- readonly canSetIamPolicy: boolean;
+ // True when the current user already holds every PROJECT_OWNER permission
+ // (workspace- or project-scoped), so they can grant access directly and have
+ // no reason to request a role. Mirrors the Vue `hasMissingPermission` gate,
+ // which checks the full owner permission set rather than `setIamPolicy` alone.
+ readonly hasFullProjectAccess: boolean;
readonly hasRequestRoleFeature: boolean;
}
@@ -37,7 +40,7 @@ export const getRequestRoleButtonState = ({
projectName,
projectReady,
allowRequestRole,
- canSetIamPolicy,
+ hasFullProjectAccess,
hasRequestRoleFeature,
}: RequestRoleButtonStateArgs): RequestRoleButtonState => {
if (!projectName) {
@@ -64,12 +67,11 @@ export const getRequestRoleButtonState = ({
};
}
- if (canSetIamPolicy) {
+ if (hasFullProjectAccess) {
return {
visible: true,
disabledReason: {
kind: "can-grant-access-directly",
- permission: "bb.projects.setIamPolicy",
},
};
}