1
1
/* eslint-disable no-alert */
2
2
import { Fragment } from 'react' ;
3
- import styled from '@emotion/styled' ;
4
3
5
4
import { Flex } from 'sentry/components/container/flex' ;
6
5
import { Button } from 'sentry/components/core/button' ;
7
6
import { LinkButton } from 'sentry/components/core/button/linkButton' ;
8
7
import { DateTime } from 'sentry/components/dateTime' ;
9
8
import { KeyValueTable , KeyValueTableRow } from 'sentry/components/keyValueTable' ;
9
+ import LoadingError from 'sentry/components/loadingError' ;
10
+ import LoadingIndicator from 'sentry/components/loadingIndicator' ;
10
11
import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle' ;
11
12
import TimeSince from 'sentry/components/timeSince' ;
12
13
import { ActionsProvider } from 'sentry/components/workflowEngine/layout/actions' ;
@@ -15,79 +16,45 @@ import DetailLayout from 'sentry/components/workflowEngine/layout/detail';
15
16
import Section from 'sentry/components/workflowEngine/ui/section' ;
16
17
import { useWorkflowEngineFeatureGate } from 'sentry/components/workflowEngine/useWorkflowEngineFeatureGate' ;
17
18
import { IconEdit } from 'sentry/icons' ;
18
- import { t } from 'sentry/locale' ;
19
+ import { t , tct } from 'sentry/locale' ;
19
20
import { space } from 'sentry/styles/space' ;
21
+ import type { Detector } from 'sentry/types/workflowEngine/detectors' ;
22
+ import getDuration from 'sentry/utils/duration/getDuration' ;
20
23
import useOrganization from 'sentry/utils/useOrganization' ;
24
+ import { useParams } from 'sentry/utils/useParams' ;
21
25
import AutomationHistoryList from 'sentry/views/automations/components/automationHistoryList' ;
22
- import ConditionsPanel from 'sentry/views/automations/components/conditionsPanel' ;
23
26
import ConnectedMonitorsList from 'sentry/views/automations/components/connectedMonitorsList' ;
27
+ import { useAutomationQuery } from 'sentry/views/automations/hooks' ;
24
28
import { makeAutomationBasePathname } from 'sentry/views/automations/pathnames' ;
25
-
26
- function HistoryAndConnectedMonitors ( ) {
27
- return (
28
- < div >
29
- < Section title = { t ( 'History' ) } >
30
- < AutomationHistoryList history = { [ ] } />
31
- </ Section >
32
- < Section title = { t ( 'Connected Monitors' ) } >
33
- < ConnectedMonitorsList monitors = { [ ] } />
34
- </ Section >
35
- </ div >
36
- ) ;
37
- }
38
-
39
- function Details ( ) {
40
- return (
41
- < Flex column gap = { space ( 3 ) } >
42
- < Flex column gap = { space ( 1 ) } >
43
- < SectionHeading > { t ( 'Last Triggered' ) } </ SectionHeading >
44
- < span >
45
- < TimeSince date = { new Date ( ) } />
46
- </ span >
47
- </ Flex >
48
- < Flex column gap = { space ( 1 ) } >
49
- < SectionHeading > { t ( 'Conditions' ) } </ SectionHeading >
50
- < ConditionsPanel
51
- when_conditions = { [
52
- t ( 'An issue escalates' ) ,
53
- t ( 'A new event is captured for an issue' ) ,
54
- ] }
55
- if_conditions = { [
56
- t ( 'Issue is assigned to no one' ) ,
57
- t ( 'Current issue priority is high' ) ,
58
- ] }
59
- actions = { [
60
- t (
61
- 'Notify Suggested Assignees and if none can be found then notify Recently Active Members'
62
- ) ,
63
- ] }
64
- />
65
- </ Flex >
66
- < Flex column gap = { space ( 1 ) } >
67
- < SectionHeading > { t ( 'Details' ) } </ SectionHeading >
68
- < KeyValueTable >
69
- < KeyValueTableRow
70
- keyName = { t ( 'Date created' ) }
71
- value = { < DateTime date = { new Date ( ) } dateOnly year /> }
72
- />
73
- < KeyValueTableRow keyName = { t ( 'Created by' ) } value = "Jane Doe" />
74
- < KeyValueTableRow
75
- keyName = { t ( 'Last modified' ) }
76
- value = { < TimeSince date = { new Date ( ) } /> }
77
- />
78
- < KeyValueTableRow keyName = { t ( 'Team' ) } value = "Platform" />
79
- </ KeyValueTable >
80
- </ Flex >
81
- </ Flex >
82
- ) ;
83
- }
29
+ import { useDetectorQueriesByIds } from 'sentry/views/detectors/hooks' ;
84
30
85
31
export default function AutomationDetail ( ) {
86
32
const organization = useOrganization ( ) ;
87
33
useWorkflowEngineFeatureGate ( { redirect : true } ) ;
34
+ const params = useParams < { automationId : string } > ( ) ;
35
+
36
+ const {
37
+ data : automation ,
38
+ isPending,
39
+ isError,
40
+ refetch,
41
+ } = useAutomationQuery ( params . automationId ) ;
42
+
43
+ const detectorsQuery = useDetectorQueriesByIds ( automation ?. detectorIds || [ ] ) ;
44
+ const detectors = detectorsQuery
45
+ . map ( result => result . data )
46
+ . filter ( ( detector ) : detector is Detector => detector !== undefined ) ;
47
+
48
+ if ( isPending ) {
49
+ return < LoadingIndicator /> ;
50
+ }
51
+
52
+ if ( isError ) {
53
+ return < LoadingError onRetry = { refetch } /> ;
54
+ }
88
55
89
56
return (
90
- < SentryDocumentTitle title = { t ( 'Automation' ) } noSuffix >
57
+ < SentryDocumentTitle title = { automation . name } noSuffix >
91
58
< BreadcrumbsProvider
92
59
crumb = { {
93
60
label : t ( 'Automations' ) ,
@@ -97,10 +64,47 @@ export default function AutomationDetail() {
97
64
< ActionsProvider actions = { < Actions /> } >
98
65
< DetailLayout >
99
66
< DetailLayout . Main >
100
- < HistoryAndConnectedMonitors />
67
+ < Section title = { t ( 'History' ) } >
68
+ < AutomationHistoryList history = { [ ] } />
69
+ </ Section >
70
+ < Section title = { t ( 'Connected Monitors' ) } >
71
+ < ConnectedMonitorsList monitors = { detectors } />
72
+ </ Section >
101
73
</ DetailLayout . Main >
102
74
< DetailLayout . Sidebar >
103
- < Details />
75
+ < Section title = { t ( 'Last Triggered' ) } >
76
+ { automation . lastTriggered ? (
77
+ < Flex gap = { space ( 1 ) } >
78
+ < TimeSince date = { automation . lastTriggered } />
79
+ < Flex >
80
+ (< DateTime date = { automation . lastTriggered } year timeZone /> )
81
+ </ Flex >
82
+ </ Flex >
83
+ ) : (
84
+ t ( 'Never' )
85
+ ) }
86
+ </ Section >
87
+ < Section title = { t ( 'Environment' ) } >
88
+ { automation . environment || t ( 'All environments' ) }
89
+ </ Section >
90
+ < Section title = { t ( 'Action Interval' ) } >
91
+ { tct ( 'Every [frequency]' , {
92
+ frequency : getDuration ( ( automation . config . frequency || 0 ) * 60 ) ,
93
+ } ) }
94
+ </ Section >
95
+ < Section title = { t ( 'Details' ) } >
96
+ < KeyValueTable >
97
+ < KeyValueTableRow
98
+ keyName = { t ( 'Date created' ) }
99
+ value = { < DateTime date = { automation . dateCreated } dateOnly year /> }
100
+ />
101
+ < KeyValueTableRow keyName = { t ( 'Created by' ) } value = "placeholder" />
102
+ < KeyValueTableRow
103
+ keyName = { t ( 'Last modified' ) }
104
+ value = { < TimeSince date = { automation . dateUpdated } /> }
105
+ />
106
+ </ KeyValueTable >
107
+ </ Section >
104
108
</ DetailLayout . Sidebar >
105
109
</ DetailLayout >
106
110
</ ActionsProvider >
@@ -124,8 +128,3 @@ function Actions() {
124
128
</ Fragment >
125
129
) ;
126
130
}
127
-
128
- const SectionHeading = styled ( 'h4' ) `
129
- font-size: ${ p => p . theme . fontSizeMedium } ;
130
- margin: 0;
131
- ` ;
0 commit comments