Skip to content

Commit b700773

Browse files
Addressed review comments
1 parent 0560992 commit b700773

File tree

13 files changed

+54
-40
lines changed

13 files changed

+54
-40
lines changed

packages/manager/cypress/e2e/core/linodes/create-linode-with-firewall.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ describe('Create Linode with Firewall (Linode Interfaces)', () => {
424424
// Switch to legacy Config Interfaces
425425
linodeCreatePage.selectLegacyConfigInterfacesType();
426426

427-
// Select a firewall for the VPC interface
427+
// Select a firewall
428428
linodeCreatePage.selectFirewall(mockFirewall.label, 'Firewall');
429429

430430
// Confirm Firewall assignment indicator is shown in Linode summary.

packages/manager/src/features/Firewalls/components/FirewallSelect.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,6 @@ describe('FirewallSelect', () => {
123123
<FirewallSelect value={NO_FIREWALL_ID} />
124124
);
125125

126-
expect(await findByDisplayValue(NO_FIREWALL_LABEL)).toBeInTheDocument();
126+
await findByDisplayValue(NO_FIREWALL_LABEL);
127127
});
128128
});

packages/manager/src/features/Linodes/LinodeCreate/Networking/utilities.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ describe('getLinodeInterfacesPayload', () => {
5050
vpc_id: 1,
5151
},
5252
}),
53-
firewall_id: null,
5453
purpose: 'public' as const,
5554
};
5655

@@ -67,7 +66,6 @@ describe('getLinodeInterfacePayload', () => {
6766
const networkInterface = {
6867
...linodeInterfaceFactoryPublic.build(),
6968
purpose: 'public' as const,
70-
firewall_id: null,
7169
};
7270

7371
expect(getLinodeInterfacePayload(networkInterface)).toEqual({
@@ -80,7 +78,6 @@ describe('getLinodeInterfacePayload', () => {
8078
const networkInterface = {
8179
...vpcInterface,
8280
purpose: 'vpc' as const,
83-
firewall_id: null,
8481
};
8582

8683
const newInterface = {
@@ -89,7 +86,6 @@ describe('getLinodeInterfacePayload', () => {
8986
};
9087
expect(getLinodeInterfacePayload(networkInterface)).toEqual({
9188
...newInterface,
92-
firewall_id: null,
9389
});
9490
});
9591
});

packages/manager/src/features/Linodes/LinodeCreate/Networking/utilities.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ interface VPC extends NonNullable<CreateLinodeInterfacePayload['vpc']> {
1919
/**
2020
* We extend the new `CreateLinodeInterfacePayload` to add extra state we need to track
2121
*/
22-
export interface LinodeCreateInterface
23-
extends Omit<CreateLinodeInterfacePayload, 'firewall_id'> {
24-
firewall_id: null | number;
22+
export interface LinodeCreateInterface extends CreateLinodeInterfacePayload {
2523
purpose: InterfacePurpose;
2624
vpc: null | VPC;
2725
}
@@ -54,19 +52,13 @@ export const getCleanedLinodeInterfaceValues = (
5452
*/
5553
export const getLinodeInterfacePayload = (
5654
networkInterface: LinodeCreateInterface
57-
): Omit<CreateLinodeInterfacePayload, 'firewall_id'> & {
58-
firewall_id: null | number;
59-
} => {
55+
): CreateLinodeInterfacePayload => {
6056
// ensure only one interface type is present
6157
const cleanedValues = getCleanedLinodeInterfaceValues(networkInterface);
6258

6359
if (cleanedValues.vpc) {
6460
const vpcValues = omitProps(cleanedValues.vpc, ['vpc_id']);
65-
return {
66-
...omitProps(cleanedValues, ['purpose']),
67-
firewall_id: cleanedValues.firewall_id,
68-
vpc: vpcValues,
69-
};
61+
return { ...omitProps(cleanedValues, ['purpose']), vpc: vpcValues };
7062
}
7163

7264
// The API errors saying address is invalid if we pass an empty string.
@@ -76,10 +68,7 @@ export const getLinodeInterfacePayload = (
7668
cleanedValues.vlan.ipam_address = null;
7769
}
7870

79-
return {
80-
...omitProps(cleanedValues, ['purpose']),
81-
firewall_id: cleanedValues.firewall_id,
82-
};
71+
return omitProps(cleanedValues, ['purpose']);
8372
};
8473

8574
/**

packages/manager/src/features/Linodes/LinodeCreate/schemas.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { array, boolean, number, object, string } from 'yup';
77
import { CreateLinodeInterfaceFormSchema } from '../LinodesDetail/LinodeNetworking/LinodeInterfaces/AddInterfaceDrawer/utilities';
88

99
import type { LinodeCreateFormValues } from './utilities';
10+
import type { InterfaceGenerationType } from '@linode/api-v4/lib/linodes/types';
1011
import type { ObjectSchema } from 'yup';
1112

1213
/**
@@ -17,6 +18,12 @@ import type { ObjectSchema } from 'yup';
1718
export const CreateLinodeSchema: ObjectSchema<LinodeCreateFormValues> =
1819
BaseCreateLinodeSchema.concat(
1920
object({
21+
firewall_id: number().when('interface_generation', {
22+
is: (value: InterfaceGenerationType) => value === 'legacy_config',
23+
then: (schema) =>
24+
schema.required('Select an option or create a new Firewall.'),
25+
otherwise: (schema) => schema.nullable().notRequired(),
26+
}),
2027
firewallOverride: boolean(),
2128
hasSignedEUAgreement: boolean(),
2229
interfaces: array(ConfigProfileInterfaceSchema).required(),

packages/manager/src/features/Linodes/LinodeCreate/utilities.test.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { createLinodeRequestFactory } from '@linode/utilities';
1+
import {
2+
createLinodeRequestFactory,
3+
getIsLegacyInterfaceArray,
4+
linodeConfigInterfaceFactory,
5+
linodeInterfaceFactoryPublic,
6+
linodeInterfaceFactoryVlan,
7+
linodeInterfaceFactoryVPC,
8+
} from '@linode/utilities';
29

310
import {
411
getDefaultInterfaceGenerationFromAccountSetting,
@@ -357,6 +364,26 @@ describe('getInterfacesPayload', () => {
357364
});
358365
});
359366

367+
describe('getIsLegacyInterfaceArray', () => {
368+
it('determines the given interfaces are legacy', () => {
369+
const legacyInterfaces = linodeConfigInterfaceFactory.buildList(3);
370+
expect(getIsLegacyInterfaceArray(legacyInterfaces)).toBe(true);
371+
expect(getIsLegacyInterfaceArray(undefined)).toBe(true);
372+
expect(getIsLegacyInterfaceArray([])).toBe(true);
373+
});
374+
375+
it('returns false if the given interfaces are new Linode Interfaces', () => {
376+
const linodeInterfacesVlan = linodeInterfaceFactoryVlan.buildList(3);
377+
expect(getIsLegacyInterfaceArray(linodeInterfacesVlan)).toBe(false);
378+
379+
const linodeInterfacesVPC = linodeInterfaceFactoryVPC.buildList(3);
380+
expect(getIsLegacyInterfaceArray(linodeInterfacesVPC)).toBe(false);
381+
382+
const linodeInterfacesPublic = linodeInterfaceFactoryPublic.buildList(3);
383+
expect(getIsLegacyInterfaceArray(linodeInterfacesPublic)).toBe(false);
384+
});
385+
});
386+
360387
describe('getLinodeLabelFromLabelParts', () => {
361388
it('should join items', () => {
362389
expect(getLinodeLabelFromLabelParts(['my-linode', 'us-east'])).toBe(

packages/manager/src/features/Linodes/LinodeCreate/utilities.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { getDefaultUDFData } from './Tabs/StackScripts/UserDefinedFields/utiliti
2525
import type { LinodeCreateInterface } from './Networking/utilities';
2626
import type {
2727
AccountSettings,
28-
CreateLinodeInterfacePayload,
2928
CreateLinodeRequest,
3029
FirewallSettings,
3130
InterfaceGenerationType,
@@ -98,8 +97,8 @@ export const getLinodeCreatePayload = (
9897
if (shouldUseNewInterfaces) {
9998
values.interfaces = formValues.linodeInterfaces.map(
10099
getLinodeInterfacePayload
101-
) as CreateLinodeInterfacePayload[];
102-
values.firewall_id = -1;
100+
);
101+
values.firewall_id = undefined;
103102
} else {
104103
values.interfaces = formValues.backup_id
105104
? undefined

packages/manager/src/features/Linodes/LinodesDetail/LinodeNetworking/LinodeInterfaces/AddInterfaceDrawer/AddInterfaceForm.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { VLANInterface } from './VLAN/VLANInterface';
2323
import { VPCInterface } from './VPC/VPCInterface';
2424

2525
import type { CreateInterfaceFormValues } from './utilities';
26-
import type { CreateLinodeInterfacePayload } from '@linode/api-v4';
2726

2827
interface Props {
2928
linodeId: number;
@@ -64,7 +63,10 @@ export const AddInterfaceForm = (props: Props) => {
6463
const { errors, values } = await yupResolver(
6564
CreateLinodeInterfaceFormSchema
6665
)(
67-
valuesWithOnlySelectedInterface as CreateInterfaceFormValues,
66+
{
67+
...valuesWithOnlySelectedInterface,
68+
firewall_id: valuesWithOnlySelectedInterface.firewall_id!,
69+
},
6870
context,
6971
options
7072
);
@@ -79,10 +81,7 @@ export const AddInterfaceForm = (props: Props) => {
7981

8082
const onSubmit = async (values: CreateInterfaceFormValues) => {
8183
try {
82-
const payload = getLinodeInterfacePayload(
83-
values
84-
) as CreateLinodeInterfacePayload;
85-
await mutateAsync(payload);
84+
await mutateAsync(getLinodeInterfacePayload(values));
8685

8786
enqueueSnackbar('Successfully added network interface.', {
8887
variant: 'success',

packages/manager/src/features/Linodes/LinodesDetail/LinodeNetworking/LinodeInterfaces/AddInterfaceDrawer/utilities.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import type { InferType } from 'yup';
99
export const CreateLinodeInterfaceFormSchema =
1010
CreateLinodeInterfaceSchema.concat(
1111
object({
12+
firewall_id: number().required(
13+
'Select an option or create a new Firewall.'
14+
),
1215
purpose: string()
1316
.oneOf(['vpc', 'vlan', 'public'])
1417
.required('You must selected an Interface type.'),

packages/manager/src/features/VPCs/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export const getVPCInterfacePayload = (inputs: {
151151

152152
if (isLinodeInterface) {
153153
return {
154-
firewall_id: firewallId!,
154+
firewall_id: firewallId,
155155
vpc: {
156156
subnet_id: subnetId ?? -1,
157157
ipv4: {

0 commit comments

Comments
 (0)