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.

feat(block-pr): add share button to PR block (#8300)

Jacob Beckerman6200a1ffe8d6
diff --git a/apps/web/src/features/block-pr/hooks/usePrShare.tsx b/apps/web/src/features/block-pr/hooks/usePrShare.tsx
new file mode 100644
index 0000000000..8bccc7ff67
--- /dev/null
+++ b/apps/web/src/features/block-pr/hooks/usePrShare.tsx
@@ -0,0 +1,153 @@
+import { MobileDrawer } from '@components/app/mobile/MobileDrawer';
+import { EntityIcon } from '@core/component/EntityIcon';
+import { ForwardToChannel } from '@core/component/ForwardToChannel';
+import { isMobile } from '@core/mobile/isMobile';
+import { fireAndForget } from '@core/util/fireAndForget';
+import { buildSimpleEntityUrl } from '@core/util/url';
+import { useCopyLink } from '@core/util/useCopyLink';
+import { Dialog } from '@kobalte/core/dialog';
+import CopyIcon from '@phosphor/copy.svg';
+import { createCallback } from '@solid-primitives/rootless';
+import { Button, Panel } from '@ui';
+import { type Accessor, createSignal, Show } from 'solid-js';
+
+interface PrShareModalProps {
+ foreignEntityId: string;
+ name: string;
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+}
+
+function prShareUrl(foreignEntityId: string): string {
+ return buildSimpleEntityUrl({ type: 'pr', id: foreignEntityId });
+}
+
+function PrShareModal(props: PrShareModalProps) {
+ const copyEntityLink = useCopyLink();
+
+ const copyLink = createCallback(() => {
+ fireAndForget(
+ copyEntityLink(prShareUrl(props.foreignEntityId)),
+ 'pr-share-modal'
+ );
+ });
+
+ return (
+ <Show
+ when={!isMobile()}
+ fallback={
+ <MobileDrawer
+ open={props.open}
+ onOpenChange={props.onOpenChange}
+ closeOnOutsidePointerStrategy="pointerdown"
+ >
+ <MobileDrawer.Portal>
+ <MobileDrawer.Overlay />
+ <MobileDrawer.Content
+ aria-label="Share"
+ class="h-[80vh] overflow-y-auto"
+ >
+ <div class="flex justify-center pt-3 pb-1 shrink-0">
+ <div class="w-10 h-1 rounded-full bg-edge-muted" />
+ </div>
+ <div class="shrink-0 flex items-center justify-between px-3 text-sm font-medium text-ink min-h-11">
+ <div class="flex items-center gap-1.5 flex-1 min-w-0">
+ <EntityIcon targetType="pr" size="sm" class="shrink-0" />
+ <span class="truncate">{props.name}</span>
+ </div>
+ </div>
+ <div class="border-b border-edge-muted mb-2" />
+ <ForwardToChannel
+ entity={{
+ entity_type: 'foreign_entity',
+ entity_id: props.foreignEntityId,
+ }}
+ name={props.name}
+ onSubmit={() => props.onOpenChange(false)}
+ submitPermissionInfo={undefined}
+ />
+ <div class="px-4 py-3 border-t border-edge-muted">
+ <Button variant="outline" onClick={copyLink}>
+ <CopyIcon class="size-4" />
+ <span>Copy Link</span>
+ </Button>
+ </div>
+ </MobileDrawer.Content>
+ </MobileDrawer.Portal>
+ </MobileDrawer>
+ }
+ >
+ <Dialog onOpenChange={props.onOpenChange} open={props.open}>
+ <Dialog.Portal>
+ <Dialog.Overlay class="z-modal fixed inset-0 scrim-glass" />
+ <div class="z-modal fixed inset-0">
+ <Dialog.Content
+ class="max-w-[calc(100vw-16px)] mt-20 sm:mt-40 mx-auto overflow-y-auto scrollbar-hidden portal-scope isolate flex flex-col gap-2 *:max-h-[75vh]"
+ style={{ width: '800px' }}
+ >
+ <Panel depth={2} class="rounded-xl bg-dialog">
+ <Panel.Header class="px-4">
+ <Dialog.Title class="flex items-center gap-1.5 min-w-0 overflow-hidden whitespace-nowrap w-full text-sm font-medium">
+ <span class="shrink-0">Share:</span>
+ <EntityIcon targetType="pr" size="sm" class="shrink-0" />
+ <span class="truncate">{props.name}</span>
+ </Dialog.Title>
+ </Panel.Header>
+ <Panel.Body>
+ <ForwardToChannel
+ entity={{
+ entity_type: 'foreign_entity',
+ entity_id: props.foreignEntityId,
+ }}
+ name={props.name}
+ onSubmit={() => props.onOpenChange(false)}
+ onCancel={() => props.onOpenChange(false)}
+ submitPermissionInfo={undefined}
+ />
+ </Panel.Body>
+ </Panel>
+ <Panel depth={2} class="rounded-xl bg-dialog">
+ <Panel.Body>
+ <div class="flex items-center justify-between p-4 text-sm">
+ <span class="text-ink-muted">
+ Anyone with access to the PR on GitHub can view it in
+ Macro
+ </span>
+ <Button variant="outline" onClick={copyLink}>
+ <CopyIcon class="size-4" />
+ <span>Copy Link</span>
+ </Button>
+ </div>
+ </Panel.Body>
+ </Panel>
+ </Dialog.Content>
+ </div>
+ </Dialog.Portal>
+ </Dialog>
+ </Show>
+ );
+}
+
+/**
+ * Hook to manage PR share modal state. Returns the modal component and an
+ * opener function.
+ */
+export function usePrShare(
+ foreignEntityId: Accessor<string>,
+ name: Accessor<string>
+) {
+ const [open, setOpen] = createSignal(false);
+
+ const openShare = () => setOpen(true);
+
+ const ShareModal = () => (
+ <PrShareModal
+ foreignEntityId={foreignEntityId()}
+ name={name()}
+ open={open()}
+ onOpenChange={setOpen}
+ />
+ );
+
+ return { openShare, ShareModal, isOpen: open };
+}
diff --git a/apps/web/src/features/block-pr/views/PrDetail.test.ts b/apps/web/src/features/block-pr/views/PrDetail.test.ts
index 3d0f08b558..3b390c964f 100644
--- a/apps/web/src/features/block-pr/views/PrDetail.test.ts
+++ b/apps/web/src/features/block-pr/views/PrDetail.test.ts
@@ -48,6 +48,14 @@ vi.mock('../component/PrTimeline', () => ({ PrTimeline: () => null }));
vi.mock('../component/sidepanel/PrSidePanelSections', () => ({
PrSidePanelSections: () => null,
}));
+// Keeps ForwardToChannel (and its websocket) out of this refresh-wiring unit.
+vi.mock('../hooks/usePrShare', () => ({
+ usePrShare: () => ({
+ openShare: () => undefined,
+ ShareModal: () => null,
+ isOpen: () => false,
+ }),
+}));
import { githubPullRequestChangesKeys } from '@queries/storage/keys';
import { usePrDetail } from './PrDetail';
diff --git a/apps/web/src/features/block-pr/views/PrDetail.tsx b/apps/web/src/features/block-pr/views/PrDetail.tsx
index b89b012083..9e6f1f325c 100644
--- a/apps/web/src/features/block-pr/views/PrDetail.tsx
+++ b/apps/web/src/features/block-pr/views/PrDetail.tsx
@@ -2,6 +2,7 @@ import { ViewShell } from '@app/components/view-shell';
import { ChangesSplit, ChangesToggle } from '@app/features/changes/changes';
import { useOptionalChanges } from '@app/features/changes/context/changes-controller';
import { useGlobalNotificationSource } from '@components/app/GlobalAppState';
+import { HeaderActionButton } from '@components/app/HeaderActionButton';
import { SidePanel } from '@components/app/side-panel';
import { SplitPanel } from '@components/app/split-panel';
import {
@@ -11,13 +12,14 @@ import {
import { fireAndForget } from '@core/util/fireAndForget';
import { GithubLabelPills } from '@entity/components/GithubLabelPill';
import { PrAgentSessionsChip } from '@entity/views/PrAgentSessionsChip';
+import IconShared from '@icon/share.svg';
import { DebouncedNotificationReadMarker } from '@notifications';
import {
type GithubPullRequestWithDetails,
useRefreshGithubPullRequest,
} from '@queries/storage/github-pull-requests';
import { githubPullRequestChangesKeys } from '@queries/storage/keys';
-import { Button, cn, Layer, Scroll } from '@ui';
+import { Button, cn, Layer, Scroll, Tooltip } from '@ui';
import { type Accessor, createMemo, Show, Suspense } from 'solid-js';
import { MergePullRequestButton } from '../component/MergePullRequestButton';
import { PrChangesProvider } from '../component/PrChanges';
@@ -41,6 +43,7 @@ import {
prForeignEntityQueryKey,
usePrForeignEntityQuery,
} from '../data/queries';
+import { usePrShare } from '../hooks/usePrShare';
import {
cleanGithubMarkdown,
githubAvatarUrl,
@@ -188,21 +191,36 @@ export function PrDetailContent(props: PrDetailBodyProps) {
}
export function PrDetailActions(props: { detail?: PrForeignEntityData }) {
+ const { openShare, ShareModal } = usePrShare(
+ () => props.detail?.id ?? '',
+ () => props.detail?.pullRequest.name ?? 'Pull request'
+ );
+
return (
<div class="ml-auto flex shrink-0 items-center gap-2">
<Show when={props.detail}>
{(detail) => (
- <MergePullRequestButton
- target={{ ...detail().prRef, title: detail().pullRequest.name }}
- status={detail().pullRequest.status}
- draft={detail().pullRequest.draft}
- checks={detail().pullRequest.checks}
- onMerged={() => invalidatePrForeignEntity(detail().id)}
- />
+ <>
+ <Tooltip label="Share pull request">
+ <HeaderActionButton
+ label="Share"
+ icon={<IconShared />}
+ onClick={openShare}
+ />
+ </Tooltip>
+ <MergePullRequestButton
+ target={{ ...detail().prRef, title: detail().pullRequest.name }}
+ status={detail().pullRequest.status}
+ draft={detail().pullRequest.draft}
+ checks={detail().pullRequest.checks}
+ onMerged={() => invalidatePrForeignEntity(detail().id)}
+ />
+ </>
)}
</Show>
<ChangesToggle />
<SidePanel.Toggle />
+ <ShareModal />
</div>
);
}