Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/forms/firewall-rules-common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const TargetAndHostFilterSubform = ({
)}
<MiniTable.ClearAndAddButtons
addButtonCopy={`Add ${sectionType === 'host' ? 'host filter' : 'target'}`}
disableClear={!value}
disabled={!value}
onClear={() => subform.reset()}
onSubmit={submitSubform}
/>
Expand Down Expand Up @@ -452,7 +452,7 @@ export const CommonFields = ({ control, nameTaken, error }: CommonFieldsProps) =
</div>
<MiniTable.ClearAndAddButtons
addButtonCopy="Add port filter"
disableClear={!portValue}
disabled={!portValue}
onClear={() => portRangeForm.reset()}
onSubmit={submitPortRange}
/>
Expand Down
2 changes: 1 addition & 1 deletion app/forms/network-interface-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function EditNetworkInterfaceForm({
</div>
<MiniTable.ClearAndAddButtons
addButtonCopy="Add Transit IP"
disableClear={!transitIpValue}
disabled={!transitIpValue}
onClear={() => transitIpsForm.reset()}
onSubmit={submitTransitIp}
/>
Expand Down
8 changes: 4 additions & 4 deletions app/ui/lib/MiniTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const RemoveCell = ({ onClick, label }: { onClick: () => void; label: str

type ClearAndAddButtonsProps = {
addButtonCopy: string
disableClear: boolean
disabled: boolean
onClear: () => void
onSubmit: () => void
}
Expand All @@ -59,15 +59,15 @@ type ClearAndAddButtonsProps = {
*/
export const ClearAndAddButtons = ({
addButtonCopy,
disableClear,
disabled,
onClear,
onSubmit,
}: ClearAndAddButtonsProps) => (
<div className="flex justify-end gap-2.5">
<Button variant="ghost" size="sm" disabled={disableClear} onClick={onClear}>
<Button variant="ghost" size="sm" onClick={onClear} disabled={disabled}>
Clear
</Button>
<Button size="sm" onClick={onSubmit}>
<Button size="sm" onClick={onSubmit} disabled={disabled}>
{addButtonCopy}
</Button>
</div>
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/firewall-rules.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ test('firewall rule form targets table', async ({ page }) => {

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

// addButton should be disabled until a value is added
await expect(addButton).toBeDisabled()

// add targets with overlapping names and types to test delete

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically covered by the click() and expectRowVisible on the next two lines, but I think having this line here (along with the expect…Disabled two lines up) makes it clear that the selectOption on the line in the middle of them is what enabled the button.

await addButton.click()
await expectRowVisible(targets, { Type: 'subnet', Value: 'mock-subnet' })

Expand Down