1
- import { css } from '@emotion/react' ;
2
1
import styled from '@emotion/styled' ;
3
2
4
- import DropdownAutoComplete from 'sentry/components/dropdownAutoComplete' ;
5
- import DropdownButton from 'sentry/components/dropdownButton' ;
6
- import { Tooltip } from 'sentry/components/tooltip' ;
3
+ import { CompactSelect , type SelectOption } from 'sentry/components/core/compactSelect' ;
7
4
import { IconNot } from 'sentry/icons' ;
8
5
import { space } from 'sentry/styles/space' ;
9
6
10
7
import { openAdminConfirmModal } from 'admin/components/adminConfirmationModal' ;
11
8
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
-
36
9
type Props = {
37
10
actions : Array < {
38
11
key : string ;
@@ -48,20 +21,44 @@ type Props = {
48
21
label ?: string ;
49
22
} ;
50
23
51
- function DropdownActions ( { actions, label} : Props ) {
52
- return (
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 ) ;
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
+ }
59
36
60
- if ( action === undefined ) {
61
- return ;
62
- }
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
+ }
63
53
64
- if ( action . disabled ) {
54
+ function DropdownActions ( { actions, label} : Props ) {
55
+ 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 ) {
65
62
return ;
66
63
}
67
64
@@ -83,41 +80,15 @@ function DropdownActions({actions, label}: Props) {
83
80
onConfirm : action . onAction ,
84
81
} ) ;
85
82
} }
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 >
83
+ triggerLabel = { label }
84
+ />
120
85
) ;
121
86
}
122
87
123
88
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