-
Notifications
You must be signed in to change notification settings - Fork 402
upcoming: [UIE-10433] - Implement feature to Unreserve IP address #13577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
grevanak-akamai
merged 3 commits into
linode:develop
from
grevanak-akamai:feature/UIE-10433-unreserve-ip
Apr 14, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-13577-upcoming-features-1776064521778.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@linode/manager": Upcoming Features | ||
| --- | ||
|
|
||
| Reserved IPs - Unreserve an IP address ([#13577](https://github.com/linode/manager/pull/13577)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
packages/manager/src/features/ReservedIps/ReservedIpsLanding/UnreserveIPDialog.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import { screen, waitFor } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import * as React from 'react'; | ||
|
|
||
| import { ipAddressFactory } from 'src/factories'; | ||
| import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
|
||
| import { UnreserveIPDialog } from './UnreserveIPDialog'; | ||
|
|
||
| const mockMutateAsync = vi.fn(); | ||
| const mockReset = vi.fn(); | ||
| const mockEnqueueSnackbar = vi.fn(); | ||
| const mockOnClose = vi.fn(); | ||
|
|
||
| const queryMocks = vi.hoisted(() => ({ | ||
| useUnReserveIPMutation: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock('@linode/queries', async (importOriginal) => ({ | ||
| ...(await importOriginal()), | ||
| useUnReserveIPMutation: queryMocks.useUnReserveIPMutation, | ||
| })); | ||
|
|
||
| vi.mock('notistack', async (importOriginal) => ({ | ||
| ...(await importOriginal()), | ||
| useSnackbar: () => ({ enqueueSnackbar: mockEnqueueSnackbar }), | ||
| })); | ||
|
|
||
| const ipAddress = ipAddressFactory.build({ address: '203.0.113.10' }); | ||
|
|
||
| const defaultProps = { | ||
| ipAddress, | ||
| onClose: mockOnClose, | ||
| open: true, | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| mockMutateAsync.mockReset(); | ||
| mockReset.mockReset(); | ||
| mockEnqueueSnackbar.mockReset(); | ||
| mockOnClose.mockReset(); | ||
|
|
||
| queryMocks.useUnReserveIPMutation.mockReturnValue({ | ||
| isPending: false, | ||
| mutateAsync: mockMutateAsync, | ||
| reset: mockReset, | ||
| }); | ||
| }); | ||
|
|
||
| describe('UnreserveIPDialog', () => { | ||
| it('renders the dialog with the correct title', () => { | ||
| renderWithTheme(<UnreserveIPDialog {...defaultProps} />); | ||
|
|
||
| expect(screen.getByText('Unreserve 203.0.113.10')).toBeVisible(); | ||
| }); | ||
|
|
||
| it('renders the confirmation message', () => { | ||
| renderWithTheme(<UnreserveIPDialog {...defaultProps} />); | ||
|
|
||
| expect( | ||
| screen.getByText( | ||
| /Unreserving this IP will remove it from your reserved list/i | ||
| ) | ||
| ).toBeVisible(); | ||
| }); | ||
|
|
||
| it('renders the Unreserve and Cancel buttons', () => { | ||
| renderWithTheme(<UnreserveIPDialog {...defaultProps} />); | ||
|
|
||
| expect(screen.getByRole('button', { name: 'Unreserve' })).toBeVisible(); | ||
| expect(screen.getByRole('button', { name: 'Cancel' })).toBeVisible(); | ||
| }); | ||
|
|
||
| it('does not render when open is false', () => { | ||
| renderWithTheme(<UnreserveIPDialog {...defaultProps} open={false} />); | ||
|
|
||
| expect(screen.queryByText('Unreserve 203.0.113.10?')).toBeNull(); | ||
| }); | ||
|
|
||
| it('calls onClose when Cancel is clicked', async () => { | ||
| renderWithTheme(<UnreserveIPDialog {...defaultProps} />); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', { name: 'Cancel' })); | ||
|
|
||
| expect(mockOnClose).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('shows success snackbar, and closes on successful submit', async () => { | ||
| mockMutateAsync.mockResolvedValueOnce({}); | ||
|
|
||
| renderWithTheme(<UnreserveIPDialog {...defaultProps} />); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', { name: 'Unreserve' })); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockMutateAsync).toHaveBeenCalled(); | ||
| }); | ||
| expect(mockEnqueueSnackbar).toHaveBeenCalledWith( | ||
| '203.0.113.10 has been unreserved.', | ||
| { variant: 'success' } | ||
| ); | ||
| expect(mockOnClose).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('shows an error notice when the API call fails', async () => { | ||
| mockMutateAsync.mockRejectedValueOnce([ | ||
| { reason: 'IP address could not be unreserved.' }, | ||
| ]); | ||
|
|
||
| renderWithTheme(<UnreserveIPDialog {...defaultProps} />); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', { name: 'Unreserve' })); | ||
|
|
||
| await waitFor(() => { | ||
| expect( | ||
| screen.getByText('IP address could not be unreserved.') | ||
| ).toBeVisible(); | ||
| }); | ||
| expect(mockOnClose).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('clears the error when the retry succeeds after a prior failure', async () => { | ||
| mockMutateAsync | ||
| .mockRejectedValueOnce([{ reason: 'Temporary network error.' }]) | ||
| .mockResolvedValueOnce({}); | ||
|
|
||
| renderWithTheme(<UnreserveIPDialog {...defaultProps} />); | ||
|
|
||
| // First attempt fails β error appears | ||
| await userEvent.click(screen.getByRole('button', { name: 'Unreserve' })); | ||
| await waitFor(() => | ||
| expect(screen.getByText('Temporary network error.')).toBeVisible() | ||
| ); | ||
|
|
||
| // Retry β should succeed and call onClose | ||
| await userEvent.click(screen.getByRole('button', { name: 'Unreserve' })); | ||
| await waitFor(() => expect(mockOnClose).toHaveBeenCalled()); | ||
| }); | ||
|
|
||
| it('disables both buttons while the request is pending', () => { | ||
| queryMocks.useUnReserveIPMutation.mockReturnValue({ | ||
| isPending: true, | ||
| mutateAsync: mockMutateAsync, | ||
| reset: mockReset, | ||
| }); | ||
|
|
||
| renderWithTheme(<UnreserveIPDialog {...defaultProps} />); | ||
|
|
||
| expect(screen.getByRole('button', { name: 'Unreserve' })).toBeDisabled(); | ||
| expect(screen.getByRole('button', { name: 'Cancel' })).toBeDisabled(); | ||
| }); | ||
| }); |
78 changes: 78 additions & 0 deletions
78
packages/manager/src/features/ReservedIps/ReservedIpsLanding/UnreserveIPDialog.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { useUnReserveIPMutation } from '@linode/queries'; | ||
| import { ActionsPanel, Notice, Typography } from '@linode/ui'; | ||
| import { useSnackbar } from 'notistack'; | ||
| import * as React from 'react'; | ||
|
|
||
| import { ConfirmationDialog } from 'src/components/ConfirmationDialog/ConfirmationDialog'; | ||
| import { getAPIErrorOrDefault } from 'src/utilities/errorUtils'; | ||
|
|
||
| import type { IPAddress } from '@linode/api-v4'; | ||
|
|
||
| interface Props { | ||
| ipAddress: IPAddress; | ||
| onClose: () => void; | ||
| open: boolean; | ||
| } | ||
|
|
||
| export const UnreserveIPDialog = (props: Props) => { | ||
| const { ipAddress, onClose, open } = props; | ||
| const { enqueueSnackbar } = useSnackbar(); | ||
|
|
||
| const { isPending, mutateAsync, reset } = useUnReserveIPMutation( | ||
| ipAddress.address | ||
| ); | ||
|
|
||
| const [error, setError] = React.useState<null | string>(null); | ||
|
|
||
| // Reset mutation state when dialog opens | ||
| React.useEffect(() => { | ||
| if (open) { | ||
| reset(); | ||
| setError(null); | ||
| } | ||
| }, [open, reset]); | ||
|
|
||
| const handleSubmit = async () => { | ||
| try { | ||
| await mutateAsync(); | ||
| enqueueSnackbar(`${ipAddress.address} has been unreserved.`, { | ||
| variant: 'success', | ||
| }); | ||
| onClose(); | ||
| } catch (err) { | ||
| setError( | ||
| getAPIErrorOrDefault(err, 'Failed to unreserve IP address.')[0]?.reason | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <ConfirmationDialog | ||
| actions={ | ||
| <ActionsPanel | ||
| primaryButtonProps={{ | ||
| disabled: isPending, | ||
| label: 'Unreserve', | ||
| loading: isPending, | ||
| onClick: handleSubmit, | ||
| }} | ||
| secondaryButtonProps={{ | ||
| disabled: isPending, | ||
| label: 'Cancel', | ||
| onClick: onClose, | ||
| }} | ||
| sx={{ padding: 0 }} | ||
| /> | ||
| } | ||
| onClose={onClose} | ||
| open={open} | ||
| title={`Unreserve ${ipAddress.address}`} | ||
| > | ||
| {error && <Notice text={error} variant="error" />} | ||
| <Typography> | ||
| Unreserving this IP will remove it from your reserved list and make it | ||
| unavailable to assign. This action can't be undone. | ||
| </Typography> | ||
| </ConfirmationDialog> | ||
| ); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's update the casing of this to be
useUnreserveIPMutation