From 6fa8b24ff1a368002b4c8ab5f92261392b39f7d9 Mon Sep 17 00:00:00 2001 From: ankitaakamai Date: Tue, 13 Jan 2026 10:38:13 +0530 Subject: [PATCH 1/8] upcoming: [DI-29177] - Remove account/region alerts from update linode payload --- .../ContextualView/AlertInformationActionTable.tsx | 12 +++++++++--- .../manager/src/features/CloudPulse/Utils/utils.ts | 9 +++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx b/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx index a8968c2b6f2..7e3f734c338 100644 --- a/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx +++ b/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx @@ -157,6 +157,9 @@ export const AlertInformationActionTable = ( resetToInitialState, } = useContextualAlertsState(alerts, entityId); + const isAccountOrRegionAlert = (alert: Alert) => + alert.scope === 'region' || alert.scope === 'account'; + // Mutation to update alerts as per service type const updateAlerts = useAlertsMutation(serviceType, entityId ?? ''); @@ -325,9 +328,12 @@ export const AlertInformationActionTable = ( if (!(isEditMode || isCreateMode)) { return null; } - const status = enabledAlerts[ - payloadAlertType(alert) - ]?.includes(alert.id); + // If alert is account or region level, enable it by default and if it is entity type alert, check if it is enabled for that entity + const status = + isAccountOrRegionAlert(alert) || + enabledAlerts[payloadAlertType(alert)]?.includes( + alert.id + ); return ( { - const isAccountOrRegion = - alert.scope === 'region' || alert.scope === 'account'; - - // include alerts which has either account or region level scope or entityId is present in the alert's entity_ids + // include alerts for which entityId is present in the alert's entity_ids const shouldInclude = entityId - ? isAccountOrRegion || alert.entity_ids.includes(entityId) - : isAccountOrRegion; + ? alert.entity_ids.includes(entityId) + : false; if (shouldInclude) { const payloadAlertType = From b872fa7061185dd4d45fb6c6178a8a2539689784 Mon Sep 17 00:00:00 2001 From: ankitaakamai Date: Tue, 13 Jan 2026 11:30:34 +0530 Subject: [PATCH 2/8] upcoming: [DI-29177] - Add tc --- .../AlertInformationActionTable.test.tsx | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.test.tsx b/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.test.tsx index e1191701576..ca42245978a 100644 --- a/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.test.tsx +++ b/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.test.tsx @@ -13,6 +13,18 @@ import type { TableColumnHeader, } from './AlertInformationActionTable'; +const mockUpdateAlerts = vi.fn(); + +vi.mock('src/queries/cloudpulse/useAlertsMutation', async () => { + const actual = await vi.importActual( + 'src/queries/cloudpulse/useAlertsMutation' + ); + return { + ...actual, + useAlertsMutation: () => mockUpdateAlerts, + }; +}); + const serviceType = 'linode'; const entityId = '123'; const entityName = 'test-instance'; @@ -22,6 +34,27 @@ const alerts = [ service_type: serviceType, status: 'enabled', }), + alertFactory.build({ + id: 9, + entity_ids: [], + service_type: serviceType, + type: 'user', + scope: 'entity', + }), + alertFactory.build({ + id: 10, + entity_ids: [], + service_type: serviceType, + type: 'user', + scope: 'account', + }), + alertFactory.build({ + id: 11, + entity_ids: [], + service_type: serviceType, + type: 'user', + scope: 'region', + }), ]; const columns: TableColumnHeader[] = [ { columnName: 'Alert Name', label: 'label' }, @@ -39,6 +72,11 @@ const props: AlertInformationActionTableProps = { }; describe('Alert Listing Reusable Table for contextual view', () => { + beforeEach(() => { + mockUpdateAlerts.mockClear(); + mockUpdateAlerts.mockResolvedValue({}); + }); + it('Should render alert table', async () => { renderWithTheme(); @@ -112,4 +150,24 @@ describe('Alert Listing Reusable Table for contextual view', () => { const saveButton = screen.getByTestId('save-alerts'); expect(saveButton).toBeDisabled(); }); + + it('Should send correct payload to the API when save button is clicked in edit mode', async () => { + renderWithTheme(); + + // Toggle entity-level user alert with ID 2 to enable it + const userAlertRow = await screen.findByTestId('9'); + await userEvent.click(await within(userAlertRow).findByRole('checkbox')); + + const saveButton = screen.getByTestId('save-alerts'); + expect(saveButton).not.toBeDisabled(); + await userEvent.click(saveButton); + + // Verify that account and region level alerts are not included in the payload + expect(mockUpdateAlerts).toHaveBeenCalledWith({ + alerts: { + system_alerts: [1, 2, 3, 4, 5, 6, 7], + user_alerts: [9], + }, + }); + }); }); From b59452fab22c3d9bc3e4e5be65bcaba85b40a66d Mon Sep 17 00:00:00 2001 From: ankitaakamai Date: Tue, 13 Jan 2026 11:43:01 +0530 Subject: [PATCH 3/8] upcoming: [DI-29177] - Update tc --- .../src/features/CloudPulse/Alerts/Utils/utils.test.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/manager/src/features/CloudPulse/Alerts/Utils/utils.test.ts b/packages/manager/src/features/CloudPulse/Alerts/Utils/utils.test.ts index e7a229816fc..8cf5887e41e 100644 --- a/packages/manager/src/features/CloudPulse/Alerts/Utils/utils.test.ts +++ b/packages/manager/src/features/CloudPulse/Alerts/Utils/utils.test.ts @@ -258,7 +258,7 @@ describe('useContextualAlertsState', () => { }); }); - it('should include alerts that match entityId or account/region level alerts in initial states', () => { + it('should include alerts that match entityId in initial states', () => { const entityId = '123'; const alerts = [ alertFactory.build({ @@ -275,13 +275,6 @@ describe('useContextualAlertsState', () => { entity_ids: [entityId], scope: 'entity', }), - alertFactory.build({ - id: 3, - label: 'alert3', - type: 'system', - entity_ids: ['456'], - scope: 'region', - }), ]; const { result } = renderHook(() => @@ -289,7 +282,6 @@ describe('useContextualAlertsState', () => { ); expect(result.current.initialState.system_alerts).toContain(1); - expect(result.current.initialState.system_alerts).toContain(3); expect(result.current.initialState.user_alerts).toContain(2); }); From 80d28784e5d1db3294c6bc0497d756419e8e6903 Mon Sep 17 00:00:00 2001 From: ankitaakamai Date: Wed, 14 Jan 2026 09:42:32 +0530 Subject: [PATCH 4/8] upcoming: [DI-29177] - Update payload for create flow --- .../ContextualView/AlertInformationActionTable.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx b/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx index 7e3f734c338..c2912efc57b 100644 --- a/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx +++ b/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx @@ -166,7 +166,18 @@ export const AlertInformationActionTable = ( React.useEffect(() => { // To send initial state of alerts through toggle handler function (For Create Flow) if (!isEditMode && onToggleAlert) { - onToggleAlert(enabledAlerts); + const accountOrRegionAlerts = alerts.filter((alert) => + isAccountOrRegionAlert(alert) + ); + const payload: CloudPulseAlertsPayload = { + system_alerts: accountOrRegionAlerts + .filter((alert) => alert.type === 'system') + .map((alert) => alert.id), + user_alerts: accountOrRegionAlerts + .filter((alert) => alert.type === 'user') + .map((alert) => alert.id), + }; + onToggleAlert(payload); } return () => { From 1a706251ca8546c2ed2fe1162c843f419fdca8fe Mon Sep 17 00:00:00 2001 From: ankitaakamai Date: Wed, 14 Jan 2026 09:46:46 +0530 Subject: [PATCH 5/8] Revert "upcoming: [DI-29177] - Update payload for create flow" This reverts commit 122d252b8fb7b76b10be52067c89c3d38cef6824. --- .../ContextualView/AlertInformationActionTable.tsx | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx b/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx index c2912efc57b..7e3f734c338 100644 --- a/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx +++ b/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx @@ -166,18 +166,7 @@ export const AlertInformationActionTable = ( React.useEffect(() => { // To send initial state of alerts through toggle handler function (For Create Flow) if (!isEditMode && onToggleAlert) { - const accountOrRegionAlerts = alerts.filter((alert) => - isAccountOrRegionAlert(alert) - ); - const payload: CloudPulseAlertsPayload = { - system_alerts: accountOrRegionAlerts - .filter((alert) => alert.type === 'system') - .map((alert) => alert.id), - user_alerts: accountOrRegionAlerts - .filter((alert) => alert.type === 'user') - .map((alert) => alert.id), - }; - onToggleAlert(payload); + onToggleAlert(enabledAlerts); } return () => { From e5e51bdc8a12d8818b328dc9a1cbcde9657605cd Mon Sep 17 00:00:00 2001 From: ankitaakamai Date: Wed, 14 Jan 2026 10:05:02 +0530 Subject: [PATCH 6/8] upcoming: [DI-29177] - Initial payload for account and region alerts isnt required --- .../Alerts/ContextualView/AlertInformationActionTable.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx b/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx index 7e3f734c338..72943787c88 100644 --- a/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx +++ b/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx @@ -164,11 +164,6 @@ export const AlertInformationActionTable = ( const updateAlerts = useAlertsMutation(serviceType, entityId ?? ''); React.useEffect(() => { - // To send initial state of alerts through toggle handler function (For Create Flow) - if (!isEditMode && onToggleAlert) { - onToggleAlert(enabledAlerts); - } - return () => { // Cleanup on unmount (For Edit flow) if (isEditMode && onToggleAlert) { From 8f458d5949c7a7d74a0abce01929c092db9f27af Mon Sep 17 00:00:00 2001 From: ankitaakamai Date: Wed, 14 Jan 2026 17:14:21 +0530 Subject: [PATCH 7/8] upcoming: [DI-29177] - Remove immediate state --- .../ContextualView/AlertInformationActionTable.tsx | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx b/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx index 72943787c88..bb8c301df1e 100644 --- a/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx +++ b/packages/manager/src/features/CloudPulse/Alerts/ContextualView/AlertInformationActionTable.tsx @@ -149,13 +149,8 @@ export const AlertInformationActionTable = ( const payloadAlertType = (alert: Alert) => alert.type === 'system' ? 'system_alerts' : 'user_alerts'; - const { - enabledAlerts, - setEnabledAlerts, - hasUnsavedChanges, - initialState, - resetToInitialState, - } = useContextualAlertsState(alerts, entityId); + const { enabledAlerts, setEnabledAlerts, hasUnsavedChanges, initialState } = + useContextualAlertsState(alerts, entityId); const isAccountOrRegionAlert = (alert: Alert) => alert.scope === 'region' || alert.scope === 'account'; @@ -193,8 +188,7 @@ export const AlertInformationActionTable = ( enqueueSnackbar('Your settings for alerts have been saved.', { variant: 'success', }); - // Reset the state to sync with the updated alerts from API - resetToInitialState(); + onToggleAlert?.({}, false); invalidateAclpAlerts(queryClient, serviceType, entityId, payload); }) .catch(() => { @@ -207,7 +201,7 @@ export const AlertInformationActionTable = ( setIsDialogOpen(false); }); }, - [updateAlerts, enqueueSnackbar, resetToInitialState] + [updateAlerts, enqueueSnackbar, onToggleAlert] ); const handleToggleAlert = React.useCallback( From b365f6169a7b9e8a4d2696d39673ad658acaabc8 Mon Sep 17 00:00:00 2001 From: ankitaakamai Date: Wed, 21 Jan 2026 17:41:55 +0530 Subject: [PATCH 8/8] upcoming: [DI-29177] - Add changeset --- .../.changeset/pr-13301-upcoming-features-1768997478204.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/manager/.changeset/pr-13301-upcoming-features-1768997478204.md diff --git a/packages/manager/.changeset/pr-13301-upcoming-features-1768997478204.md b/packages/manager/.changeset/pr-13301-upcoming-features-1768997478204.md new file mode 100644 index 00000000000..b2ac5efb976 --- /dev/null +++ b/packages/manager/.changeset/pr-13301-upcoming-features-1768997478204.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Upcoming Features +--- + +CloudPulse-Alerts: Exclude account/region alerts in api payload while updating alerts for a linode and fix state reset issue on save ([#13301](https://github.com/linode/manager/pull/13301))