1
+ import { css } from '@emotion/react' ;
1
2
import styled from '@emotion/styled' ;
2
3
3
- import { CompactSelect , type SelectOption } from 'sentry/components/core/compactSelect' ;
4
+ import DropdownAutoComplete from 'sentry/components/dropdownAutoComplete' ;
5
+ import DropdownButton from 'sentry/components/dropdownButton' ;
6
+ import { Tooltip } from 'sentry/components/tooltip' ;
4
7
import { IconNot } from 'sentry/icons' ;
5
8
import { space } from 'sentry/styles/space' ;
6
9
7
10
import { openAdminConfirmModal } from 'admin/components/adminConfirmationModal' ;
8
11
12
+ const ActionName = styled ( 'div' ) `
13
+ display: flex;
14
+ align-items: center;
15
+ gap: ${ space ( 0.5 ) } ;
16
+ ` ;
17
+
18
+ const ActionLabel = styled ( 'div' ) < { isDisabled : boolean } > `
19
+ width: 350px;
20
+ ${ p =>
21
+ p . isDisabled &&
22
+ css `
23
+ color : ${ p . theme . subText } ;
24
+ svg {
25
+ color : ${ p . theme . red200 } ;
26
+ }
27
+ ` }
28
+ ` ;
29
+
30
+ const HelpText = styled ( 'div' ) `
31
+ font-size: ${ p => p . theme . fontSizeSmall } ;
32
+ color: ${ p => p . theme . subText } ;
33
+ line-height: 1.2;
34
+ ` ;
35
+
9
36
type Props = {
10
37
actions : Array < {
11
38
key : string ;
@@ -21,44 +48,20 @@ type Props = {
21
48
label ?: string ;
22
49
} ;
23
50
24
- /**
25
- * Map actions to a format that can be used by the CompactSelect component. This exists
26
- * because this used a component with a different signature, and I
27
- */
28
- function mapActionsToCompactSelect (
29
- actions : Props [ 'actions' ]
30
- ) : Array < SelectOption < string > > {
31
- return actions
32
- . map ( action => {
33
- if ( action . visible === false ) {
34
- return null ;
35
- }
36
-
37
- return {
38
- value : action . key ,
39
- label : (
40
- < div >
41
- { action . name }
42
- < StyledIconNot size = "xs" />
43
- </ div >
44
- ) ,
45
- details : action . help ,
46
- disabled : action . disabled ,
47
- tooltip : action . disabled ? action . disabledReason : undefined ,
48
- help : action . help ,
49
- } ;
50
- } )
51
- . filter ( Boolean ) as Array < SelectOption < string > > ;
52
- }
53
-
54
51
function DropdownActions ( { actions, label} : Props ) {
55
52
return (
56
- < CompactSelect
57
- searchable
58
- options = { mapActionsToCompactSelect ( actions ) }
59
- onChange = { option => {
60
- const action = actions . find ( a => a . key === option . value ) ;
61
- if ( ! action || action . disabled ) {
53
+ < DropdownAutoComplete
54
+ alignMenu = "right"
55
+ searchPlaceholder = "Filter actions"
56
+ noResultsMessage = "No actions match your filter"
57
+ onSelect = { ( { value} ) => {
58
+ const action = actions . find ( a => a . key === value ) ;
59
+
60
+ if ( action === undefined ) {
61
+ return ;
62
+ }
63
+
64
+ if ( action . disabled ) {
62
65
return ;
63
66
}
64
67
@@ -80,15 +83,41 @@ function DropdownActions({actions, label}: Props) {
80
83
onConfirm : action . onAction ,
81
84
} ) ;
82
85
} }
83
- triggerLabel = { label }
84
- />
86
+ items = { actions
87
+ . filter ( action => action . visible !== false )
88
+ . map ( action => {
89
+ const actionLabel = (
90
+ < ActionLabel
91
+ data-test-id = { `action-${ action . key } ` }
92
+ isDisabled = { ! ! action . disabled }
93
+ aria-disabled = { ! ! action . disabled }
94
+ >
95
+ < ActionName >
96
+ { action . name }
97
+ { action . disabled && (
98
+ < Tooltip skipWrapper title = { action . disabledReason } >
99
+ < IconNot size = "xs" data-test-id = "icon-not" />
100
+ </ Tooltip >
101
+ ) }
102
+ </ ActionName >
103
+ { action . help && < HelpText > { action . help } </ HelpText > }
104
+ </ ActionLabel >
105
+ ) ;
106
+
107
+ return {
108
+ value : action . key ,
109
+ searchKey : action . name ,
110
+ label : actionLabel ,
111
+ } ;
112
+ } ) }
113
+ >
114
+ { ( { isOpen} ) => (
115
+ < DropdownButton data-test-id = "detail-actions" size = "sm" isOpen = { isOpen } >
116
+ { label }
117
+ </ DropdownButton >
118
+ ) }
119
+ </ DropdownAutoComplete >
85
120
) ;
86
121
}
87
122
88
123
export default DropdownActions ;
89
-
90
- const StyledIconNot = styled ( IconNot ) `
91
- color: ${ p => p . theme . red200 } ;
92
- margin-left: ${ space ( 0.5 ) } ;
93
- transform: translateY(2px);
94
- ` ;
0 commit comments