Skip to content

Commit acdf974

Browse files
upcoming: [DI-23784] - Restrict actions in alerts action menu (#11860)
## Description 📝 Restrict actions in alerts action menu based on alert status. ## Changes 🔄 - Show 'Disable' and 'Edit' button in disabled form under alert action menu if the alert status is `in progress` or `failed`. ## Target release date 🗓️ Next Release ## Preview 📷 | Before | After | | ------- | ------- | | in progress status and failed status didn't exist | ![image](https://github.com/user-attachments/assets/aac63035-5b80-4d8a-998b-5b1a90583c74) | ## How to test 🧪 ### Verification steps (How to verify changes) - Navigate to alerts under monitor tab. - Go to the action menu of any alert whose status is not 'enabled' or 'disabled', for ex- 'in progress' or 'failed'. - Verify that the action menu has 'Disable' button and 'Edit' button in disabled form. <details> <summary> Author Checklists </summary> ## As an Author, to speed up the review process, I considered 🤔 👀 Doing a self review ❔ Our [contribution guidelines](https://github.com/linode/manager/blob/develop/docs/CONTRIBUTING.md) 🤏 Splitting feature into small PRs ➕ Adding a [changeset](https://github.com/linode/manager/blob/develop/docs/CONTRIBUTING.md#writing-a-changeset) 🧪 Providing/improving test coverage 🔐 Removing all sensitive information from the code and PR description 🚩 Using a feature flag to protect the release 👣 Providing comprehensive reproduction steps 📑 Providing or updating our documentation 🕛 Scheduling a pair reviewing session 📱 Providing mobile support ♿ Providing accessibility support <br/> - [x] I have read and considered all applicable items listed above. ## As an Author, before moving this PR from Draft to Open, I confirmed ✅ - [x] All unit tests are passing - [x] TypeScript compilation succeeded without errors - [x] Code passes all linting rules </details> ---
1 parent 4a73d84 commit acdf974

File tree

9 files changed

+81
-14
lines changed

9 files changed

+81
-14
lines changed

packages/api-v4/src/cloudpulse/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type DimensionFilterOperatorType =
99
| 'startswith'
1010
| 'endswith';
1111
export type AlertDefinitionType = 'system' | 'user';
12-
export type AlertStatusType = 'enabled' | 'disabled';
12+
export type AlertStatusType = 'enabled' | 'disabled' | 'in progress' | 'failed';
1313
export type CriteriaConditionType = 'ALL';
1414
export type MetricUnitType =
1515
| 'number'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Upcoming Features
3+
---
4+
5+
Restrict enable/disable actions in alerts action menu based on alert status at `AlertsActionMenu.ts` ([#11860](https://github.com/linode/manager/pull/11860))

packages/manager/cypress/support/constants/alert.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ export const aggregationTypeMap: Record<MetricAggregationType, string> = {
4141
export const statusMap: Record<AlertStatusType, string> = {
4242
disabled: 'Disabled',
4343
enabled: 'Enabled',
44+
failed: 'Failed',
45+
'in progress': 'In Progress',
4446
};

packages/manager/src/features/CloudPulse/Alerts/AlertsListing/AlertTableRow.test.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,48 @@ describe('Alert Row', () => {
143143
await userEvent.click(ActionMenu);
144144
expect(getByText('Disable')).toBeInTheDocument();
145145
});
146+
147+
it("should disable 'Disable' action item in menu if alert has no enabled/disabled status", async () => {
148+
const alert = alertFactory.build({ status: 'in progress', type: 'user' });
149+
const { getByLabelText, getByText } = renderWithTheme(
150+
<AlertTableRow
151+
handlers={{
152+
handleDetails: vi.fn(),
153+
handleEdit: vi.fn(),
154+
handleEnableDisable: vi.fn(),
155+
}}
156+
alert={alert}
157+
services={mockServices}
158+
/>
159+
);
160+
const ActionMenu = getByLabelText(`Action menu for Alert ${alert.label}`);
161+
await userEvent.click(ActionMenu);
162+
expect(getByText('In Progress')).toBeInTheDocument();
163+
expect(getByText('Disable').closest('li')).toHaveAttribute(
164+
'aria-disabled',
165+
'true'
166+
);
167+
});
168+
169+
it("should disable 'Edit' action item in menu if alert has no enabled/disabled status", async () => {
170+
const alert = alertFactory.build({ status: 'in progress', type: 'user' });
171+
const { getByLabelText, getByText } = renderWithTheme(
172+
<AlertTableRow
173+
handlers={{
174+
handleDetails: vi.fn(),
175+
handleEdit: vi.fn(),
176+
handleEnableDisable: vi.fn(),
177+
}}
178+
alert={alert}
179+
services={mockServices}
180+
/>
181+
);
182+
const ActionMenu = getByLabelText(`Action menu for Alert ${alert.label}`);
183+
await userEvent.click(ActionMenu);
184+
expect(getByText('In Progress')).toBeInTheDocument();
185+
expect(getByText('Edit').closest('li')).toHaveAttribute(
186+
'aria-disabled',
187+
'true'
188+
);
189+
});
146190
});

packages/manager/src/features/CloudPulse/Alerts/AlertsListing/AlertTableRow.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Box } from '@linode/ui';
2-
import { capitalize } from '@linode/utilities';
32
import * as React from 'react';
43
import { useLocation } from 'react-router-dom';
54

@@ -9,11 +8,12 @@ import { TableCell } from 'src/components/TableCell';
98
import { TableRow } from 'src/components/TableRow';
109
import { formatDate } from 'src/utilities/formatDate';
1110

11+
import { alertStatusToIconStatusMap, alertStatuses } from '../constants';
1212
import { AlertActionMenu } from './AlertActionMenu';
1313

1414
import type { Item } from '../constants';
1515
import type { ActionHandlers } from './AlertActionMenu';
16-
import type { Alert, AlertServiceType, AlertStatusType } from '@linode/api-v4';
16+
import type { Alert, AlertServiceType } from '@linode/api-v4';
1717

1818
interface Props {
1919
/**
@@ -30,15 +30,6 @@ interface Props {
3030
services: Item<string, AlertServiceType>[];
3131
}
3232

33-
const getStatus = (status: AlertStatusType) => {
34-
if (status === 'enabled') {
35-
return 'active';
36-
} else if (status === 'disabled') {
37-
return 'inactive';
38-
}
39-
return 'other';
40-
};
41-
4233
export const AlertTableRow = (props: Props) => {
4334
const { alert, handlers, services } = props;
4435
const location = useLocation();
@@ -53,8 +44,11 @@ export const AlertTableRow = (props: Props) => {
5344
</TableCell>
5445
<TableCell>
5546
<Box alignItems="center" display="flex">
56-
<StatusIcon data-testid="status-icon" status={getStatus(status)} />
57-
{capitalize(status)}
47+
<StatusIcon
48+
data-testid="status-icon"
49+
status={alertStatusToIconStatusMap[status]}
50+
/>
51+
{alertStatuses[status]}
5852
</Box>
5953
</TableCell>
6054
<TableCell>

packages/manager/src/features/CloudPulse/Alerts/AlertsListing/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const statusToActionMap: Record<
3030
> = {
3131
disabled: 'Enable',
3232
enabled: 'Disable',
33+
failed: 'Disable',
34+
'in progress': 'Disable',
3335
};
3436

3537
export const AlertContextualViewTableHeaderMap: TableColumnHeader[] = [

packages/manager/src/features/CloudPulse/Alerts/Utils/AlertsActionMenu.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ export const getAlertTypeToActionsList = (
2929
title: 'Show Details',
3030
},
3131
{
32+
disabled: alertStatus === 'in progress' || alertStatus === 'failed',
3233
onClick: handleEdit,
3334
title: 'Edit',
3435
},
3536
{
37+
disabled: alertStatus === 'in progress' || alertStatus === 'failed',
3638
onClick: handleEnableDisable,
3739
title: getTitleForEnableDisable(alertStatus),
3840
},

packages/manager/src/features/CloudPulse/Alerts/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ export const severityMap: Record<AlertSeverityType, string> = {
128128
export const alertStatusToIconStatusMap: Record<AlertStatusType, Status> = {
129129
disabled: 'inactive',
130130
enabled: 'active',
131+
failed: 'error',
132+
'in progress': 'other',
131133
};
132134

133135
export const channelTypeOptions: Item<string, ChannelType>[] = [
@@ -163,6 +165,8 @@ export const dimensionOperatorTypeMap: Record<
163165
export const alertStatuses: Record<AlertStatusType, string> = {
164166
disabled: 'Disabled',
165167
enabled: 'Enabled',
168+
failed: 'Failed',
169+
'in progress': 'In Progress',
166170
};
167171

168172
export const alertStatusOptions: Item<

packages/manager/src/mocks/serverHandlers.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,6 +2524,20 @@ export const handlers = [
25242524
...defaultAlertsWithServiceType,
25252525
...alertFactory.buildList(3),
25262526
...customAlertsWithServiceType,
2527+
...alertFactory.buildList(2, {
2528+
created_by: 'user1',
2529+
service_type: 'linode',
2530+
status: 'in progress',
2531+
type: 'user',
2532+
updated_by: 'user1',
2533+
}),
2534+
...alertFactory.buildList(2, {
2535+
created_by: 'user1',
2536+
service_type: 'linode',
2537+
status: 'failed',
2538+
type: 'user',
2539+
updated_by: 'user1',
2540+
}),
25272541
];
25282542
return HttpResponse.json(makeResourcePage(alerts));
25292543
}),

0 commit comments

Comments
 (0)