-
Notifications
You must be signed in to change notification settings - Fork 367
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
upcoming: [DI-22217] - Added the Alert Listing page with Alerting Table and added relevant api endpoints #11346
Merged
jaalah-akamai
merged 12 commits into
linode:develop
from
santoshp210-akamai:feature/list-alert-definition-landing-page
Dec 10, 2024
+380
β19
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
875f278
upcoming: [DI-22217] - Added AlertListing component With Table headerβ¦
santoshp210-akamai 65c0a6d
upcoming : [DI-22217] - Added the TableRowError and TableRowLoading fβ¦
santoshp210-akamai 80389f5
upcoming: [DI-22217] - Added changesets
santoshp210-akamai 34acc0a
upcoming: [DI-22217] - Review changes: Improving AlertListing test caβ¦
santoshp210-akamai af30200
upcoming: [DI-22217] - Removed unused import
santoshp210-akamai 5766503
upcoming: [DI-22217] - Review changes: Removed redundant checks, remoβ¦
santoshp210-akamai 07fb774
upcoming: [DI-22217] - Restructured the alert queries
santoshp210-akamai 0e44318
upcoming: [DI-22217] - Review changes: Added a TableRowLabelMap for tβ¦
santoshp210-akamai 22c408c
upcoming: [DI-22217] - fixed eslint error
santoshp210-akamai b610948
upcoming: [DI-22217] - Minor styling changes and fixed failing tests
santoshp210-akamai 087f86a
upcoming: [DI-22217] - minor changes: changed the key when mapping ovβ¦
santoshp210-akamai 291fadb
Merge pull request #40 from linode/develop
santoshp210-akamai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/api-v4": Changed | ||
--- | ||
|
||
Type of `AlertDefinitionType` to `'system'|'user'` ([#11346](https://github.com/linode/manager/pull/11346)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Added | ||
--- | ||
|
||
AlertListing component and AlertTableRow component with Unit Tests ([#11346](https://github.com/linode/manager/pull/11346)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 3 additions & 11 deletions
14
packages/manager/src/features/CloudPulse/Alerts/AlertsLanding/AlertsDefinitionLanding.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,21 @@ | ||
import { Paper, Typography } from '@linode/ui'; | ||
import * as React from 'react'; | ||
import { Route, Switch } from 'react-router-dom'; | ||
|
||
import { AlertListing } from '../AlertsListing/AlertListing'; | ||
import { CreateAlertDefinition } from '../CreateAlert/CreateAlertDefinition'; | ||
|
||
export const AlertDefinitionLanding = () => { | ||
return ( | ||
<Switch> | ||
<Route | ||
component={AlertDefinition} | ||
component={AlertListing} | ||
exact | ||
path="/monitor/alerts/definitions" | ||
/> | ||
<Route | ||
component={() => <CreateAlertDefinition />} | ||
component={CreateAlertDefinition} | ||
path="/monitor/alerts/definitions/create" | ||
/> | ||
</Switch> | ||
); | ||
}; | ||
|
||
const AlertDefinition = () => { | ||
return ( | ||
<Paper> | ||
<Typography variant="body1">Alert Definition</Typography> | ||
</Paper> | ||
); | ||
}; |
36 changes: 36 additions & 0 deletions
36
packages/manager/src/features/CloudPulse/Alerts/AlertsListing/AlertActionMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as React from 'react'; | ||
|
||
import { ActionMenu } from 'src/components/ActionMenu/ActionMenu'; | ||
|
||
import type { AlertDefinitionType } from '@linode/api-v4'; | ||
|
||
export interface ActionHandlers { | ||
// These handlers will be enhanced based on the alert type and actions required | ||
/** | ||
* Callback for delete action | ||
*/ | ||
handleDelete: () => void; | ||
|
||
/** | ||
* Callback for show details action | ||
*/ | ||
handleDetails: () => void; | ||
} | ||
|
||
export interface AlertActionMenuProps { | ||
/** | ||
* Type of the alert | ||
*/ | ||
alertType?: AlertDefinitionType; | ||
/** | ||
* Handlers for alert actions like delete, show details etc., | ||
*/ | ||
handlers?: ActionHandlers; | ||
} | ||
|
||
/** | ||
* The handlers and alertType are made optional only temporarily, they will be enabled but they are dependent on another feature which will be part of next PR | ||
*/ | ||
export const AlertActionMenu = () => { | ||
return <ActionMenu actionsList={[]} ariaLabel={'Action menu for Alert'} />; | ||
}; |
62 changes: 62 additions & 0 deletions
62
packages/manager/src/features/CloudPulse/Alerts/AlertsListing/AlertListing.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as React from 'react'; | ||
|
||
import { alertFactory } from 'src/factories/cloudpulse/alerts'; | ||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { AlertListing } from './AlertListing'; | ||
|
||
const queryMocks = vi.hoisted(() => ({ | ||
useAllAlertDefinitionsQuery: vi.fn().mockReturnValue({}), | ||
})); | ||
|
||
vi.mock('src/queries/cloudpulse/alerts', async () => { | ||
const actual = await vi.importActual('src/queries/cloudpulse/alerts'); | ||
return { | ||
...actual, | ||
useAllAlertDefinitionsQuery: queryMocks.useAllAlertDefinitionsQuery, | ||
}; | ||
}); | ||
|
||
const mockResponse = alertFactory.buildList(3); | ||
|
||
describe('Alert Listing', () => { | ||
it('should render the error message', async () => { | ||
queryMocks.useAllAlertDefinitionsQuery.mockReturnValue({ | ||
data: undefined, | ||
error: 'an error happened', | ||
isError: true, | ||
isLoading: false, | ||
}); | ||
const { getAllByText } = renderWithTheme(<AlertListing />); | ||
getAllByText('Error in fetching the alerts.'); | ||
}); | ||
|
||
it('should render the alert landing table with items', async () => { | ||
queryMocks.useAllAlertDefinitionsQuery.mockReturnValue({ | ||
data: mockResponse, | ||
isError: false, | ||
isLoading: false, | ||
status: 'success', | ||
}); | ||
const { getByText } = renderWithTheme(<AlertListing />); | ||
expect(getByText('Alert Name')).toBeInTheDocument(); | ||
expect(getByText('Service')).toBeInTheDocument(); | ||
expect(getByText('Status')).toBeInTheDocument(); | ||
expect(getByText('Last Modified')).toBeInTheDocument(); | ||
expect(getByText('Created By')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the alert row', async () => { | ||
queryMocks.useAllAlertDefinitionsQuery.mockReturnValue({ | ||
data: mockResponse, | ||
isError: false, | ||
isLoading: false, | ||
status: 'success', | ||
}); | ||
|
||
const { getByText } = renderWithTheme(<AlertListing />); | ||
expect(getByText(mockResponse[0].label)).toBeInTheDocument(); | ||
expect(getByText(mockResponse[1].label)).toBeInTheDocument(); | ||
expect(getByText(mockResponse[2].label)).toBeInTheDocument(); | ||
}); | ||
}); |
72 changes: 72 additions & 0 deletions
72
packages/manager/src/features/CloudPulse/Alerts/AlertsListing/AlertListing.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Paper } from '@linode/ui'; | ||
import { Grid } from '@mui/material'; | ||
import React from 'react'; | ||
|
||
import { Table } from 'src/components/Table'; | ||
import { TableBody } from 'src/components/TableBody'; | ||
import { TableCell } from 'src/components/TableCell'; | ||
import { TableHead } from 'src/components/TableHead'; | ||
import { TableRow } from 'src/components/TableRow'; | ||
import { TableRowError } from 'src/components/TableRowError/TableRowError'; | ||
import { TableRowLoading } from 'src/components/TableRowLoading/TableRowLoading'; | ||
import { TableSortCell } from 'src/components/TableSortCell'; | ||
import { StyledPlaceholder } from 'src/features/StackScripts/StackScriptBase/StackScriptBase.styles'; | ||
import { useAllAlertDefinitionsQuery } from 'src/queries/cloudpulse/alerts'; | ||
|
||
import { AlertTableRow } from './AlertTableRow'; | ||
import { AlertListingTableLabelMap } from './constants'; | ||
|
||
export const AlertListing = () => { | ||
// These are dummy order value and handleOrder methods, will replace them in the next PR | ||
const order = 'asc'; | ||
const handleOrderChange = () => { | ||
return 'asc'; | ||
}; | ||
const { data: alerts, isError, isLoading } = useAllAlertDefinitionsQuery(); | ||
if (alerts?.length === 0) { | ||
return ( | ||
<Grid item xs={12}> | ||
<Paper> | ||
<StyledPlaceholder | ||
subtitle="Start Monitoring your resources." | ||
title="" | ||
/> | ||
</Paper> | ||
</Grid> | ||
); | ||
} | ||
return ( | ||
<Grid marginTop={2}> | ||
<Table colCount={7} size="small"> | ||
<TableHead> | ||
<TableRow> | ||
{AlertListingTableLabelMap.map((value) => ( | ||
<TableSortCell | ||
active={true} | ||
direction={order} | ||
handleClick={handleOrderChange} | ||
key={value.label} | ||
label={value.label} | ||
> | ||
{value.colName} | ||
</TableSortCell> | ||
))} | ||
<TableCell actionCell /> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{isError && ( | ||
<TableRowError | ||
colSpan={7} | ||
message={'Error in fetching the alerts.'} | ||
/> | ||
)} | ||
{isLoading && <TableRowLoading columns={7} />} | ||
{alerts?.map((alert) => ( | ||
<AlertTableRow alert={alert} key={alert.id} /> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</Grid> | ||
); | ||
}; |
29 changes: 29 additions & 0 deletions
29
packages/manager/src/features/CloudPulse/Alerts/AlertsListing/AlertTableRow.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as React from 'react'; | ||
|
||
import { alertFactory } from 'src/factories/cloudpulse/alerts'; | ||
import { capitalize } from 'src/utilities/capitalize'; | ||
import { renderWithTheme, wrapWithTableBody } from 'src/utilities/testHelpers'; | ||
|
||
import { AlertTableRow } from './AlertTableRow'; | ||
|
||
describe('Alert Row', () => { | ||
it('should render an alert row', async () => { | ||
const alert = alertFactory.build(); | ||
const renderedAlert = <AlertTableRow alert={alert} />; | ||
const { getByText } = renderWithTheme(wrapWithTableBody(renderedAlert)); | ||
expect(getByText(alert.label)).toBeVisible(); | ||
}); | ||
|
||
/** | ||
* As of now the styling for the status 'enabled' is decided, in the future if they decide on the | ||
other styles possible status values, will update them and test them accordingly. | ||
*/ | ||
it('should render the status field in green color if status is enabled', () => { | ||
const statusValue = 'enabled'; | ||
const alert = alertFactory.build({ status: statusValue }); | ||
const renderedAlert = <AlertTableRow alert={alert} />; | ||
const { getByText } = renderWithTheme(wrapWithTableBody(renderedAlert)); | ||
const statusElement = getByText(capitalize(statusValue)); | ||
expect(getComputedStyle(statusElement).color).toBe('rgb(0, 176, 80)'); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
packages/manager/src/features/CloudPulse/Alerts/AlertsListing/AlertTableRow.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Typography } from '@linode/ui'; | ||
import { useTheme } from '@mui/material'; | ||
import * as React from 'react'; | ||
|
||
import { DateTimeDisplay } from 'src/components/DateTimeDisplay'; | ||
import { TableCell } from 'src/components/TableCell'; | ||
import { TableRow } from 'src/components/TableRow'; | ||
import { capitalize } from 'src/utilities/capitalize'; | ||
|
||
import { AlertActionMenu } from './AlertActionMenu'; | ||
|
||
import type { Alert } from '@linode/api-v4'; | ||
|
||
interface Props { | ||
/** | ||
* alert details used by the component to fill the row details | ||
*/ | ||
alert: Alert; | ||
} | ||
|
||
export const AlertTableRow = (props: Props) => { | ||
const { alert } = props; | ||
const { created_by, id, label, service_type, status, updated } = alert; | ||
const theme = useTheme(); | ||
return ( | ||
<TableRow data-qa-alert-cell={id} key={`alert-row-${id}`}> | ||
<TableCell>{label}</TableCell> | ||
<TableCell>{service_type}</TableCell> | ||
<TableCell> | ||
<Typography | ||
color={ | ||
status === 'enabled' | ||
? theme.tokens.color.Green[70] | ||
: theme.tokens.color.Neutrals[60] | ||
} | ||
> | ||
{capitalize(status)} | ||
</Typography> | ||
</TableCell> | ||
Comment on lines
+29
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine but I'm wondering why UX didn't just use our Status Icon |
||
<TableCell> | ||
<DateTimeDisplay value={updated} /> | ||
</TableCell> | ||
<TableCell>{created_by}</TableCell> | ||
<TableCell actionCell> | ||
{/* handlers are supposed to be passed to this AlertActionMenu, | ||
it is dependent on other feature and will added as that feature in the next PR | ||
*/} | ||
<AlertActionMenu /> | ||
</TableCell> | ||
</TableRow> | ||
); | ||
}; |
22 changes: 22 additions & 0 deletions
22
packages/manager/src/features/CloudPulse/Alerts/AlertsListing/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const AlertListingTableLabelMap = [ | ||
{ | ||
colName: 'Alert Name', | ||
label: 'alertName', | ||
}, | ||
{ | ||
colName: 'Service', | ||
label: 'service', | ||
}, | ||
{ | ||
colName: 'Status', | ||
label: 'status', | ||
}, | ||
{ | ||
colName: 'Last Modified', | ||
label: 'lastModified', | ||
}, | ||
{ | ||
colName: 'Created By', | ||
label: 'createdBy', | ||
}, | ||
]; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we going to API paginate or client side paginate? We generally like to API paginate whenever possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are going with client side paginate as decided during the API specification discussion. As per the mockups: https://www.figma.com/design/26kXnWVNU5tK2xQdDdISuC/Custom-Alerts?node-id=182-31355&node-type=canvas&t=RpnzXG6qoW63ls4N-0.
We have a searching, filtering functionality to be added for these alerts and we are not doing that from API side, so pagination also is being done client side.