-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathfirewall-rules-common.tsx
More file actions
730 lines (667 loc) · 24.2 KB
/
firewall-rules-common.tsx
File metadata and controls
730 lines (667 loc) · 24.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright Oxide Computer Company
*/
import { useEffect, type ReactNode } from 'react'
import { useController, useForm, type Control } from 'react-hook-form'
import { Badge } from '@oxide/design-system/ui'
import {
api,
q,
usePrefetchedQuery,
type ApiError,
type Instance,
type Vpc,
type VpcFirewallIcmpFilter,
type VpcFirewallRuleAction,
type VpcFirewallRuleDirection,
type VpcFirewallRuleHostFilter,
type VpcFirewallRuleProtocol,
type VpcFirewallRuleTarget,
type VpcSubnet,
} from '~/api'
import { parsePortRange } from '~/api/util'
import { CheckboxField } from '~/components/form/fields/CheckboxField'
import { ComboboxField } from '~/components/form/fields/ComboboxField'
import { DescriptionField } from '~/components/form/fields/DescriptionField'
import { ListboxField } from '~/components/form/fields/ListboxField'
import { NameField, validateName } from '~/components/form/fields/NameField'
import { NumberField } from '~/components/form/fields/NumberField'
import { RadioField } from '~/components/form/fields/RadioField'
import { TextField, TextFieldInner } from '~/components/form/fields/TextField'
import { useVpcSelector } from '~/hooks/use-params'
import {
ProtocolCell,
ProtocolCodeCell,
ProtocolTypeCell,
} from '~/table/cells/ProtocolCell'
import { toComboboxItems } from '~/ui/lib/Combobox'
import { FormDivider } from '~/ui/lib/Divider'
import { FieldLabel } from '~/ui/lib/FieldLabel'
import { Message } from '~/ui/lib/Message'
import { ClearAndAddButtons, MiniTable } from '~/ui/lib/MiniTable'
import { SideModal } from '~/ui/lib/SideModal'
import { TextInputHint } from '~/ui/lib/TextInput'
import { KEYS } from '~/ui/util/keys'
import { ALL_ISH } from '~/util/consts'
import { validateIp, validateIpNet } from '~/util/ip'
import { links } from '~/util/links'
import { getProtocolDisplayName, getProtocolKey, ICMP_TYPES } from '~/util/protocol'
import { capitalize, normalizeDashes } from '~/util/str'
import { type FirewallRuleValues } from './firewall-rules-util'
/**
* This is a large file. The main thing to be aware of is that the firewall rules
* form is made up of two main sections: Targets and Filters. Filters, then, has
* a few sub-sections (Ports, Protocols, and Hosts).
*
* The Targets section and the Filters:Hosts section are very similar, so we've
* pulled common code to the TargetAndHostFilterSubform components.
* We also then set up the Targets / Ports / Hosts variables at the top of the
* CommonFields component.
*/
type TargetAndHostFilterType =
| VpcFirewallRuleTarget['type']
// oxlint-disable-next-line @typescript-eslint/no-duplicate-type-constituents
| VpcFirewallRuleHostFilter['type']
type TargetAndHostFormValues = {
type: TargetAndHostFilterType
value: string
}
// these are part of the target and host filter form;
// the specific values depend on the target or host filter type selected
const getFilterValueProps = (targetOrHostType: TargetAndHostFilterType) => {
switch (targetOrHostType) {
case 'vpc':
return { label: 'VPC name' }
case 'subnet':
return { label: 'Subnet name' }
case 'instance':
return { label: 'Instance name' }
case 'ip':
return { label: 'IP address', description: 'Enter an IPv4 or IPv6 address' }
case 'ip_net':
return {
label: 'IP network',
description: 'Looks like 192.168.0.0/16 or fd00:1122:3344:0001::1/64',
}
}
}
const TargetAndHostFilterSubform = ({
sectionType,
control,
messageContent,
}: {
sectionType: 'target' | 'host'
control: Control<FirewallRuleValues>
messageContent: ReactNode
}) => {
const { project, vpc } = useVpcSelector()
// prefetchedApiQueries below are prefetched in firewall-rules-create and -edit
const {
data: { items: instances },
} = usePrefetchedQuery(q(api.instanceList, { query: { project, limit: ALL_ISH } }))
const {
data: { items: vpcs },
} = usePrefetchedQuery(q(api.vpcList, { query: { project, limit: ALL_ISH } }))
const {
data: { items: vpcSubnets },
} = usePrefetchedQuery(q(api.vpcSubnetList, { query: { project, vpc, limit: ALL_ISH } }))
const subform = useForm({ defaultValues: targetAndHostDefaultValues })
const field = useController({ name: `${sectionType}s`, control }).field
const submitSubform = subform.handleSubmit(({ type, value }) => {
if (!type || !value) return
if (field.value.some((f) => f.type === type && f.value === value)) return
field.onChange([...field.value, { type, value }])
subform.reset(targetAndHostDefaultValues)
})
// HACK: we need to reset the target form completely after a successful submit,
// including especially `isSubmitted`, because that governs whether we're in
// the validate regime (which doesn't validate until submit) or the reValidate
// regime (which validate on every keypress). The reset inside `handleSubmit`
// doesn't do that for us because `handleSubmit` set `isSubmitted: true` after
// running the callback. So we have to watch for a successful submit and call
// the reset again here.
// https://github.com/react-hook-form/react-hook-form/blob/9a497a70a/src/logic/createFormControl.ts#L1194-L1203
const { isSubmitSuccessful: subformSubmitSuccessful } = subform.formState
useEffect(() => {
if (subformSubmitSuccessful) subform.reset(targetAndHostDefaultValues)
}, [subformSubmitSuccessful, subform])
const [valueType, value] = subform.watch(['type', 'value'])
const sectionItems = {
vpc: availableItems(field.value, 'vpc', vpcs),
subnet: availableItems(field.value, 'subnet', vpcSubnets),
instance: availableItems(field.value, 'instance', instances),
ip: [],
ip_net: [],
}
const items = toComboboxItems(sectionItems[valueType])
const subformControl = subform.control
// HACK: reset the whole subform, keeping type (because we just set
// it). most importantly, this resets isSubmitted so the form can go
// back to validating on submit instead of change. Also resets readyToSubmit.
const onTypeChange = () => {
subform.reset({ type: subform.getValues('type'), value: '' })
}
const onInputChange = (value: string) => {
subform.setValue('value', value)
}
const noun = sectionType === 'target' ? 'target' : 'host filter'
const nounTitle = capitalize(noun) + 's'
return (
<>
<SideModal.Heading>{nounTitle}</SideModal.Heading>
<Message variant="info" content={messageContent} />
<ListboxField
name="type"
label={`${capitalize(sectionType)} type`}
control={subformControl}
items={targetHostTypeItems}
onChange={onTypeChange}
hideOptionalTag
/>
{/* In the firewall rules form, a few types get comboboxes instead of text fields */}
{valueType === 'vpc' || valueType === 'subnet' || valueType === 'instance' ? (
<ComboboxField
disabled={subform.formState.isSubmitting}
name="value"
{...getFilterValueProps(valueType)}
description="Select an option or enter a custom value"
control={subformControl}
onEnter={submitSubform}
onInputChange={onInputChange}
items={items}
allowArbitraryValues
hideOptionalTag
validate={(value) =>
// required: false arg is desirable because otherwise if you put in
// a bad name and submit, causing it to revalidate onChange, then
// clear the field you're left with a BS "Target name is required"
// error message
validateName(value, `${capitalize(sectionType)} name`, false)
}
/>
) : (
<TextField
name="value"
{...getFilterValueProps(valueType)}
control={subformControl}
disabled={subform.formState.isSubmitting}
onKeyDown={(e) => {
if (e.key === KEYS.enter) {
e.preventDefault() // prevent full form submission
submitSubform(e)
}
}}
validate={(value) =>
(valueType === 'ip' && validateIp(value)) ||
(valueType === 'ip_net' && validateIpNet(value)) ||
undefined
}
/>
)}
<ClearAndAddButtons
addButtonCopy={`Add ${noun}`}
disabled={!value}
onClear={() => subform.reset()}
onSubmit={submitSubform}
/>
<MiniTable
className="mb-4"
ariaLabel={nounTitle}
items={field.value}
columns={targetAndHostTableColumns}
rowKey={({ type, value }: VpcFirewallRuleTarget | VpcFirewallRuleHostFilter) =>
`${type}|${value}`
}
onRemoveItem={({
type,
value,
}: VpcFirewallRuleTarget | VpcFirewallRuleHostFilter) => {
field.onChange(field.value.filter((i) => !(i.value === value && i.type === type)))
}}
/>
</>
)
}
/** Given an array of *committed* items (VPCs, Subnets, Instances) and a list of *all* items,
* return the items that are available */
const availableItems = (
committedItems: Array<VpcFirewallRuleTarget | VpcFirewallRuleHostFilter>,
itemType: 'vpc' | 'subnet' | 'instance',
items: Array<Vpc | VpcSubnet | Instance>
) => {
if (!items) return []
return (
items
// remove any items that match the committed items on both type and value
.filter(
({ name }) =>
!committedItems.filter((ci) => ci.type === itemType && ci.value === name).length
)
)
}
// Protocol selection form values for the subform
type ProtocolFormValues = {
protocolType: VpcFirewallRuleProtocol['type'] | ''
icmpType?: string // ComboboxField with allowArbitraryValues can return strings
icmpCode?: string
}
const targetHostTypeItems: Array<{
value: VpcFirewallRuleHostFilter['type']
label: string
}> = [
{ value: 'vpc', label: 'VPC' },
{ value: 'subnet', label: 'VPC subnet' },
{ value: 'instance', label: 'Instance' },
{ value: 'ip', label: 'IP' },
{ value: 'ip_net', label: 'IP subnet' },
]
const actionItems: Array<{ value: VpcFirewallRuleAction; label: string }> = [
{ value: 'allow', label: 'Allow' },
{ value: 'deny', label: 'Deny' },
]
const directionItems: Array<{ value: VpcFirewallRuleDirection; label: string }> = [
{ value: 'inbound', label: 'Inbound' },
{ value: 'outbound', label: 'Outbound' },
]
const protocolTypeItems: Array<{ value: VpcFirewallRuleProtocol['type']; label: string }> =
[
{ value: 'tcp', label: 'TCP' },
{ value: 'udp', label: 'UDP' },
{ value: 'icmp', label: 'ICMP' },
]
const icmpTypeItems = [
{ value: '', label: 'All types', selectedLabel: 'All types' },
...Object.entries(ICMP_TYPES).map(([type, name]) => ({
value: type,
label: `${type} - ${name}`,
selectedLabel: type,
})),
]
const targetAndHostTableColumns = [
{
header: 'Type',
cell: (item: VpcFirewallRuleTarget | VpcFirewallRuleHostFilter) => (
<Badge>{item.type}</Badge>
),
},
{
header: 'Value',
text: (item: VpcFirewallRuleTarget | VpcFirewallRuleHostFilter) => item.value,
},
]
const portTableColumns = [{ header: 'Port ranges', text: (p: string) => p }]
const protocolTableColumns = [
{
header: 'Protocol',
cell: (protocol: VpcFirewallRuleProtocol) => <ProtocolCell protocol={protocol} />,
},
{
header: 'Type',
cell: (protocol: VpcFirewallRuleProtocol) => <ProtocolTypeCell protocol={protocol} />,
},
{
header: 'Code',
cell: (protocol: VpcFirewallRuleProtocol) => <ProtocolCodeCell protocol={protocol} />,
},
]
const isDuplicateProtocol = (
newProtocol: VpcFirewallRuleProtocol,
existingProtocols: VpcFirewallRuleProtocol[]
) => {
if (newProtocol.type === 'tcp' || newProtocol.type === 'udp') {
return existingProtocols.some((p) => p.type === newProtocol.type)
}
if (newProtocol.type === 'icmp') {
if (newProtocol.value === null) {
return existingProtocols.some((p) => p.type === 'icmp' && p.value === null)
}
return existingProtocols.some(
(p) =>
p.type === 'icmp' &&
p.value?.icmpType === newProtocol.value?.icmpType &&
p.value?.code === newProtocol.value?.code
)
}
return false
}
type ParseResult<T> = { success: true; data: T } | { success: false; message: string }
const parseIcmpType = (value: string | undefined): ParseResult<number | undefined> => {
if (value === undefined || value === '') return { success: true, data: undefined }
const parsed = parseInt(value, 10)
if (isNaN(parsed) || parsed < 0 || parsed > 255) {
return { success: false, message: `ICMP type must be a number between 0 and 255` }
}
return { success: true, data: parsed }
}
const icmpCodeValidation = (value: string | undefined) => {
if (!value || value.trim() === '') return undefined // allow empty
const trimmedValue = value.trim()
// Check if it's a single number
if (/^\d+$/.test(trimmedValue)) {
const num = parseInt(trimmedValue, 10)
if (num < 0 || num > 255) {
return 'ICMP code must be between 0 and 255'
}
return undefined
}
// Check if it's a range (e.g., "0-255", "1-10")
if (/^\d+-\d+$/.test(trimmedValue)) {
const [startStr, endStr] = trimmedValue.split('-')
const start = parseInt(startStr, 10)
const end = parseInt(endStr, 10)
if (start < 0 || start > 255) {
return 'ICMP code range start must be between 0 and 255'
}
if (end < 0 || end > 255) {
return 'ICMP code range end must be between 0 and 255'
}
if (start > end) {
return 'ICMP code range start must be less than or equal to range end'
}
return undefined
}
return 'ICMP code must be a number or numeric range'
}
const ProtocolFilters = ({ control }: { control: Control<FirewallRuleValues> }) => {
const protocols = useController({ name: 'protocols', control }).field
const protocolForm = useForm<ProtocolFormValues>({
defaultValues: { protocolType: '' },
})
const selectedProtocolType = protocolForm.watch('protocolType')
const selectedIcmpType = protocolForm.watch('icmpType')
const addProtocolIfUnique = (newProtocol: VpcFirewallRuleProtocol) => {
if (!isDuplicateProtocol(newProtocol, protocols.value)) {
protocols.onChange([...protocols.value, newProtocol])
}
}
const submitProtocol = protocolForm.handleSubmit((values) => {
if (values.protocolType === 'tcp' || values.protocolType === 'udp') {
addProtocolIfUnique({ type: values.protocolType })
} else if (values.protocolType === 'icmp') {
// this parse should never fail because we've already validated, but doing
// it this way keeps the just-in-case early return logic consistent
const parseResult = parseIcmpType(values.icmpType)
if (!parseResult.success) return
const icmpType = parseResult.data
if (icmpType === undefined) {
// All ICMP types
addProtocolIfUnique({ type: 'icmp', value: null })
} else {
// Specific ICMP type
const icmpValue: VpcFirewallIcmpFilter = { icmpType }
if (values.icmpCode) {
icmpValue.code = values.icmpCode
}
addProtocolIfUnique({ type: 'icmp', value: icmpValue })
}
}
protocolForm.reset()
})
const removeProtocol = (protocolToRemove: VpcFirewallRuleProtocol) => {
const newProtocols = protocols.value.filter((protocol) => protocol !== protocolToRemove)
protocols.onChange(newProtocols)
}
return (
<>
<div className="space-y-3">
<div className="space-y-5">
<ListboxField
name="protocolType"
label="Protocol filters"
hideOptionalTag
control={protocolForm.control}
placeholder=""
items={protocolTypeItems}
/>
{selectedProtocolType === 'icmp' && (
<>
<ComboboxField
label="ICMP type"
name="icmpType"
control={protocolForm.control}
description="Leave blank to match any type"
placeholder=""
allowArbitraryValues
onInputChange={(value) => protocolForm.setValue('icmpType', value)}
items={icmpTypeItems}
validate={(value) => {
const result = parseIcmpType(value)
if (!result.success) return result.message
}}
/>
{selectedIcmpType !== undefined && selectedIcmpType !== '' && (
<TextField
label="ICMP code"
name="icmpCode"
control={protocolForm.control}
description={
<>
Enter a code (0) or range (e.g., 1–3). Leave blank for all
traffic of type {selectedIcmpType}.
</>
}
placeholder=""
validate={icmpCodeValidation}
transform={normalizeDashes}
onKeyDown={(e) => {
if (e.key === KEYS.enter) {
e.preventDefault() // prevent full form submission
submitProtocol(e)
}
}}
/>
)}
</>
)}
</div>
<ClearAndAddButtons
addButtonCopy="Add protocol filter"
disabled={!selectedProtocolType}
onClear={() => protocolForm.reset()}
onSubmit={submitProtocol}
/>
</div>
{protocols.value.length > 0 && (
<MiniTable
ariaLabel="Protocol filters"
items={protocols.value}
columns={protocolTableColumns}
rowKey={getProtocolKey}
emptyState={{ title: 'No protocols', body: 'Add a protocol to see it here' }}
onRemoveItem={removeProtocol}
removeLabel={(protocol) => `Remove ${getProtocolDisplayName(protocol)}`}
/>
)}
</>
)
}
type CommonFieldsProps = {
control: Control<FirewallRuleValues>
nameTaken: (name: string) => boolean
error: ApiError | null
}
const targetAndHostDefaultValues: TargetAndHostFormValues = {
type: 'vpc',
value: '',
}
export const CommonFields = ({ control, nameTaken, error }: CommonFieldsProps) => {
// Ports
const portRangeForm = useForm({ defaultValues: { portRange: '' } })
const ports = useController({ name: 'ports', control }).field
const portValue = portRangeForm.watch('portRange')
const submitPortRange = portRangeForm.handleSubmit(({ portRange }) => {
const portRangeValue = portRange.trim()
// at this point we've already validated in validate() that it parses and
// that it is not already in the list
ports.onChange([...ports.value, portRangeValue])
portRangeForm.reset()
})
return (
<>
<Message
variant="info"
content={
<>
Read the{' '}
<a
href={links.firewallRulesDocs}
// don't need color and hover color because message text is already color-info anyway
className="underline"
target="_blank"
rel="noreferrer"
>
Networking
</a>{' '}
guide and the{' '}
<a
href="https://docs.oxide.computer/api/vpc_firewall_rules_update"
// don't need color and hover color because message text is already color-info anyway
className="underline"
target="_blank"
rel="noreferrer"
>
API docs
</a>{' '}
to learn more about firewall rules.
</>
}
/>
{/* omitting value prop makes it a boolean value. beautiful */}
{/* TODO: better text or heading or tip or something on this checkbox */}
<CheckboxField name="enabled" control={control}>
Enabled
</CheckboxField>
<NameField
name="name"
control={control}
validate={(name) => {
if (nameTaken(name)) {
// TODO: might be worth mentioning that the names are unique per VPC as opposed to globally
return 'Name taken. To update an existing rule, edit it directly.'
}
}}
/>
<DescriptionField name="description" control={control} />
<RadioField name="action" column control={control} items={actionItems} />
<RadioField
name="direction"
label="Direction of traffic"
column
control={control}
description={
<>
An inbound rule applies to traffic <em>to</em> the targets, while an outbound
rule applies to traffic <em>from</em> the targets.
</>
}
items={directionItems}
/>
<NumberField
name="priority"
description="Must be 0–65535. Lower-numbered rules apply first."
required
control={control}
/>
<FormDivider />
<TargetAndHostFilterSubform
sectionType="target"
control={control}
messageContent={
<>
<p>
Targets determine the instances to which this rule applies. You can target
instances directly or specify a VPC, VPC subnet, IP, or IP subnet, which will
apply the rule to traffic going to all matching instances.
</p>
<p className="mt-2">
Targets are additive: the rule applies to instances matching <em>any</em>{' '}
target.
</p>
</>
}
/>
<FormDivider />
<SideModal.Heading>Filters</SideModal.Heading>
<Message
variant="info"
content={
<>
Filters reduce the scope of this rule. Without filters, the rule applies to all
traffic to the targets (or from the targets, if it’s an outbound rule).
With multiple filter types, the rule applies to traffic matching at least one
filter of <em>every</em> type.
</>
}
/>
<div className="flex flex-col gap-3">
{/* We have to blow this up instead of using TextField to get better
text styling on the label */}
<div className="mt-2">
<FieldLabel id="portRange-label" htmlFor="portRange">
Port filters
</FieldLabel>
<TextInputHint id="portRange-help-text" className="mb-2">
A single destination port (1234) or a range (1234–2345)
</TextInputHint>
<TextFieldInner
id="portRange"
name="portRange"
required
control={portRangeForm.control}
onKeyDown={(e) => {
if (e.key === KEYS.enter) {
e.preventDefault() // prevent full form submission
submitPortRange(e)
}
}}
validate={(value) => {
if (!parsePortRange(value)) return 'Not a valid port range'
if (ports.value.includes(value.trim())) return 'Port range already added'
}}
/>
</div>
<ClearAndAddButtons
addButtonCopy="Add port filter"
disabled={!portValue}
onClear={() => portRangeForm.reset()}
onSubmit={submitPortRange}
/>
</div>
{ports.value.length > 0 && (
<MiniTable
className="mb-4"
ariaLabel="Port filters"
items={ports.value}
columns={portTableColumns}
rowKey={(port) => port}
emptyState={{ title: 'No ports', body: 'Add a port to see it here' }}
onRemoveItem={(p) => ports.onChange(ports.value.filter((p1) => p1 !== p))}
removeLabel={(port) => `remove port ${port}`}
/>
)}
<ProtocolFilters control={control} />
<FormDivider />
<TargetAndHostFilterSubform
sectionType="host"
control={control}
messageContent={
<>
Host filters match the “other end” of traffic from the
target’s perspective: for an inbound rule, they match the source of
traffic. For an outbound rule, they match the destination.
</>
}
/>
{error && (
<>
<FormDivider />
<div className="text-destructive">{error.message}</div>
</>
)}
</>
)
}