-
Notifications
You must be signed in to change notification settings - Fork 12
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
Tweak IP pool edit onSuccess
logic
#2409
Merged
Merged
Changes from all commits
Commits
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
This file contains 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 |
---|---|---|
|
@@ -35,19 +35,21 @@ export function EditIpPoolSideModalForm() { | |
const { data: pool } = usePrefetchedApiQuery('ipPoolView', { path: poolSelector }) | ||
|
||
const form = useForm({ defaultValues: pool }) | ||
const onDismiss = () => navigate(pb.ipPool({ pool: poolSelector.pool })) | ||
|
||
const editPool = useApiMutation('ipPoolUpdate', { | ||
onSuccess(_pool) { | ||
onSuccess(updatedPool) { | ||
queryClient.invalidateQueries('ipPoolList') | ||
if (pool.name !== _pool.name) { | ||
// as the pool's name has changed, we need to navigate to an updated URL | ||
navigate(pb.ipPool({ pool: _pool.name })) | ||
} else { | ||
navigate(pb.ipPool({ pool: updatedPool.name })) | ||
addToast({ content: 'Your IP pool has been updated' }) | ||
|
||
// Only invalidate if we're staying on the same page. If the name | ||
// _has_ changed, invalidating ipPoolView causes an error page to flash | ||
// while the loader for the target page is running because the current | ||
// page's pool gets cleared out while we're still on the page. If we're | ||
// navigating to a different page, its query will fetch anew regardless. | ||
if (pool.name === updatedPool.name) { | ||
queryClient.invalidateQueries('ipPoolView') | ||
onDismiss() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found the if-else confusing because the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good point. |
||
addToast({ content: 'Your IP pool has been updated' }) | ||
}, | ||
}) | ||
|
||
|
@@ -56,7 +58,7 @@ export function EditIpPoolSideModalForm() { | |
form={form} | ||
formType="edit" | ||
resourceName="IP pool" | ||
onDismiss={onDismiss} | ||
onDismiss={() => navigate(pb.ipPool({ pool: poolSelector.pool }))} | ||
onSubmit={({ name, description }) => { | ||
editPool.mutate({ path: poolSelector, body: { name, description } }) | ||
}} | ||
|
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.
Another way of doing this that's worth considering would be to add the ability to
invalidateQueries
to invalidate more narrowly than an entire endpoint.console/app/api/hooks.ts
Lines 243 to 253 in c648c44
So in this case we'd be able to avoid the conditional by invalidating the fetch under the old name, but not the new name. Working on a quick PR showing that option. I thought it was kind of dicey but it's not.
#2410
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.
As I mentioned in the other PR, I prefer (w/o strong feelings on it) the way you have it in this PR. But open to either direction.