Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(channels): show shared pull requests instead of no access (#8818)

Jacob Beckermanc2f88a85d2d4
diff --git a/apps/web/src/features/block-pr/component/PullRequestAttachment.test.tsx b/apps/web/src/features/block-pr/component/PullRequestAttachment.test.tsx
new file mode 100644
index 0000000000..e64c0e0d09
--- /dev/null
+++ b/apps/web/src/features/block-pr/component/PullRequestAttachment.test.tsx
@@ -0,0 +1,77 @@
+/** @vitest-environment jsdom */
+import type { ForeignEntity } from '@service-storage/generated/schemas';
+import { cleanup, render, screen } from '@solidjs/testing-library';
+import type { JSX } from 'solid-js';
+import { afterEach, beforeEach, expect, it, vi } from 'vitest';
+
+const query = {
+ isSuccess: false,
+ isLoading: false,
+ data: undefined as ForeignEntity | undefined,
+};
+
+vi.mock('@queries/storage/pr-mention', () => ({
+ usePrMentionQuery: () => query,
+}));
+vi.mock('@components/app/split-layout/layout', () => ({
+ useSplitLayout: () => ({ openWithSplit: vi.fn() }),
+}));
+vi.mock('@core/util/useSplitNavigationHandler', () => ({
+ useSplitNavigationHandler: () => ({}),
+}));
+vi.mock('@core/component/HoverCard', () => ({
+ HoverCard: (props: { trigger: JSX.Element }) => props.trigger,
+}));
+
+import { PullRequestAttachment } from './PullRequestAttachment';
+
+const title = 'fix(channels): keep the gif picker visible on mobile';
+const pullRequest: ForeignEntity = {
+ id: 'pr-1',
+ foreignEntityId: 'macro-inc/macro/pull/8813',
+ foreignEntitySource: 'github_pull_request',
+ metadata: {
+ name: title,
+ owner: 'macro-inc',
+ repo: 'macro',
+ number: 8813,
+ status: 'open',
+ },
+ createdAt: '',
+ updatedAt: '',
+ storedForAuthEntity: 'team',
+ storedForId: 'team-1',
+};
+
+beforeEach(() => {
+ query.isSuccess = false;
+ query.isLoading = false;
+ query.data = undefined;
+});
+afterEach(cleanup);
+
+it('shows the mention face for a pull request the viewer can read', () => {
+ query.isSuccess = true;
+ query.data = pullRequest;
+
+ render(() => <PullRequestAttachment id={pullRequest.id} />);
+
+ expect(screen.getByText(title)).toBeTruthy();
+ expect(screen.getByText('#8813')).toBeTruthy();
+ expect(screen.queryByText('No Access')).toBeNull();
+});
+
+it('stays on the loading pill until the pull request read settles', () => {
+ query.isLoading = true;
+
+ render(() => <PullRequestAttachment id={pullRequest.id} />);
+
+ expect(screen.getByText('Loading...')).toBeTruthy();
+ expect(screen.queryByText('No Access')).toBeNull();
+});
+
+it('shows no access when the pull request read is denied', () => {
+ render(() => <PullRequestAttachment id={pullRequest.id} />);
+
+ expect(screen.getByText('No Access')).toBeTruthy();
+});
diff --git a/apps/web/src/features/block-pr/component/PullRequestAttachment.tsx b/apps/web/src/features/block-pr/component/PullRequestAttachment.tsx
new file mode 100644
index 0000000000..70a899c46b
--- /dev/null
+++ b/apps/web/src/features/block-pr/component/PullRequestAttachment.tsx
@@ -0,0 +1,54 @@
+import { PullRequestEntityLink } from '@core/component/LexicalMarkdown/component/decorator/PullRequestMention';
+import EyeSlash from '@phosphor/eye-slash.svg';
+import LoadingSpinner from '@phosphor/spinner.svg';
+import { usePrMentionQuery } from '@queries/storage/pr-mention';
+import { type JSX, Show } from 'solid-js';
+
+function StatusPill(props: { children: JSX.Element }) {
+ return (
+ <span class="inline-flex h-6 items-center gap-2 rounded-md border border-edge-muted/50 px-2 text-sm text-ink opacity-50">
+ {props.children}
+ </span>
+ );
+}
+
+/**
+ * A shared pull request on a channel message. The mention face reads the
+ * foreign-entity record; the generic attachment preview has no such read and
+ * renders every one as "No Access".
+ */
+export function PullRequestAttachment(props: { id: string }) {
+ const query = usePrMentionQuery(() => props.id);
+ const entity = () => (query.isSuccess ? query.data : undefined);
+
+ return (
+ <Show
+ when={entity()}
+ fallback={
+ <Show
+ when={!query.isLoading}
+ fallback={
+ <StatusPill>
+ <span class="size-3.5 animate-spin">
+ <LoadingSpinner />
+ </span>
+ Loading...
+ </StatusPill>
+ }
+ >
+ <StatusPill>
+ <EyeSlash class="size-3.5 text-ink-muted" />
+ No Access
+ </StatusPill>
+ </Show>
+ }
+ >
+ {(loaded) => (
+ <PullRequestEntityLink
+ entity={loaded()}
+ class="h-6 rounded-md border border-edge-muted/50 px-2 text-sm"
+ />
+ )}
+ </Show>
+ );
+}
diff --git a/apps/web/src/features/channel/Message/Attachments.test.tsx b/apps/web/src/features/channel/Message/Attachments.test.tsx
index 8f9d74153f..1e2e6c211b 100644
--- a/apps/web/src/features/channel/Message/Attachments.test.tsx
+++ b/apps/web/src/features/channel/Message/Attachments.test.tsx
@@ -7,6 +7,11 @@ vi.mock('@app/features/projects/project-attachment', () => ({
<span>Native project {props.id}</span>
),
}));
+vi.mock('@app/features/block-pr/component/PullRequestAttachment', () => ({
+ PullRequestAttachment: (props: { id: string }) => (
+ <span>Pull request {props.id}</span>
+ ),
+}));
vi.mock('@core/component/ItemPreview', () => ({
ItemPreview: (props: { id: string; type: string }) => (
<span>
@@ -15,7 +20,8 @@ vi.mock('@core/component/ItemPreview', () => ({
),
}));
vi.mock('@service-storage/client', () => ({
- stringToItemType: (type: string) => type,
+ stringToItemType: (type: string) =>
+ type === 'foreign' || type === 'foreign_entity' ? 'foreign' : type,
}));
vi.mock('@channel/Media/media-items', () => ({
partitionAttachments: (attachments: unknown[]) => ({
@@ -32,15 +38,21 @@ vi.mock('./context', () => ({
{ entity_type: 'initiative', entity_id: 'launch' },
{ entity_type: 'document', entity_id: 'note' },
{ entity_type: 'project', entity_id: 'folder' },
+ { entity_type: 'foreign_entity', entity_id: 'pr-1' },
+ { entity_type: 'foreign', entity_id: 'pr-2' },
],
}),
}));
afterEach(cleanup);
-it('routes only initiative attachments to the native project preview', () => {
+it('routes initiative and pull request attachments to their own previews', () => {
render(() => <Attachments />);
expect(screen.getByText('Native project launch')).toBeTruthy();
expect(screen.getByText('Existing document note')).toBeTruthy();
expect(screen.getByText('Existing project folder')).toBeTruthy();
+ expect(screen.getByText('Pull request pr-1')).toBeTruthy();
+ expect(screen.getByText('Pull request pr-2')).toBeTruthy();
expect(screen.queryByText('Existing initiative launch')).toBeNull();
+ expect(screen.queryByText('Existing foreign pr-1')).toBeNull();
+ expect(screen.queryByText('Existing foreign_entity pr-1')).toBeNull();
});
diff --git a/apps/web/src/features/channel/Message/Attachments.tsx b/apps/web/src/features/channel/Message/Attachments.tsx
index b43ce7f650..26f6e9a4e6 100644
--- a/apps/web/src/features/channel/Message/Attachments.tsx
+++ b/apps/web/src/features/channel/Message/Attachments.tsx
@@ -1,3 +1,4 @@
+import { PullRequestAttachment } from '@app/features/block-pr/component/PullRequestAttachment';
import { ProjectAttachment } from '@app/features/projects/project-attachment';
import {
type MediaItem,
@@ -7,7 +8,7 @@ import {
import { ItemPreview } from '@core/component/ItemPreview';
import { stringToItemType } from '@service-storage/client';
import { cn } from '@ui';
-import { createMemo, For, Show } from 'solid-js';
+import { createMemo, For, Match, Show, Switch } from 'solid-js';
import { useMessage } from './context';
import { MediaPreview } from './MediaPreview';
@@ -43,8 +44,7 @@ export function Attachments(props: AttachmentsProps) {
<div class="flex flex-row mt-2 gap-2 flex-wrap max-w-full">
<For each={buckets().documentAttachments}>
{(attachment) => (
- <Show
- when={attachment.entity_type === 'initiative'}
+ <Switch
fallback={
<ItemPreview
id={attachment.entity_id}
@@ -52,8 +52,17 @@ export function Attachments(props: AttachmentsProps) {
/>
}
>
- <ProjectAttachment id={attachment.entity_id} />
- </Show>
+ <Match when={attachment.entity_type === 'initiative'}>
+ <ProjectAttachment id={attachment.entity_id} />
+ </Match>
+ <Match
+ when={
+ stringToItemType(attachment.entity_type) === 'foreign'
+ }
+ >
+ <PullRequestAttachment id={attachment.entity_id} />
+ </Match>
+ </Switch>
)}
</For>
</div>
diff --git a/apps/web/src/lib/service-clients/service-storage/itemType.test.ts b/apps/web/src/lib/service-clients/service-storage/itemType.test.ts
index 632385009d..eb8837aed2 100644
--- a/apps/web/src/lib/service-clients/service-storage/itemType.test.ts
+++ b/apps/web/src/lib/service-clients/service-storage/itemType.test.ts
@@ -72,6 +72,13 @@ describe('stringToItemType', () => {
}
);
+ test.each(['foreign', 'foreign_entity'])(
+ 'reads the pull request spelling %s as a foreign entity',
+ (raw) => {
+ expect(stringToItemType(raw)).toBe('foreign');
+ }
+ );
+
test.each(['channel_message', 'bogus'])('rejects %s', (raw) => {
expect(stringToItemType(raw)).toBeUndefined();
});
diff --git a/apps/web/src/lib/service-clients/service-storage/itemType.ts b/apps/web/src/lib/service-clients/service-storage/itemType.ts
index e28985d991..7bcf938fd3 100644
--- a/apps/web/src/lib/service-clients/service-storage/itemType.ts
+++ b/apps/web/src/lib/service-clients/service-storage/itemType.ts
@@ -45,6 +45,8 @@ export function itemTypeToReferenceEntityType(itemType: ItemType): string {
* Never cast these strings to `ItemType` directly.
*/
export function stringToItemType(str: string): ItemType | undefined {
+ // Mentions store `foreign`. The pull-request share button stores
+ // `foreign_entity`. Both are the same record.
return match<string, ItemType | undefined>(str)
.with('email', 'thread', 'email_thread', () => 'email')
.with('routine', 'automation', () => 'routine')
@@ -64,6 +66,7 @@ export function stringToItemType(str: string): ItemType | undefined {
'initiative',
(itemType) => itemType
)
+ .with('foreign', 'foreign_entity', () => 'foreign')
.otherwise(() => undefined);
}