Skip to content

Commit cac8d8c

Browse files
upcoming: [DPS-41183] - Migrate content to details for Notification Channels (#13495)
* upcoming: [DPS-41183] - Migrate content to details for Notification Channels * add changesets
1 parent 6f39842 commit cac8d8c

13 files changed

Lines changed: 77 additions & 178 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/api-v4": Upcoming Features
3+
---
4+
5+
Replaced `content` with `details` in cloudpulse/types.ts for ACLP-Alerts Notification Channels ([#13495](https://github.com/linode/manager/pull/13495))

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

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type AlertNotificationEmail = 'email';
4747
type AlertNotificationSlack = 'slack';
4848
type AlertNotificationPagerDuty = 'pagerduty';
4949
type AlertNotificationWebHook = 'webhook';
50-
type EmailRecipientType =
50+
export type EmailRecipientType =
5151
| 'admin_users'
5252
| 'read_users'
5353
| 'read_write_users'
@@ -303,14 +303,7 @@ interface NotificationChannelBase {
303303

304304
interface NotificationChannelEmail extends NotificationChannelBase {
305305
channel_type: AlertNotificationEmail;
306-
content?: {
307-
email: {
308-
email_addresses: string[];
309-
message: string;
310-
subject: string;
311-
};
312-
};
313-
details?: {
306+
details: {
314307
email: {
315308
recipient_type: EmailRecipientType;
316309
usernames: string[];
@@ -320,14 +313,7 @@ interface NotificationChannelEmail extends NotificationChannelBase {
320313

321314
interface NotificationChannelSlack extends NotificationChannelBase {
322315
channel_type: AlertNotificationSlack;
323-
content?: {
324-
slack: {
325-
message: string;
326-
slack_channel: string;
327-
slack_webhook_url: string;
328-
};
329-
};
330-
details?: {
316+
details: {
331317
slack: {
332318
slack_channel: string;
333319
slack_webhook_url: string;
@@ -337,14 +323,7 @@ interface NotificationChannelSlack extends NotificationChannelBase {
337323

338324
interface NotificationChannelPagerDuty extends NotificationChannelBase {
339325
channel_type: AlertNotificationPagerDuty;
340-
content?: {
341-
pagerduty: {
342-
attributes: string[];
343-
description: string;
344-
service_api_key: string;
345-
};
346-
};
347-
details?: {
326+
details: {
348327
pagerduty: {
349328
attributes: string[];
350329
description: string;
@@ -354,16 +333,7 @@ interface NotificationChannelPagerDuty extends NotificationChannelBase {
354333
}
355334
interface NotificationChannelWebHook extends NotificationChannelBase {
356335
channel_type: AlertNotificationWebHook;
357-
content?: {
358-
webhook: {
359-
http_headers: {
360-
header_key: string;
361-
header_value: string;
362-
}[];
363-
webhook_url: string;
364-
};
365-
};
366-
details?: {
336+
details: {
367337
webhook: {
368338
alert_body: {
369339
body: string;
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+
Migrated to `details` from `content` in ACLP-Alerts Notification Channels ([#13495](https://github.com/linode/manager/pull/13495))

packages/manager/cypress/e2e/core/cloudpulse/alert-notification-channel-create.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ const notificationChannels = notificationChannelFactory.buildList(5);
3030
const createNotificationChannel = notificationChannelFactory.build({
3131
label: 'Test Channel Name',
3232
channel_type: 'email',
33-
content: {
33+
details: {
3434
email: {
35-
email_addresses: ['user1', 'user2'],
36-
message: 'You have a new Alert',
37-
subject: 'Sample Alert',
35+
usernames: ['user1', 'user2'],
3836
},
3937
},
4038
});

packages/manager/cypress/e2e/core/cloudpulse/alert-notification-channel-list.spec.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
} from 'src/features/CloudPulse/Alerts/NotificationChannels/NotificationsChannelsListing/constants';
3030
import { formatDate } from 'src/utilities/formatDate';
3131

32-
import type { NotificationChannel } from '@linode/api-v4';
32+
import type { EmailRecipientType, NotificationChannel } from '@linode/api-v4';
3333

3434
const sortOrderMap = {
3535
ascending: 'asc',
@@ -163,15 +163,14 @@ const { label: userChannelLabel, id: userChannelId } = findChannel(
163163
0 // alertsLength (0 = no alerts)
164164
);
165165

166-
const isEmailContent = (
167-
content: NotificationChannel['content']
168-
): content is {
166+
const isEmailChannel = (
167+
details: NotificationChannel['details']
168+
): details is {
169169
email: {
170-
email_addresses: string[];
171-
message: string;
172-
subject: string;
170+
recipient_type: EmailRecipientType;
171+
usernames: string[];
173172
};
174-
} => content !== undefined && 'email' in content;
173+
} => details !== undefined && 'email' in details;
175174
const mockProfile = profileFactory.build({
176175
timezone: 'gmt',
177176
});
@@ -272,15 +271,12 @@ describe('Notification Channel Listing Page', () => {
272271
expect(item.updated_by).to.eq(expected.updated_by);
273272

274273
// Email content (safe narrow)
275-
if (isEmailContent(item.content) && isEmailContent(expected.content)) {
276-
expect(item.content.email.email_addresses).to.deep.eq(
277-
expected.content.email.email_addresses
274+
if (isEmailChannel(item.details) && isEmailChannel(expected.details)) {
275+
expect(item.details.email.usernames).to.deep.eq(
276+
expected.details.email.usernames
278277
);
279-
expect(item.content.email.subject).to.eq(
280-
expected.content.email.subject
281-
);
282-
expect(item.content.email.message).to.eq(
283-
expected.content.email.message
278+
expect(item.details.email.recipient_type).to.eq(
279+
expected.details.email.recipient_type
284280
);
285281
}
286282

packages/manager/src/factories/cloudpulse/channels.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ export const notificationChannelFactory =
1212
alert_count: 1,
1313
url: 'monitor/alert-channels/{id}/alerts',
1414
},
15-
channel_type: 'email',
16-
content: {
15+
details: {
1716
email: {
18-
email_addresses: ['test@test.com', 'test2@test.com'],
19-
message: 'You have a new Alert',
20-
subject: 'Sample Alert',
17+
recipient_type: 'user',
18+
usernames: ['test@test.com', 'test2@test.com'],
2119
},
2220
},
21+
channel_type: 'email',
2322
created: new Date().toISOString(),
2423
created_by: 'user1',
2524
id: Factory.each((i) => i),

packages/manager/src/features/CloudPulse/Alerts/AlertsDetail/AlertDetailNotification.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { renderWithTheme } from 'src/utilities/testHelpers';
77
import { AlertDetailNotification } from './AlertDetailNotification';
88

99
const notificationChannels = notificationChannelFactory.buildList(3, {
10-
content: {
10+
details: {
1111
email: {
12-
email_addresses: ['1@test.com', '2@test.com'],
12+
usernames: ['1@test.com', '2@test.com'],
1313
},
1414
},
1515
});

packages/manager/src/features/CloudPulse/Alerts/CreateAlert/NotificationChannels/AddChannelListing.test.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ vi.mock('src/queries/cloudpulse/alerts', async () => {
2525
});
2626

2727
const mockNotificationData: NotificationChannel[] = [
28-
notificationChannelFactory.build({ id: 0 }),
28+
notificationChannelFactory.build({
29+
id: 0,
30+
details: {
31+
email: { usernames: ['user1', 'user2'], recipient_type: 'user' },
32+
},
33+
}),
2934
];
3035

3136
queryMocks.useAllAlertNotificationChannelsQuery.mockReturnValue({
@@ -40,8 +45,8 @@ describe('Channel Listing component', () => {
4045
it('should render the notification channels ', () => {
4146
const emailAddresses =
4247
mockNotificationData[0].channel_type === 'email' &&
43-
mockNotificationData[0].content?.email
44-
? mockNotificationData[0].content.email.email_addresses
48+
mockNotificationData[0].details?.email
49+
? mockNotificationData[0].details.email.usernames
4550
: [];
4651

4752
const { getByText } =
@@ -57,8 +62,8 @@ describe('Channel Listing component', () => {
5762
});
5863
expect(getByText('4. Notification Channels')).toBeVisible();
5964
expect(getByText(capitalize(mockNotificationData[0].label))).toBeVisible();
60-
expect(getByText(emailAddresses[0])).toBeInTheDocument();
61-
expect(getByText(emailAddresses[1])).toBeInTheDocument();
65+
expect(getByText(emailAddresses[0])).toBeVisible();
66+
expect(getByText(emailAddresses[1])).toBeVisible();
6267
});
6368

6469
it('should disable the add notification button when service type is null', () => {

packages/manager/src/features/CloudPulse/Alerts/CreateAlert/NotificationChannels/RenderChannelDetails.test.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,31 @@ import { RenderChannelDetails } from './RenderChannelDetails';
88

99
import type { NotificationChannel } from '@linode/api-v4';
1010

11-
const mockData: NotificationChannel = notificationChannelFactory.build();
11+
const mockData = notificationChannelFactory.build({
12+
details: {
13+
email: {
14+
recipient_type: 'read_write_users',
15+
usernames: [],
16+
},
17+
},
18+
});
1219

1320
describe('RenderChannelDetails component', () => {
14-
it('should render the email channel type notification details', () => {
15-
const emailAddresses =
16-
mockData.channel_type === 'email' && mockData.content?.email
17-
? mockData.content.email.email_addresses
18-
: [];
19-
const container = renderWithTheme(
21+
it('should render the email channel type notification details with recipient_type if no usernames are there', () => {
22+
const { getByText } = renderWithTheme(
2023
<RenderChannelDetails template={mockData} />
2124
);
22-
expect(container.getByText(emailAddresses[0])).toBeVisible();
23-
expect(container.getByText(emailAddresses[1])).toBeVisible();
25+
const recipientType =
26+
mockData.channel_type === 'email'
27+
? mockData.details.email.recipient_type
28+
: '';
29+
expect(getByText(recipientType)).toBeVisible();
2430
});
2531
it('should render the email channel with usernames if details is present', () => {
2632
const usernames = ['user1', 'user2'];
2733
const mockDataWithDetails: NotificationChannel =
2834
notificationChannelFactory.build({
2935
channel_type: 'email',
30-
content: {},
3136
details: {
3237
email: {
3338
usernames,

packages/manager/src/features/CloudPulse/Alerts/CreateAlert/NotificationChannels/RenderChannelDetails.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { Chip } from '@mui/material';
22
import * as React from 'react';
33

4-
import { shouldUseContentsForEmail } from '../../Utils/utils';
5-
64
import type { NotificationChannel } from '@linode/api-v4';
75

86
interface RenderChannelDetailProps {
@@ -14,14 +12,14 @@ interface RenderChannelDetailProps {
1412
export const RenderChannelDetails = (props: RenderChannelDetailProps) => {
1513
const { template } = props;
1614
if (template.channel_type === 'email') {
17-
const contentEmail = template.content?.email;
18-
const detailEmail = template.details?.email;
19-
const useContents = shouldUseContentsForEmail(template);
15+
const detailEmail = template.details.email;
2016

21-
const recipients = useContents
22-
? (contentEmail?.email_addresses ?? [])
23-
: (detailEmail?.usernames ?? []);
17+
const hasUserNames =
18+
detailEmail.recipient_type === 'user' && detailEmail.usernames.length;
2419

20+
const recipients = hasUserNames
21+
? detailEmail.usernames
22+
: [detailEmail.recipient_type];
2523
return (
2624
<>
2725
{recipients.map((value) => (

0 commit comments

Comments
 (0)