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(pr): close the details sheet when opening linked work on touch (#9373)

Eric Hayes5857a582336e
diff --git a/apps/web/src/features/block-pr/component/sidepanel/PrAgentSessionsSection.tsx b/apps/web/src/features/block-pr/component/sidepanel/PrAgentSessionsSection.tsx
index e974bd1219..b54fe16498 100644
--- a/apps/web/src/features/block-pr/component/sidepanel/PrAgentSessionsSection.tsx
+++ b/apps/web/src/features/block-pr/component/sidepanel/PrAgentSessionsSection.tsx
@@ -1,6 +1,5 @@
import { ListFilterDropdown } from '@app/components/view-shell';
import { SidePanel } from '@components/app/side-panel';
-import { useSplitLayout } from '@components/app/split-layout/layout';
import { AgentSessionMentionLabel } from '@core/component/LexicalMarkdown/component/decorator/AgentSessionMentionLabel';
import { toast } from '@core/component/Toast/Toast';
import { fireAndForget } from '@core/util/fireAndForget';
@@ -16,18 +15,14 @@ import {
import { useQuickAccessAgentSessionsQuery } from '@queries/soup/quick-access-agent-sessions';
import { Button, Dropdown, Tooltip } from '@ui';
import { For, Match, Show, Switch } from 'solid-js';
+import { useOpenFromSidePanel } from './open-from-side-panel';
const pullRequestKey = (url: string) =>
url.replace(/^https:\/\/github\.com\//i, '').toLowerCase();
-function LinkedSessionRow(props: { sessionId: string; url: string }) {
- const layout = useSplitLayout();
- const preview = useAgentSessionMentionPreview(
- () => props.sessionId,
- () => true
- );
- const links = useAgentSessionPullRequestsQuery(() => props.sessionId);
- const unlink = useUnlinkAgentSessionPullRequestMutation();
+/** An agent session's name, or why it can't be shown. */
+export function useAgentSessionLabel(sessionId: () => string) {
+ const preview = useAgentSessionMentionPreview(sessionId, () => true);
const session = () => {
const current = preview.isSuccess ? preview.data : undefined;
return current?.access === 'access' ? current.data : undefined;
@@ -38,6 +33,14 @@ function LinkedSessionRow(props: { sessionId: string; url: string }) {
if (current?.access === 'does_not_exist') return 'Deleted agent session';
return session()?.name || 'Agent session';
};
+ return { session, label };
+}
+
+function LinkedSessionRow(props: { sessionId: string; url: string }) {
+ const open = useOpenFromSidePanel();
+ const { session, label } = useAgentSessionLabel(() => props.sessionId);
+ const links = useAgentSessionPullRequestsQuery(() => props.sessionId);
+ const unlink = useUnlinkAgentSessionPullRequestMutation();
// The pull request the session's agent opened cannot be unlinked.
const linkedByPerson = () =>
links.isSuccess &&
@@ -55,10 +58,7 @@ function LinkedSessionRow(props: { sessionId: string; url: string }) {
class="w-full min-w-0 truncate text-left disabled:text-ink-placeholder"
disabled={!session()}
onClick={(event) =>
- layout?.openWithSplit(
- { type: 'agent', id: props.sessionId },
- { preferNewSplit: event.shiftKey }
- )
+ open({ type: 'agent', id: props.sessionId }, event.shiftKey)
}
>
<AgentSessionMentionLabel label={label()} />
diff --git a/apps/web/src/features/block-pr/component/sidepanel/PrLinkedWorkSection.test.tsx b/apps/web/src/features/block-pr/component/sidepanel/PrLinkedWorkSection.test.tsx
new file mode 100644
index 0000000000..236daf02e3
--- /dev/null
+++ b/apps/web/src/features/block-pr/component/sidepanel/PrLinkedWorkSection.test.tsx
@@ -0,0 +1,80 @@
+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
+import type { JSX } from 'solid-js';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import type { PrLinks } from '../../data/pr-links';
+
+const openWithSplit = vi.fn();
+const setIsOpen = vi.fn();
+let touch = false;
+let links: PrLinks;
+
+vi.mock('@components/app/side-panel', () => ({
+ SidePanel: { Section: (props: { children: JSX.Element }) => props.children },
+ useSidePanel: () => ({ setIsOpen }),
+}));
+vi.mock('@components/app/split-layout/layout', () => ({
+ useSplitLayout: () => ({ openWithSplit }),
+}));
+vi.mock('@core/mobile/isTouchDevice', () => ({
+ isTouchDevice: () => touch,
+}));
+vi.mock('@core/context/channels', () => ({
+ useChannelName: () => () => 'bug-reports',
+}));
+vi.mock('../../queries/pr-links-query', () => ({
+ prLinksTarget: () => ({ url: 'https://github.com/org/repo/pull/7' }),
+ usePrLinksQuery: () => ({
+ linksFor: () => links,
+ companyName: () => undefined,
+ isError: () => false,
+ retry: vi.fn(),
+ }),
+}));
+vi.mock('./PrAgentSessionsSection', () => ({
+ useAgentSessionLabel: () => ({ label: () => 'Fix the sharing button' }),
+}));
+
+import { PrLinkedWorkSection } from './PrLinkedWorkSection';
+
+const pullRequest = { owner: 'org', repo: 'repo', number: 7 };
+
+afterEach(cleanup);
+beforeEach(() => {
+ openWithSplit.mockReset();
+ setIsOpen.mockReset();
+ touch = false;
+ links = {
+ sessions: [],
+ tasks: [],
+ channelIds: ['channel-1'],
+ channelOrigins: [],
+ companyIds: [],
+ priority: { id: 'none' },
+ origin: { tool: 'macro', signal: 'agent-session', sessionId: 'session-1' },
+ };
+});
+
+describe('PR linked work', () => {
+ it('names the agent session the pull request was started from', () => {
+ render(() => <PrLinkedWorkSection pullRequest={pullRequest} />);
+ fireEvent.click(screen.getByRole('button', { name: /Fix the sharing/ }));
+ expect(openWithSplit).toHaveBeenCalledWith(
+ { type: 'agent', id: 'session-1' },
+ { preferNewSplit: false }
+ );
+ expect(setIsOpen).not.toHaveBeenCalled();
+ });
+
+ it('closes the touch sheet before opening a linked item', () => {
+ touch = true;
+ render(() => <PrLinkedWorkSection pullRequest={pullRequest} />);
+ fireEvent.click(screen.getByRole('button', { name: /Fix the sharing/ }));
+ fireEvent.click(screen.getByRole('button', { name: /bug-reports/ }));
+ expect(setIsOpen).toHaveBeenCalledTimes(2);
+ expect(setIsOpen).toHaveBeenCalledWith(false);
+ expect(openWithSplit).toHaveBeenCalledWith(
+ { type: 'channel', id: 'channel-1' },
+ { preferNewSplit: false }
+ );
+ });
+});
diff --git a/apps/web/src/features/block-pr/component/sidepanel/PrLinkedWorkSection.tsx b/apps/web/src/features/block-pr/component/sidepanel/PrLinkedWorkSection.tsx
index 4cacb304b4..d4dbc6a97f 100644
--- a/apps/web/src/features/block-pr/component/sidepanel/PrLinkedWorkSection.tsx
+++ b/apps/web/src/features/block-pr/component/sidepanel/PrLinkedWorkSection.tsx
@@ -1,8 +1,8 @@
import { SidePanel } from '@components/app/side-panel';
-import { useSplitLayout } from '@components/app/split-layout/layout';
import type { SplitContent } from '@components/app/split-layout/layoutManager';
import { useChannelName } from '@core/context/channels';
import { fireAndForget } from '@core/util/fireAndForget';
+import { openExternalUrl } from '@core/util/url';
import BuildingsIcon from '@icon/system/regular/buildings.svg';
import HashIcon from '@icon/system/regular/hash.svg';
import { Button, cn } from '@ui';
@@ -12,17 +12,21 @@ import {
type PrLinks,
priorityTaskName,
} from '../../data/pr-links';
+import { PR_ORIGIN_LABELS, type PrOrigin } from '../../data/pr-origin';
import { prLinksTarget, usePrLinksQuery } from '../../queries/pr-links-query';
-import { PrOriginBadge, PrPriorityIcon, prOriginDescription } from '../PrLinks';
+import { PrOriginIcon, PrPriorityIcon, prOriginDescription } from '../PrLinks';
+import { useOpenFromSidePanel } from './open-from-side-panel';
+import { useAgentSessionLabel } from './PrAgentSessionsSection';
function LinkRow(props: {
icon?: Component<{ class?: string }>;
leading?: JSX.Element;
- content: SplitContent;
+ /** The item to open, or a handler for one that opens outside Macro. */
+ content: SplitContent | (() => void);
children: JSX.Element;
class?: string;
}) {
- const layout = useSplitLayout();
+ const open = useOpenFromSidePanel();
return (
<button
type="button"
@@ -30,11 +34,11 @@ function LinkRow(props: {
'flex h-6 w-full min-w-0 items-center gap-2 rounded text-left hover:text-ink',
props.class
)}
- onClick={(event) =>
- layout?.openWithSplit(props.content, {
- preferNewSplit: event.shiftKey,
- })
- }
+ onClick={(event) => {
+ const content = props.content;
+ if (typeof content === 'function') content();
+ else open(content, event.shiftKey);
+ }}
>
<Show when={props.icon} fallback={props.leading}>
{(icon) => {
@@ -47,6 +51,52 @@ function LinkRow(props: {
);
}
+function SessionOriginRow(props: { origin: PrOrigin; sessionId: string }) {
+ const { label } = useAgentSessionLabel(() => props.sessionId);
+ return (
+ <LinkRow
+ leading={<PrOriginIcon tool={props.origin.tool} class="size-3.5" />}
+ content={{ type: 'agent', id: props.sessionId }}
+ >
+ {label()}
+ </LinkRow>
+ );
+}
+
+/**
+ * Where the pull request was started: the Macro agent session by name, the
+ * external session link, or just the tool when nothing links to it.
+ */
+function OriginRow(props: { origin: PrOrigin }) {
+ const tool = () => PR_ORIGIN_LABELS[props.origin.tool];
+ return (
+ <Switch
+ fallback={
+ <div class="flex h-6 min-w-0 items-center gap-2">
+ <PrOriginIcon tool={props.origin.tool} class="size-3.5" />
+ <span class="min-w-0 truncate">{tool()}</span>
+ </div>
+ }
+ >
+ <Match when={props.origin.sessionId}>
+ {(sessionId) => (
+ <SessionOriginRow origin={props.origin} sessionId={sessionId()} />
+ )}
+ </Match>
+ <Match when={props.origin.url}>
+ {(url) => (
+ <LinkRow
+ leading={<PrOriginIcon tool={props.origin.tool} class="size-3.5" />}
+ content={() => openExternalUrl(url())}
+ >
+ {tool()}
+ </LinkRow>
+ )}
+ </Match>
+ </Switch>
+ );
+}
+
function ChannelRow(props: { id: string }) {
const name = useChannelName(props.id, 'Channel');
return (
@@ -87,7 +137,6 @@ export function PrLinkedWorkSection(props: {
authorLogin?: string | null;
};
}) {
- const layout = useSplitLayout();
const target = () =>
props.pullRequest ? prLinksTarget(props.pullRequest) : undefined;
const query = usePrLinksQuery(() => {
@@ -123,16 +172,7 @@ export function PrLinkedWorkSection(props: {
<Show when={current().origin}>
{(origin) => (
<LinkGroup label="Started from">
- <div class="flex h-6 items-center">
- <PrOriginBadge
- origin={origin()}
- onOpen={(content, newSplit) =>
- layout?.openWithSplit(content, {
- preferNewSplit: newSplit,
- })
- }
- />
- </div>
+ <OriginRow origin={origin()} />
<div class="text-ink-placeholder">
{prOriginDescription(origin())}
</div>
diff --git a/apps/web/src/features/block-pr/component/sidepanel/open-from-side-panel.ts b/apps/web/src/features/block-pr/component/sidepanel/open-from-side-panel.ts
new file mode 100644
index 0000000000..9a1de27560
--- /dev/null
+++ b/apps/web/src/features/block-pr/component/sidepanel/open-from-side-panel.ts
@@ -0,0 +1,19 @@
+import { useSidePanel } from '@components/app/side-panel';
+import { useSplitLayout } from '@components/app/split-layout/layout';
+import type { SplitContent } from '@components/app/split-layout/layoutManager';
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
+import type { OpenPrLink } from '../PrLinks';
+
+/**
+ * Opens a linked item from the pull request's side panel. On touch the panel
+ * is a sheet over the pane, so it closes first; otherwise it would cover what
+ * just opened.
+ */
+export function useOpenFromSidePanel(): OpenPrLink {
+ const layout = useSplitLayout();
+ const sidePanel = useSidePanel();
+ return (content: SplitContent, newSplit: boolean) => {
+ if (isTouchDevice()) sidePanel?.setIsOpen(false);
+ layout?.openWithSplit(content, { preferNewSplit: newSplit });
+ };
+}