TypeScript
feat(web): setting to open pull request links on GitHub (#19719)
Theo Brownecd34df59a1ba
diff --git a/apps/web/src/components/settings/IntegrationsSettings.tsx b/apps/web/src/components/settings/IntegrationsSettings.tsxindex a0c0a79bebc..c375ee910a1 100644--- a/apps/web/src/components/settings/IntegrationsSettings.tsx+++ b/apps/web/src/components/settings/IntegrationsSettings.tsx@@ -622,6 +622,35 @@ function BrowserLinkTargetSetting({ disabled }: { readonly disabled: boolean }));}+function PullRequestLinksOpenInAppSetting() {+ const openInApp = useClientSettings((settings) => settings.pullRequestLinksOpenInApp);+ const updateSettings = useUpdatePrimarySettings();++ return (+ <SettingsRow+ {...searchableSetting("pull-request-links-open-in-app")}+ description="Clicking a pull request link opens it in T3 Code. Turn off to open pull request links like any other link, on GitHub or your git host."+ resetAction={+ openInApp ? null : (+ <SettingResetButton+ label="open pull requests in T3 Code"+ onClick={() => updateSettings({ pullRequestLinksOpenInApp: true })}+ />+ )+ }+ control={+ <Switch+ checked={openInApp}+ onCheckedChange={(checked) =>+ updateSettings({ pullRequestLinksOpenInApp: Boolean(checked) })+ }+ aria-label="Open pull requests in T3 Code"+ />+ }+ />+ );+}+function DeviceIntegrationSettings() {const { search, environment: selected } = useSettingsScope();const settings = useScopedSettings();@@ -1545,6 +1574,7 @@ export function IntegrationsSettingsPanel() {) : (previewDefaults)}+ <PullRequestLinksOpenInAppSetting /></SettingsSection><DeviceIntegrationSettings /></SettingsPageContainer>diff --git a/apps/web/src/components/settings/SettingsPanels.logic.test.ts b/apps/web/src/components/settings/SettingsPanels.logic.test.tsindex fe26ce23939..f790b47ac44 100644--- a/apps/web/src/components/settings/SettingsPanels.logic.test.ts+++ b/apps/web/src/components/settings/SettingsPanels.logic.test.ts@@ -242,6 +242,7 @@ describe("getChangedBrowserSettingLabels", () => {browserRecordingShowMousePresses: true,browserLinkTarget: "app",browserAutoShowFloatingPreview: !DEFAULT_UNIFIED_SETTINGS.browserAutoShowFloatingPreview,+ pullRequestLinksOpenInApp: false,}),).toEqual(["Browser viewport",@@ -252,6 +253,7 @@ describe("getChangedBrowserSettingLabels", () => {"Recording mouse presses","Open links in","Floating preview",+ "Open pull requests in T3 Code",]);});});diff --git a/apps/web/src/components/settings/SettingsPanels.logic.ts b/apps/web/src/components/settings/SettingsPanels.logic.tsindex 232357b5482..f24f040c292 100644--- a/apps/web/src/components/settings/SettingsPanels.logic.ts+++ b/apps/web/src/components/settings/SettingsPanels.logic.ts@@ -118,6 +118,7 @@ export type BrowserDefaultSettings = Pick<| "browserRecordingShowMousePresses"| "browserLinkTarget"| "browserAutoShowFloatingPreview"+ | "pullRequestLinksOpenInApp">;/**@@ -166,6 +167,9 @@ export function getChangedBrowserSettingLabels(settings: BrowserDefaultSettings)DEFAULT_UNIFIED_SETTINGS.browserAutoShowFloatingPreview? ["Floating preview"]: []),+ ...(settings.pullRequestLinksOpenInApp !== DEFAULT_UNIFIED_SETTINGS.pullRequestLinksOpenInApp+ ? ["Open pull requests in T3 Code"]+ : []),];}diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsxindex e408312cddf..ef60c9e3c3c 100644--- a/apps/web/src/components/settings/SettingsPanels.tsx+++ b/apps/web/src/components/settings/SettingsPanels.tsx@@ -676,6 +676,7 @@ export function useSettingsRestore(onRestored?: () => void) {settings.browserRecordingShowMousePresses,settings.browserLinkTarget,settings.browserAutoShowFloatingPreview,+ settings.pullRequestLinksOpenInApp,settings.appearanceContrast,settings.diffColorScheme,settings.chatWidth,@@ -855,6 +856,7 @@ export function useSettingsRestore(onRestored?: () => void) {browserRecordingShowMousePresses: DEFAULT_UNIFIED_SETTINGS.browserRecordingShowMousePresses,browserLinkTarget: DEFAULT_UNIFIED_SETTINGS.browserLinkTarget,browserAutoShowFloatingPreview: DEFAULT_UNIFIED_SETTINGS.browserAutoShowFloatingPreview,+ pullRequestLinksOpenInApp: DEFAULT_UNIFIED_SETTINGS.pullRequestLinksOpenInApp,// Re-granted like any other default. The confirmation dialog lists it by// name, so a user restoring defaults is told the agent regains access// rather than discovering it later.diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.tsindex 0ee55ef3785..5747fc59d9c 100644--- a/apps/web/src/components/settings/settingsSearch.ts+++ b/apps/web/src/components/settings/settingsSearch.ts@@ -778,6 +778,12 @@ export const SETTINGS_SEARCH_ITEMS = [to: "/settings/integrations",searchTerms: ["links default browser in-app browser external open"],},+ {+ id: "pull-request-links-open-in-app",+ title: "Open pull requests in T3 Code",+ to: "/settings/integrations",+ searchTerms: ["pr links github browser external click default pull request view panel"],+ },{id: "browser-auto-show-floating-preview",title: "Auto-show floating preview",diff --git a/apps/web/src/lib/openPullRequestLink.ts b/apps/web/src/lib/openPullRequestLink.tsindex 1c701fb4f0f..9d473c783a1 100644--- a/apps/web/src/lib/openPullRequestLink.ts+++ b/apps/web/src/lib/openPullRequestLink.ts@@ -8,6 +8,7 @@ import { parseChangeRequestUrl, type ChangeRequestLink } from "@t3tools/shared/cimport { sourceControlRepositorySelector } from "@t3tools/shared/sourceControl";import { useOpenLink } from "../browser/useOpenLink";+import { useClientSettings } from "../hooks/useSettings";import { stackedThreadToast, toastManager } from "../components/ui/toast";import { useRightPanelStore } from "../rightPanelStore";import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";@@ -122,6 +123,8 @@ export function findProjectOnChangeRequestHost(* the pull requests page: a reader following a link the agent wrote is reading the thread, and* should still be reading it afterwards. Any change request opens there, not only the thread's* own, since the panel is told which one to show.+ *+ * With "Open pull requests in T3 Code" turned off, every link is left alone.*/export function shouldOpenPullRequestExternally(event: Pick<MouseEvent<HTMLElement>, "metaKey" | "ctrlKey">,@@ -145,9 +148,10 @@ export function useOpenChangeRequestLink(const allProjects = useProjects();const serverConfigs = useServerConfigs();const primaryEnvironmentId = usePrimaryEnvironmentId();+ const openInApp = useClientSettings((settings) => settings.pullRequestLinksOpenInApp);return useCallback((event, targetUrl, targetThreadRef, targetEnvironmentId) => {- if (shouldOpenPullRequestExternally(event)) return false;+ if (!openInApp || shouldOpenPullRequestExternally(event)) return false;const resolvedThreadRef = targetThreadRef ?? threadRef;const resolvedPanelRef = panelRef ?? resolvedThreadRef;const parsed = parseChangeRequestUrl(targetUrl);@@ -243,7 +247,7 @@ export function useOpenChangeRequestLink(});return true;},- [allProjects, navigate, panelRef, primaryEnvironmentId, serverConfigs, threadRef],+ [allProjects, navigate, openInApp, panelRef, primaryEnvironmentId, serverConfigs, threadRef],);}diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.tsindex 52ebb8947c7..569fcf40cf8 100644--- a/packages/contracts/src/settings.ts+++ b/packages/contracts/src/settings.ts@@ -441,6 +441,12 @@ export const ClientSettingsSchema = Schema.Struct({TrimmedNonEmptyString,PullRequestMergeMethod,).pipe(Schema.withDecodingDefault(Effect.succeed({}))),+ /**+ * Whether clicking a pull request link opens T3 Code's pull request view.+ * When false, pull request links open like any other link, so they reach+ * GitHub or the repository's other host.+ */+ pullRequestLinksOpenInApp: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),// Legacy plan mode. The composer's Build/Plan toggle was removed from the// default UI; this beta flag restores it (plus the /plan and /default slash// commands) for users who still rely on the old workflow.@@ -1742,6 +1748,7 @@ export const ClientSettingsPatch = Schema.Struct({pullRequestMergeMethodOverrides: Schema.optionalKey(Schema.Record(TrimmedNonEmptyString, PullRequestMergeMethod),),+ pullRequestLinksOpenInApp: Schema.optionalKey(Schema.Boolean),planModeEnabled: Schema.optionalKey(Schema.Boolean),contextWindowMeterEnabled: Schema.optionalKey(Schema.Boolean),composerCollapseOnScroll: Schema.optionalKey(Schema.Boolean),