Skip to content

Commit 0c89563

Browse files
committed
Add "report issue" button in error component #911
1 parent 1492af8 commit 0c89563

File tree

5 files changed

+49
-37
lines changed

5 files changed

+49
-37
lines changed

browser/data-browser/src/components/CodeBlock.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export const CodeBlockStyled = styled.pre<Props>`
5959
border-radius: ${p => p.theme.radius};
6060
border: solid 1px ${p => p.theme.colors.bg2};
6161
padding: 0.3rem;
62+
min-height: 2.2rem;
63+
font-size: 0.8rem;
6264
font-family: monospace;
6365
width: 100%;
6466
overflow-x: auto;

browser/data-browser/src/components/ErrorLook.tsx

+38-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { styled, css } from 'styled-components';
44
import { FaExclamationTriangle } from 'react-icons/fa';
55
import { Column } from './Row';
66
import { CodeBlock } from './CodeBlock';
7+
import { Button } from './Button';
78

89
export const errorLookStyle = css`
910
color: ${props => props.theme.colors.alert};
@@ -20,6 +21,43 @@ export interface ErrorBlockProps {
2021
showTrace?: boolean;
2122
}
2223

24+
const githubIssueTemplate = (
25+
message,
26+
stack,
27+
) => `**Describe what you did to produce the bug**
28+
29+
## Error message
30+
\`\`\`
31+
${message}
32+
\`\`\`
33+
34+
## Stack trace
35+
\`\`\`
36+
${stack}
37+
\`\`\`
38+
`;
39+
40+
/** Returns github URL for new bugs */
41+
export function createGithubIssueLink(error: Error): string {
42+
const url = new URL(
43+
'https://github.com/atomicdata-dev/atomic-server/issues/new',
44+
);
45+
url.searchParams.set('body', githubIssueTemplate(error.message, error.stack));
46+
url.searchParams.set('labels', 'bug');
47+
48+
console.log('opening', url);
49+
50+
return url.href;
51+
}
52+
53+
export function GitHubIssueButton({ error }) {
54+
return (
55+
<Button onClick={() => window.open(createGithubIssueLink(error), '_blank')}>
56+
Report on Github
57+
</Button>
58+
);
59+
}
60+
2361
export function ErrorBlock({ error, showTrace }: ErrorBlockProps): JSX.Element {
2462
return (
2563
<ErrorLookBig>
@@ -48,14 +86,6 @@ const ErrorLookBig = styled.div`
4886
background-color: ${p => p.theme.colors.bg};
4987
`;
5088

51-
const Pre = styled.pre`
52-
white-space: pre-wrap;
53-
border-radius: ${p => p.theme.radius};
54-
padding: ${p => p.theme.margin}rem;
55-
background-color: ${p => p.theme.colors.bg};
56-
font-size: 0.9rem;
57-
`;
58-
5989
const BiggerText = styled.p`
6090
color: ${p => p.theme.colors.alert};
6191
font-size: 1.3rem;

browser/data-browser/src/routes/DataRoute.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function Data(): JSX.Element {
5959
setTextResponseLoading(true);
6060

6161
try {
62-
const resp = await window.fetch(subject!, { headers: headers });
62+
const resp = await fetch(subject!, { headers: headers });
6363
const body = await resp.text();
6464
setTextResponseLoading(false);
6565
setTextResponse(body);

browser/data-browser/src/views/CrashPage.tsx

+6-27
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import * as React from 'react';
22
import { Resource } from '@tomic/react';
33

44
import { ContainerWide } from '../components/Containers';
5-
import { ErrorBlock } from '../components/ErrorLook';
5+
import {
6+
createGithubIssueLink,
7+
ErrorBlock,
8+
GitHubIssueButton,
9+
} from '../components/ErrorLook';
610
import { Button } from '../components/Button';
711
import { Column, Row } from '../components/Row';
812

@@ -14,32 +18,6 @@ type ErrorPageProps = {
1418
clearError: () => void;
1519
};
1620

17-
const githubIssueTemplate = (
18-
message,
19-
stack,
20-
) => `**Describe what you did to produce the bug**
21-
22-
## Error message
23-
\`\`\`
24-
${message}
25-
\`\`\`
26-
27-
## Stack trace
28-
\`\`\`
29-
${stack}
30-
\`\`\`
31-
`;
32-
33-
function createGithubIssueLink(error: Error): string {
34-
const url = new URL(
35-
'https://github.com/atomicdata-dev/atomic-data-browser/issues/new',
36-
);
37-
url.searchParams.set('body', githubIssueTemplate(error.message, error.stack));
38-
url.searchParams.set('labels', 'bug');
39-
40-
return url.href;
41-
}
42-
4321
/** If the entire app crashes, show this page */
4422
function CrashPage({
4523
resource,
@@ -53,6 +31,7 @@ function CrashPage({
5331
{children ? children : <ErrorBlock error={error} showTrace />}
5432
<Row>
5533
<a href={createGithubIssueLink(error)}>Create Github issue</a>
34+
<GitHubIssueButton error={error} />
5635
{clearError && <Button onClick={clearError}>Clear error</Button>}
5736
<Button
5837
onClick={() =>

browser/data-browser/src/views/ErrorPage.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { isUnauthorized, useStore } from '@tomic/react';
33
import { ContainerWide } from '../components/Containers';
4-
import { ErrorBlock } from '../components/ErrorLook';
4+
import { ErrorBlock, GitHubIssueButton } from '../components/ErrorLook';
55
import { Button } from '../components/Button';
66
import { useSettings } from '../helpers/AppSettings';
77
import { ResourcePageProps } from './ResourcePage';
@@ -63,6 +63,7 @@ function ErrorPage({ resource }: ResourcePageProps): JSX.Element {
6363
<h1>Could not open {resource.subject}</h1>
6464
<ErrorBlock error={resource.error!} showTrace />
6565
<Row>
66+
<GitHubIssueButton error={resource.error} />
6667
<Button
6768
onClick={() =>
6869
store.fetchResourceFromServer(subject, { setLoading: true })

0 commit comments

Comments
 (0)