Skip to content

Commit bfb44fb

Browse files
feat(web): copy the app version from General settings (#24788)
1 parent ec9d994 commit bfb44fb

3 files changed

Lines changed: 70 additions & 9 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect, it, vi } from "vite-plus/test";
2+
import { page } from "vite-plus/test/browser";
3+
4+
import { render } from "../../../test/render";
5+
import { APP_VERSION } from "../../branding";
6+
import { AnchoredToastProvider } from "../ui/toast";
7+
import { AboutVersionTitle } from "./AboutVersionTitle";
8+
9+
it("shows copy confirmation when the version is clicked without waiting for a hover tooltip", async () => {
10+
await using screen = await render(
11+
<AnchoredToastProvider>
12+
<AboutVersionTitle />
13+
</AnchoredToastProvider>,
14+
);
15+
using write = vi.spyOn(navigator.clipboard, "writeText").mockResolvedValue(undefined);
16+
17+
await screen.getByRole("button", { name: `Copy version ${APP_VERSION}` }).click();
18+
19+
expect(write).toHaveBeenCalledWith(APP_VERSION);
20+
await expect.element(page.getByText(/^Copied!?$/)).toBeVisible();
21+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { useRef } from "react";
2+
3+
import { APP_VERSION } from "../../branding";
4+
import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
5+
import { showAnchoredCopySuccessToast } from "../ui/anchoredCopyToast";
6+
import { InlineButton } from "../ui/button";
7+
import { stackedThreadToast, toastManager } from "../ui/toast";
8+
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
9+
10+
export function AboutVersionTitle() {
11+
const copyButtonRef = useRef<HTMLButtonElement>(null);
12+
const { copyToClipboard } = useCopyToClipboard<void>({
13+
target: "version",
14+
onCopy: () => showAnchoredCopySuccessToast(copyButtonRef),
15+
onError: (error) => {
16+
toastManager.add(
17+
stackedThreadToast({
18+
type: "error",
19+
title: "Could not copy version",
20+
description: error.message,
21+
}),
22+
);
23+
},
24+
});
25+
26+
return (
27+
<span className="inline-flex items-baseline gap-2">
28+
<span>Version</span>
29+
<code className="text-2xs font-medium">
30+
<Tooltip>
31+
<TooltipTrigger
32+
render={
33+
<InlineButton
34+
ref={copyButtonRef}
35+
tone="muted"
36+
aria-label={`Copy version ${APP_VERSION}`}
37+
onClick={() => copyToClipboard(APP_VERSION, undefined)}
38+
>
39+
{APP_VERSION}
40+
</InlineButton>
41+
}
42+
/>
43+
<TooltipPopup>Copy version</TooltipPopup>
44+
</Tooltip>
45+
</code>
46+
</span>
47+
);
48+
}

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { createModelSelection } from "@t3tools/shared/model";
2626
import * as Equal from "effect/Equal";
2727
import * as Schema from "effect/Schema";
2828
import { APP_VERSION, HOSTED_APP_CHANNEL, HOSTED_APP_CHANNEL_LABEL } from "../../branding";
29+
import { AboutVersionTitle } from "./AboutVersionTitle";
2930
import { CliCommandSettingsRow } from "./CliCommandSettingsRow";
3031
import { MobileAppSettingsRow } from "./MobileAppSettingsRow";
3132
import {
@@ -140,15 +141,6 @@ const QUIT_CONFIRMATION_MODE_LABELS: Record<QuitConfirmationMode, string> = {
140141
};
141142

142143
const DEFAULT_DRIVER_KIND = ProviderDriverKind.make("codex");
143-
function AboutVersionTitle() {
144-
return (
145-
<span className="inline-flex items-baseline gap-2">
146-
<span>Version</span>
147-
<code className="text-2xs font-medium text-muted-foreground">{APP_VERSION}</code>
148-
</span>
149-
);
150-
}
151-
152144
function AboutVersionSection() {
153145
const updateState = useDesktopUpdateState();
154146
const [switchChannel, setSwitchChannel] = useState<DesktopUpdateChannel | null>(null);

0 commit comments

Comments
 (0)