Skip to content

Commit 99df719

Browse files
authored
Report a bug in the app: the screen, Your bug reports, and Admin's list (#2815)
* Report a bug in the app: the screen, Your bug reports, Admin's list, and the record of recent failed requests * Report a bug on the generated client: the spec's shapes, one key per report, the saved state in the form's card, and the screens in a real browser * Format the bug report screens and their browser test * Run the bug report screens' browser test in CI's WebKit and Chromium job
1 parent f68b136 commit 99df719

25 files changed

Lines changed: 2630 additions & 11 deletions

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,9 @@ jobs:
585585
# calls it that, the answer sent from it closes the question, and the box goes back to "Ask
586586
# anything", wide and on a phone, light and dark.
587587
# And Audit's "Try a change" handing its action to What would happen by an all-digit handle: the
588-
# link, the page, a reload, and the bare address an older tab kept. In the image, as above:
588+
# link, the page, a reload, and the bare address an older tab kept.
589+
# And Report a bug, Your bug reports and Admin's Bug reports, wide and on a phone, light and dark,
590+
# held against Add credential and the Vault: a file taken, one refused, the report saved. In the image, as above:
589591
# WebKit's system packages are about 94 MB, which took nine minutes from the mirror on a slow day.
590592
#
591593
# The files run side by side, like the Chromium list's, but eight at a time rather than a worker
@@ -669,6 +671,7 @@ jobs:
669671
app/tests/bots-panel-start-conversation.test.tsx
670672
app/tests/browse-apps-pages.test.tsx
671673
app/tests/browse-steps-layout.test.tsx
674+
app/tests/bug-reports-layout.test.tsx
672675
app/tests/chunk-recovery.test.tsx
673676
app/tests/command-card-layout.test.tsx
674677
app/tests/component-bots-layout.test.tsx

‎app/src/components/admin/admin-sections.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
IconBrain,
3+
IconBug,
34
IconBuildingBank,
45
IconBulb,
56
IconCloudCog,
@@ -212,6 +213,14 @@ export const ADMIN_SECTIONS: readonly AdminSection[] = [
212213
icon: IconBrain,
213214
linkOptions: { to: "/admin/providers" },
214215
},
216+
{
217+
/* Every report sent with Report a bug in the organization; each person sees their own. */
218+
title: "Bug reports",
219+
description:
220+
"See the bugs people in this organization reported, and where each one stands.",
221+
icon: IconBug,
222+
linkOptions: { to: "/admin/bug-reports" },
223+
},
215224
],
216225
},
217226
];

‎app/src/components/app-sidebar/help-menu.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import {
1010
import { currentUserQueryOptions } from "@/lib/auth/queries";
1111
import { OpenBotVersion } from "../layout/openbot-version";
1212
import { DesktopAppMenuItem } from "./desktop-app-item";
13+
import { ReportBugMenuItem } from "./report-bug-item";
1314
import { TroubleshootingLogsMenuItem } from "./troubleshooting-logs-item";
1415

1516
/**
16-
* Help, in the account menu: what a person needs now and then, out of the menu's main list. Get the
17-
* desktop app (on OpenBot Cloud in a browser), Get troubleshooting logs, and the release the server
18-
* runs, so a bug report can say which one it was.
17+
* Help, in the account menu: what a person needs now and then, out of the menu's main list. Report a
18+
* bug, Get the desktop app (on OpenBot Cloud in a browser), Get troubleshooting logs, and the release
19+
* the server runs.
1920
*/
2021
export function HelpMenu({ itemClassName }: { itemClassName: string }) {
2122
return (
@@ -25,6 +26,7 @@ export function HelpMenu({ itemClassName }: { itemClassName: string }) {
2526
<span className="flex-1">Help</span>
2627
</DropdownMenuSubTrigger>
2728
<DropdownMenuSubContent className={accountSubmenuClassName}>
29+
<ReportBugMenuItem className={itemClassName} />
2830
<DesktopAppMenuItem className={itemClassName} />
2931
<TroubleshootingLogsMenuItem className={itemClassName} />
3032
<HelpVersion />
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Link, useRouterState } from "@tanstack/react-router";
2+
import { IconBug } from "@/components/icons";
3+
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
4+
5+
/**
6+
* Report a bug, in Help: opens the screen of its own, carrying the page the person was on (its path
7+
* alone, never its query), so the report can say where it happened.
8+
*/
9+
export function ReportBugMenuItem({ className }: { className?: string }) {
10+
const path = useRouterState({ select: (state) => state.location.pathname });
11+
const from = path === "/report-a-bug" ? undefined : path;
12+
return (
13+
<DropdownMenuItem
14+
className={className}
15+
render={<Link search={from ? { from } : {}} to="/report-a-bug" />}
16+
>
17+
<IconBug />
18+
Report a bug
19+
</DropdownMenuItem>
20+
);
21+
}
Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
import { useMutation } from "@tanstack/react-query";
2+
import { Link } from "@tanstack/react-router";
3+
import { useId, useRef, useState } from "react";
4+
import {
5+
IconChevronRight,
6+
IconCircleCheck,
7+
IconFileText,
8+
IconPhoto,
9+
IconX,
10+
} from "@/components/icons";
11+
import {
12+
PageCard,
13+
PageRows,
14+
PageSection,
15+
PageShell,
16+
} from "@/components/layout/page-shell";
17+
import { Button } from "@/components/ui/button";
18+
import {
19+
Field,
20+
FieldDescription,
21+
FieldError,
22+
FieldGroup,
23+
FieldLabel,
24+
} from "@/components/ui/field";
25+
import {
26+
Item,
27+
ItemActions,
28+
ItemContent,
29+
ItemDescription,
30+
ItemMedia,
31+
ItemTitle,
32+
} from "@/components/ui/item";
33+
import { Separator } from "@/components/ui/separator";
34+
import { Textarea } from "@/components/ui/textarea";
35+
import {
36+
ATTACHMENT_ACCEPT,
37+
ATTACHMENT_HINT,
38+
addAttachments,
39+
fileSize,
40+
MAX_ATTACHMENTS,
41+
} from "@/lib/bug-reports/attachments";
42+
import { idempotencyKey } from "@/lib/api/request";
43+
import {
44+
type BugReportInput,
45+
createBugReportMutationOptions,
46+
} from "@/lib/bug-reports/mutations";
47+
import { reportName } from "@/lib/bug-reports/words";
48+
import { failureSaid } from "@/lib/load-failure";
49+
import { queryClient } from "@/query-client";
50+
51+
/** The most either text field takes, as the server does. */
52+
export const MAX_TEXT = 4000;
53+
54+
/**
55+
* Report a bug: what went wrong, what the person expected, and a screenshot or a file if they have
56+
* one. Nothing else to fill in. OpenBot adds its version and the app's recent failed requests itself
57+
* (lib/bug-reports/mutations.ts), and the server adds the rest; the person never sees a log.
58+
*
59+
* Its own screen, reached from Help in the account menu with the page the person was on (`from`), so
60+
* the report can say where it happened.
61+
*/
62+
export function ReportBugPage({ from }: { from?: string }) {
63+
const create = useMutation(createBugReportMutationOptions(queryClient));
64+
const sent = create.data;
65+
return (
66+
<PageShell
67+
description="Tell the OpenBot team what went wrong, and they'll look into it."
68+
title="Report a bug"
69+
>
70+
{sent ? (
71+
/* In the card the form was in, so the answer reads as the form's own. */
72+
<PageCard
73+
footer={
74+
<>
75+
<Button onClick={() => create.reset()} variant="outline">
76+
Report another bug
77+
</Button>
78+
<Button
79+
render={(props) => (
80+
<Link
81+
{...props}
82+
params={{ reportId: sent.id }}
83+
to="/bug-reports/$reportId"
84+
/>
85+
)}
86+
>
87+
See the report
88+
</Button>
89+
</>
90+
}
91+
>
92+
<div className="flex items-start gap-3" role="status">
93+
<IconCircleCheck className="mt-0.5 size-4 shrink-0 text-success" />
94+
<div className="flex flex-col gap-1">
95+
<h2 className="font-medium text-sm">
96+
{`${reportName(sent.number)} is saved`}
97+
</h2>
98+
<p className="text-muted-foreground text-sm">
99+
The OpenBot team will look at it. You can see where it stands in
100+
Your bug reports.
101+
</p>
102+
</div>
103+
</div>
104+
</PageCard>
105+
) : (
106+
<ReportForm
107+
from={from}
108+
onSend={(input) => create.mutate(input)}
109+
error={create.error}
110+
sending={create.isPending}
111+
/>
112+
)}
113+
<PageSection>
114+
<PageRows>
115+
<Item render={<Link to="/bug-reports" />} size="sm">
116+
<ItemContent>
117+
<ItemTitle>Your bug reports</ItemTitle>
118+
<ItemDescription>
119+
See the bugs you've reported and where each one stands.
120+
</ItemDescription>
121+
</ItemContent>
122+
<ItemActions>
123+
<IconChevronRight className="size-4 text-muted-foreground" />
124+
</ItemActions>
125+
</Item>
126+
</PageRows>
127+
</PageSection>
128+
</PageShell>
129+
);
130+
}
131+
132+
function ReportForm({
133+
error,
134+
from,
135+
onSend,
136+
sending,
137+
}: {
138+
error: Error | null;
139+
from: string | undefined;
140+
onSend: (input: BugReportInput) => void;
141+
sending: boolean;
142+
}) {
143+
const ids = useId();
144+
const [whatHappened, setWhatHappened] = useState("");
145+
const [expected, setExpected] = useState("");
146+
const [files, setFiles] = useState<File[]>([]);
147+
const [refused, setRefused] = useState<string | null>(null);
148+
const [missing, setMissing] = useState(false);
149+
/*
150+
* One key for the report as it stands: pressing Send again after a send that got no answer sends
151+
* the same key, so the server makes the report once. Any change makes it another report.
152+
*/
153+
const [key, setKey] = useState(idempotencyKey);
154+
const changed = () => setKey(idempotencyKey());
155+
const picker = useRef<HTMLInputElement>(null);
156+
157+
return (
158+
<form
159+
noValidate
160+
onSubmit={(event) => {
161+
event.preventDefault();
162+
if (!whatHappened.trim()) {
163+
setMissing(true);
164+
return;
165+
}
166+
onSend({
167+
whatHappened,
168+
expected,
169+
pageUrl: from,
170+
attachments: files,
171+
idempotencyKey: key,
172+
});
173+
}}
174+
>
175+
<PageCard
176+
footer={
177+
<Button disabled={sending} type="submit">
178+
{sending ? "Sending…" : "Send report"}
179+
</Button>
180+
}
181+
>
182+
<FieldGroup>
183+
<Field data-invalid={missing || undefined}>
184+
<FieldLabel htmlFor={`${ids}-what`}>What went wrong</FieldLabel>
185+
<Textarea
186+
aria-invalid={missing || undefined}
187+
id={`${ids}-what`}
188+
maxLength={MAX_TEXT}
189+
name="whatHappened"
190+
onChange={(event) => {
191+
setWhatHappened(event.target.value);
192+
changed();
193+
if (event.target.value.trim()) setMissing(false);
194+
}}
195+
placeholder="I asked my Bot to draft an email and it stopped halfway."
196+
required
197+
rows={4}
198+
value={whatHappened}
199+
/>
200+
{missing ? <FieldError>Say what went wrong.</FieldError> : null}
201+
</Field>
202+
<Field>
203+
<FieldLabel htmlFor={`${ids}-expected`}>
204+
What did you expect
205+
</FieldLabel>
206+
<Textarea
207+
id={`${ids}-expected`}
208+
maxLength={MAX_TEXT}
209+
name="expected"
210+
onChange={(event) => {
211+
setExpected(event.target.value);
212+
changed();
213+
}}
214+
placeholder="Optional"
215+
rows={3}
216+
value={expected}
217+
/>
218+
</Field>
219+
{/*
220+
* Not marked invalid when a file is refused: that turns the whole field red, the files
221+
* already added with it. The refusal says itself, under the button.
222+
*/}
223+
<Field>
224+
<FieldLabel htmlFor={`${ids}-files`}>
225+
Add a screenshot or file
226+
</FieldLabel>
227+
<FieldDescription>{ATTACHMENT_HINT}</FieldDescription>
228+
<input
229+
accept={ATTACHMENT_ACCEPT}
230+
className="sr-only"
231+
id={`${ids}-files`}
232+
multiple
233+
onChange={(event) => {
234+
const picked = [...(event.target.files ?? [])];
235+
// The same file can be picked again after it was removed.
236+
event.target.value = "";
237+
const next = addAttachments(files, picked);
238+
setFiles(next.files);
239+
setRefused(next.refused);
240+
changed();
241+
}}
242+
ref={picker}
243+
tabIndex={-1}
244+
type="file"
245+
/>
246+
{files.length > 0 ? (
247+
<PageRows>
248+
{files.map((file, index) => (
249+
<div key={`${file.name}-${file.size}-${file.lastModified}`}>
250+
{index > 0 ? <Separator /> : null}
251+
<Item size="sm">
252+
<ItemMedia variant="icon">
253+
{file.type.startsWith("image/") ? (
254+
<IconPhoto />
255+
) : (
256+
<IconFileText />
257+
)}
258+
</ItemMedia>
259+
<ItemContent>
260+
<ItemTitle className="break-all">{file.name}</ItemTitle>
261+
<ItemDescription>{fileSize(file.size)}</ItemDescription>
262+
</ItemContent>
263+
<ItemActions>
264+
<Button
265+
aria-label={`Remove ${file.name}`}
266+
onClick={() => {
267+
setFiles(files.filter((one) => one !== file));
268+
setRefused(null);
269+
changed();
270+
}}
271+
size="icon-sm"
272+
type="button"
273+
variant="ghost"
274+
>
275+
<IconX />
276+
</Button>
277+
</ItemActions>
278+
</Item>
279+
</div>
280+
))}
281+
</PageRows>
282+
) : null}
283+
<div>
284+
<Button
285+
disabled={files.length >= MAX_ATTACHMENTS}
286+
onClick={() => picker.current?.click()}
287+
size="sm"
288+
type="button"
289+
variant="outline"
290+
>
291+
Choose a file
292+
</Button>
293+
</div>
294+
{refused ? <FieldError>{refused}</FieldError> : null}
295+
</Field>
296+
</FieldGroup>
297+
<p className="mt-6 text-muted-foreground text-sm">
298+
OpenBot adds the technical details itself, such as its version and
299+
recent errors. None of your messages are sent.
300+
</p>
301+
{error ? (
302+
<p className="mt-4 text-destructive text-sm" role="alert">
303+
{failureSaid(error)}
304+
</p>
305+
) : null}
306+
</PageCard>
307+
</form>
308+
);
309+
}

0 commit comments

Comments
 (0)