Skip to content

Commit 1d5d5f9

Browse files
Revert "Reapply "admin: drop deprecated usage od DropdownActions (#89197)" (#89342)"
This reverts commit ed99062. Co-authored-by: JonasBa <9317857+JonasBa@users.noreply.github.com>
1 parent ed99062 commit 1d5d5f9

8 files changed

+249
-167
lines changed

static/gsAdmin/components/dropdownActions.tsx

Lines changed: 74 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
1+
import {css} from '@emotion/react';
12
import styled from '@emotion/styled';
23

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';
47
import {IconNot} from 'sentry/icons';
58
import {space} from 'sentry/styles/space';
69

710
import {openAdminConfirmModal} from 'admin/components/adminConfirmationModal';
811

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+
936
type Props = {
1037
actions: Array<{
1138
key: string;
@@ -21,44 +48,20 @@ type Props = {
2148
label?: string;
2249
};
2350

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-
5451
function DropdownActions({actions, label}: Props) {
5552
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) {
6265
return;
6366
}
6467

@@ -80,15 +83,41 @@ function DropdownActions({actions, label}: Props) {
8083
onConfirm: action.onAction,
8184
});
8285
}}
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>
85120
);
86121
}
87122

88123
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-
`;

static/gsAdmin/components/policies/policyRevisions.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import styled from '@emotion/styled';
22
import moment from 'moment-timezone';
33

44
import {Tag} from 'sentry/components/core/badge/tag';
5-
import {Button} from 'sentry/components/core/button';
65
import ExternalLink from 'sentry/components/links/externalLink';
76
import {space} from 'sentry/styles/space';
87

8+
import DropdownActions from 'admin/components/dropdownActions';
99
import ResultGrid from 'admin/components/resultGrid';
1010
import type {Policy, PolicyRevision} from 'getsentry/types';
1111

@@ -37,17 +37,18 @@ const getRow = ({row, policy, onUpdate}: RowProps) => {
3737
<br />
3838
</td>,
3939
<td key="actions" data-test-id="revision-actions">
40-
<Button
41-
title={
42-
policy.version === row.version
43-
? 'This is already the current version'
44-
: 'Make this the active version of this policy.'
45-
}
46-
disabled={policy.version === row.version}
47-
onClick={() => onUpdate({current: true}, row.version)}
48-
>
49-
Make current
50-
</Button>
40+
<DropdownActions
41+
actions={[
42+
{
43+
key: 'make-current',
44+
name: 'Make current',
45+
help: 'Make this the active version of this policy.',
46+
skipConfirmModal: true,
47+
disabled: policy.version === row.version,
48+
onAction: () => onUpdate({current: true}, row.version),
49+
},
50+
]}
51+
/>
5152
</td>,
5253
];
5354
};

0 commit comments

Comments
 (0)