-
Notifications
You must be signed in to change notification settings - Fork 389
poc: [M3-9996, M3-10048] - Assigning alert definitions (beta) to a Linode during creation
#12248
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4cd5b39
Add beta ACLP alerts to Alerts tab on Linode details page
pmakode-akamai 99cfdbd
Added changeset: Add beta ACLP contextual alerts to the Alerts tab onβ¦
pmakode-akamai e896c4e
Rename legacy alerts heading to `Default Alerts`
pmakode-akamai f09962b
Merge branch 'develop' into M3-9989-add-beta-aclp-alerts-on-linode-deβ¦
pmakode-akamai 4c6d60a
Save progress...
pmakode-akamai c61d3ce
Fix aclp alerts validation schema
pmakode-akamai 4024fe6
Support initial values for legacy alerts in createLinode flow
pmakode-akamai 238bccb
Merge branch 'develop' into poc/M3-9996
pmakode-akamai a2c6464
Some clean up...
pmakode-akamai 1d398af
Fix alerts validation schema
pmakode-akamai 0f9dde1
Merge branch 'develop' into poc/M3-9996
pmakode-akamai 26724f0
Merge branch 'develop' into poc/M3-9996
pmakode-akamai 6c9ff39
Merge branch 'develop' into poc/M3-9996
pmakode-akamai 258fc1c
Keep AlertsReusableComponent decoupled
pmakode-akamai cda86a8
Merge branch 'develop' into poc/M3-9996
pmakode-akamai f316d4a
Merge edit & create logic in action table (#1)
ankita-akamai 12d116c
Add Additional Options section to Create Linode flow
pmakode-akamai 656131a
Added changeset: Assigning alert definitions to a Linode during creation
pmakode-akamai f517604
Added changeset: Beta ACLP alerts property to the `CreateLinodeRequesβ¦
pmakode-akamai b38b95f
Clean up: types
pmakode-akamai 7fd1131
Fix: Use relative type import in apiv4
pmakode-akamai 90123d7
Resolve merge conflict and get latest from develop
pmakode-akamai 43f6381
Update imports after merging the latest from develop
pmakode-akamai c112f1d
Resolve merge conflicts and get latest from develop
pmakode-akamai 0d80d6d
Resolve merge conficts and document aclp alerts payload type
pmakode-akamai 8950229
Update feature flag references
pmakode-akamai 2b95ba8
Merge branch 'develop' into poc/M3-9996
pmakode-akamai c5c4196
Destruture linode create payload options
pmakode-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 hidden or 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
173 changes: 173 additions & 0 deletions
173
.../manager/src/features/CloudPulse/Alerts/ContextualView/AlertInfoActionTableCreateFlow.tsx
This file contains hidden or 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,173 @@ | ||
| import { Box } from '@linode/ui'; | ||
| import { Grid, TableBody, TableHead } from '@mui/material'; | ||
| import React from 'react'; | ||
| import { useController, useFormContext } from 'react-hook-form'; | ||
|
|
||
| import OrderBy from 'src/components/OrderBy'; | ||
| import Paginate from 'src/components/Paginate'; | ||
| import { PaginationFooter } from 'src/components/PaginationFooter/PaginationFooter'; | ||
| import { Table } from 'src/components/Table'; | ||
| import { TableCell } from 'src/components/TableCell'; | ||
| import { TableContentWrapper } from 'src/components/TableContentWrapper/TableContentWrapper'; | ||
| import { TableRow } from 'src/components/TableRow'; | ||
| import { TableSortCell } from 'src/components/TableSortCell'; | ||
| import { getAPIErrorOrDefault } from 'src/utilities/errorUtils'; | ||
|
|
||
| import { AlertInformationActionRow } from './AlertInformationActionRow'; | ||
|
|
||
| import type { Alert, APIError, LinodeAclpAlertsPayload } from '@linode/api-v4'; | ||
| import type { LinodeCreateFormValues } from 'src/features/Linodes/LinodeCreate/utilities'; | ||
|
|
||
| export interface AlertInfoActionTableCreateFlowProps { | ||
| /** | ||
| * List of alerts to be displayed | ||
| */ | ||
| alerts: Alert[]; | ||
|
|
||
| /** | ||
| * List of table headers for each column | ||
| */ | ||
| columns: TableColumnHeader[]; | ||
|
|
||
| /** | ||
| * Error received from API | ||
| */ | ||
| error?: APIError[] | null; | ||
|
|
||
| /** | ||
| * Column name by which columns will be ordered by default | ||
| */ | ||
| orderByColumn: string; | ||
| } | ||
|
|
||
| export interface TableColumnHeader { | ||
| /** | ||
| * Name of the column to be displayed | ||
| */ | ||
| columnName: string; | ||
|
|
||
| /** | ||
| * Corresponding key name in the alert object for which this column is | ||
| */ | ||
| label: string; | ||
| } | ||
|
|
||
| export const AlertInfoActionTableCreateFlow = ( | ||
| props: AlertInfoActionTableCreateFlowProps | ||
| ) => { | ||
| const { alerts, columns, error, orderByColumn } = props; | ||
|
|
||
| const _error = error | ||
| ? getAPIErrorOrDefault(error, 'Error while fetching the alerts') | ||
| : undefined; | ||
|
|
||
| const generateInitialAlertsPayload = (alerts: Alert[]) => { | ||
| const initialPayload: LinodeAclpAlertsPayload = { system: [], user: [] }; | ||
| alerts.forEach((alert) => { | ||
| if (alert.type === 'system') { | ||
| initialPayload.system.push(alert.id); | ||
| } else if (alert.type === 'user') { | ||
| initialPayload.user.push(alert.id); | ||
| } | ||
| }); | ||
| return initialPayload; | ||
| }; | ||
|
|
||
| const initialPayload = generateInitialAlertsPayload(alerts); | ||
|
|
||
| const { control } = useFormContext<LinodeCreateFormValues>(); | ||
| const { field } = useController({ | ||
| control, | ||
| name: 'alerts', | ||
| defaultValue: initialPayload, | ||
| }); | ||
|
|
||
| const handleToggleCreateFlow = (alert: Alert) => { | ||
| const alerts = field.value; | ||
| const currentAlertIds = alerts?.[alert.type] || []; | ||
| const updatedAlerts = { ...alerts }; | ||
|
|
||
| if (currentAlertIds?.includes(alert.id)) { | ||
| // Disable the alert (remove from the list) | ||
| updatedAlerts[alert.type] = currentAlertIds.filter( | ||
| (id) => id !== alert.id | ||
| ); | ||
| } else { | ||
| // Enable the alert (add to the list) | ||
| updatedAlerts[alert.type] = [...currentAlertIds, alert.id]; | ||
| } | ||
|
|
||
| field.onChange(updatedAlerts); | ||
| }; | ||
pmakode-akamai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <OrderBy data={alerts} order="asc" orderBy={orderByColumn}> | ||
| {({ data: orderedData, handleOrderChange, order, orderBy }) => ( | ||
| <Paginate data={orderedData}> | ||
| {({ | ||
| count, | ||
| data: paginatedAndOrderedAlerts, | ||
| handlePageChange, | ||
| handlePageSizeChange, | ||
| page, | ||
| pageSize, | ||
| }) => ( | ||
| <Box> | ||
| <Grid> | ||
| <Table | ||
| colCount={columns.length + 1} | ||
| data-testid="alert-table" | ||
| size="small" | ||
| > | ||
| <TableHead> | ||
| <TableRow> | ||
| <TableCell actionCell /> | ||
| {columns.map(({ columnName, label }) => { | ||
| return ( | ||
| <TableSortCell | ||
| active={orderBy === label} | ||
| data-qa-header={label} | ||
| data-qa-sorting={label} | ||
| direction={order} | ||
| handleClick={handleOrderChange} | ||
| key={label} | ||
| label={label} | ||
| > | ||
| {columnName} | ||
| </TableSortCell> | ||
| ); | ||
| })} | ||
| </TableRow> | ||
| </TableHead> | ||
| <TableBody> | ||
| <TableContentWrapper | ||
| error={_error} | ||
| length={paginatedAndOrderedAlerts.length} | ||
| loading={false} | ||
| /> | ||
| {paginatedAndOrderedAlerts?.map((alert) => ( | ||
| <AlertInformationActionRow | ||
| alert={alert} | ||
| handleToggle={handleToggleCreateFlow} | ||
| key={alert.id} | ||
| status={field.value?.[alert.type].includes(alert.id)} | ||
| /> | ||
| ))} | ||
| </TableBody> | ||
| </Table> | ||
| </Grid> | ||
| <PaginationFooter | ||
| count={count} | ||
| eventCategory="Alert Definitions Table" | ||
| handlePageChange={handlePageChange} | ||
| handleSizeChange={handlePageSizeChange} | ||
| page={page} | ||
| pageSize={pageSize} | ||
| /> | ||
| </Box> | ||
| )} | ||
| </Paginate> | ||
| )} | ||
| </OrderBy> | ||
| ); | ||
| }; | ||
This file contains hidden or 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 hidden or 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
29 changes: 29 additions & 0 deletions
29
packages/manager/src/features/Linodes/LinodeCreate/Alerts/Alerts.tsx
This file contains hidden or 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 { usePreferences } from '@linode/queries'; | ||
| import { Box } from '@linode/ui'; | ||
| import * as React from 'react'; | ||
|
|
||
| import { AlertReusableComponent } from 'src/features/CloudPulse/Alerts/ContextualView/AlertReusableComponent'; | ||
| import { useFlags } from 'src/hooks/useFlags'; | ||
|
|
||
| import { AclpPreferenceToggle } from '../../LinodesDetail/AclpPreferenceToggle'; | ||
| import { LinodeSettingsAlertsPanel } from '../../LinodesDetail/LinodeSettings/LinodeSettingsAlertsPanel'; | ||
|
|
||
| export const Alerts = () => { | ||
| const flags = useFlags(); | ||
| const { data: isAclpAlertsPreferenceBeta } = usePreferences( | ||
| (preferences) => preferences?.isAclpAlertsBeta | ||
| ); | ||
|
|
||
| return ( | ||
| <Box> | ||
| {flags.aclpIntegration && <AclpPreferenceToggle type="alerts" />} | ||
| {flags.aclpIntegration && isAclpAlertsPreferenceBeta ? ( | ||
| <AlertReusableComponent serviceType="linode" /> | ||
| ) : ( | ||
| <LinodeSettingsAlertsPanel isCreateFlow /> | ||
| )} | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| export default Alerts; |
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.