Skip to content

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

fix: url copy button is disabled in share popover (#20594)

ecmadao28153926c742
diff --git a/frontend/src/react/components/sql-editor/SharePopoverBody.test.tsx b/frontend/src/react/components/sql-editor/SharePopoverBody.test.tsx
index 07e2527cdd..ab2f8b3efd 100644
--- a/frontend/src/react/components/sql-editor/SharePopoverBody.test.tsx
+++ b/frontend/src/react/components/sql-editor/SharePopoverBody.test.tsx
@@ -14,9 +14,6 @@ const mocks = vi.hoisted(() => ({
| undefined,
useCurrentUser: vi.fn(),
patchWorksheet: vi.fn().mockResolvedValue({}),
- // `useSQLEditorTabState(selector)` runs `selector` against this stub
- // state; the component selects `tabsById.get(currentTabId)?.status`.
- tabStatus: "CLEAN" as string,
pushNotification: vi.fn(),
extractProjectResourceName: vi.fn(
(name: string) => name.split("/")[1] ?? name
@@ -50,19 +47,6 @@ vi.mock("@/react/stores/app", () => {
};
});
-vi.mock("@/react/stores/sqlEditor/tab", () => ({
- useSQLEditorTabState: (
- selector: (s: {
- currentTabId: string;
- tabsById: Map<string, { status: string }>;
- }) => unknown
- ) =>
- selector({
- currentTabId: "t1",
- tabsById: new Map([["t1", { status: mocks.tabStatus }]]),
- }),
-}));
-
vi.mock("@/utils", () => ({
extractProjectResourceName: mocks.extractProjectResourceName,
extractWorksheetID: mocks.extractWorksheetID,
@@ -145,7 +129,6 @@ beforeEach(async () => {
name: "users/[email protected]",
});
mocks.patchWorksheet.mockResolvedValue({});
- mocks.tabStatus = "CLEAN";
// Mock clipboard
Object.defineProperty(navigator, "clipboard", {
@@ -257,11 +240,12 @@ describe("SharePopoverBody", () => {
unmount();
});
- test("copy button disabled when currentTab status is not CLEAN", () => {
- mocks.tabStatus = "DIRTY";
-
+ test("copy button disabled when there is no shareable worksheet link", () => {
+ // No worksheet (an unsaved draft) → no link → copy disabled. A saved
+ // worksheet from the tree always has a link, so copy is enabled regardless
+ // of the current tab's status (covered by the private-worksheet test below).
const { container, render, unmount } = renderIntoContainer(
- <SharePopoverBody worksheet={mockWorksheet as never} />
+ <SharePopoverBody worksheet={undefined as never} />
);
render();
diff --git a/frontend/src/react/components/sql-editor/SharePopoverBody.tsx b/frontend/src/react/components/sql-editor/SharePopoverBody.tsx
index 0e73a9f5a4..a6471df553 100644
--- a/frontend/src/react/components/sql-editor/SharePopoverBody.tsx
+++ b/frontend/src/react/components/sql-editor/SharePopoverBody.tsx
@@ -19,7 +19,6 @@ import { cn } from "@/react/lib/utils";
import { router } from "@/react/router";
import { SQL_EDITOR_WORKSHEET_MODULE } from "@/react/router/handles";
import { useAppStore } from "@/react/stores/app";
-import { useSQLEditorTabState } from "@/react/stores/sqlEditor/tab";
import type { Worksheet } from "@/types/proto-es/v1/worksheet_service_pb";
import { Worksheet_Visibility } from "@/types/proto-es/v1/worksheet_service_pb";
import { extractProjectResourceName, extractWorksheetID } from "@/utils";
@@ -43,9 +42,6 @@ export function SharePopoverBody({ worksheet }: Props) {
const { t } = useTranslation();
const workspaceExternalURL = useAppStore((s) => s.serverInfo?.externalUrl);
const currentUser = useCurrentUser();
- const tabStatus = useSQLEditorTabState(
- (s) => s.tabsById.get(s.currentTabId)?.status
- );
const accessOptions = useMemo<AccessOption[]>(
() => [
@@ -235,14 +231,17 @@ export function SharePopoverBody({ worksheet }: Props) {
value={sharedTabLink}
className="flex-1 min-w-0 h-full px-2 bg-white text-control text-sm cursor-text appearance-none border-0 shadow-none outline-hidden focus:outline-hidden focus:ring-0 focus:border-0 focus:shadow-none"
/>
- {/* Copy button — always available regardless of share status; only
- disabled while the tab has unsaved changes. */}
+ {/* Copy button — enabled whenever the shared worksheet has a link.
+ Gated on the shared worksheet (sharedTabLink), NOT the current tab's
+ status: the popover can be opened for any worksheet from the tree,
+ so the current tab's dirty state is irrelevant. Only an unsaved draft
+ (no worksheet → no link) disables it. */}
<Button
type="button"
variant="ghost"
size="sm"
data-copy-btn
- disabled={tabStatus !== "CLEAN"}
+ disabled={!sharedTabLink}
onClick={handleCopyLink}
className="h-full rounded-none border-l border-control-border bg-white enabled:hover:bg-control-bg-hover enabled:hover:text-main disabled:bg-control-bg focus-visible:ring-inset focus-visible:ring-offset-0"
>