bruno icon indicating copy to clipboard operation
bruno copied to clipboard

[Feature] Default environment

Open majkinetor opened this issue 1 year ago • 18 comments

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.

majkinetor avatar Oct 03 '23 08:10 majkinetor

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

f15u avatar Oct 04 '23 14:10 f15u

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.

majkinetor avatar Oct 04 '23 14:10 majkinetor

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).

n00o avatar Nov 19 '23 03:11 n00o

@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 avatar Nov 19 '23 09:11 helloanoop

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.

helloanoop avatar Nov 19 '23 09:11 helloanoop

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.

n00o avatar Nov 21 '23 15:11 n00o

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 avatar Nov 21 '23 17:11 majkinetor

Regarding https://github.com/usebruno/bruno/issues/303#issuecomment-1817804698 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.

majkinetor avatar Nov 21 '23 17:11 majkinetor

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 avatar Nov 21 '23 18:11 n00o

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 ?

martinsefcik avatar Nov 24 '23 08:11 martinsefcik

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.

majkinetor avatar Nov 24 '23 09:11 majkinetor

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.

n00o avatar Nov 24 '23 22:11 n00o

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.

majkinetor avatar Nov 24 '23 22:11 majkinetor

@majkinetor did someone work on "colored environment"? I don't have this feature, I only found this issue, i added a draft PR. https://github.com/usebruno/bruno/issues/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 🙏

MathieuDreano avatar Nov 25 '23 03:11 MathieuDreano

@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 avatar Nov 25 '23 12:11 majkinetor

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.

majkinetor avatar Nov 25 '23 12:11 majkinetor

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.

binaryfire avatar Dec 30 '23 01:12 binaryfire

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

joceqo avatar Mar 26 '24 21:03 joceqo

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

leoferreiralima avatar May 04 '24 20:05 leoferreiralima