Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(pr-mention): render as plain link when GitHub is not connected (#8047)
gbirman29e54989f734
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.test.tsxindex ac1e192926..f45e3bc5d9 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.test.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.test.tsx@@ -1,21 +1,38 @@import type { ForeignEntity } from '@service-storage/generated/schemas';import { render, screen } from '@solidjs/testing-library';-import { createSignal } from 'solid-js';+import type { LexicalCommand } from 'lexical';+import { createSignal, type JSX } from 'solid-js';import { beforeEach, describe, expect, it, vi } from 'vitest';+const mocks = vi.hoisted(() => ({+ openWithSplit: vi.fn(),+ openExternalUrl: vi.fn(),+}));+vi.mock('@components/app/split-layout/layout', () => ({- useSplitLayout: () => ({ openWithSplit: vi.fn() }),+ useSplitLayout: () => ({ openWithSplit: mocks.openWithSplit }),+}));+vi.mock('@core/util/url', () => ({+ openExternalUrl: mocks.openExternalUrl,}));vi.mock('@queries/storage/pr-mention', () => ({usePrMentionQuery: () => idQuery,usePullRequestByGithubKeyQuery: () => githubKeyQuery,}));+vi.mock('@queries/auth/github-link', () => ({+ useGithubLinkStatusQuery: () => githubLinkStatusQuery,+}));vi.mock('@core/component/HoverCard', () => ({- HoverCard: (props: { trigger: import('solid-js').JSX.Element }) =>- props.trigger,+ HoverCard: (props: { trigger: JSX.Element }) => props.trigger,}));vi.mock('../../plugins', () => ({ autoRegister: vi.fn() }));+vi.mock('../../context/LexicalWrapperContext', async () => {+ const { createContext } = await import('solid-js');+ return { LexicalWrapperContext: createContext() };+});+import { KEY_ENTER_COMMAND } from 'lexical';+import { LexicalWrapperContext } from '../../context/LexicalWrapperContext';import { PullRequestMention } from './PullRequestMention';const title = 'feat(text-paste): smart paste for GitHub pull request URLs';@@ -39,6 +56,10 @@ const pullRequest: ForeignEntity = {};const [resolved, setResolved] = createSignal<ForeignEntity>();+const [githubLinkStatus, setGithubLinkStatus] = createSignal<+ 'linked' | 'unlinked' | 'reauthentication_required'+>('linked');+// Reading a pending solid-query `data` suspends the caller, so it throws here.const idQuery = {get isSuccess() {@@ -58,9 +79,20 @@ const githubKeyQuery = {return resolved() ?? null;},};+const githubLinkStatusQuery = {+ get isFetched() {+ return true;+ },+ get data() {+ return { status: githubLinkStatus() };+ },+};beforeEach(() => {setResolved(undefined);+ setGithubLinkStatus('linked');+ mocks.openWithSplit.mockReset();+ mocks.openExternalUrl.mockReset();});describe('pull request mention face', () => {@@ -117,4 +149,126 @@ describe('pull request mention face', () => {expect(agentWritten.textContent).toBe(`${title} #7956`);expect(agentWritten.classList.contains('w-[32em]')).toBe(true);});++ it('renders as a plain link when GitHub is not linked', () => {+ setGithubLinkStatus('unlinked');++ const view = render(() => (+ <PullRequestMention+ id=""+ url={url}+ label="macro-inc/macro#7956"+ key="node"+ theme={{}}+ />+ ));++ const link = screen.getByRole('link');+ expect(link.getAttribute('href')).toBe(url);+ expect(link.getAttribute('target')).toBe('_blank');+ expect(link.textContent).toBe('macro-inc/macro#7956');+ expect(view.container.querySelector('[data-pr-mention]')).toBeNull();+ });++ it('renders as a plain link when GitHub reauthentication is required', () => {+ setGithubLinkStatus('reauthentication_required');++ const view = render(() => (+ <PullRequestMention+ id=""+ url={url}+ label="macro-inc/macro#7956"+ key="node"+ theme={{}}+ />+ ));++ const link = screen.getByRole('link');+ expect(link.getAttribute('href')).toBe(url);+ expect(view.container.querySelector('[data-pr-mention]')).toBeNull();+ });++ it('renders as fancy mention when GitHub is linked', () => {+ setGithubLinkStatus('linked');++ const view = render(() => (+ <PullRequestMention+ id=""+ url={url}+ label="macro-inc/macro#7956"+ key="node"+ theme={{}}+ />+ ));++ const mention = view.container.querySelector('[data-pr-mention]');+ expect(mention).not.toBeNull();+ expect(screen.queryByRole('link')).toBeNull();+ });++ it('renders as a plain link when GitHub is unlinked even with a nonempty id', () => {+ setGithubLinkStatus('unlinked');++ const view = render(() => (+ <PullRequestMention+ id={pullRequest.id}+ url={url}+ label="macro-inc/macro#7956"+ key="node"+ theme={{}}+ />+ ));++ const link = screen.getByRole('link');+ expect(link.getAttribute('href')).toBe(url);+ expect(view.container.querySelector('[data-pr-mention]')).toBeNull();+ });++ it('opens the GitHub URL on Enter when GitHub is unlinked and the mention has an id', () => {+ setGithubLinkStatus('unlinked');+ type EnterHandler = (event: KeyboardEvent | null) => boolean;+ let enterHandler: EnterHandler | undefined;+ const editor = {+ registerCommand: <T,>(+ command: LexicalCommand<T>,+ handler: (payload: T) => boolean+ ) => {+ if (command === KEY_ENTER_COMMAND) {+ enterHandler = handler as EnterHandler;+ }+ return () => {};+ },+ };+ const selection = {+ type: 'node' as const,+ nodeKeys: new Set(['node']),+ };++ render(() => (+ <LexicalWrapperContext.Provider+ value={{+ type: 'markdown',+ owner: null,+ plugins: {} as never,+ editor: editor as never,+ cleanup: () => {},+ isInteractable: () => true,+ selection: selection as never,+ }}+ >+ <PullRequestMention+ id={pullRequest.id}+ url={url}+ label="macro-inc/macro#7956"+ key="node"+ theme={{}}+ />+ </LexicalWrapperContext.Provider>+ ));++ expect(enterHandler).toBeDefined();+ expect(enterHandler?.(null)).toBe(true);+ expect(mocks.openExternalUrl).toHaveBeenCalledWith(url);+ expect(mocks.openWithSplit).not.toHaveBeenCalled();+ });});diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsxindex 5a68f779df..196f6c31ec 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/PullRequestMention.tsx@@ -23,6 +23,7 @@ import OpenIcon from '@phosphor/arrows-out.svg';import ChatCircle from '@phosphor/chat-circle.svg';import GitMerge from '@phosphor/git-merge.svg';import GitPullRequest from '@phosphor/git-pull-request.svg';+import { useGithubLinkStatusQuery } from '@queries/auth/github-link';import {usePrMentionQuery,usePullRequestByGithubKeyQuery,@@ -550,6 +551,11 @@ export function PullRequestMention(props: PullRequestMentionDecoratorProps) {const selection = () => lexicalWrapper?.selection;const { openWithSplit } = useSplitLayout()!;+ const githubLinkQuery = useGithubLinkStatusQuery({+ enabled: () => !lexicalWrapper?.skipPreviewFetch,+ });+ const isGithubLinked = () => githubLinkQuery.data?.status === 'linked';+const isSelectedAsNode = () => {const sel = selection();if (!sel) return false;@@ -562,7 +568,19 @@ export function PullRequestMention(props: PullRequestMentionDecoratorProps) {);const entityId = () => props.id || urlEntity()?.id;+ // When GitHub is not linked, render as a plain link instead of the fancy mention UI+ const shouldRenderAsPlainLink = () => {+ if (lexicalWrapper?.skipPreviewFetch) return false;+ return !!(githubLinkQuery.isFetched && !isGithubLinked() && props.url);+ };+const open = (e: MouseEvent | KeyboardEvent | null) => {+ // Match the rendered plain-link destination: Enter must not open the+ // internal PR split when GitHub is unlinked, even if props.id is set.+ if (shouldRenderAsPlainLink()) {+ openExternalUrl(props.url!);+ return;+ }const id = entityId();if (!id) {// A PR Macro has not synced has no split to open; fall back to GitHub.@@ -597,40 +615,54 @@ export function PullRequestMention(props: PullRequestMentionDecoratorProps) {});return (- <HoverCard- trigger={- <span class="relative">- <span- class={cn(- 'size-full py-0.5 cursor-default rounded-xs hover:bg-hover focus:bg-active',- isSelectedAsNode() && 'bg-active text-ink'- )}- {...navHandlers}- >- <PullRequestMentionContent {...props} />- </span>- <MentionTooltip show={isSelectedAsNode()} text="Open" />- </span>- }- content={- <Show- when={entityId()}- fallback={- <UnsyncedPullRequestPreviewCard- label={fallbackLabel(mentionFallbackLabel(props))}- url={props.url}- />- }+ <Show+ when={!shouldRenderAsPlainLink()}+ fallback={+ <a+ href={props.url}+ target="_blank"+ rel="noreferrer"+ class="text-link hover:text-link-hover visited:text-link-visited underline">- {(id) => (- <PullRequestPreviewCard- id={id()}- fallbackLabel={mentionFallbackLabel(props)}- />- )}- </Show>+ {fallbackLabel(mentionFallbackLabel(props))}+ </a>}- />+ >+ <HoverCard+ trigger={+ <span class="relative">+ <span+ class={cn(+ 'size-full py-0.5 cursor-default rounded-xs hover:bg-hover focus:bg-active',+ isSelectedAsNode() && 'bg-active text-ink'+ )}+ {...navHandlers}+ >+ <PullRequestMentionContent {...props} />+ </span>+ <MentionTooltip show={isSelectedAsNode()} text="Open" />+ </span>+ }+ content={+ <Show+ when={entityId()}+ fallback={+ <UnsyncedPullRequestPreviewCard+ label={fallbackLabel(mentionFallbackLabel(props))}+ url={props.url}+ />+ }+ >+ {(id) => (+ <PullRequestPreviewCard+ id={id()}+ fallbackLabel={mentionFallbackLabel(props)}+ />+ )}+ </Show>+ }+ />+ </Show>);}