Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DI-23201 : Add scaffolding for new edit resource component for system alerts in CloudPulse alerting #11583

Open
wants to merge 26 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
286f9ff
upcoming: [DI-23201] - Setup action item for edit resources
venkat199501 Jan 27, 2025
e0d6a3d
upcoming: [DI-23201] - Rename methods
venkat199501 Jan 27, 2025
9b2829f
upcoming: [DI-23201] - Checkbox initial setup
venkat199501 Jan 27, 2025
dc28ce8
upcoming: [DI-23201] - Checkbox initial setup
venkat199501 Jan 27, 2025
82c3d64
upcoming: [DI-23201] - Missed commits
venkat199501 Jan 27, 2025
78ffbe3
upcoming: [DI-23201] - linting issue fixes
venkat199501 Jan 27, 2025
3752f9f
upcoming: [DI-23201] - Type setup
venkat199501 Jan 27, 2025
3755783
upcoming: [DI-23201] - Retain selections
venkat199501 Jan 28, 2025
6bc6848
Merge branch 'develop' of github.com:linode/manager into edit_default…
venkat199501 Jan 28, 2025
67789fa
upcoming: [DI-23201] - UT
venkat199501 Jan 28, 2025
697ee1f
upcoming: [DI-23201] - UT updates for utils
venkat199501 Jan 28, 2025
40afa96
Merge branch 'develop' of github.com:linode/manager into edit_default…
venkat199501 Jan 29, 2025
2318266
upcoming: [DI-22283] - UT updates
venkat199501 Jan 29, 2025
0f57bfd
DI-23201: fix issues and state updates
venkat199501 Jan 29, 2025
3e1dd5a
Merge branch 'develop' of github.com:linode/manager into edit_default…
venkat199501 Jan 29, 2025
4c7cbb1
upcoming: [DI-23201]: type fix
venkat199501 Jan 29, 2025
30555c2
upcoming: [DI-23201]: Code refactoring
venkat199501 Jan 29, 2025
4245bf9
upcoming: [DI-23201] - Method and use hook name updates
venkat199501 Jan 30, 2025
ecd75ad
upcoming: [DI-23201] - Code refactoring and changes
venkat199501 Jan 30, 2025
edda39a
upcoming: [DI-23201] - Code refactoring and changes
venkat199501 Jan 30, 2025
8180967
upcoming: [DI-23201] - Code refactoring and changes
venkat199501 Jan 30, 2025
a801f17
Added changeset: Add new `editAlertDefinition` endpoint to edit the r…
venkat199501 Jan 30, 2025
a96b345
upcoming: [DI-23201] - Changeset
venkat199501 Jan 30, 2025
2b205ab
Merge branch 'develop' of github.com:linode/manager into edit_default…
venkat199501 Jan 30, 2025
ee82fde
upcoming: [DI-23201] - Code refactoring and changes
venkat199501 Jan 30, 2025
be8e0f4
upcoming: [DI-23201] - Code refactoring and changes
venkat199501 Jan 30, 2025
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": Upcoming Features
---

Add new `editAlertDefinition` endpoint to edit the resources associated with CloudPulse alerts ([#11583](https://github.com/linode/manager/pull/11583))
15 changes: 15 additions & 0 deletions packages/api-v4/src/cloudpulse/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Alert,
AlertServiceType,
CreateAlertDefinitionPayload,
EditAlertDefinitionPayload,
NotificationChannel,
} from './types';
import { BETA_API_ROOT as API_ROOT } from '../constants';
Expand Down Expand Up @@ -50,6 +51,20 @@ export const getAlertDefinitionByServiceTypeAndId = (
setMethod('GET')
);

export const editAlertDefinition = (
data: EditAlertDefinitionPayload,
serviceType: string,
alertId: number
) =>
Request<Alert>(
setURL(
`${API_ROOT}/monitor/services/${encodeURIComponent(
serviceType
)}/alert-definitions/${encodeURIComponent(alertId)}`
),
setMethod('PUT'),
setData(data)
);
export const getNotificationChannels = (params?: Params, filters?: Filter) =>
Request<ResourcePage<NotificationChannel>>(
setURL(`${API_ROOT}/monitor/alert-channels`),
Expand Down
4 changes: 4 additions & 0 deletions packages/api-v4/src/cloudpulse/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,7 @@ export type NotificationChannel =
| NotificationChannelSlack
| NotificationChannelWebHook
| NotificationChannelPagerDuty;

export interface EditAlertDefinitionPayload {
entity_ids: string[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

Add scaffolding for new edit resource component for system alerts in CloudPulse alerts section ([#11583](https://github.com/linode/manager/pull/11583))
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { AlertDetailCriteria } from './AlertDetailCriteria';
import { AlertDetailNotification } from './AlertDetailNotification';
import { AlertDetailOverview } from './AlertDetailOverview';

interface RouteParams {
export interface AlertRouteParams {
/**
* The id of the alert for which the data needs to be shown
*/
Expand All @@ -27,7 +27,7 @@ interface RouteParams {
}

export const AlertDetail = () => {
const { alertId, serviceType } = useParams<RouteParams>();
const { alertId, serviceType } = useParams<AlertRouteParams>();

const { data: alertDetails, isError, isFetching } = useAlertDefinitionQuery(
Number(alertId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Route, Switch } from 'react-router-dom';
import { AlertDetail } from '../AlertsDetail/AlertDetail';
import { AlertListing } from '../AlertsListing/AlertListing';
import { CreateAlertDefinition } from '../CreateAlert/CreateAlertDefinition';
import { EditAlertResources } from '../EditAlert/EditAlertResources';

export const AlertDefinitionLanding = () => {
return (
Expand All @@ -19,6 +20,12 @@ export const AlertDefinitionLanding = () => {
>
<AlertDetail />
</Route>
<Route
exact
path="/monitor/alerts/definitions/edit/:serviceType/:alertId"
>
<EditAlertResources />
</Route>
<Route
component={CreateAlertDefinition}
path="/monitor/alerts/definitions/create"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export interface ActionHandlers {
* Callback for show details action
*/
handleDetails: () => void;

/**
* Callback for edit alerts action
*/
handleEdit: () => void;
}

export interface AlertActionMenuProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export const AlertListing = () => {
history.push(`${location.pathname}/detail/${serviceType}/${id}`);
};

const handleEdit = ({ id, service_type: serviceType }: Alert) => {
history.push(`${location.pathname}/edit/${serviceType}/${id}`);
};

if (alerts?.length === 0) {
return (
<Grid item xs={12}>
Expand Down Expand Up @@ -76,6 +80,7 @@ export const AlertListing = () => {
<AlertTableRow
handlers={{
handleDetails: () => handleDetails(alert),
handleEdit: () => handleEdit(alert),
}}
alert={alert}
key={alert.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('Alert Row', () => {
<AlertTableRow
handlers={{
handleDetails: vi.fn(),
handleEdit: vi.fn(),
}}
alert={alert}
/>
Expand All @@ -32,6 +33,7 @@ describe('Alert Row', () => {
<AlertTableRow
handlers={{
handleDetails: vi.fn(),
handleEdit: vi.fn(),
}}
alert={alert}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { linodeFactory, regionFactory } from 'src/factories';
import { renderWithTheme } from 'src/utilities/testHelpers';

import { AlertResources } from './AlertsResources';
import { CloudPulseResources } from '../../shared/CloudPulseResourcesSelect';

vi.mock('src/queries/cloudpulse/resources', () => ({
...vi.importActual('src/queries/cloudpulse/resources'),
Expand Down Expand Up @@ -33,6 +34,14 @@ const linodes = linodeFactory.buildList(3).map((value, index) => {

const searchPlaceholder = 'Search for a Region or Resource';
const regionPlaceholder = 'Select Regions';
const checkedAttribute = 'data-qa-checked';
const cloudPulseResources: CloudPulseResources[] = linodes.map((linode) => {
return {
id: String(linode.id),
label: linode.label,
region: linode.region,
};
});

beforeAll(() => {
window.scrollTo = vi.fn(); // mock for scrollTo and scroll
Expand All @@ -41,7 +50,7 @@ beforeAll(() => {

beforeEach(() => {
queryMocks.useResourcesQuery.mockReturnValue({
data: linodes,
data: cloudPulseResources,
isError: false,
isFetching: false,
});
Expand Down Expand Up @@ -173,4 +182,51 @@ describe('AlertResources component tests', () => {
.every((text, index) => text?.includes(linodes[index].region)) // validation
).toBe(true);
});

it('should handle selection correctly and publish', async () => {
const handleResourcesSelection = vi.fn();

const { getByTestId } = renderWithTheme(
<AlertResources
alertResourceIds={['1', '2']}
handleResourcesSelection={handleResourcesSelection}
isSelectionsNeeded
serviceType="linode"
/>
);
// validate, by default selections are there
expect(getByTestId('select_item_1')).toHaveAttribute(
checkedAttribute,
'true'
);
expect(getByTestId('select_item_3')).toHaveAttribute(
checkedAttribute,
'false'
);

// validate it selects 3
await userEvent.click(getByTestId('select_item_3'));
expect(getByTestId('select_item_3')).toHaveAttribute(
checkedAttribute,
'true'
);
expect(handleResourcesSelection).toHaveBeenCalledWith(['1', '2', '3']);

// unselect 3 and test
await userEvent.click(getByTestId('select_item_3'));
// validate it gets unselected
expect(getByTestId('select_item_3')).toHaveAttribute(
checkedAttribute,
'false'
);
expect(handleResourcesSelection).toHaveBeenLastCalledWith(['1', '2']);

// click select all
await userEvent.click(getByTestId('select_all_in_page_1'));
expect(handleResourcesSelection).toHaveBeenLastCalledWith(['1', '2', '3']);

// click select all again to unselect all
await userEvent.click(getByTestId('select_all_in_page_1'));
expect(handleResourcesSelection).toHaveBeenLastCalledWith([]);
});
});
Loading