@@ -3,6 +3,7 @@ import styled from '@emotion/styled';
3
3
4
4
import { Button } from 'sentry/components/core/button' ;
5
5
import LoadingError from 'sentry/components/loadingError' ;
6
+ import type { CursorHandler } from 'sentry/components/pagination' ;
6
7
import Pagination from 'sentry/components/pagination' ;
7
8
import Placeholder from 'sentry/components/placeholder' ;
8
9
import { SimpleTable } from 'sentry/components/tables/simpleTable' ;
@@ -11,18 +12,24 @@ import AutomationTitleCell from 'sentry/components/workflowEngine/gridCell/autom
11
12
import { TimeAgoCell } from 'sentry/components/workflowEngine/gridCell/timeAgoCell' ;
12
13
import { t } from 'sentry/locale' ;
13
14
import { space } from 'sentry/styles/space' ;
15
+ import type { Automation } from 'sentry/types/workflowEngine/automations' ;
14
16
import type { Detector } from 'sentry/types/workflowEngine/detectors' ;
15
- import { useLocation } from 'sentry/utils/useLocation' ;
16
- import { useNavigate } from 'sentry/utils/useNavigate' ;
17
17
import { useAutomationsQuery } from 'sentry/views/automations/hooks' ;
18
18
import { getAutomationActions } from 'sentry/views/automations/hooks/utils' ;
19
19
20
- const AUTOMATIONS_PER_PAGE = 10 ;
20
+ const DEFAULT_AUTOMATIONS_PER_PAGE = 10 ;
21
21
22
- type Props = {
23
- automationIds : Detector [ 'workflowIds' ] ;
22
+ type Props = React . HTMLAttributes < HTMLDivElement > & {
23
+ /**
24
+ * If null, all automations will be fetched.
25
+ */
26
+ automationIds : Detector [ 'workflowIds' ] | null ;
27
+ cursor : string | undefined ;
28
+ onCursor : CursorHandler ;
24
29
connectedAutomationIds ?: Set < string > ;
25
- toggleConnected ?: ( id : string ) => void ;
30
+ emptyMessage ?: string ;
31
+ limit ?: number | null ;
32
+ toggleConnected ?: ( params : { automation : Automation } ) => void ;
26
33
} ;
27
34
28
35
function Skeletons ( { canEdit, numberOfRows} : { canEdit : boolean ; numberOfRows : number } ) {
@@ -54,12 +61,15 @@ export function ConnectedAutomationsList({
54
61
automationIds,
55
62
connectedAutomationIds,
56
63
toggleConnected,
64
+ emptyMessage = t ( 'No automations connected' ) ,
65
+ cursor,
66
+ onCursor,
67
+ limit = DEFAULT_AUTOMATIONS_PER_PAGE ,
68
+ ...props
57
69
} : Props ) {
58
70
const canEdit = Boolean (
59
71
connectedAutomationIds && typeof toggleConnected === 'function'
60
72
) ;
61
- const navigate = useNavigate ( ) ;
62
- const location = useLocation ( ) ;
63
73
64
74
const {
65
75
data : automations ,
@@ -69,16 +79,17 @@ export function ConnectedAutomationsList({
69
79
getResponseHeader,
70
80
} = useAutomationsQuery (
71
81
{
72
- ids : automationIds ,
73
- limit : AUTOMATIONS_PER_PAGE ,
74
- cursor :
75
- typeof location . query . cursor === 'string' ? location . query . cursor : undefined ,
82
+ ids : automationIds ?? undefined ,
83
+ limit : limit ?? undefined ,
84
+ cursor,
76
85
} ,
77
- { enabled : automationIds . length > 0 }
86
+ { enabled : automationIds === null || automationIds . length > 0 }
78
87
) ;
79
88
89
+ const pageLinks = getResponseHeader ?.( 'Link' ) ;
90
+
80
91
return (
81
- < Container >
92
+ < Container { ... props } >
82
93
< SimpleTableWithColumns >
83
94
< SimpleTable . Header >
84
95
< SimpleTable . HeaderCell > { t ( 'Name' ) } </ SimpleTable . HeaderCell >
@@ -93,12 +104,17 @@ export function ConnectedAutomationsList({
93
104
{ isLoading && (
94
105
< Skeletons
95
106
canEdit = { canEdit }
96
- numberOfRows = { Math . min ( automationIds . length , AUTOMATIONS_PER_PAGE ) }
107
+ numberOfRows = {
108
+ automationIds === null
109
+ ? ( limit ?? DEFAULT_AUTOMATIONS_PER_PAGE )
110
+ : Math . min ( automationIds ?. length ?? 0 , DEFAULT_AUTOMATIONS_PER_PAGE )
111
+ }
97
112
/>
98
113
) }
99
114
{ isError && < LoadingError /> }
100
- { automationIds . length === 0 && (
101
- < SimpleTable . Empty > { t ( 'No automations connected' ) } </ SimpleTable . Empty >
115
+ { ( ( isSuccess && automations . length === 0 ) ||
116
+ ( automationIds !== null && automationIds . length === 0 ) ) && (
117
+ < SimpleTable . Empty > { emptyMessage } </ SimpleTable . Empty >
102
118
) }
103
119
{ isSuccess &&
104
120
automations . map ( automation => (
@@ -117,7 +133,7 @@ export function ConnectedAutomationsList({
117
133
</ SimpleTable . RowCell >
118
134
{ canEdit && (
119
135
< SimpleTable . RowCell data-column-name = "connected" justify = "flex-end" >
120
- < Button onClick = { ( ) => toggleConnected ?.( automation . id ) } size = "sm" >
136
+ < Button onClick = { ( ) => toggleConnected ?.( { automation} ) } size = "sm" >
121
137
{ connectedAutomationIds ?. has ( automation . id )
122
138
? t ( 'Disconnect' )
123
139
: t ( 'Connect' ) }
@@ -127,18 +143,7 @@ export function ConnectedAutomationsList({
127
143
</ SimpleTable . Row >
128
144
) ) }
129
145
</ SimpleTableWithColumns >
130
- < Pagination
131
- onCursor = { cursor => {
132
- navigate ( {
133
- pathname : location . pathname ,
134
- query : {
135
- ...location . query ,
136
- cursor,
137
- } ,
138
- } ) ;
139
- } }
140
- pageLinks = { getResponseHeader ?.( 'Link' ) }
141
- />
146
+ { limit === null ? null : < Pagination onCursor = { onCursor } pageLinks = { pageLinks } /> }
142
147
</ Container >
143
148
) ;
144
149
}
0 commit comments