Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Changed
---

ACLP-Alerting: Notification Channel types to support API changes and backward compatibility ([#13227](https://github.com/linode/manager/pull/13227))
47 changes: 43 additions & 4 deletions packages/api-v4/src/cloudpulse/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ type AlertNotificationEmail = 'email';
type AlertNotificationSlack = 'slack';
type AlertNotificationPagerDuty = 'pagerduty';
type AlertNotificationWebHook = 'webhook';
type EmailRecipientType =
| 'admin_users'
| 'read_users'
| 'read_write_users'
| 'user';
export interface Dashboard {
created: string;
group_by?: string[];
Expand Down Expand Up @@ -298,29 +303,48 @@ interface NotificationChannelBase {

interface NotificationChannelEmail extends NotificationChannelBase {
channel_type: AlertNotificationEmail;
content: {
content?: {
email: {
email_addresses: string[];
message: string;
subject: string;
};
};
details?: {
email: {
recipient_type: EmailRecipientType;
usernames: string[];
};
};
}

interface NotificationChannelSlack extends NotificationChannelBase {
channel_type: AlertNotificationSlack;
content: {
content?: {
slack: {
message: string;
slack_channel: string;
slack_webhook_url: string;
};
};
details?: {
slack: {
slack_channel: string;
slack_webhook_url: string;
};
};
}

interface NotificationChannelPagerDuty extends NotificationChannelBase {
channel_type: AlertNotificationPagerDuty;
content: {
content?: {
pagerduty: {
attributes: string[];
description: string;
service_api_key: string;
};
};
details?: {
pagerduty: {
attributes: string[];
description: string;
Expand All @@ -330,12 +354,27 @@ interface NotificationChannelPagerDuty extends NotificationChannelBase {
}
interface NotificationChannelWebHook extends NotificationChannelBase {
channel_type: AlertNotificationWebHook;
content: {
content?: {
webhook: {
http_headers: {
header_key: string;
header_value: string;
}[];
webhook_url: string;
};
};
details?: {
webhook: {
alert_body: {
body: string;
subject: string;
};
http_headers: {
header_key: string;
header_value: string;
}[];
method: 'GET' | 'POST' | 'PUT';
request_body: string;
webhook_url: string;
};
};
Expand Down
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-13227-fixed-1767012195840.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Fixed
---

Null and Undefined checks in components and tests to support ACLP-Alerting: Notification Channel Type changes ([#13227](https://github.com/linode/manager/pull/13227))
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const isEmailContent = (
message: string;
subject: string;
};
} => 'email' in content;
} => content !== undefined && 'email' in content;
const mockProfile = profileFactory.build({
timezone: 'gmt',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Channel Listing component', () => {
it('should render the notification channels ', () => {
const emailAddresses =
mockNotificationData[0].channel_type === 'email' &&
mockNotificationData[0].content.email
mockNotificationData[0].content?.email
? mockNotificationData[0].content.email.email_addresses
: [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const mockData: NotificationChannel = notificationChannelFactory.build();
describe('RenderChannelDetails component', () => {
it('should render the email channel type notification details', () => {
const emailAddresses =
mockData.channel_type === 'email' && mockData.content.email
mockData.channel_type === 'email' && mockData.content?.email
? mockData.content.email.email_addresses
: [];
const container = renderWithTheme(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface RenderChannelDetailProps {
export const RenderChannelDetails = (props: RenderChannelDetailProps) => {
const { template } = props;
if (template.channel_type === 'email') {
return template.content.email.email_addresses.map((value, index) => (
return template.content?.email.email_addresses.map((value, index) => (
<Chip key={index} label={value} />
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,22 @@ export const getChipLabels = (
if (value.channel_type === 'email') {
return {
label: 'To',
values: value.content.email.email_addresses,
values: value.content?.email.email_addresses ?? [],
};
} else if (value.channel_type === 'slack') {
return {
label: 'Slack Webhook URL',
values: [value.content.slack.slack_webhook_url],
values: [value.content?.slack.slack_webhook_url ?? ''],
};
} else if (value.channel_type === 'pagerduty') {
return {
label: 'Service API Key',
values: [value.content.pagerduty.service_api_key],
values: [value.content?.pagerduty.service_api_key ?? ''],
};
} else {
return {
label: 'Webhook URL',
values: [value.content.webhook.webhook_url],
values: [value.content?.webhook.webhook_url ?? ''],
};
}
};
Expand Down