Skip to content

Commit 23e4858

Browse files
refactor: [DI-27807] - Change status of edit & delete button in alert list table based on status (linode#13052)
* refactor: [DI-27807] - Change status of edit & delete button in alert list table based on status * Added comment * Added changeset * refactor: [DI-27807] - Updated test cases
1 parent cfdac60 commit 23e4858

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/manager": Changed
3+
---
4+
5+
ACLP Alert: control `edit & delete button` based on status using flag ([#13052](https://github.com/linode/manager/pull/13052))

packages/manager/src/featureFlags.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { OCA } from './features/OneClickApps/types';
22
import type { Region } from '@linode/api-v4';
33
import type {
4+
AlertStatusType,
45
CloudPulseServiceType,
56
TPAProvider,
67
} from '@linode/api-v4/lib/profile';
@@ -141,6 +142,7 @@ interface AclpAlerting {
141142
accountAlertLimit: number;
142143
accountMetricLimit: number;
143144
alertDefinitions: boolean;
145+
editDisabledStatuses?: AlertStatusType[];
144146
notificationChannels: boolean;
145147
recentActivity: boolean;
146148
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22

33
import { ActionMenu } from 'src/components/ActionMenu/ActionMenu';
4+
import { useFlags } from 'src/hooks/useFlags';
45

56
import { getAlertTypeToActionsList } from '../Utils/AlertsActionMenu';
67

@@ -48,9 +49,19 @@ export interface AlertActionMenuProps {
4849

4950
export const AlertActionMenu = (props: AlertActionMenuProps) => {
5051
const { alertLabel, alertStatus, alertType, handlers } = props;
52+
53+
// Get the statuses to be disabled in alert action menu based on the flag etc..
54+
const { aclpAlerting } = useFlags();
55+
5156
return (
5257
<ActionMenu
53-
actionsList={getAlertTypeToActionsList(handlers, alertStatus)[alertType]}
58+
actionsList={
59+
getAlertTypeToActionsList(
60+
handlers,
61+
alertStatus,
62+
aclpAlerting?.editDisabledStatuses
63+
)[alertType]
64+
}
5465
ariaLabel={`Action menu for Alert ${alertLabel}`}
5566
/>
5667
);

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ describe('Alert Row', () => {
172172

173173
it("should disable 'Edit' action item in menu if alert has no enabled/disabled status", async () => {
174174
const alert = alertFactory.build({ status: 'in progress', type: 'user' });
175+
175176
const { getByLabelText, getByText } = renderWithTheme(
176177
<AlertTableRow
177178
alert={alert}
@@ -182,7 +183,19 @@ describe('Alert Row', () => {
182183
handleStatusChange: vi.fn(),
183184
}}
184185
services={mockServices}
185-
/>
186+
/>,
187+
{
188+
flags: {
189+
aclpAlerting: {
190+
editDisabledStatuses: ['failed', 'in progress'],
191+
accountAlertLimit: 10,
192+
accountMetricLimit: 100,
193+
alertDefinitions: true,
194+
notificationChannels: false,
195+
recentActivity: false,
196+
},
197+
},
198+
}
186199
);
187200
const ActionMenu = getByLabelText(`Action menu for Alert ${alert.label}`);
188201
await userEvent.click(ActionMenu);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export const getAlertTypeToActionsList = (
1515
handleEdit,
1616
handleStatusChange,
1717
}: ActionHandlers,
18-
alertStatus: AlertStatusType
18+
alertStatus: AlertStatusType,
19+
editDisableStatuses: AlertStatusType[] = []
1920
): Record<AlertDefinitionType, Action[]> => ({
2021
// for now there is system and user alert types, in future more alert types can be added and action items will differ according to alert types
2122
system: [
@@ -34,7 +35,7 @@ export const getAlertTypeToActionsList = (
3435
title: 'Show Details',
3536
},
3637
{
37-
disabled: alertStatus === 'in progress' || alertStatus === 'failed',
38+
disabled: editDisableStatuses.includes(alertStatus),
3839
onClick: handleEdit,
3940
title: 'Edit',
4041
},
@@ -44,7 +45,7 @@ export const getAlertTypeToActionsList = (
4445
title: getTitleForStatusChange(alertStatus),
4546
},
4647
{
47-
disabled: alertStatus === 'in progress' || alertStatus === 'failed',
48+
disabled: editDisableStatuses.includes(alertStatus),
4849
onClick: handleDelete,
4950
title: 'Delete',
5051
},

0 commit comments

Comments
 (0)