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

feat: [M3-6731] – Add VPC and Firewall sections in Linode Create flow #9635

Merged
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
f8d5d85
Initial groundwork for VPCPanel and FirewallPanel components
DevDW Aug 16, 2023
ef62b27
Merge branch 'develop' into M3-6731-vpc-firewall-sections-linode-create
DevDW Aug 30, 2023
2affd24
Merge branch 'develop' into M3-6731-vpc-firewall-sections-linode-create
DevDW Sep 5, 2023
fd3f5e1
Core functionality in place: Firewalls work well, VPC works but needs…
DevDW Sep 5, 2023
1d267f1
Merge in latest develop, resolve conflicts
DevDW Sep 13, 2023
5b703e9
Progress: validation on VPC fields; 'Create VPC' link opens in new ta…
DevDW Sep 14, 2023
4a9755c
Merge in latest develop and resolve conflicts
DevDW Sep 15, 2023
7140d99
More error handling
DevDW Sep 15, 2023
cc54063
Add parenthetical IPv4 ranges to subnet options
DevDW Sep 18, 2023
e6ec6ac
Cleanup, move VPC data into interfaces property of Linode Create payl…
DevDW Sep 19, 2023
e681167
Merge branch 'develop' into M3-6731-vpc-firewall-sections-linode-create
DevDW Sep 20, 2023
a2d5d61
FirewallPanel feedback: moved from src/features/Linodes/LinodesCreate…
DevDW Sep 20, 2023
022f800
Small refactors, UX interaction improvements, copy changes
DevDW Sep 21, 2023
4037307
Fix firewall_id in payload (important for Create Using Command Line),…
DevDW Sep 21, 2023
af20dd2
Open 'Create Firewall' link in new tab
DevDW Sep 21, 2023
ed628f7
Remove now unneeded changes in src/queries/linodes/configs.ts
DevDW Sep 21, 2023
8768182
Added changeset: VPCs added to region Capabilities type
DevDW Sep 21, 2023
446c214
Added changeset: linodeInterfaceSchema now validates a single interfa…
DevDW Sep 21, 2023
dc0ce51
Added changeset: VPC and Firewall assignment within Linode Create flow
DevDW Sep 21, 2023
9690963
Merge branch 'develop' into M3-6731-vpc-firewall-sections-linode-create
DevDW Sep 22, 2023
eb43f78
linodeCreateWithFirewall feature flag logic
DevDW Sep 22, 2023
9c845c8
Unit tests + some minor changes
DevDW Sep 25, 2023
959f206
Merge in latest develop and resolve conflicts
DevDW Sep 26, 2023
3338425
Feedback: checkbox spacing, 'Firewall Assigned' in summary paper, rel…
DevDW Sep 26, 2023
9daf1c7
Restore conditional render logic in VPCPanel.tsx and remove it from L…
DevDW Sep 26, 2023
e349e3e
Feedback: cut down on unnecessary requests to /vpcs; scroll to VPC er…
DevDW Sep 27, 2023
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
---

VPCs added to region Capabilities type ([#9635](https://github.com/linode/manager/pull/9635))
12 changes: 6 additions & 6 deletions packages/api-v4/src/account/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ export interface Account {
export type BillingSource = 'linode' | 'akamai';

export type AccountCapability =
| 'Linodes'
| 'NodeBalancers'
| 'Block Storage'
| 'Object Storage'
| 'Kubernetes'
| 'Cloud Firewall'
| 'Vlans'
| 'Machine Images'
| 'Kubernetes'
| 'Linodes'
| 'LKE HA Control Planes'
| 'Machine Images'
| 'Managed Databases'
| 'NodeBalancers'
| 'Object Storage'
| 'Vlans'
| 'VPCs';

export interface AccountSettings {
Expand Down
15 changes: 8 additions & 7 deletions packages/api-v4/src/regions/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
export type Capabilities =
| 'Bare Metal'
| 'Block Storage'
| 'Cloud Firewall'
| 'GPU Linodes'
| 'Kubernetes'
| 'Linodes'
| 'Metadata'
| 'NodeBalancers'
| 'Block Storage'
| 'Object Storage'
| 'Kubernetes'
| 'GPU Linodes'
| 'Cloud Firewall'
| 'Premium Plans'
| 'Vlans'
| 'Bare Metal'
| 'Metadata'
| 'Premium Plans';
| 'VPCs';

export interface DNSResolvers {
ipv4: string; // Comma-separated IP addresses
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

VPC and Firewall assignment within Linode Create flow ([#9635](https://github.com/linode/manager/pull/9635))
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { waitFor } from '@testing-library/react';
import * as React from 'react';
import { QueryClient } from 'react-query';

import { mockMatchMedia, renderWithTheme } from 'src/utilities/testHelpers';

import { SelectFirewallPanel } from './SelectFirewallPanel';

const queryClient = new QueryClient();

beforeAll(() => mockMatchMedia());
afterEach(() => {
queryClient.clear();
});

const testId = 'select-firewall-panel';

describe('SelectFirewallPanel', () => {
it('should render', async () => {
const wrapper = renderWithTheme(
<SelectFirewallPanel
handleFirewallChange={jest.fn()}
helperText={<span>Testing</span>}
/>,
{
queryClient,
}
);

await waitFor(() => {
expect(wrapper.getByTestId(testId)).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import Stack from '@mui/material/Stack';
import * as React from 'react';

import Select from 'src/components/EnhancedSelect';
import { Paper } from 'src/components/Paper';
import { Typography } from 'src/components/Typography';
import { APP_ROOT } from 'src/constants';
import { useFirewallsQuery } from 'src/queries/firewalls';

import { StyledCreateLink } from '../../features/Linodes/LinodesCreate/LinodeCreate.styles';

interface Props {
handleFirewallChange: (firewallID: number) => void;
helperText: JSX.Element;
}

export const SelectFirewallPanel = (props: Props) => {
const { handleFirewallChange, helperText } = props;

const { data: firewallsData, error, isLoading } = useFirewallsQuery();

const firewalls = firewallsData?.data ?? [];
const firewallsDropdownOptions = firewalls.map((firewall) => ({
label: firewall.label,
value: firewall.id,
}));

firewallsDropdownOptions.unshift({
label: 'None',
value: -1,
});

return (
<Paper
data-testid="select-firewall-panel"
sx={(theme) => ({ marginTop: theme.spacing(3) })}
>
<Typography
sx={(theme) => ({ marginBottom: theme.spacing(2) })}
variant="h2"
>
Firewall
</Typography>
<Stack>
{helperText}
<Select
defaultValue={firewallsDropdownOptions[0]}
errorText={error?.[0].reason}
isClearable={false}
isLoading={isLoading}
label="Assign Firewall"
noOptionsMessage={() => 'Create a Firewall to assign to this Linode.'}
onChange={(selection) => handleFirewallChange(selection.value)}
options={firewallsDropdownOptions}
placeholder={''}
/>
<StyledCreateLink to={`${APP_ROOT}/firewalls/create`}>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APP_ROOT is used to ensure the link opens up in a new tab (can't be done with a relative path without adding the external prop which would be misleading)

Create Firewall
</StyledCreateLink>
</Stack>
</Paper>
);
};
23 changes: 23 additions & 0 deletions packages/manager/src/containers/account.container.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Account } from '@linode/api-v4/lib';
import { APIError } from '@linode/api-v4/lib/types';
import * as React from 'react';
import { UseQueryResult } from 'react-query';

import { useAccount } from 'src/queries/account';

export interface WithAccountProps {
account: UseQueryResult<Account, APIError[]>;
}

export const withAccount = <Props>(
Component: React.ComponentType<Props & WithAccountProps>
) => {
return (props: Props) => {
const account = useAccount();

return React.createElement(Component, {
...props,
account,
});
};
};
1 change: 1 addition & 0 deletions packages/manager/src/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface Flags {
dcSpecificPricing: boolean;
ipv6Sharing: boolean;
kubernetesDashboardAvailability: boolean;
linodeCreateWithFirewall: boolean;
mainContentBanner: MainContentBanner;
metadata: boolean;
oneClickApps: OneClickApp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { waitFor } from '@testing-library/react';
import React from 'react';

import { linodeTypeFactory } from 'src/factories/linodes';
Expand Down Expand Up @@ -166,6 +167,10 @@ const props: AddonsPanelProps = {
vlanLabel: 'abc',
};

const privateIPContextualCopyTestId = 'private-ip-contextual-copy';
const vlanAccordionTestId = 'vlan-accordion';
const attachVLANTestId = 'attach-vlan';

describe('AddonsPanel', () => {
it('should render AddonsPanel', () => {
renderWithTheme(<AddonsPanel {...props} />);
Expand Down Expand Up @@ -245,4 +250,56 @@ describe('AddonsPanel', () => {

expect(getByText(/\$3.57/)).toBeInTheDocument();
});

it('should display the VLANAccordion component instead of the AttachVLAN component when VPCs are viewable in the flow', async () => {
const _props: AddonsPanelProps = { ...props, createType: 'fromImage' };

const wrapper = renderWithTheme(<AddonsPanel {..._props} />, {
flags: { vpc: true },
});

await waitFor(() => {
expect(wrapper.getByTestId(vlanAccordionTestId)).toBeInTheDocument();
expect(wrapper.queryByTestId(attachVLANTestId)).not.toBeInTheDocument();
});
});

it('should display the AttachVLAN component instead of the VLANAccordion component when VPCs are not viewable in the flow', async () => {
const _props: AddonsPanelProps = { ...props, createType: 'fromImage' };

const wrapper = renderWithTheme(<AddonsPanel {..._props} />, {
flags: { vpc: false },
});

await waitFor(() => {
expect(wrapper.getByTestId(attachVLANTestId)).toBeInTheDocument();
expect(
wrapper.queryByTestId(vlanAccordionTestId)
).not.toBeInTheDocument();
});
});

it('should have contextual copy for the Private IP add-on when VPC is enabled', async () => {
const wrapper = renderWithTheme(<AddonsPanel {...props} />, {
flags: { vpc: true },
});

await waitFor(() => {
expect(
wrapper.getByTestId(privateIPContextualCopyTestId)
).toBeInTheDocument();
});
});

it('should not have contextual copy for the Private IP add-on if VPC is not enabled', async () => {
const wrapper = renderWithTheme(<AddonsPanel {...props} />, {
flags: { vpc: false },
});

await waitFor(() => {
expect(
wrapper.queryByTestId(privateIPContextualCopyTestId)
).not.toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import { TooltipIcon } from 'src/components/TooltipIcon';
import { Typography } from 'src/components/Typography';
import { UserDataAccordionProps } from 'src/features/Linodes/LinodesCreate/UserDataAccordion/UserDataAccordion';
import { useFlags } from 'src/hooks/useFlags';
import { useAccount } from 'src/queries/account';
import { useImageQuery } from 'src/queries/images';
import { CreateTypes } from 'src/store/linodeCreate/linodeCreate.actions';
import { isFeatureEnabled } from 'src/utilities/accountCapabilities';
import { privateIPRegex } from 'src/utilities/ipUtils';

import { AttachVLAN } from './AttachVLAN';
Expand Down Expand Up @@ -72,6 +74,7 @@ export const AddonsPanel = React.memo((props: AddonsPanelProps) => {

const theme = useTheme();
const flags = useFlags();
const { data: account } = useAccount();

const { data: image } = useImageQuery(
selectedImageID ?? '',
Expand Down Expand Up @@ -124,6 +127,12 @@ export const AddonsPanel = React.memo((props: AddonsPanelProps) => {
// The backups warning is shown when the user checks to enable backups, but they are using a custom image that may not be compatible.
const showBackupsWarning = checkBackupsWarning();

const showVPCs = isFeatureEnabled(
'VPCs',
Boolean(flags.vpc),
account?.capabilities ?? []
);

// Check whether the source Linode has been allocated a private IP to select/unselect the 'Private IP' checkbox.
React.useEffect(() => {
if (selectedLinodeID) {
Expand All @@ -144,8 +153,8 @@ export const AddonsPanel = React.memo((props: AddonsPanelProps) => {

return (
<>
{!flags.vpc &&
showVlans && ( // @TODO Delete this conditional and AttachVLAN component once VPC is released
{!showVPCs &&
showVlans && ( // @TODO VPC: Delete this conditional and AttachVLAN component once VPC is fully rolled out
<AttachVLAN
handleVLANChange={handleVLANChange}
helperText={vlanDisabledReason}
Expand All @@ -157,7 +166,7 @@ export const AddonsPanel = React.memo((props: AddonsPanelProps) => {
vlanLabel={vlanLabel}
/>
)}
{flags.vpc && showVlans && (
{showVPCs && showVlans && (
<VLANAccordion
handleVLANChange={handleVLANChange}
helperText={vlanDisabledReason}
Expand Down Expand Up @@ -236,6 +245,15 @@ export const AddonsPanel = React.memo((props: AddonsPanelProps) => {
}
label="Private IP"
/>
{showVPCs && (
<StyledTypography
data-testid="private-ip-contextual-copy"
variant="body1"
>
Use this for a backend node to a NodeBalancer. Use VPC instead for
private communication between your Linodes.
</StyledTypography>
)}
</Paper>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ export const AttachVLAN = React.memo((props: Props) => {
)}.`;

return (
<Paper sx={{ marginTop: theme.spacing(3) }} data-qa-add-ons>
<Paper
data-qa-add-ons
data-testid="attach-vlan"
sx={{ marginTop: theme.spacing(3) }}
>
<Typography
sx={{
'& button': {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { styled } from '@mui/material/styles';
import { isPropValid } from 'src/utilities/isPropValid';

import { Box } from 'src/components/Box';
import { Button } from 'src/components/Button/Button';
import { Link } from 'src/components/Link';
import { Paper } from 'src/components/Paper';
import type { LinodeCreateProps } from './LinodeCreate';
import { TabPanels } from 'src/components/ReachTabPanels';
import { isPropValid } from 'src/utilities/isPropValid';

import type { LinodeCreateProps } from './LinodeCreate';

type StyledLinodeCreateProps = Pick<LinodeCreateProps, 'showAgreement'>;

Expand Down Expand Up @@ -33,7 +36,7 @@ export const StyledForm = styled('form', { label: 'StyledForm' })({
export const StyledMessageDiv = styled('div', {
label: 'StyledMessageDiv',
shouldForwardProp: (prop) => isPropValid(['showAgreement'], prop),
})<StyledLinodeCreateProps>(({ theme, showAgreement }) => ({
})<StyledLinodeCreateProps>(({ showAgreement, theme }) => ({
display: 'flex',
flexDirection: 'column' as const,
flexGrow: 1,
Expand Down Expand Up @@ -69,3 +72,13 @@ export const StyledTabPanel = styled(TabPanels, { label: 'StyledTabPanel' })(
},
})
);

// Currently used in VPC and Firewall panels
export const StyledCreateLink = styled(Link, {
label: 'StyledCreateLink',
})(({ theme }) => ({
fontSize: '14px',
marginBottom: theme.spacing(2),
marginTop: theme.spacing(1.5),
width: '100px',
}));
Loading