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

Prevent losing unsaved environment variable data when attempting to change env #2034

Merged

Conversation

AngelaSYuan
Copy link
Contributor

@AngelaSYuan AngelaSYuan commented Apr 8, 2024

Description

Addressing #1997

When modifying environment variables, changing environments without clicking the "Save" button loses the user's progress. This can be frustrating as there are no warnings beforehand.

With this pull request, I fixed this bug by detecting if any field in a variable in the current environment is changed, or if environment variables were added or deleted. If so, it gives a warning and prevents the user from switching, creating, and improving environments without either first saving or reverting their changes. Their changes will not be unexpectedly lost.

Bruno.Bug.Fix.Preventing.Lost.Env.When.Switching.mov

Contribution Checklist:

  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

@AngelaSYuan AngelaSYuan changed the title Bugfix/prevent losing env on switch Prevent losing environment variable data on switch when attempting to change env Apr 8, 2024
@AngelaSYuan AngelaSYuan changed the title Prevent losing environment variable data on switch when attempting to change env Prevent losing unsaved environment variable data when attempting to change env Apr 8, 2024
@VictorioBerra
Copy link

@AngelaSYuan I would argue that might not be great UX. For exaple, what if you don't care about the change and decide to simply discard it? You now HAVE to save. You did not show if you could close the dialog and discard the changes that way.

There is already an existing dialog that IMO has better UX and gives the user a choice:

image

Can you implement that dialog?

@VictorioBerra
Copy link

@AngelaSYuan You can just pay the $19 to support the project lol its not like you wont use it. But I have no control over licensing, maybe @sanjai0py can get you a license key.

@AngelaSYuan
Copy link
Contributor Author

@VictorioBerra True haha, thanks! I'm going to work on implementing this dialog for the environment switch.

@AngelaSYuan
Copy link
Contributor Author

I just added the functionalities for the dialog box! The PR should be updated @VictorioBerra @sanjai0py

Screen.Recording.2024-04-09.at.4.23.05.PM.mov

@VictorioBerra
Copy link

@AngelaSYuan I like it, hopefully they approve. Slight nitpick but is there a way to make other dialogs not open after it? For example when you clicked "+ Create" it prompted you with the save dialog, and when you dismissed it (either with dont save, cancel or save) it immediately threw up the new environment dialog. Is there a way to make it not do that?

Like i said nitpick I dont think that should make or break this PR since this is a big life saver we did not have before.

@AngelaSYuan
Copy link
Contributor Author

@VictorioBerra Thanks! And got it, are you saying when I clicked on "+ Create", after I hit "Save", the "Create Environment" dialog popped up immediately after? I had intended that to be a feature haha, so that the user didn't need to click on "+ Create" again after clicking save on the warning dialog.

But I can definitely have the screen return to just showing the variables (no immediately following dialog), if that's what you mean? I can see how it might not be UX friendly in some cases.

@VictorioBerra
Copy link

@AngelaSYuan Yeah I think it can be jarring to be bombarded with dialogs. I think just return the user to where they were before they tried to leave without saving. Obviously if they click "Dont Save" I would expect the changes to be reverted.

@AngelaSYuan
Copy link
Contributor Author

Just fixed, so that we don't immediately switch environments/pop up the other dialog, whether we click "Don't Save" or "Save." Let me know if you have any other suggestions/if it might be able to be merged! @sanjai0py @VictorioBerra

Screen.Recording.2024-04-09.at.11.40.06.PM.mov

Copy link
Member

@Its-treason Its-treason left a comment

Choose a reason for hiding this comment

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

Hey, your PR already looks pretty solid already, good job. I added some smaller comments on it.

Also, I saw some unused Imports and Leftover code comments, could you also remove those?

@AngelaSYuan
Copy link
Contributor Author

@Its-treason Thank you! I just fixed the confirm warning modal to be centered using CreatePortal, and got rid of the isModified state. I also removed comments and unused imports. Let me know how it looks!

@AngelaSYuan
Copy link
Contributor Author

@sanjai0py @helloanoop Hi, just curious if my PR is merge-ready? If not, what other steps do I need to take?

@helloanoop
Copy link
Contributor

Hi @AngelaSYuan !

Thanks for working on this. I am onboard with the UX updates done.

I am worried about the formik logic moved to 2 levels up in the component tree.
Ideally, we would want the formik stuff to stay inside the component that renders the form.

Was this intentional or did you have to move it because you were not able to the make the close dialog stuff work with the formik staying inside the EnvironmentVariables component ?

@AngelaSYuan
Copy link
Contributor Author

Hi @helloanoop, thank you! I would say it was both intentional in terms of the design, but also so that I could pass down the appropriate variables for the close dialog functionality (which wasn't possible with formik being in the EnvironmentVariables component.

Would this change be alright? I believe everything should work the same since these components are rendered together, and moving the formik would enable us to access the needed variables!

@AngelaSYuan
Copy link
Contributor Author

Hi @helloanoop! I just wanted to check in and see if this modification would be alright? For context, my school assignment on getting a PR merged with Bruno is due this Thursday, so I wanted to see if it's still possible to merge before then. I really appreciate your time!

@helloanoop
Copy link
Contributor

Hi @AngelaSYuan

We need to figure out how this can be made possible with formik being in the EnvironmentVariables component.

I understand that the react way of passing data down the component tree makes this pattern difficult to implement, but we need to figure out a way.

One way to implement this might be to dispatch an action whenever an environment gets edited and add a property called 'dirty' as true inside the environment.

You can then use the dirty flag check before switching the environment

@AngelaSYuan
Copy link
Contributor Author

@helloanoop Got it! I just made changes to the PR. Now, formik is back in EnvironmentVariables and I use a dirty flag to track if the field has been modified. How does this update look to you?

@helloanoop helloanoop merged commit c17e4ef into usebruno:main Apr 26, 2024
3 checks passed
@helloanoop
Copy link
Contributor

Hey @AngelaSYuan Nice work!

Merged.

lizziemac pushed a commit to lizziemac/bruno that referenced this pull request May 4, 2024
…hange env (usebruno#2034)

* trying to begin changes

* Env bug fixed with only switching env when saved

* dialog box working, formik in EnvironmentSettings to pass props, selectedEnvironment in EnvrionmentSettings to pass props

* Removing some uneccessary comments

* no immediate following dialog pop up after warning dialog

* Wrapping commit warning moidal in CreatePortal, removing unnecessary isModified state, removing comments

* modifying dialog and adding formik back to EnvironmentVariables

* Removing unnecessary comments

---------

Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants