Skip to content

fix: Show Final Request Variables#7789

Open
karthikeyansundaram2 wants to merge 1 commit intousebruno:mainfrom
karthikeyansundaram2:fix/issue-5456-show-final-request-variables
Open

fix: Show Final Request Variables#7789
karthikeyansundaram2 wants to merge 1 commit intousebruno:mainfrom
karthikeyansundaram2:fix/issue-5456-show-final-request-variables

Conversation

@karthikeyansundaram2
Copy link
Copy Markdown

@karthikeyansundaram2 karthikeyansundaram2 commented Apr 17, 2026

Summary

Closes #5456

Addresses: Show Final Request Variables

Changes

 .../Vars/EffectiveVarsTable/StyledWrapper.js       | 55 +++++++++++++++
 .../RequestPane/Vars/EffectiveVarsTable/index.js   | 79 ++++++++++++++++++++++
 .../src/components/RequestPane/Vars/index.js       | 10 +++
 packages/bruno-app/src/utils/collections/index.js  | 63 +++++++++++++++++
 4 files changed, 207 insertions(+)

Contribution by @karthikeyansundaram2

Summary by CodeRabbit

  • New Features
    • Added an Effective Variables section in the Request pane that displays variables from Collection, Environment, Folder, and Request scopes in order of precedence. Includes a toggle control to show or hide secret values, with each variable listing its name, value, and source.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 17, 2026

Walkthrough

Adds a feature to display effective request variables in the Variables tab, showing final resolved values after applying precedence rules (Request > Folder > Collection > Environment). Includes a new utility function to compute effective variables, a React component to render them in a table with source attribution, and styling for the display.

Changes

Cohort / File(s) Summary
Styled Component
packages/bruno-app/src/components/RequestPane/Vars/EffectiveVarsTable/StyledWrapper.js
Introduces Wrapper styled-component with table styling (full width, collapsed borders, theme-driven borders), thead/td text alignment and colors, padding/word-wrapping for cells, plus .source-tag and .secret-toggle class styles with theme integration.
Effective Variables Component
packages/bruno-app/src/components/RequestPane/Vars/EffectiveVarsTable/index.js
New EffectiveVarsTable React component that memoizes effective variables, toggles secret visibility with keyboard support, and renders a table with variable name, masked/raw value, and source attribution; displays empty state when no variables exist.
Variables Tab Integration
packages/bruno-app/src/components/RequestPane/Vars/index.js
Integrates EffectiveVarsTable into the Vars component to display effective variables section alongside existing Pre Request and Post Response tabs.
Variable Aggregation Utility
packages/bruno-app/src/utils/collections/index.js
Adds getEffectiveRequestVariables utility that aggregates and deduplicates variables from Collection, Environment (active), Folder hierarchy, and Request item with proper precedence, marking environment variables as secrets and returning alphabetically sorted results.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

size/M

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno
  • bijin-bruno

Poem

Variables unified, secrets masked tight 🔐
From collection down to request's might
Precedence flows, colors align ✨
Effective values in a table so fine
Context-aware, the variables shine 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: Show Final Request Variables' directly relates to the main changeset, which implements functionality to display effective request variables with their sources and values.
Linked Issues check ✅ Passed The implementation satisfies all requirements from issue #5456: displays variable name, resolved value, and source origin; applies correct precedence (Request > Folder > Collection > Environment); updates automatically via memoized dependencies.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #5456: new styled components, EffectiveVarsTable component, utility function for computing effective variables, and integration into the Vars UI. No unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/bruno-app/src/components/RequestPane/Vars/EffectiveVarsTable/index.js (2)

9-22: useMemo dep list is doing a lot of heavy lifting.

Deps include item?.request, collection?.root, collection?.draft, collection?.items, collection?.environments — all object references. This relies on Redux giving you fresh references on every relevant update, which is generally true in this codebase but is a subtle coupling. Since getEffectiveRequestVariables is quite cheap (one Map traversal per scope), consider dropping the memo entirely and computing inline — simpler and no risk of stale values if a reducer ever mutates in place.

♻️ Proposed simplification
-  const variables = useMemo(
-    () => getEffectiveRequestVariables(collection, item),
-    [
-      item?.uid,
-      item?.draft,
-      item?.request,
-      collection?.uid,
-      collection?.activeEnvironmentUid,
-      collection?.environments,
-      collection?.root,
-      collection?.draft,
-      collection?.items
-    ]
-  );
+  const variables = getEffectiveRequestVariables(collection, item);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/bruno-app/src/components/RequestPane/Vars/EffectiveVarsTable/index.js`
around lines 9 - 22, The useMemo around getEffectiveRequestVariables (creating
variables) relies on many object-refs and is fragile; remove the useMemo and
compute variables inline by directly calling
getEffectiveRequestVariables(collection, item) where variables is used (replace
the useMemo block that defines variables) so the value is always derived from
current props/state without depending on item?.request, collection?.root,
collection?.draft, collection?.items, or collection?.environments references.

39-53: Add a data-testid for Playwright and consider a real <button>.

Two small things:

  1. As per coding guidelines ("Add data-testid to testable elements for Playwright"), the secret-toggle is a prime candidate.
  2. role="button" + tabIndex={0} + manual Enter/Space handling is reinventing <button type="button">. A real button gives you keyboard behavior, focus ring, and disabled semantics for free.
♻️ Proposed change
-        <div
-          className="secret-toggle mb-2"
-          role="button"
-          tabIndex={0}
-          onClick={() => setShowSecret((s) => !s)}
-          onKeyDown={(e) => {
-            if (e.key === 'Enter' || e.key === ' ') {
-              e.preventDefault();
-              setShowSecret((s) => !s);
-            }
-          }}
-        >
+        <button
+          type="button"
+          className="secret-toggle mb-2"
+          data-testid="effective-vars-secret-toggle"
+          onClick={() => setShowSecret((s) => !s)}
+        >
           {showSecret ? <IconEyeOff size={16} strokeWidth={1.5} /> : <IconEye size={16} strokeWidth={1.5} />}
           <span>{showSecret ? 'Hide secret variable values' : 'Show secret variable values'}</span>
-        </div>
+        </button>

As per coding guidelines: "Add data-testid to testable elements for Playwright."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/bruno-app/src/components/RequestPane/Vars/EffectiveVarsTable/index.js`
around lines 39 - 53, Replace the clickable div with a proper interactive
element: change the element using className "secret-toggle" to a <button
type="button"> (keep onClick handler that calls setShowSecret and preserve
IconEye/IconEyeOff and the label span), remove role="button", tabIndex and
manual onKeyDown logic, and add a data-testid attribute like
data-testid="secret-toggle" for Playwright; also set an ARIA state such as
aria-pressed={showSecret} to reflect the toggle state so assistive tech stays
accurate.
packages/bruno-app/src/utils/collections/index.js (1)

1337-1344: Minor: consistency with mergeVars for request-var extraction.

mergeVars above handles the request item via the tree-path loop (non-folder branch). Here you re-read request vars off item directly. Functionally equivalent for the current call sites, but if item is ever absent from requestTreePath (e.g., transient/detached items), behavior could diverge. Not blocking — just flagging for awareness.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-app/src/utils/collections/index.js` around lines 1337 - 1344,
The request variable extraction repeats direct access to item (const requestVars
= item.draft ? get(item, 'draft.request.vars.req', []) : get(item,
'request.vars.req', [])) which can diverge from the earlier mergeVars logic that
uses the requestTreePath traversal; change this block to obtain the request node
via the same requestTreePath loop used in mergeVars (use the same traversal
logic to find the request node before reading vars) and then iterate that node's
'request.vars.req' (preserving the draft vs non-draft selection and filtering by
v.name && v.enabled) before calling result.set, so behavior remains consistent
even for transient/detached items (refer to mergeVars and requestTreePath
handling to mirror the lookup).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/bruno-app/src/components/RequestPane/Vars/index.js`:
- Around line 22-27: The displayed precedence label in the Vars component is
inconsistent with the canonical order referenced in utils/collections/index.js
and getEffectiveRequestVariables; update the label text in the JSX (the span
inside the "Effective Variables" header) to match the confirmed canonical order
(either "Request > Folder > Collection > Environment" or the opposite), and then
ensure getEffectiveRequestVariables, its JSDoc, and any resolver in
utils/collections/index.js use the exact same ordering; pick the canonical
precedence, update the header string, update the JSDoc comment for
getEffectiveRequestVariables, and adjust the resolver logic in
utils/collections/index.js so all three (label, JSDoc, resolver) match exactly.

---

Nitpick comments:
In
`@packages/bruno-app/src/components/RequestPane/Vars/EffectiveVarsTable/index.js`:
- Around line 9-22: The useMemo around getEffectiveRequestVariables (creating
variables) relies on many object-refs and is fragile; remove the useMemo and
compute variables inline by directly calling
getEffectiveRequestVariables(collection, item) where variables is used (replace
the useMemo block that defines variables) so the value is always derived from
current props/state without depending on item?.request, collection?.root,
collection?.draft, collection?.items, or collection?.environments references.
- Around line 39-53: Replace the clickable div with a proper interactive
element: change the element using className "secret-toggle" to a <button
type="button"> (keep onClick handler that calls setShowSecret and preserve
IconEye/IconEyeOff and the label span), remove role="button", tabIndex and
manual onKeyDown logic, and add a data-testid attribute like
data-testid="secret-toggle" for Playwright; also set an ARIA state such as
aria-pressed={showSecret} to reflect the toggle state so assistive tech stays
accurate.

In `@packages/bruno-app/src/utils/collections/index.js`:
- Around line 1337-1344: The request variable extraction repeats direct access
to item (const requestVars = item.draft ? get(item, 'draft.request.vars.req',
[]) : get(item, 'request.vars.req', [])) which can diverge from the earlier
mergeVars logic that uses the requestTreePath traversal; change this block to
obtain the request node via the same requestTreePath loop used in mergeVars (use
the same traversal logic to find the request node before reading vars) and then
iterate that node's 'request.vars.req' (preserving the draft vs non-draft
selection and filtering by v.name && v.enabled) before calling result.set, so
behavior remains consistent even for transient/detached items (refer to
mergeVars and requestTreePath handling to mirror the lookup).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7100c760-43e5-4a4f-b977-f42c3e63ab90

📥 Commits

Reviewing files that changed from the base of the PR and between c6281d3 and 4a53698.

📒 Files selected for processing (4)
  • packages/bruno-app/src/components/RequestPane/Vars/EffectiveVarsTable/StyledWrapper.js
  • packages/bruno-app/src/components/RequestPane/Vars/EffectiveVarsTable/index.js
  • packages/bruno-app/src/components/RequestPane/Vars/index.js
  • packages/bruno-app/src/utils/collections/index.js

Comment on lines +22 to +27
<div className="mt-3 mb-3 title text-xs">
Effective Variables
<span className="ml-2 text-xs font-normal opacity-70">
Request &gt; Folder &gt; Environment &gt; Collection
</span>
</div>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Label precedence disagrees with issue #5456.

The header reads Request > Folder > Environment > Collection, which matches the implementation in getEffectiveRequestVariables but contradicts the linked issue (Request > Folder > Collection > Environment). Align this with whichever precedence is confirmed canonical (see the related comment on utils/collections/index.js). Whatever you pick, the label, the JSDoc, and the resolver must all agree.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-app/src/components/RequestPane/Vars/index.js` around lines 22
- 27, The displayed precedence label in the Vars component is inconsistent with
the canonical order referenced in utils/collections/index.js and
getEffectiveRequestVariables; update the label text in the JSX (the span inside
the "Effective Variables" header) to match the confirmed canonical order (either
"Request > Folder > Collection > Environment" or the opposite), and then ensure
getEffectiveRequestVariables, its JSDoc, and any resolver in
utils/collections/index.js use the exact same ordering; pick the canonical
precedence, update the header string, update the JSDoc comment for
getEffectiveRequestVariables, and adjust the resolver logic in
utils/collections/index.js so all three (label, JSDoc, resolver) match exactly.

@karthikeyansundaram2
Copy link
Copy Markdown
Author

Thanks for the review! I'll look into the suggestions:

    • const variables = useMemo(
    • () => getEffectiveRequestVariables(collection, item),
    •  item?.uid,
      

Will push an update if the suggestions improve correctness or edge case handling.

@helloanoop
Copy link
Copy Markdown
Contributor

Hey @karthikeyansundaram2 Thanks for the PR!

It would be great if you could share a demo video. Also, just a heads-up that this issue is currently in our backlog, and it may take some time before our team is able to pick it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show Final Request Variables

2 participants