Skip to content

Commit 0c11781

Browse files
JonasBaandrewshie-sentry
authored andcommitted
Reapply "admin: drop deprecated usage od DropdownActions (#89197)" (#89342)
Lets see where acceptance flakes
1 parent bbfb471 commit 0c11781

8 files changed

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

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';
74
import {IconNot} from 'sentry/icons';
85
import {space} from 'sentry/styles/space';
96

107
import {openAdminConfirmModal} from 'admin/components/adminConfirmationModal';
118

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-
369
type Props = {
3710
actions: Array<{
3811
key: string;
@@ -48,20 +21,44 @@ type Props = {
4821
label?: string;
4922
};
5023

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+
}
5936

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+
}
6353

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) {
6562
return;
6663
}
6764

@@ -83,41 +80,15 @@ function DropdownActions({actions, label}: Props) {
8380
onConfirm: action.onAction,
8481
});
8582
}}
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+
/>
12085
);
12186
}
12287

12388
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: 12 additions & 13 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';
56
import ExternalLink from 'sentry/components/links/externalLink';
67
import {space} from 'sentry/styles/space';
78

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

@@ -37,18 +37,17 @@ const getRow = ({row, policy, onUpdate}: RowProps) => {
3737
<br />
3838
</td>,
3939
<td key="actions" data-test-id="revision-actions">
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-
/>
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>
5251
</td>,
5352
];
5453
};

0 commit comments

Comments
 (0)