Skip to content
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

[UI v2] feat: Have UX related mutation callbacks be handled in the UX layer #16136

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

devinvillarosa
Copy link
Contributor

@devinvillarosa devinvillarosa commented Nov 27, 2024

What does this PR do and why?

This PR handles all UX related mutation callbacks to be handled on the UX layer.

useMutation is divided into 2 separate concerns: 1️⃣ Data, 2️⃣ UX.
Upon success on the data layer, it is not guaranteed that the UX related callbacks will be invoked.

This is why after calling a defined useMutation, there are callback options to pass, in which all UX related callbacks should be handled there.

Here is a good article of how useMutation is architected with seperation of concerns:
https://tkdodo.eu/blog/mastering-mutations-in-react-query#some-callbacks-might-not-fire
Screenshot 2024-11-27 at 10 24 04 AM

Overall, useMutation should be designed with 2 considerations:
1️⃣ When initially creating a mutation, handle all data / cache related callbacks here
2️⃣ When calling the mutation in a UX component, handle the UX updates (eg: re-routing, toasts) there

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • If this pull request adds new functionality, it includes unit tests that cover the changes
  • If this pull request removes docs files, it includes redirect settings in mint.json.
  • If this pull request adds functions or classes, it includes helpful docstrings.

Related to #15512

@devinvillarosa devinvillarosa force-pushed the move-toast-to-ui-concern branch from 86f5d57 to de7c909 Compare November 27, 2024 18:13
@devinvillarosa devinvillarosa added development Tech debt, refactors, CI, tests, and other related work. ui Related to the Prefect web interface labels Nov 27, 2024
@devinvillarosa devinvillarosa force-pushed the move-toast-to-ui-concern branch from de7c909 to 92b7271 Compare November 27, 2024 18:19
Copy link
Contributor Author

@devinvillarosa devinvillarosa Nov 27, 2024

Choose a reason for hiding this comment

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

By moving the toast as a callback to onSuccess caught the test to mock the delete endpoint

@devinvillarosa devinvillarosa force-pushed the move-toast-to-ui-concern branch from 92b7271 to a9a1a08 Compare November 27, 2024 18:22
@devinvillarosa devinvillarosa marked this pull request as ready for review November 27, 2024 18:25
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

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

Nice! This makes way more sense!

Comment on lines 547 to 551
server.use(
http.delete("http://localhost:4200/api/variables/:id", () => {
return HttpResponse.json({ status: 204 });
}),
);
Copy link
Member

Choose a reason for hiding this comment

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

This is a general enough mock that I think adding it to ui-v2/tests/mocks/handlers.ts might make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Updated in latest push

@devinvillarosa devinvillarosa force-pushed the move-toast-to-ui-concern branch from a9a1a08 to d549842 Compare November 27, 2024 19:14
@devinvillarosa devinvillarosa force-pushed the move-toast-to-ui-concern branch from d549842 to a35ae10 Compare November 27, 2024 19:15
@devinvillarosa devinvillarosa merged commit e63efd1 into main Nov 27, 2024
7 checks passed
@devinvillarosa devinvillarosa deleted the move-toast-to-ui-concern branch November 27, 2024 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Tech debt, refactors, CI, tests, and other related work. ui Related to the Prefect web interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants