Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ describe('AgentHandoffProductPrompt', () => {
{organization}
);

expect(screen.getByRole('link', {name: 'View all instructions'})).toHaveAttribute(
'href',
'https://sentry.io/agent-handoff.md'
);
expect(
screen.queryByRole('link', {name: 'View all instructions'})
).not.toBeInTheDocument();
expect(screen.getByText(/Read and follow/)).toHaveTextContent(
'Read and follow https://sentry-jest-tests.example.com/agent-handoff.md verbatim to set up tracing. Your handoff code is sntryh_****.'
);
Expand Down Expand Up @@ -89,8 +88,10 @@ describe('AgentHandoffProductPrompt', () => {
{organization}
);

await userEvent.click(screen.getByRole('button', {name: 'Advanced options'}));
await userEvent.click(screen.getByRole('menuitemradio', {name: /Use IP pinning/}));
const ipPinning = screen.getByRole('checkbox', {name: 'Only allow this network'});
expect(ipPinning).toBeChecked();
await userEvent.click(ipPinning);
expect(ipPinning).not.toBeChecked();

expect(
screen.getByText(/anyone with this prompt can use its handoff code/)
Expand Down
138 changes: 66 additions & 72 deletions static/app/components/agentHandoff/agentHandoffProductPrompt.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import styled from '@emotion/styled';
import {IconCopy} from '@sentry/icons/copy';
import {IconOpen} from '@sentry/icons/open';
import {useStore} from 'zustand';

import {Button} from '@sentry/scraps/button';
import {Flex, Stack} from '@sentry/scraps/layout';
import {ExternalLink} from '@sentry/scraps/link';
import {Text} from '@sentry/scraps/text';
import {Flex, Grid, Stack} from '@sentry/scraps/layout';
import {Heading, Text} from '@sentry/scraps/text';

import {FeedbackButton} from 'sentry/components/feedbackButton/feedbackButton';
import {List} from 'sentry/components/list';
import {ListItem} from 'sentry/components/list/listItem';
import {t} from 'sentry/locale';
import {ConfigStore} from 'sentry/stores/configStore';

import {
getHandoffPreviewUrl,
HandoffAdvancedMenu,
HandoffIpPinningCheckbox,
HandoffPromptAlerts,
HandoffPromptBox,
} from './handoffPromptParts';
Expand All @@ -24,8 +18,8 @@ import {useHandoffPromptCopy} from './useHandoffPromptCopy';

interface AgentHandoffProductPromptProps {
/**
* Short phrases describing what the agent will do, shown as checkmark bullets above
* "View all instructions". Keep to 3–5 items.
* Short phrases describing what the agent will do, shown as bullets under the prompt.
* Keep to 3–5 items.
*/
agentSteps: string[];
context: AddFeatureContext | null;
Expand All @@ -41,79 +35,79 @@ export function AgentHandoffProductPrompt({
onCopySuccess,
onSelect,
}: AgentHandoffProductPromptProps) {
const sentryUrl = useStore(ConfigStore, state => state.links.sentryUrl);
const previewUrl = getHandoffPreviewUrl(sentryUrl);

const {copyPrompt, copyDisabled, handoff, useIpPinning, toggleIpPinning} =
useHandoffPromptCopy({flow: AgentHandoffFlow.ADD_FEATURE, context, onCopySuccess});

return (
<Stack gap="xl">
<Stack gap="md">
<Text size="sm" variant="secondary">
{t('Paste this prompt into your coding agent')}
</Text>

<HandoffPromptBox
flow={AgentHandoffFlow.ADD_FEATURE}
context={context}
onCopyPrompt={copyPrompt}
onSelect={onSelect}
/>

<Flex align="center" gap="md">
<Button
busy={handoff.isPending}
disabled={copyDisabled}
icon={<IconCopy />}
variant="primary"
onClick={copyPrompt}
>
{t('Copy prompt')}
</Button>

<FeedbackButton
size="md"
variant="secondary"
feedbackOptions={{tags: {'feedback.source': feedbackSource}}}
<Stack gap="2xl">
{/* The steps sit beside the prompt once the card is wide enough for both. */}
<Grid
columns={{zero: 'minmax(0, 1fr)', '3xl': 'minmax(0, 1fr) minmax(0, 340px)'}}
gap="2xl"
align="start"
>
<Stack gap="md">
<HandoffPromptBox
flow={AgentHandoffFlow.ADD_FEATURE}
context={context}
onCopyPrompt={copyPrompt}
onSelect={onSelect}
/>

<Flex flex={1} align="center" justify="end">
<HandoffAdvancedMenu
<Flex align="center" justify="between" gap="xl" paddingTop="xs">
<HandoffIpPinningCheckbox
disabled={copyDisabled}
useIpPinning={useIpPinning}
onToggle={toggleIpPinning}
/>
<Button
aria-label={t('Copy prompt')}
busy={handoff.isPending}
disabled={copyDisabled}
icon={<IconCopy />}
variant="primary"
onClick={copyPrompt}
>
{t('Copy')}
</Button>
</Flex>
</Flex>

<HandoffPromptAlerts useIpPinning={useIpPinning} error={handoff.error} />
</Stack>
<HandoffPromptAlerts useIpPinning={useIpPinning} error={handoff.error} />
</Stack>

<Stack gap="lg">
<Heading as="h3" size="md">
{t('Your agent will')}
</Heading>
<Stack as="ul" role="list" gap="md" margin="0" padding="0">
{agentSteps.map(step => (
<Flex as="li" key={step} align="center" gap="md">
<StepBullet aria-hidden />
<Text size="md" density="comfortable">
{step}
</Text>
</Flex>
))}
</Stack>
</Stack>
</Grid>

<Stack gap="xs">
<Text size="sm" variant="secondary">
{t('Your agent will:')}
</Text>
<List symbol="bullet">
{[
...agentSteps.map(step => (
<ListItem key={step}>
<Text size="sm">{step}</Text>
</ListItem>
)),
<ListItem key="view-all-instructions">
<Text size="sm">
<ExternalLink href={previewUrl}>
<Flex as="span" align="center" gap="xs">
{t('View all instructions')}
<IconOpen size="xs" />
</Flex>
</ExternalLink>
</Text>
</ListItem>,
]}
</List>
</Stack>
<Flex justify="end">
<FeedbackButton
size="xs"
feedbackOptions={{tags: {'feedback.source': feedbackSource}}}
>
{t('Give feedback')}
</FeedbackButton>
</Flex>
</Stack>
);
}

const StepBullet = styled('span')`
flex-shrink: 0;
width: 4px;
height: 4px;
border-radius: ${p => p.theme.radius.full};
background: ${p => p.theme.tokens.graphics.neutral.moderate};
`;
53 changes: 50 additions & 3 deletions static/app/components/agentHandoff/handoffPromptParts.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {Fragment, useState, type PointerEventHandler, type ReactNode} from 'react';
import {Fragment, useId, useState, type PointerEventHandler, type ReactNode} from 'react';
import {css, ThemeProvider, type Theme} from '@emotion/react';
import styled from '@emotion/styled';
import {IconSettings} from '@sentry/icons/settings';

import {Alert} from '@sentry/scraps/alert';
import {Checkbox} from '@sentry/scraps/checkbox';
import {DropdownMenu} from '@sentry/scraps/dropdownMenu';
import {InfoText} from '@sentry/scraps/info';
import {Container} from '@sentry/scraps/layout';
import {InfoText, InfoTip} from '@sentry/scraps/info';
import {Container, Flex, Stack} from '@sentry/scraps/layout';
import {ExternalLink} from '@sentry/scraps/link';
import {OverlayTrigger} from '@sentry/scraps/overlayTrigger';
import {Text} from '@sentry/scraps/text';
Expand Down Expand Up @@ -69,6 +70,52 @@ export function HandoffAdvancedMenu({
);
}

interface HandoffIpPinningCheckboxProps {
disabled: boolean;
onToggle: () => void;
useIpPinning: boolean;
}

export function HandoffIpPinningCheckbox({
disabled,
useIpPinning,
onToggle,
}: HandoffIpPinningCheckboxProps) {
const checkboxId = useId();
const descriptionId = useId();

return (
<Flex align="start" gap="md">
<Checkbox
id={checkboxId}
aria-describedby={descriptionId}
checked={useIpPinning}
disabled={disabled}
onChange={onToggle}
/>
<Stack gap="sm">
<Flex align="center" gap="xs">
<Text as="label" htmlFor={checkboxId} size="md">
{t('Only allow this network')}
</Text>
<InfoTip
size="xs"
title={t('Keeps your secret token safe if the prompt leaks.')}
/>
</Flex>
<IpPinningDescription id={descriptionId} size="sm" variant="muted">
{t('Uncheck if your agent runs in the cloud, or you use iCloud Private Relay.')}
</IpPinningDescription>
</Stack>
</Flex>
);
}

// Help text reads best a little looser than the largest density token (1.4).
const IpPinningDescription = styled(Text)`
line-height: 1.5;
`;

interface HandoffPromptAlertsProps {
error: Error | null;
useIpPinning: boolean;
Expand Down
9 changes: 6 additions & 3 deletions static/app/components/onboarding/benefit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ import type {ReactNode} from 'react';
import {IconCheckmark} from '@sentry/icons/checkmark';

import {Flex} from '@sentry/scraps/layout';
import {Text} from '@sentry/scraps/text';
import {Text, type TextProps} from '@sentry/scraps/text';

interface BenefitProps {
children: ReactNode;
density?: TextProps<'span'>['density'];
size?: 'sm' | 'md' | 'lg';
}

export function Benefit({children, size = 'md'}: BenefitProps) {
export function Benefit({children, density, size = 'md'}: BenefitProps) {
return (
<Flex as="li" align="center" gap="sm">
<IconCheckmark size="sm" variant="success" />
<Text size={size}>{children}</Text>
<Text size={size} density={density}>
{children}
</Text>
</Flex>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('ProductEmptyState', () => {

render(<ProductEmptyState {...baseProps} />, {organization});

await userEvent.click(screen.getByRole('radio', {name: 'Set up manually'}));
await userEvent.click(screen.getByRole('radio', {name: 'Manually'}));

expect(trackAnalytics).toHaveBeenCalledWith(
'product_empty_state.agent_setup_mode_selected',
Expand All @@ -113,10 +113,10 @@ describe('ProductEmptyState', () => {
);
});

it('"Set up manually" shows the manual content', async () => {
it('"Manually" shows the manual content', async () => {
render(<ProductEmptyState {...baseProps} />, {organization});

await userEvent.click(screen.getByRole('radio', {name: 'Set up manually'}));
await userEvent.click(screen.getByRole('radio', {name: 'Manually'}));

expect(screen.getByTestId('manual-content')).toBeInTheDocument();
expect(screen.queryByRole('button', {name: 'Copy prompt'})).not.toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const project = {

## Default (agent tab)

Shows the intro benefits section and the setup card with the "Use my coding agent" tab selected.
Shows the intro benefits section and the setup card with the "Using my coding agent" tab selected.

<Storybook.Demo>
<Container maxWidth="960px">
Expand Down Expand Up @@ -59,7 +59,7 @@ Shows the intro benefits section and the setup card with the "Use my coding agen

## With manual setup content

Clicking "Set up manually" reveals the `manualSetup` slot instead of the agent prompt.
Clicking "Manually" reveals the `manualSetup` slot instead of the agent prompt.

<Storybook.Demo>
<Container maxWidth="960px">
Expand Down
25 changes: 15 additions & 10 deletions static/app/components/productEmptyState/productEmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ export function ProductEmptyState({

return (
<Stack gap="md" width="100%" maxWidth="960px" margin="0 auto">
<Flex align="center" justify="between" gap="2xl" padding="3xl 2xl">
<Flex align="center" justify="between" gap="2xl" padding="3xl xl">
<Stack gap="xl" flex={1}>
<Heading as="h2" size="2xl">
{title}
</Heading>
<Stack as="ul" role="list" gap="sm" padding="0" margin="0">
{benefits.map(benefit => (
<Benefit key={benefit}>{benefit}</Benefit>
<Benefit key={benefit} size="lg" density="comfortable">
{benefit}
</Benefit>
))}
</Stack>
</Stack>
Expand All @@ -109,29 +111,32 @@ export function ProductEmptyState({
align="center"
justify="between"
gap="md"
padding="lg 2xl"
padding="lg xl"
background="secondary"
borderBottom="primary"
wrap="wrap"
>
<Flex align="center" gap="sm">
<Text bold>{tct('Set up [productName] for', {productName})}</Text>
<ProjectBadge project={project} avatarSize={16} />
<Text size="lg" bold>
{tct('Set up [productName] for', {productName})}
</Text>
{/* The badge inherits its name's size and weight. */}
<Text as="div" size="lg" bold>
<ProjectBadge project={project} avatarSize={16} />
</Text>
</Flex>
<SegmentedControl<SetupMode>
value={mode}
onChange={handleModeChange}
aria-label={t('Setup mode')}
>
<SegmentedControl.Item key="agent">
{t('Use my coding agent')}
</SegmentedControl.Item>
<SegmentedControl.Item key="manual">
{t('Set up manually')}
{t('Using my coding agent')}
</SegmentedControl.Item>
<SegmentedControl.Item key="manual">{t('Manually')}</SegmentedControl.Item>
</SegmentedControl>
</Flex>
<Container padding="2xl">
<Container padding="xl xl lg">
{mode === 'agent' ? (
<AgentHandoffProductPrompt
agentSteps={agentSteps}
Expand Down
Loading
Loading