-
Notifications
You must be signed in to change notification settings - Fork 399
feat: [M3 7015] - Create nodebalancer tab in firewalls landing #9590
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
tyler-akamai
merged 11 commits into
linode:feature/firewall-nodebalancer
from
tyler-akamai:M3-7015-create-nodebalancer-tab-in-firewalls-landing
Aug 28, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
eb6c376
initial changes
TylerWJ 45d36b4
finished the firewall device landing updates
TylerWJ 89e34cf
Added changeset: Create nodebalancer tab in firewalls landing
TylerWJ cfa17cd
fixed breadcrumb and variable names
TylerWJ ddbd965
added FirewallDeviceLanding test file
TylerWJ 094ec75
added initial unit tests
TylerWJ 1c95c8c
updated jest.mock function, still not working
TylerWJ 7cfdaf3
swapped from jest.mock to MSW, still need some work
TylerWJ 71af81d
fixed unit tests
TylerWJ 160acc6
fixed tests for FirewallDeviceLanding
TylerWJ fa6b944
fixed merge conflict
TylerWJ 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
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-9590-upcoming-features-1692899572064.md
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,5 @@ | ||
| --- | ||
| "@linode/manager": Upcoming Features | ||
| --- | ||
|
|
||
| Create NodeBalancer tab in Firewalls landing ([#9590](https://github.com/linode/manager/pull/9590)) |
61 changes: 61 additions & 0 deletions
61
...ages/manager/src/features/Firewalls/FirewallDetail/Devices/FirewallDeviceLanding.test.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,61 @@ | ||
| import * as React from 'react'; | ||
|
|
||
| import { firewallDeviceFactory } from 'src/factories'; | ||
| import { rest, server } from 'src/mocks/testServer'; | ||
| import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
|
||
| import { | ||
| FirewallDeviceLanding, | ||
| FirewallDeviceLandingProps, | ||
| } from './FirewallDeviceLanding'; | ||
|
|
||
| import type { FirewallDeviceEntityType } from '@linode/api-v4'; | ||
|
|
||
| const baseProps = ( | ||
| type: FirewallDeviceEntityType | ||
| ): FirewallDeviceLandingProps => ({ | ||
| disabled: true, | ||
| firewallID: 1, | ||
| firewallLabel: 'test', | ||
| type, | ||
| }); | ||
|
|
||
| const devices = ['linode', 'nodebalancer']; | ||
|
|
||
| devices.forEach((device: FirewallDeviceEntityType) => { | ||
| describe(`Firewall ${device} device`, () => { | ||
| let addButton: HTMLElement; | ||
| let permissionNotice: HTMLElement; | ||
| let table: HTMLElement; | ||
|
|
||
| beforeEach(() => { | ||
| server.use( | ||
| rest.get('*/firewalls/*', (req, res, ctx) => { | ||
| return res(ctx.json(firewallDeviceFactory.buildList(1))); | ||
| }) | ||
| ); | ||
| const { getByRole, getByTestId } = renderWithTheme( | ||
| <FirewallDeviceLanding {...baseProps(device)} /> | ||
| ); | ||
| addButton = getByTestId('add-device-button'); | ||
| permissionNotice = getByRole('alert'); | ||
| table = getByRole('table'); | ||
| }); | ||
|
|
||
| it(`should render an add ${device} button`, () => { | ||
| expect(addButton).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it(`should render a disabled add ${device} button`, () => { | ||
| expect(addButton).toBeDisabled(); | ||
| }); | ||
|
|
||
| it(`should render a permission denied notice`, () => { | ||
| expect(permissionNotice).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it(`should render a table`, () => { | ||
| expect(table).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); | ||
135 changes: 135 additions & 0 deletions
135
packages/manager/src/features/Firewalls/FirewallDetail/Devices/FirewallDeviceLanding.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,135 @@ | ||
| import Grid from '@mui/material/Unstable_Grid2'; | ||
| import { styled } from '@mui/material/styles'; | ||
| import * as React from 'react'; | ||
|
|
||
| import { Button } from 'src/components/Button/Button'; | ||
| import { Notice } from 'src/components/Notice/Notice'; | ||
| import { Typography } from 'src/components/Typography'; | ||
| import { useAllFirewallDevicesQuery } from 'src/queries/firewalls'; | ||
|
|
||
| import { AddDeviceDrawer } from './AddDeviceDrawer'; | ||
| import { FirewallDevicesTable } from './FirewallDevicesTable'; | ||
| import { RemoveDeviceDialog } from './RemoveDeviceDialog'; | ||
|
|
||
| import type { FirewallDeviceEntityType } from '@linode/api-v4'; | ||
|
|
||
| export interface FirewallDeviceLandingProps { | ||
| disabled: boolean; | ||
| firewallID: number; | ||
| firewallLabel: string; | ||
| type: FirewallDeviceEntityType; | ||
| } | ||
|
|
||
| const formattedTypes = { | ||
| linode: 'Linode', | ||
| nodebalancer: 'NodeBalancer', | ||
| }; | ||
|
|
||
| export const FirewallDeviceLanding = React.memo( | ||
| (props: FirewallDeviceLandingProps) => { | ||
| const { disabled, firewallID, firewallLabel, type } = props; | ||
|
|
||
| const { data: allDevices, error, isLoading } = useAllFirewallDevicesQuery( | ||
| firewallID | ||
| ); | ||
|
|
||
| const devices = | ||
| allDevices?.filter((device) => device.entity.type === type) || []; | ||
|
|
||
| const [ | ||
| isRemoveDeviceDialogOpen, | ||
| setIsRemoveDeviceDialogOpen, | ||
| ] = React.useState<boolean>(false); | ||
|
|
||
| const [selectedDeviceId, setSelectedDeviceId] = React.useState<number>(-1); | ||
|
|
||
| const selectedDevice = devices?.find( | ||
| (device) => device.id === selectedDeviceId | ||
| ); | ||
|
|
||
| const [addDeviceDrawerOpen, setDeviceDrawerOpen] = React.useState<boolean>( | ||
| false | ||
| ); | ||
|
|
||
| const handleClose = () => { | ||
| setDeviceDrawerOpen(false); | ||
| }; | ||
|
|
||
| const formattedType = formattedTypes[type]; | ||
|
|
||
| return ( | ||
| <> | ||
| {disabled ? ( | ||
| <Notice | ||
| text={ | ||
| "You don't have permissions to modify this Firewall. Please contact an account administrator for details." | ||
| } | ||
| important | ||
| variant="error" | ||
| /> | ||
| ) : null} | ||
| <Grid container direction="column"> | ||
| <Grid style={{ paddingBottom: 0 }}> | ||
| <StyledTypography> | ||
| The following {formattedType}s have been assigned to this | ||
| Firewall. A {formattedType} can only be assigned to a single | ||
| Firewall. | ||
| </StyledTypography> | ||
| </Grid> | ||
| <StyledGrid> | ||
| <Button | ||
| buttonType="primary" | ||
| data-testid="add-device-button" | ||
| disabled={disabled} | ||
| onClick={() => setDeviceDrawerOpen(true)} | ||
| > | ||
| Add {formattedType}s to Firewall | ||
| </Button> | ||
| </StyledGrid> | ||
| </Grid> | ||
| <FirewallDevicesTable | ||
| triggerRemoveDevice={(id) => { | ||
| setSelectedDeviceId(id); | ||
| setIsRemoveDeviceDialogOpen(true); | ||
| }} | ||
| devices={devices ?? []} | ||
| disabled={disabled} | ||
| error={error ?? undefined} | ||
| loading={isLoading} | ||
| /> | ||
| <AddDeviceDrawer onClose={handleClose} open={addDeviceDrawerOpen} /> | ||
| <RemoveDeviceDialog | ||
| device={selectedDevice} | ||
| firewallId={firewallID} | ||
| firewallLabel={firewallLabel} | ||
| linodeId={selectedDevice?.entity.id} | ||
| onClose={() => setIsRemoveDeviceDialogOpen(false)} | ||
| open={isRemoveDeviceDialogOpen} | ||
| /> | ||
| </> | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| const StyledTypography = styled(Typography, { label: 'StyledTypography' })( | ||
| ({ theme }) => ({ | ||
| fontSize: '0.875rem', | ||
| marginTop: theme.spacing(), | ||
| [theme.breakpoints.down('lg')]: { | ||
| marginLeft: theme.spacing(), | ||
| marginRight: theme.spacing(), | ||
| }, | ||
| }) | ||
| ); | ||
|
|
||
| const StyledGrid = styled(Grid, { label: 'StyledGrid' })(({ theme }) => ({ | ||
| '&.MuiGrid-item': { | ||
| paddingTop: 0, | ||
| }, | ||
| display: 'flex', | ||
| justifyContent: 'flex-end', | ||
| marginBottom: theme.spacing(), | ||
| [theme.breakpoints.only('sm')]: { | ||
| marginRight: theme.spacing(), | ||
| }, | ||
| })); |
120 changes: 0 additions & 120 deletions
120
packages/manager/src/features/Firewalls/FirewallDetail/Devices/FirewallLinodesLanding.tsx
This file was deleted.
Oops, something went wrong.
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.