@@ -4,27 +4,33 @@ import {flattie} from 'flattie';
4
4
5
5
import { Flex } from 'sentry/components/container/flex' ;
6
6
import { Button } from 'sentry/components/core/button' ;
7
+ import { LinkButton } from 'sentry/components/core/button/linkButton' ;
7
8
import SelectField from 'sentry/components/forms/fields/selectField' ;
8
9
import Form from 'sentry/components/forms/form' ;
9
10
import FormModel from 'sentry/components/forms/model' ;
11
+ import useDrawer from 'sentry/components/globalDrawer' ;
12
+ import { DrawerBody , DrawerHeader } from 'sentry/components/globalDrawer/components' ;
10
13
import { useDocumentTitle } from 'sentry/components/sentryDocumentTitle' ;
11
14
import { DebugForm } from 'sentry/components/workflowEngine/form/debug' ;
12
15
import { Card } from 'sentry/components/workflowEngine/ui/card' ;
13
16
import { IconAdd , IconEdit } from 'sentry/icons' ;
14
17
import { t } from 'sentry/locale' ;
15
18
import { space } from 'sentry/styles/space' ;
16
19
import type { Detector } from 'sentry/types/workflowEngine/detectors' ;
20
+ import useOrganization from 'sentry/utils/useOrganization' ;
17
21
import AutomationBuilder from 'sentry/views/automations/components/automationBuilder' ;
18
22
import {
19
23
AutomationBuilderContext ,
20
24
initialAutomationBuilderState ,
21
25
useAutomationBuilderReducer ,
22
26
} from 'sentry/views/automations/components/automationBuilderContext' ;
23
27
import ConnectedMonitorsList from 'sentry/views/automations/components/connectedMonitorsList' ;
28
+ import EditConnectedMonitors from 'sentry/views/automations/components/editConnectedMonitors' ;
24
29
import {
25
30
NEW_AUTOMATION_CONNECTED_IDS_KEY ,
26
31
useConnectedIds ,
27
32
} from 'sentry/views/automations/hooks/utils' ;
33
+ import { makeMonitorBasePathname } from 'sentry/views/detectors/pathnames' ;
28
34
29
35
const FREQUENCY_OPTIONS = [
30
36
{ value : '5' , label : t ( '5 minutes' ) } ,
@@ -39,6 +45,7 @@ const FREQUENCY_OPTIONS = [
39
45
] ;
40
46
41
47
export default function AutomationForm ( ) {
48
+ const organization = useOrganization ( ) ;
42
49
const title = useDocumentTitle ( ) ;
43
50
const { state, actions} = useAutomationBuilderReducer ( ) ;
44
51
const [ model ] = useState ( ( ) => new FormModel ( ) ) ;
@@ -48,11 +55,34 @@ export default function AutomationForm() {
48
55
} , [ title , model ] ) ;
49
56
50
57
const monitors : Detector [ ] = [ ] ; // TODO: Fetch monitors from API
58
+ const storageKey = NEW_AUTOMATION_CONNECTED_IDS_KEY ; // TODO: use automation id for storage key when editing an existing automation
51
59
const { connectedIds, toggleConnected} = useConnectedIds ( {
52
- storageKey : NEW_AUTOMATION_CONNECTED_IDS_KEY ,
60
+ storageKey,
53
61
} ) ;
54
62
const connectedMonitors = monitors . filter ( monitor => connectedIds . has ( monitor . id ) ) ;
55
63
64
+ const { openDrawer : openEditMonitorsDrawer , isDrawerOpen : isEditMonitorsDrawerOpen } =
65
+ useDrawer ( ) ;
66
+
67
+ const showEditMonitorsDrawer = ( ) => {
68
+ if ( ! isEditMonitorsDrawerOpen ) {
69
+ openEditMonitorsDrawer (
70
+ ( ) => (
71
+ < div >
72
+ < DrawerHeader />
73
+ < DrawerBody >
74
+ < EditConnectedMonitors storageKey = { storageKey } />
75
+ </ DrawerBody >
76
+ </ div >
77
+ ) ,
78
+ {
79
+ ariaLabel : 'Edit Monitors Drawer' ,
80
+ drawerKey : 'edit-monitors-drawer' ,
81
+ }
82
+ ) ;
83
+ }
84
+ } ;
85
+
56
86
return (
57
87
< Form
58
88
hideFooter
@@ -69,8 +99,15 @@ export default function AutomationForm() {
69
99
toggleConnected = { toggleConnected }
70
100
/>
71
101
< ButtonWrapper justify = "space-between" >
72
- < Button icon = { < IconAdd /> } > { t ( 'Create New Monitor' ) } </ Button >
73
- < Button icon = { < IconEdit /> } > { t ( 'Edit Monitors' ) } </ Button >
102
+ < LinkButton
103
+ icon = { < IconAdd /> }
104
+ to = { `${ makeMonitorBasePathname ( organization . slug ) } new/` }
105
+ >
106
+ { t ( 'Create New Monitor' ) }
107
+ </ LinkButton >
108
+ < Button icon = { < IconEdit /> } onClick = { showEditMonitorsDrawer } >
109
+ { t ( 'Edit Monitors' ) }
110
+ </ Button >
74
111
</ ButtonWrapper >
75
112
</ Card >
76
113
< Card >
0 commit comments