1
1
import styled from '@emotion/styled' ;
2
2
3
+ import { useFormField } from 'sentry/components/workflowEngine/form/useFormField' ;
3
4
import { t } from 'sentry/locale' ;
4
5
import type { UptimeDetector } from 'sentry/types/workflowEngine/detectors' ;
6
+ import { HTTPSnippet } from 'sentry/views/alerts/rules/uptime/httpSnippet' ;
5
7
import { AutomateSection } from 'sentry/views/detectors/components/forms/automateSection' ;
6
8
import { AssignSection } from 'sentry/views/detectors/components/forms/common/assignSection' ;
7
9
import { useSetAutomaticName } from 'sentry/views/detectors/components/forms/common/useSetAutomaticName' ;
@@ -15,6 +17,32 @@ import {
15
17
import { UptimeRegionWarning } from 'sentry/views/detectors/components/forms/uptime/regionWarning' ;
16
18
import { UptimeDetectorResolveSection } from 'sentry/views/detectors/components/forms/uptime/resolve' ;
17
19
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
+
18
46
function UptimeDetectorForm ( ) {
19
47
useSetAutomaticName ( form => {
20
48
const url = form . getValue ( 'url' ) ;
@@ -38,6 +66,7 @@ function UptimeDetectorForm() {
38
66
< FormStack >
39
67
< UptimeRegionWarning />
40
68
< UptimeDetectorFormDetectSection />
69
+ < ConnectedHttpSnippet />
41
70
< UptimeDetectorResolveSection />
42
71
< AssignSection />
43
72
< AutomateSection />
0 commit comments