Skip to content

Commit d8b0a05

Browse files
fix(clients): Claude question option previews are shown under their option (pingdotgg#34784)
1 parent 7aaf5ce commit d8b0a05

4 files changed

Lines changed: 100 additions & 52 deletions

File tree

‎apps/mobile/src/features/threads/PendingUserInputCard.tsx‎

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ function QuestionText(props: {
8181
readonly threadId: ThreadId;
8282
readonly workspaceRoot: string | null;
8383
readonly setDirection: TextDirection | undefined;
84+
readonly preserveSoftBreaks?: boolean;
8485
}) {
8586
const styles = useMarkdownPreviewStyles();
8687
const markdown = useLiveThreadLinkLabels(props.markdown, props.environmentId);
@@ -113,6 +114,7 @@ function QuestionText(props: {
113114
Platform.OS === "android" ? undefined : props.setDirection === "rtl" ? "right" : "left"
114115
}
115116
onLinkPress={openLink}
117+
preserveSoftBreaks={props.preserveSoftBreaks}
116118
/>
117119
);
118120
}
@@ -279,43 +281,56 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
279281
const description =
280282
option.description !== option.label ? option.description : undefined;
281283
return (
282-
<Pressable
283-
key={optionValue}
284-
accessibilityRole={question.multiSelect ? "checkbox" : "radio"}
285-
accessibilityState={{ checked: selected, disabled: responseDisabled }}
286-
disabled={responseDisabled}
287-
className={cn(
288-
"min-h-12 w-full rounded-2xl border px-3.5 py-3",
289-
selected ? "border-primary bg-primary/10" : "border-border bg-input",
290-
)}
291-
onPress={() =>
292-
props.onSelectOption(
293-
props.pendingUserInput.requestId,
294-
question,
295-
optionValue,
296-
)
297-
}
298-
>
299-
<View className="min-w-0 flex-1 gap-0.5">
300-
<Text
301-
className={cn(
302-
"font-t3-bold text-sm",
303-
selected ? "text-foreground" : "text-foreground-secondary",
304-
)}
305-
style={proseDirectionStyle(option.label, setDirection)}
306-
>
307-
{option.label}
308-
</Text>
309-
{description ? (
284+
<View key={optionValue} className="gap-1.5">
285+
<Pressable
286+
accessibilityRole={question.multiSelect ? "checkbox" : "radio"}
287+
accessibilityState={{ checked: selected, disabled: responseDisabled }}
288+
disabled={responseDisabled}
289+
className={cn(
290+
"min-h-12 w-full rounded-2xl border px-3.5 py-3",
291+
selected ? "border-primary bg-primary/10" : "border-border bg-input",
292+
)}
293+
onPress={() =>
294+
props.onSelectOption(
295+
props.pendingUserInput.requestId,
296+
question,
297+
optionValue,
298+
)
299+
}
300+
>
301+
<View className="min-w-0 flex-1 gap-0.5">
310302
<Text
311-
className="font-sans text-sm leading-5 text-foreground-muted"
312-
style={proseDirectionStyle(description, setDirection)}
303+
className={cn(
304+
"font-t3-bold text-sm",
305+
selected ? "text-foreground" : "text-foreground-secondary",
306+
)}
307+
style={proseDirectionStyle(option.label, setDirection)}
313308
>
314-
{description}
309+
{option.label}
315310
</Text>
316-
) : null}
317-
</View>
318-
</Pressable>
311+
{description ? (
312+
<Text
313+
className="font-sans text-sm leading-5 text-foreground-muted"
314+
style={proseDirectionStyle(description, setDirection)}
315+
>
316+
{description}
317+
</Text>
318+
) : null}
319+
</View>
320+
</Pressable>
321+
{option.preview ? (
322+
<View className="px-3.5">
323+
<QuestionText
324+
markdown={option.preview}
325+
environmentId={props.environmentId}
326+
threadId={props.threadId}
327+
workspaceRoot={props.workspaceRoot}
328+
setDirection={setDirection}
329+
preserveSoftBreaks
330+
/>
331+
</View>
332+
) : null}
333+
</View>
319334
);
320335
})}
321336
</View>

‎apps/web/src/components/chat/ComposerPendingUserInputPanel.direction.browser.test.tsx‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel";
1111
type Question = {
1212
header: string;
1313
question: string;
14-
options: { label: string; description: string }[];
14+
options: { label: string; description: string; preview?: string }[];
1515
};
1616

1717
const renderPanel = (questions: Question[], questionIndex = 0) =>
@@ -98,3 +98,25 @@ it("keeps one direction for the whole set when a single question is Hebrew", asy
9898
.element(screen.getByText("גרסה 3 (חדשה!)", { exact: true }))
9999
.toHaveStyle({ direction: "rtl" });
100100
});
101+
102+
it("shows an option's preview so the user can see what they are approving", async () => {
103+
await using screen = await renderPanel([
104+
{
105+
header: "Issue",
106+
question: "Approve this issue title and body?",
107+
options: [
108+
{
109+
label: "Approve",
110+
description: "File it as drafted.",
111+
preview: "Title: Login fails\n\nBody: A quote in the password breaks login.",
112+
},
113+
{ label: "Cancel", description: "Do not file it." },
114+
],
115+
},
116+
]);
117+
118+
await screen.getByRole("button", { name: /Approve/ }).hover();
119+
await expect
120+
.element(screen.getByText("A quote in the password breaks login.", { exact: false }))
121+
.toBeVisible();
122+
});

‎apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -310,19 +310,30 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
310310
) : null}
311311
</>
312312
);
313+
// The preview sits outside the button: it can hold links, and a click on a single-select option advances.
313314
return (
314-
<button
315-
key={`${activeQuestion.id}:${optionValue}`}
316-
type="button"
317-
aria-pressed={isSelected}
318-
disabled={disabled || isResponding}
319-
onClick={() => {
320-
handleOptionSelection(activeQuestion.id, optionValue);
321-
}}
322-
className={className}
323-
>
324-
{content}
325-
</button>
315+
<div key={`${activeQuestion.id}:${optionValue}`}>
316+
<button
317+
type="button"
318+
aria-pressed={isSelected}
319+
disabled={disabled || isResponding}
320+
onClick={() => {
321+
handleOptionSelection(activeQuestion.id, optionValue);
322+
}}
323+
className={className}
324+
>
325+
{content}
326+
</button>
327+
{option.preview ? (
328+
<ChatMarkdown
329+
text={option.preview}
330+
cwd={cwd}
331+
threadRef={threadRef}
332+
lineBreaks
333+
className="ps-9 pe-2 pb-1.5 text-xs text-foreground/70 sm:ps-8"
334+
/>
335+
) : null}
336+
</div>
326337
);
327338
})}
328339
</div>

‎apps/web/src/pendingUserInput.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ export function threadContextsReferencedByAnswer(
4242
return threadContexts.filter((record) => referencedIds.has(record.contextId));
4343
}
4444

45-
export interface PendingUserInputProgress {
45+
export interface PendingUserInputProgress<Q extends UserInputQuestion = UserInputQuestion> {
4646
questionIndex: number;
47-
activeQuestion: UserInputQuestion | null;
47+
activeQuestion: Q | null;
4848
activeDraft: PendingUserInputDraftAnswer | undefined;
4949
selectedOptionValues: ReadonlyArray<string>;
5050
customAnswer: string;
@@ -83,11 +83,11 @@ function countAnsweredPendingUserInputQuestions(
8383
}, 0);
8484
}
8585

86-
export function derivePendingUserInputProgress(
87-
questions: ReadonlyArray<UserInputQuestion>,
86+
export function derivePendingUserInputProgress<Q extends UserInputQuestion>(
87+
questions: ReadonlyArray<Q>,
8888
draftAnswers: Record<string, PendingUserInputDraftAnswer>,
8989
questionIndex: number,
90-
): PendingUserInputProgress {
90+
): PendingUserInputProgress<Q> {
9191
const normalizedQuestionIndex =
9292
questions.length === 0 ? 0 : Math.max(0, Math.min(questionIndex, questions.length - 1));
9393
const activeQuestion = questions[normalizedQuestionIndex] ?? null;

0 commit comments

Comments
 (0)