flawiddsouza / Restfox

Offline-First Minimalistic HTTP & Socket Testing Client for the Web & Desktop
https://restfox.dev
MIT License
2.03k stars 98 forks source link

Environment Var dropdown introduces a 'space' between key and brace #168

Closed ricktimmis-xia closed 4 months ago

ricktimmis-xia commented 4 months ago

Current Behaviour Automatic dropdown for Environment Variable selection, adds a space between the variable name and the }. This means these variables do not resolve to their value.

Expected Behavior Selections from the dropdown should resolve to their reference correctly, and go green. See example screenshot below.

Shot 1 - Dropdown image

Shot 2 - Note {{OCAPI_USER_LOGIN }} has a trailing space. image

Shot 3 - Removal of space and variable correctly resolves image

Steps to reproduce

  1. Add one or more variables into an Environment
  2. Goto 'Auth Basic' tab
  3. Begin typing at Env Var value
  4. Select choice from the Dropdown
  5. Notice a space added before the closing bracket

Also, as I typed up this ticket, I discovered that it you just begin typing the Env Var name without double opening brace '{{' when you select from the dropdown the prefix braces are omitted, but the suffix braces are applied but with a space

System and Version

Kubuntu 24.04 LTS

Restfox installed via snap package:

`name: restfox summary: Lightweight REST / HTTP Client publisher: Artelin (flawid) store-url: https://snapcraft.io/restfox license: unset description: | A lightweight REST / HTTP Client based on Insomnia and Postman.

Features:

kobenguyent commented 4 months ago

Oh, is there an inconsistency when resolving the env var in URL fields and other places? 😅

In this PR, env var in Url is resolved when having spaces. https://github.com/flawiddsouza/Restfox/issues/165

flawiddsouza commented 4 months ago

Some users like writing env vars without spaces, so when they type and accept the auto complete: This:

{{M

becomes:

{{MyAutoCompletedVar }}

Valid: {{ MyAutoCompletedVar }} one space at the beginning and one at the end {{MyAutoCompletedVar}} no space at the beginning and end

Invalid: {{MyAutoCompletedVar }} no space at the beginning but one space at the end {{ MyAutoCompletedVar}} one space at the beginning but no space at the end

So we need to do 3 things.

1) If user starts typing {{M and accepts auto complete, it should become {{MyAutoCompletedVar}} 2) If user starts typing {{ M and accepts auto complete, it should become {{ MyAutoCompletedVar }} 3) If user starts typing M without {{ or {{ at the beginning, it should become {{MyAutoCompletedVar}}

All the logic required most likely should be doable inside this:

image It might be a bit complex as there's a bit of backtracking involved. To check for the {{ and {{

@kobenguyent Do you want to pick this up?

kobenguyent commented 4 months ago

Hey @flawiddsouza sure, let me give it a try

kobenguyent commented 4 months ago

@flawiddsouza @ricktimmis-xia Does it sound simpler for user like he starts typing without any { and if he chooses the Suggestion, it returns immediately {{ Suggestion }}, that somehow saves user some keystrokes when typing either { or {{, on the same time, our code doesn't need to have complex logic to handle the env var resolving?

https://github.com/flawiddsouza/Restfox/assets/7845001/f8c96778-c436-4f87-b04e-7bbabee32e13

flawiddsouza commented 4 months ago

@kobenguyent This is good but I want users to have the choice of using the software how they want, rather than how we want them to use it. People have different behaviors and it's always nice to account for them.

Also, with this change, if a user starts typing {{ u and accepts auto complete, it will be come {{ {{ user }}

image

image

They'll have to delete the first few characters, which can be quite annoying if happens again and again.

kobenguyent commented 4 months ago

Well, yeah. I got the point. Just thinking of the way to streamline how user interacts with env var. Right, like you sugguested, we would do something in the end that makes env var resolved.