Skip to content

Commit 87ec424

Browse files
feat(detectors): Show HTTPSnippet on uptime forms (#101227)
We can iterate on these in the future Fixes [NEW-558: Form should show request previews](https://linear.app/getsentry/issue/NEW-558/form-should-show-request-previews)
1 parent 6da80cf commit 87ec424

File tree

1 file changed

+29
-0
lines changed
  • static/app/views/detectors/components/forms/uptime

1 file changed

+29
-0
lines changed

static/app/views/detectors/components/forms/uptime/index.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import styled from '@emotion/styled';
22

3+
import {useFormField} from 'sentry/components/workflowEngine/form/useFormField';
34
import {t} from 'sentry/locale';
45
import type {UptimeDetector} from 'sentry/types/workflowEngine/detectors';
6+
import {HTTPSnippet} from 'sentry/views/alerts/rules/uptime/httpSnippet';
57
import {AutomateSection} from 'sentry/views/detectors/components/forms/automateSection';
68
import {AssignSection} from 'sentry/views/detectors/components/forms/common/assignSection';
79
import {useSetAutomaticName} from 'sentry/views/detectors/components/forms/common/useSetAutomaticName';
@@ -15,6 +17,32 @@ import {
1517
import {UptimeRegionWarning} from 'sentry/views/detectors/components/forms/uptime/regionWarning';
1618
import {UptimeDetectorResolveSection} from 'sentry/views/detectors/components/forms/uptime/resolve';
1719

20+
const HTTP_METHODS_NO_BODY = ['GET', 'HEAD', 'OPTIONS'];
21+
22+
function ConnectedHttpSnippet() {
23+
const url = useFormField<string>('url');
24+
const method = useFormField<string>('method');
25+
const headers = useFormField<Array<[string, string]>>('headers');
26+
const body = useFormField<string>('body');
27+
const traceSampling = useFormField<boolean>('traceSampling');
28+
29+
if (!url || !method) {
30+
return null;
31+
}
32+
33+
const shouldIncludeBody = !HTTP_METHODS_NO_BODY.includes(method);
34+
35+
return (
36+
<HTTPSnippet
37+
url={url}
38+
method={method}
39+
headers={headers ?? []}
40+
body={shouldIncludeBody ? (body ?? null) : null}
41+
traceSampling={traceSampling ?? false}
42+
/>
43+
);
44+
}
45+
1846
function UptimeDetectorForm() {
1947
useSetAutomaticName(form => {
2048
const url = form.getValue('url');
@@ -38,6 +66,7 @@ function UptimeDetectorForm() {
3866
<FormStack>
3967
<UptimeRegionWarning />
4068
<UptimeDetectorFormDetectSection />
69+
<ConnectedHttpSnippet />
4170
<UptimeDetectorResolveSection />
4271
<AssignSection />
4372
<AutomateSection />

0 commit comments

Comments
 (0)