Skip to content

Commit 3229c5b

Browse files
committed
copy update
1 parent cda1c1f commit 3229c5b

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

packages/manager/src/features/Firewalls/FirewallDetail/Devices/AddLinodeDrawer.tsx

+38-37
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { getLinodeInterfaces, type Linode } from '@linode/api-v4';
1+
import { getLinodeInterfaces } from '@linode/api-v4';
22
import {
33
useAddFirewallDeviceMutation,
44
useAllFirewallsQuery,
55
useGrants,
66
useProfile,
77
} from '@linode/queries';
88
import { LinodeSelect } from '@linode/shared';
9-
import { ActionsPanel, Drawer, Notice, Select } from '@linode/ui';
9+
import { ActionsPanel, Drawer, Notice, Select, Typography } from '@linode/ui';
1010
import { getEntityIdsByPermission } from '@linode/utilities';
11-
import { Stack, Typography, useTheme } from '@mui/material';
11+
import { useTheme } from '@mui/material';
1212
import { useParams } from '@tanstack/react-router';
1313
import { useSnackbar } from 'notistack';
1414
import * as React from 'react';
@@ -20,7 +20,7 @@ import { getLinodeInterfaceType } from 'src/features/Linodes/LinodesDetail/Linod
2020
import { getAPIErrorOrDefault } from 'src/utilities/errorUtils';
2121
import { sanitizeHTML } from 'src/utilities/sanitizeHTML';
2222

23-
import type { LinodeInterface } from '@linode/api-v4';
23+
import type { Linode, LinodeInterface } from '@linode/api-v4';
2424

2525
interface Props {
2626
helperText: string;
@@ -65,14 +65,14 @@ export const AddLinodeDrawer = (props: Props) => {
6565
const { isPending: addDeviceIsLoading, mutateAsync: addDevice } =
6666
useAddFirewallDeviceMutation();
6767

68-
// keeps track of Linodes using configuration profile interfaces to add
68+
// Keep track of Linodes to add using configuration profile interfaces
6969
const [linodesToAdd, setLinodesToAdd] = React.useState<Linode[]>([]);
70-
// keeps track of interface devices to add
70+
// Keep track of interface devices to be added, mapping Linode ID to selected interface
7171
const [interfacesToAddMap, setInterfacesToAddMap] = React.useState<
7272
Map<number, InterfaceDeviceInfo | null>
7373
>(new Map());
7474
// Keep track of the linodes with multiple eligible linode interfaces to determine additional selects to show
75-
// Once an interface is selected, interfacesToAddMap will be updated
75+
// Once an interface is selected, interfacesToAddMap will be updated for that Linode ID
7676
const [linodesWithMultiInterfaces, setLinodesWithMultiInterfaces] =
7777
React.useState<LinodeWithMultiLinodeInterfaces[]>([]);
7878

@@ -246,16 +246,19 @@ export const AddLinodeDrawer = (props: Props) => {
246246
interfaceLinodes.map(async (linode) => {
247247
const linodeId = linode.id;
248248
const interfaces = await getLinodeInterfaces(linodeId);
249+
// vlan interfaces cannot have a firewall assigned to them
249250
const nonVlanInterfaces = interfaces.interfaces.filter(
250251
(iface) => !iface.vlan
251252
);
253+
252254
if (nonVlanInterfaces.length === 1) {
253255
_interfacesToAddMap.set(linodeId, {
254256
linodeId,
255257
linodeLabel: linode.label,
256258
interfaceId: nonVlanInterfaces[0].id,
257259
});
258260
}
261+
259262
if (nonVlanInterfaces.length > 1) {
260263
if (!interfacesToAddMap.has(linodeId)) {
261264
_interfacesToAddMap.set(linodeId, null);
@@ -265,17 +268,20 @@ export const AddLinodeDrawer = (props: Props) => {
265268
interfacesToAddMap.get(linodeId) ?? null
266269
);
267270
}
271+
268272
const interfacesWithLabels = nonVlanInterfaces.map((iface) => ({
269273
...iface,
270274
label: `${getLinodeInterfaceType(iface)} Interface (ID : ${iface.id})`,
271275
value: iface.id,
272276
}));
277+
273278
return {
274279
linodeId,
275280
linodeLabel: linode.label,
276281
linodeInterfaces: interfacesWithLabels,
277282
};
278283
}
284+
279285
return null;
280286
})
281287
);
@@ -328,39 +334,34 @@ export const AddLinodeDrawer = (props: Props) => {
328334
]}
329335
/>
330336
{linodesWithMultiInterfaces.length > 0 && (
331-
<Typography marginTop={2}>
332-
Please select the Linode Interface to add to this firewall for the
333-
below Linode(s).
337+
<Typography marginTop={3}>
338+
{`The following ${linodesWithMultiInterfaces.length === 1 ? 'Linode has' : 'Linodes have'}
339+
more than one interface to which a firewall can be applied. Select which interface.`}
334340
</Typography>
335341
)}
336342
{linodesWithMultiInterfaces.map((linode) => (
337-
<Stack key={linode.linodeId} marginTop={2}>
338-
<Typography>
339-
<strong>{linode.linodeLabel}</strong>
340-
</Typography>
341-
<Select
342-
label="Interfaces"
343-
onChange={(e, option) => {
344-
const updatedInterfacesToAdd = new Map(interfacesToAddMap);
345-
updatedInterfacesToAdd.set(linode.linodeId, {
346-
linodeId: linode.linodeId,
347-
linodeLabel: linode.linodeLabel,
348-
interfaceId: option.value,
349-
});
350-
setInterfacesToAddMap(updatedInterfacesToAdd);
351-
}}
352-
options={linode.linodeInterfaces}
353-
placeholder="Select Interface"
354-
sx={{ marginTop: -1 }}
355-
value={
356-
linode.linodeInterfaces.find(
357-
(iface) =>
358-
iface.id ===
359-
interfacesToAddMap.get(linode.linodeId)?.interfaceId
360-
) ?? null
361-
}
362-
/>
363-
</Stack>
343+
<Select
344+
key={linode.linodeId}
345+
label={`${linode.linodeLabel} Interface`}
346+
onChange={(e, option) => {
347+
const updatedInterfacesToAdd = new Map(interfacesToAddMap);
348+
updatedInterfacesToAdd.set(linode.linodeId, {
349+
linodeId: linode.linodeId,
350+
linodeLabel: linode.linodeLabel,
351+
interfaceId: option.value,
352+
});
353+
setInterfacesToAddMap(updatedInterfacesToAdd);
354+
}}
355+
options={linode.linodeInterfaces}
356+
placeholder="Select Interface"
357+
value={
358+
linode.linodeInterfaces.find(
359+
(iface) =>
360+
iface.id ===
361+
interfacesToAddMap.get(linode.linodeId)?.interfaceId
362+
) ?? null
363+
}
364+
/>
364365
))}
365366
<ActionsPanel
366367
primaryButtonProps={{

0 commit comments

Comments
 (0)