Skip to content

Commit 108f760

Browse files
fix(uptime): Make the actions menu delete button work (#76204)
1 parent 182b4c3 commit 108f760

File tree

2 files changed

+49
-14
lines changed

2 files changed

+49
-14
lines changed

static/app/views/alerts/list/rules/alertRulesList.spec.tsx

+41
Original file line numberDiff line numberDiff line change
@@ -595,4 +595,45 @@ describe('AlertRulesList', () => {
595595
expect(await screen.findByText('Auto Detected')).toBeInTheDocument();
596596
expect(await screen.findByText('Up')).toBeInTheDocument();
597597
});
598+
599+
it('deletes an uptime rule', async () => {
600+
const deletedRuleName = 'Uptime Rule';
601+
const uptimeRule = UptimeRuleFixture({owner: undefined});
602+
603+
MockApiClient.addMockResponse({
604+
url: '/organizations/org-slug/combined-rules/',
605+
headers: {Link: pageLinks},
606+
body: [{...uptimeRule, type: CombinedAlertType.UPTIME}],
607+
});
608+
609+
const {router, project, organization} = initializeOrg({organization: defaultOrg});
610+
render(<AlertRulesList />, {router, organization});
611+
renderGlobalModal();
612+
613+
const deleteMock = MockApiClient.addMockResponse({
614+
url: `/projects/${organization.slug}/${project.slug}/uptime/${uptimeRule.id}/`,
615+
method: 'DELETE',
616+
body: {},
617+
});
618+
619+
const actions = (await screen.findAllByRole('button', {name: 'Actions'}))[0];
620+
621+
// Add a new response to the mock with no rules
622+
const emptyListMock = MockApiClient.addMockResponse({
623+
url: '/organizations/org-slug/combined-rules/',
624+
headers: {Link: pageLinks},
625+
body: [],
626+
});
627+
628+
expect(
629+
screen.queryByRole('link', {name: 'Uptime Rule Auto Detected'})
630+
).toBeInTheDocument();
631+
await userEvent.click(actions);
632+
await userEvent.click(screen.getByRole('menuitemradio', {name: 'Delete'}));
633+
await userEvent.click(screen.getByRole('button', {name: 'Delete Rule'}));
634+
635+
expect(deleteMock).toHaveBeenCalledTimes(1);
636+
expect(emptyListMock).toHaveBeenCalledTimes(1);
637+
expect(screen.queryByText(deletedRuleName)).not.toBeInTheDocument();
638+
});
598639
});

static/app/views/alerts/list/rules/alertRulesList.tsx

+8-14
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import useOrganization from 'sentry/utils/useOrganization';
3333
import useRouter from 'sentry/utils/useRouter';
3434

3535
import FilterBar from '../../filterBar';
36-
import type {CombinedAlerts, CombinedMetricIssueAlerts} from '../../types';
36+
import type {CombinedAlerts} from '../../types';
3737
import {AlertRuleType, CombinedAlertType} from '../../types';
3838
import {getTeamParams, isIssueAlert} from '../../utils';
3939
import AlertHeader from '../header';
@@ -139,21 +139,15 @@ function AlertRulesList() {
139139
};
140140

141141
const handleDeleteRule = async (projectId: string, rule: CombinedAlerts) => {
142-
// TODO(davidenwang): Once we have edit apis for uptime alerts, fill this in
143-
if (rule.type === CombinedAlertType.UPTIME) {
144-
return;
145-
}
142+
const deleteEndpoints = {
143+
[CombinedAlertType.ISSUE]: `/projects/${organization.slug}/${projectId}/rules/${rule.id}/`,
144+
[CombinedAlertType.METRIC]: `/projects/${organization.slug}/${projectId}/rules/${rule.id}/`,
145+
[CombinedAlertType.UPTIME]: `/projects/${organization.slug}/${projectId}/uptime/${rule.id}/`,
146+
};
146147

147148
try {
148-
await api.requestPromise(
149-
isIssueAlert(rule)
150-
? `/projects/${organization.slug}/${projectId}/rules/${rule.id}/`
151-
: `/organizations/${organization.slug}/alert-rules/${rule.id}/`,
152-
{
153-
method: 'DELETE',
154-
}
155-
);
156-
setApiQueryData<Array<CombinedMetricIssueAlerts | null>>(
149+
await api.requestPromise(deleteEndpoints[rule.type], {method: 'DELETE'});
150+
setApiQueryData<Array<CombinedAlerts | null>>(
157151
queryClient,
158152
getAlertListQueryKey(organization.slug, location.query),
159153
data => data?.filter(r => r?.id !== rule.id && r?.type !== rule.type)

0 commit comments

Comments
 (0)