Skip to content

Commit 8297880

Browse files
authored
Disable ephemeral IP attach button instead of hiding (#3044)
disable ephemeral ip attach button, not hide
1 parent 986e6df commit 8297880

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

app/pages/project/instances/NetworkingTab.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,12 @@ export default function NetworkingTab() {
517517
getCoreRowModel: getCoreRowModel(),
518518
})
519519

520-
// If there's already an ephemeral IP, or if there are no network interfaces,
521-
// they shouldn't be able to attach an ephemeral IP
522-
const enableEphemeralAttachButton =
523-
eips.items.filter((ip) => ip.kind === 'ephemeral').length === 0 && nics.length > 0
520+
const ephemeralDisabledReason =
521+
nics.length === 0
522+
? 'Instance has no network interfaces'
523+
: eips.items.some((ip) => ip.kind === 'ephemeral')
524+
? 'Instance already has an ephemeral IP'
525+
: null
524526

525527
const floatingDisabledReason =
526528
eips.items.filter((ip) => ip.kind === 'floating').length >= 32
@@ -534,16 +536,14 @@ export default function NetworkingTab() {
534536
<CardBlock>
535537
<CardBlock.Header title="External IPs" titleId="attached-ips-label">
536538
<div className="flex gap-3">
537-
{/*
538-
We normally wouldn't hide this button and would just have a disabled state on it,
539-
but it is very rare for this button to be necessary, and it would be disabled
540-
most of the time, for most users. To reduce clutter on the screen, we're hiding it.
541-
*/}
542-
{enableEphemeralAttachButton && (
543-
<Button size="sm" onClick={() => setAttachEphemeralModalOpen(true)}>
544-
Attach ephemeral IP
545-
</Button>
546-
)}
539+
<Button
540+
size="sm"
541+
onClick={() => setAttachEphemeralModalOpen(true)}
542+
disabled={!!ephemeralDisabledReason}
543+
disabledReason={ephemeralDisabledReason}
544+
>
545+
Attach ephemeral IP
546+
</Button>
547547
<Button
548548
size="sm"
549549
onClick={() => setAttachFloatingModalOpen(true)}

test/e2e/instance-networking.e2e.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ test('Instance networking tab — Detach / Attach Ephemeral IPs', async ({ page
118118
// We start out with an ephemeral IP attached
119119
await expect(ephemeralCell).toBeVisible()
120120

121-
// The 'Attach ephemeral IP' button should be hidden when there is still an existing ephemeral IP
122-
await expect(attachEphemeralIpButton).toBeHidden()
121+
// The 'Attach ephemeral IP' button should be disabled when there is already an ephemeral IP
122+
await expect(attachEphemeralIpButton).toBeDisabled()
123123

124124
// Detach the existing ephemeral IP
125125
await clickRowAction(page, 'ephemeral', 'Detach')
@@ -146,8 +146,8 @@ test('Instance networking tab — Detach / Attach Ephemeral IPs', async ({ page
146146
'IP pool': 'ip-pool-1',
147147
})
148148

149-
// The 'Attach ephemeral IP' button should be hidden after attaching an ephemeral IP
150-
await expect(attachEphemeralIpButton).toBeHidden()
149+
// The 'Attach ephemeral IP' button should be disabled after attaching an ephemeral IP
150+
await expect(attachEphemeralIpButton).toBeDisabled()
151151

152152
// Detach and test with explicit pool selection
153153
await clickRowAction(page, 'ephemeral', 'Detach')
@@ -168,8 +168,8 @@ test('Instance networking tab — Detach / Attach Ephemeral IPs', async ({ page
168168
'IP pool': 'ip-pool-2',
169169
})
170170

171-
// The 'Attach ephemeral IP' button should be hidden after attaching an ephemeral IP
172-
await expect(attachEphemeralIpButton).toBeHidden()
171+
// The 'Attach ephemeral IP' button should be disabled after attaching an ephemeral IP
172+
await expect(attachEphemeralIpButton).toBeDisabled()
173173
})
174174

175175
test('Instance networking tab — floating IPs', async ({ page }) => {

0 commit comments

Comments
 (0)