@@ -33,7 +33,6 @@ import { RadioField } from '~/components/form/fields/RadioField'
3333import { TextField , TextFieldInner } from '~/components/form/fields/TextField'
3434import { useVpcSelector } from '~/hooks/use-params'
3535import { Badge } from '~/ui/lib/Badge'
36- import { Button } from '~/ui/lib/Button'
3736import { FormDivider } from '~/ui/lib/Divider'
3837import { Message } from '~/ui/lib/Message'
3938import * as MiniTable from '~/ui/lib/MiniTable'
@@ -50,9 +49,9 @@ import { type FirewallRuleValues } from './firewall-rules-util'
5049 * a few sub-sections (Ports, Protocols, and Hosts).
5150 *
5251 * The Targets section and the Filters:Hosts section are very similar, so we've
53- * pulled common code to the DynamicTypeAndValueFields and ClearAndAddButtons
54- * components. We also then set up the Targets / Ports / Hosts variables at the
55- * top of the CommonFields component.
52+ * pulled common code to the DynamicTypeAndValueFields components.
53+ * We also then set up the Targets / Ports / Hosts variables at the top of the
54+ * CommonFields component.
5655 */
5756
5857type TargetAndHostFilterType =
@@ -154,34 +153,6 @@ const DynamicTypeAndValueFields = ({
154153 )
155154}
156155
157- // The "Clear" and "Add …" buttons that appear below the filter input fields
158- const ClearAndAddButtons = ( {
159- isDirty,
160- onClear,
161- onSubmit,
162- buttonCopy,
163- } : {
164- isDirty : boolean
165- onClear : ( ) => void
166- onSubmit : ( ) => void
167- buttonCopy : string
168- } ) => (
169- < div className = "flex justify-end" >
170- < Button
171- variant = "ghost"
172- size = "sm"
173- className = "mr-2.5"
174- disabled = { ! isDirty }
175- onClick = { onClear }
176- >
177- Clear
178- </ Button >
179- < Button size = "sm" onClick = { onSubmit } >
180- { buttonCopy }
181- </ Button >
182- </ div >
183- )
184-
185156type TypeAndValueTableProps = {
186157 sectionType : 'target' | 'host'
187158 items : ControllerRenderProps < FirewallRuleValues , 'targets' | 'hosts' >
@@ -447,11 +418,11 @@ export const CommonFields = ({ control, nameTaken, error }: CommonFieldsProps) =
447418 onInputChange = { ( value ) => targetForm . setValue ( 'value' , value ) }
448419 onSubmitTextField = { submitTarget }
449420 />
450- < ClearAndAddButtons
451- isDirty = { ! ! targetValue }
421+ < MiniTable . ClearAndAddButtons
422+ addButtonCopy = "Add target"
423+ disableClear = { ! ! targetValue }
452424 onClear = { ( ) => targetForm . reset ( ) }
453425 onSubmit = { submitTarget }
454- buttonCopy = "Add target"
455426 />
456427 </ div >
457428 { ! ! targets . value . length && < TypeAndValueTable sectionType = "target" items = { targets } /> }
@@ -498,11 +469,11 @@ export const CommonFields = ({ control, nameTaken, error }: CommonFieldsProps) =
498469 } }
499470 />
500471 </ div >
501- < ClearAndAddButtons
502- isDirty = { ! ! portValue }
472+ < MiniTable . ClearAndAddButtons
473+ addButtonCopy = "Add port filter"
474+ disableClear = { ! ! portValue }
503475 onClear = { portRangeForm . reset }
504476 onSubmit = { submitPortRange }
505- buttonCopy = "Add port filter"
506477 />
507478 </ div >
508479 { ! ! ports . value . length && (
@@ -554,11 +525,11 @@ export const CommonFields = ({ control, nameTaken, error }: CommonFieldsProps) =
554525 onInputChange = { ( value ) => hostForm . setValue ( 'value' , value ) }
555526 onSubmitTextField = { submitHost }
556527 />
557- < ClearAndAddButtons
558- isDirty = { ! ! hostValue }
528+ < MiniTable . ClearAndAddButtons
529+ addButtonCopy = "Add host filter"
530+ disableClear = { ! ! hostValue }
559531 onClear = { ( ) => hostForm . reset ( ) }
560532 onSubmit = { submitHost }
561- buttonCopy = "Add host filter"
562533 />
563534 </ div >
564535 { ! ! hosts . value . length && < TypeAndValueTable sectionType = "host" items = { hosts } /> }
0 commit comments