fix(web): open modified PR clicks in browser (#6278)
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: maria <[email protected]>
This commit is contained in:
1 parent
770946d026
commit
8d24b5131f
2 files changed
+23
-1
No files matched your search
@@ -5,6 +5,7 @@ import {
|
||||
openPullRequestLink,
|
||||
parseChangeRequestUrl,
|
||||
PullRequestLinkOpenError,
|
||||
shouldOpenPullRequestExternally,
|
||||
} from "./openPullRequestLink";
|
||||
|
||||
describe("openPullRequestLink", () => {
|
||||
@@ -34,6 +35,17 @@ describe("openPullRequestLink", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldOpenPullRequestExternally", () => {
|
||||
it("uses the browser for command-click and control-click", () => {
|
||||
expect(shouldOpenPullRequestExternally({ metaKey: true, ctrlKey: false })).toBe(true);
|
||||
expect(shouldOpenPullRequestExternally({ metaKey: false, ctrlKey: true })).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps an unmodified click in the pull request view", () => {
|
||||
expect(shouldOpenPullRequestExternally({ metaKey: false, ctrlKey: false })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseChangeRequestUrl", () => {
|
||||
it("reads a GitHub pull request", () => {
|
||||
expect(parseChangeRequestUrl("https://github.com/T3Tools/T3Code/pull/123")).toEqual({
|
||||
|
||||
@@ -173,10 +173,19 @@ export function findProjectForChangeRequest(
|
||||
* 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.
|
||||
*/
|
||||
export function shouldOpenPullRequestExternally(
|
||||
event: Pick<MouseEvent<HTMLElement>, "metaKey" | "ctrlKey">,
|
||||
): boolean {
|
||||
return event.metaKey || event.ctrlKey;
|
||||
}
|
||||
|
||||
export function useOpenChangeRequestLink(
|
||||
threadRef?: ScopedThreadRef,
|
||||
): (
|
||||
event: Pick<MouseEvent<HTMLElement>, "preventDefault" | "stopPropagation">,
|
||||
event: Pick<
|
||||
MouseEvent<HTMLElement>,
|
||||
"preventDefault" | "stopPropagation" | "metaKey" | "ctrlKey"
|
||||
>,
|
||||
targetUrl: string,
|
||||
targetThreadRef?: ScopedThreadRef,
|
||||
) => boolean {
|
||||
@@ -186,6 +195,7 @@ export function useOpenChangeRequestLink(
|
||||
const primaryEnvironmentId = usePrimaryEnvironmentId();
|
||||
return useCallback(
|
||||
(event, targetUrl, targetThreadRef) => {
|
||||
if (shouldOpenPullRequestExternally(event)) return false;
|
||||
const resolvedThreadRef = targetThreadRef ?? threadRef;
|
||||
const environmentId = resolvedThreadRef?.environmentId ?? primaryEnvironmentId;
|
||||
if (
|
||||
|
||||
Reference in new issue
Block a user