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

[Feature] Default environment #303

Open
majkinetor opened this issue Oct 3, 2023 · 19 comments · May be fixed by #1032
Open

[Feature] Default environment #303

majkinetor opened this issue Oct 3, 2023 · 19 comments · May be fixed by #1032
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@majkinetor
Copy link

Currently, when you open a request for collection, you always have to first set the environment.

I suggest we have a default environment that will be used upon opening a request collection if user didn't set anything. It can be settable either in collection properties (selecting existing environment) or in environment config (ticking a default checkbox).

This way, executing requests can be made to work immediately upon opening them and CLI will work without mandatory --env parameter.

@FedericoBiccheddu
Copy link

In the desktop app, as a user, I expect the most recently selected env to remain unchanged.

@majkinetor
Copy link
Author

This has nothing to do with it.

When you open collection, there is no environment set. It should only affect that case. Any explicit selection, either manually or via cmd line param should not be touched.

@n00o
Copy link
Contributor

n00o commented Nov 19, 2023

I would like to tackle this feature request because its annoying to have to remember to select an environment when first opening up a request. This just seems like a very nice QOL feature.

As I have looked into this, it seems like we need a .bru language change for this to work. The current structure for environments files is:

vars {
  name: value
}

I propose adding a group of values called defaults where something like defaultEnv could be set to true or false. This would allow me to make a Default checkbox inside the EnvironmentVariables tab that could save to the environment file. It could also open the way for future default settings that could be added to requests like default parameter values selected from a list of possible values. What are your thoughts on this @helloanoop?

I guess the alternative would be to add defaultEnv inside of bruno.json. That might a quick easy solution without having to change the structure of the .bru language. Downside of this method is that if the environment gets deleted then the default environment would not work anymore (unless you delete the defaultEnv when it gets deleted).

@helloanoop
Copy link
Contributor

helloanoop commented Nov 19, 2023

@n00o

I just merged a PR that supports presets/defaults for request url and type. (#718)

Here is my proposal.
Let's add a new property environment inside the presets in bruno.json

{
  "version": "1",
  "name": "bruno-testbench",
  "type": "collection",
  "presets": {
    "requestType": "http",
    "requestUrl": "http://localhost:6000",
    "environment": "local"
  }
}

In the UI, the label will be Environment and the value will be a dropdown.

  • By default, it's value will be 'No Environment'
  • If a preset was chosen, then displayed the chosen environment
  • If a preset was chosen, and the environment is not found - then display 'No Environment'

Similar logic applies to the main collection dropdown in the top right corner

  • If an env was set in the preset is present, then select that environment
  • Else display 'No Environment'

image

@helloanoop
Copy link
Contributor

helloanoop commented Nov 19, 2023

In the desktop app, as a user, I expect the most recently selected env to remain unchanged.

@FedericoBiccheddu I agree with this. So when the preset environment feature lands, we will have to decide what env to select on opening the app

  1. Preset env
  2. Last opened env

I think it makes sense to support option # 2 by default, and then provide a toggle in "App Level Settings" to choose # 1.

@Its-treason @mirkogolze @martinsefcik Let me know if you have additional feedback on this issue.

n00o added a commit to n00o/bruno that referenced this issue Nov 21, 2023
Add environment to the presets tab which will set the default environment on opening a collection. Show default environment inside of environment selector. Also add cli support for default environments.
@n00o
Copy link
Contributor

n00o commented Nov 21, 2023

I am testing a branch for default environments for both the UI and CLI. If you have the time, @majkinetor test it out and see if this is what you are looking for. Here:
https://github.com/n00o/bruno/tree/feature/Default_Environment

To set a default environment go to: Collection Settings > Presets > Environment and pick an environment in the dropdown. It won't change the current environment since the collection is already open but the next time the collection is opened the default environment will be set. This is to avoid being unable to being unable to set the environment to No Environment because the default environment overrides it.

Not sure how to best format the UI so feel free to offer suggestions if you have them.

@majkinetor
Copy link
Author

Hey @n00o

I tried it, and it looks good to me, and works as expected. I didn't try CLI app with environment override but only GUI options.

Presets should probably be renamed to Defaults IMO.

@majkinetor
Copy link
Author

majkinetor commented Nov 21, 2023

Regarding #303 (comment) about App level settings, I agree, however, keep in mind that:

  1. It makes sense to use option 1 (Presets) even if Last opened env is selected, if there is no last open env.
  2. Last opened env (and other "last usage" data) are local setting, it should not go to the repository or different team members will overwrite each other's last opened environment. It's questionable if it should live in the bruno folder or user's HOME/whatever. Since this should work cross-platform, I guess it's way easier for bruno to just create gitignore for this local file.

@n00o
Copy link
Contributor

n00o commented Nov 21, 2023

To test the dev CLI app, I had to use a command like this in packages/bruno-cli/bin (excluding --env for testing):

node bru.js run 'filename.bru' 

Making sure to place these files in packages/bruno-cli/bin:

  • filename.bru
  • bruno.json (with the preset environment)
  • The correct environment file in a environments sub folder

If you want to test the CLI using this method, let me know if it works too @majkinetor.

n00o added a commit to n00o/bruno that referenced this issue Nov 23, 2023
Add environment to the presets tab which will set the default environment on opening a collection. Show default environment inside of environment selector. Also add cli support for default environments.
@n00o n00o linked a pull request Nov 23, 2023 that will close this issue
5 tasks
n00o added a commit to n00o/bruno that referenced this issue Nov 23, 2023
Add environment to the presets tab which will set the default environment on opening a collection. Show default environment inside of environment selector. Also add cli support for default environments.
@martinsefcik
Copy link
Contributor

To set a default environment go to: Collection Settings > Presets > Environment and pick an environment in the dropdown.

I would expect that it will be configurable in environments dialog. I don't want to configure two closely related things (default environment and environments itself) in two places in application.

Also wouldn't it be better to store default environment flag directly in environment bru file ?

@majkinetor
Copy link
Author

I initially wrote that but deleted it. It makes sense, but there are other defaults, all available in single place under Presets, so it makes sense to have environment there too. Perhaps we could have it on both places - single checkbox in environment detail and combo box under Presets.

@n00o
Copy link
Contributor

n00o commented Nov 24, 2023

I initially wrote that but deleted it. It makes sense, but there are other defaults, all available in single place under Presets, so it makes sense to have environment there too. Perhaps we could have it on both places - single checkbox in environment detail and combo box under Presets.

I can add a default checkbox inside of the environment settings tab but I still think its best to only have the preset in the main bruno.json file.

Also wouldn't it be better to store default environment flag directly in environment bru file ?

If we store it on an individual environment .bru file then people could edit multiple environment files (in a text editor) to be the default environment and we would have to arbitrarily pick which one is the actual default environment.

@majkinetor
Copy link
Author

but I still think its best to only have the preset in the main bruno.json file.

Yeah, less maintenance and single place of truth. Also, environment name is colored so you know even without looking at presets.

@MathieuDreano
Copy link

MathieuDreano commented Nov 25, 2023

@majkinetor did someone work on "colored environment"? I don't have this feature, I only found this issue, i added a draft PR. #304

I vote in favor of bruno.json instead of env.bru
The reason is that someone might want to share it's env files, while default env if user specific.
But still, the button could be on the environment settings modal.>
Please only one source of truth 🙏

@majkinetor
Copy link
Author

majkinetor commented Nov 25, 2023

@MathieuDreano

@majkinetor did someone work on "colored environment"?

@n00o colored it, in dark theme default was yellow (or green :))

But this has nothing to do with colored environment, its only for the default

@majkinetor
Copy link
Author

But, if both are present we will have a problem as we won't be able to tell what is environment color and what is default. Probably something else than should be used to mark environment as default, such as bold or italic font, some symbol etc.

@binaryfire
Copy link

Just a bit of feedback: I'm moving my team from Postman to Bruno atm and hving to select the environment each time the app is opened was confusing for the junior dev. Personally I think remembering the last set environment would be more helpful than a default, but having both would be better of course!

Some kind of error message when a request is made and no environment is set would be helpful too.

@jocelinqueau
Copy link

yeah resetting the environment everytime is not helping migrating from others api client to bruno. However great work / product on every other aspect, thanks 🙏

@sanjai0py sanjai0py added enhancement New feature or request help wanted Extra attention is needed labels Mar 27, 2024
@leoferreiralima
Copy link
Contributor

leoferreiralima commented May 4, 2024

I opened a PR that maybe fix this issue
The last env that you chosse is saved and automaticly set on next startup of Bruno

#2238

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants