Skip to content

Commit b886e4b

Browse files
authored
Disallow firewall-rule subform submission when target / host filter value is missing (#2550)
disallow subform submission when value is missing
1 parent 7303d9d commit b886e4b

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

app/forms/firewall-rules-common.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ const TargetAndHostFilterSubform = ({
211211
)}
212212
<MiniTable.ClearAndAddButtons
213213
addButtonCopy={`Add ${sectionType === 'host' ? 'host filter' : 'target'}`}
214-
disableClear={!value}
214+
disabled={!value}
215215
onClear={() => subform.reset()}
216216
onSubmit={submitSubform}
217217
/>
@@ -452,7 +452,7 @@ export const CommonFields = ({ control, nameTaken, error }: CommonFieldsProps) =
452452
</div>
453453
<MiniTable.ClearAndAddButtons
454454
addButtonCopy="Add port filter"
455-
disableClear={!portValue}
455+
disabled={!portValue}
456456
onClear={() => portRangeForm.reset()}
457457
onSubmit={submitPortRange}
458458
/>

app/forms/network-interface-edit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export function EditNetworkInterfaceForm({
128128
</div>
129129
<MiniTable.ClearAndAddButtons
130130
addButtonCopy="Add Transit IP"
131-
disableClear={!transitIpValue}
131+
disabled={!transitIpValue}
132132
onClear={() => transitIpsForm.reset()}
133133
onSubmit={submitTransitIp}
134134
/>

app/ui/lib/MiniTable.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const RemoveCell = ({ onClick, label }: { onClick: () => void; label: str
4848

4949
type ClearAndAddButtonsProps = {
5050
addButtonCopy: string
51-
disableClear: boolean
51+
disabled: boolean
5252
onClear: () => void
5353
onSubmit: () => void
5454
}
@@ -59,15 +59,15 @@ type ClearAndAddButtonsProps = {
5959
*/
6060
export const ClearAndAddButtons = ({
6161
addButtonCopy,
62-
disableClear,
62+
disabled,
6363
onClear,
6464
onSubmit,
6565
}: ClearAndAddButtonsProps) => (
6666
<div className="flex justify-end gap-2.5">
67-
<Button variant="ghost" size="sm" disabled={disableClear} onClick={onClear}>
67+
<Button variant="ghost" size="sm" onClick={onClear} disabled={disabled}>
6868
Clear
6969
</Button>
70-
<Button size="sm" onClick={onSubmit}>
70+
<Button size="sm" onClick={onSubmit} disabled={disabled}>
7171
{addButtonCopy}
7272
</Button>
7373
</div>

test/e2e/firewall-rules.e2e.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ test('firewall rule form targets table', async ({ page }) => {
160160

161161
const addButton = page.getByRole('button', { name: 'Add target' })
162162

163+
// addButton should be disabled until a value is added
164+
await expect(addButton).toBeDisabled()
165+
163166
// add targets with overlapping names and types to test delete
164167

165168
await targetVpcNameField.fill('abc')
@@ -181,7 +184,10 @@ test('firewall rule form targets table', async ({ page }) => {
181184
// add a subnet by selecting from a dropdown; make sure 'mock-subnet' is present in the dropdown,
182185
// even though VPC:'mock-subnet' has already been added
183186
await selectOption(page, 'Target type', 'VPC subnet')
187+
// addButton should be disabled again, as type has changed but no value has been entered
188+
await expect(addButton).toBeDisabled()
184189
await selectOption(page, subnetNameField, 'mock-subnet')
190+
await expect(addButton).toBeEnabled()
185191
await addButton.click()
186192
await expectRowVisible(targets, { Type: 'subnet', Value: 'mock-subnet' })
187193

0 commit comments

Comments
 (0)