Skip to content

Commit b026e5f

Browse files
Revert "upcoming: [DI-29113] - Support for User Channel Details in Alert flow…" (#13252)
This reverts commit e77c677.
1 parent e77c677 commit b026e5f

File tree

14 files changed

+51
-173
lines changed

14 files changed

+51
-173
lines changed

packages/api-v4/.changeset/pr-13246-changed-1767779941145.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,14 @@ export interface Alert {
282282
updated_by: string;
283283
}
284284

285-
interface NotificationChannelAlertInfo {
286-
alert_count: number;
285+
interface NotificationChannelAlerts {
286+
id: number;
287+
label: string;
287288
type: 'alerts-definitions';
288289
url: string;
289290
}
290291
interface NotificationChannelBase {
291-
alerts: NotificationChannelAlertInfo;
292+
alerts: NotificationChannelAlerts[];
292293
channel_type: ChannelType;
293294
created: string;
294295
created_by: string;

packages/manager/.changeset/pr-13246-added-1767776466714.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ const notificationChannels = notificationChannelFactory
4141
.buildList(26)
4242
.map((ch, i) => {
4343
const isEmail = i % 2 === 0;
44-
const alerts = {
45-
alert_count: isEmail ? 5 : 3,
46-
url: `monitor/alert-channels/${i + 1}/alerts`,
44+
const alerts = Array.from({ length: isEmail ? 5 : 3 }).map((_, idx) => ({
45+
id: idx + 1,
46+
label: `Alert-${idx + 1}`,
4747
type: 'alerts-definitions',
48-
};
48+
url: 'Sample',
49+
}));
4950

5051
if (isEmail) {
5152
return {
@@ -146,7 +147,7 @@ const VerifyChannelSortingParams = (
146147
);
147148

148149
const order = sortOrderMap[sortOrder];
149-
const orderBy = encodeURIComponent(LabelLookup[columnLabel]);
150+
const orderBy = LabelLookup[columnLabel];
150151

151152
cy.url().should(
152153
'endWith',
@@ -214,7 +215,16 @@ describe('Notification Channel Listing Page', () => {
214215
}
215216

216217
// Alerts list
217-
expect(item.alerts.alert_count).to.eq(expected.alerts.alert_count);
218+
expect(item.alerts.length).to.eq(expected.alerts.length);
219+
220+
item.alerts.forEach((alert, aIndex) => {
221+
const expAlert = expected.alerts[aIndex];
222+
223+
expect(alert.id).to.eq(expAlert.id);
224+
expect(alert.label).to.eq(expAlert.label);
225+
expect(alert.type).to.eq(expAlert.type);
226+
expect(alert.url).to.eq(expAlert.url);
227+
});
218228
});
219229
});
220230
});
@@ -244,9 +254,7 @@ describe('Notification Channel Listing Page', () => {
244254

245255
cy.wrap($row).within(() => {
246256
cy.findByText(expected.label).should('be.visible');
247-
cy.findByText(String(expected.alerts.alert_count)).should(
248-
'be.visible'
249-
);
257+
cy.findByText(String(expected.alerts.length)).should('be.visible');
250258
cy.findByText('Email').should('be.visible');
251259
cy.get('td').eq(3).should('have.text', expected.created_by);
252260
cy.findByText(
@@ -276,20 +284,11 @@ describe('Notification Channel Listing Page', () => {
276284
{
277285
column: 'Alerts',
278286
ascending: [...notificationChannels]
279-
.sort(
280-
// Primary sort by `alert_count`. When two items have the same
281-
// alert count, fall back to `a.id - b.id` as a deterministic
282-
// tie-breaker so test expectations remain stable.
283-
(a, b) => a.alerts.alert_count - b.alerts.alert_count
284-
)
287+
.sort((a, b) => a.alerts.length - b.alerts.length)
285288
.map((ch) => ch.id),
286289

287290
descending: [...notificationChannels]
288-
.sort(
289-
// Primary sort by `alert_count` (desc). Tie-break with `a.id - b.id`
290-
// to keep ordering deterministic for assertions.
291-
(a, b) => b.alerts.alert_count - a.alerts.alert_count
292-
)
291+
.sort((a, b) => b.alerts.length - a.alerts.length)
293292
.map((ch) => ch.id),
294293
},
295294

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import type { NotificationChannel } from '@linode/api-v4';
44

55
export const notificationChannelFactory =
66
Factory.Sync.makeFactory<NotificationChannel>({
7-
alerts: {
8-
type: 'alerts-definitions',
9-
alert_count: 1,
10-
url: 'monitor/alert-channels/{id}/alerts',
11-
},
7+
alerts: [
8+
{
9+
id: Number(Factory.each((i) => i)),
10+
label: String(Factory.each((id) => `Alert-${id}`)),
11+
type: 'alerts-definitions',
12+
url: 'Sample',
13+
},
14+
],
1215
channel_type: 'email',
1316
content: {
1417
email: {
Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { screen } from '@testing-library/react';
21
import * as React from 'react';
32

43
import { notificationChannelFactory } from 'src/factories/cloudpulse/channels';
@@ -22,21 +21,4 @@ describe('RenderChannelDetails component', () => {
2221
expect(container.getByText(emailAddresses[0])).toBeVisible();
2322
expect(container.getByText(emailAddresses[1])).toBeVisible();
2423
});
25-
it('should render the email channel with usernames if details is present', () => {
26-
const usernames = ['user1', 'user2'];
27-
const mockDataWithDetails: NotificationChannel =
28-
notificationChannelFactory.build({
29-
channel_type: 'email',
30-
content: {},
31-
details: {
32-
email: {
33-
usernames,
34-
recipient_type: 'user',
35-
},
36-
},
37-
});
38-
renderWithTheme(<RenderChannelDetails template={mockDataWithDetails} />);
39-
expect(screen.getByText(usernames[0])).toBeVisible();
40-
expect(screen.getByText(usernames[1])).toBeVisible();
41-
});
4224
});
Lines changed: 3 additions & 17 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,21 +12,9 @@ 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);
20-
21-
const recipients = useContents
22-
? (contentEmail?.email_addresses ?? [])
23-
: (detailEmail?.usernames ?? []);
24-
25-
return (
26-
<>
27-
{recipients.map((value) => (
28-
<Chip key={value} label={value} />
29-
))}
30-
</>
31-
);
15+
return template.content?.email.email_addresses.map((value, index) => (
16+
<Chip key={index} label={value} />
17+
));
3218
}
3319
return null;
3420
};

packages/manager/src/features/CloudPulse/Alerts/NotificationChannels/NotificationsChannelsListing/NotificationChannelListTable.test.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { NotificationChannelListTable } from './NotificationChannelListTable';
1010

1111
const mockScrollToElement = vi.fn();
1212

13+
const ALERT_TYPE = 'alerts-definitions';
14+
1315
describe('NotificationChannelListTable', () => {
1416
it('should render the notification channel table headers', () => {
1517
renderWithTheme(
@@ -125,7 +127,11 @@ describe('NotificationChannelListTable', () => {
125127

126128
it('should display correct alerts count', () => {
127129
const channel = notificationChannelFactory.build({
128-
alerts: { alert_count: 3 },
130+
alerts: [
131+
{ id: 1, label: 'Alert 1', type: ALERT_TYPE, url: 'url1' },
132+
{ id: 2, label: 'Alert 2', type: ALERT_TYPE, url: 'url2' },
133+
{ id: 3, label: 'Alert 3', type: ALERT_TYPE, url: 'url3' },
134+
],
129135
});
130136

131137
renderWithTheme(

packages/manager/src/features/CloudPulse/Alerts/NotificationChannels/NotificationsChannelsListing/NotificationChannelTableRow.test.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ describe('NotificationChannelTableRow', () => {
1818
it('should render a notification channel row with all fields', () => {
1919
const updated = new Date().toISOString();
2020
const channel = notificationChannelFactory.build({
21-
alerts: {
22-
type: 'alerts-definitions',
23-
alert_count: 2,
24-
url: 'monitor/alert-channels/{id}/alerts',
25-
},
21+
alerts: [
22+
{ id: 1, label: 'Alert 1', type: 'alerts-definitions', url: 'url1' },
23+
{ id: 2, label: 'Alert 2', type: 'alerts-definitions', url: 'url2' },
24+
],
2625
channel_type: 'email',
2726
created_by: 'user1',
2827
label: 'Test Channel',
@@ -143,7 +142,7 @@ describe('NotificationChannelTableRow', () => {
143142

144143
it('should render zero alerts count when no alerts are associated', () => {
145144
const channel = notificationChannelFactory.build({
146-
alerts: { alert_count: 0 },
145+
alerts: [],
147146
});
148147

149148
renderWithTheme(

packages/manager/src/features/CloudPulse/Alerts/NotificationChannels/NotificationsChannelsListing/NotificationChannelTableRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const NotificationChannelTableRow = (
5252
{label}
5353
</Link>
5454
</TableCell>
55-
<TableCell>{alerts.alert_count}</TableCell>
55+
<TableCell>{alerts.length}</TableCell>
5656
<TableCell>{channelTypeMap[channel_type]}</TableCell>
5757
<TableCell>{created_by}</TableCell>
5858
<TableCell>

0 commit comments

Comments
 (0)