Repository navigation
feat(variables): add scope-aware variable creation - #8665
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughVariable tooltips now support selecting scopes for new variables, navigating to existing definitions, and creating missing environment or global variables. Responsive styling and tests cover the expanded behavior. ChangesVariable scope flow
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant CodeMirrorTooltip
participant ReduxStore
participant SettingsTabs
participant DefinitionRow
CodeMirrorTooltip->>ReduxStore: read scope state or dispatch navigation
CodeMirrorTooltip->>SettingsTabs: open matching settings tab
SettingsTabs->>DefinitionRow: scroll to and highlight definition
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js (1)
114-160: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueFolder-context scope options skip ancestor folders.
When
item.type === 'folder', only the current folder is offered as a creatable scope; the request branch below, by contrast, includes the full ancestorfolderPath. If the tooltip is opened from a nested folder's settings, ancestor folders won't be selectable, unlike the symmetric request case.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bruno-app/src/utils/codemirror/brunoVarInfo.js` around lines 114 - 160, Update the item.type === 'folder' branch to derive and include the full ancestor folderPath, matching the request branch behavior. Add scope options for each ancestor folder in path order while retaining the current folder option and existing labels/data structure.packages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.js (1)
599-615: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a cross-item navigation test for "go to definition".
The only request-scope test opens the same item that's already rendered (
requestItempassed both asitemand asscopeInfo.data.item), so it can't catch the case where the definition lives in a request that isn't currently open — the actual use case this button targets. As per coding guidelines, tests should cover "realistically problematic paths, including errors and relevant edge cases." A test with a distinct target item (and assertingaddTabgets dispatched) would have caught the missing-addTabgap flagged inbrunoVarInfo.js.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.js` around lines 599 - 615, Add a request-scope go-to-definition test near the existing “should dispatch navigation actions for request-scoped variables” case in `brunoVarInfo.spec.js` using distinct rendered and target request items. Trigger `.var-definition-button`, then assert `store.dispatch` receives the target request’s `addTab` navigation action, along with the existing request-pane navigation expectations.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 2392-2405: Update the global environment variable handling around
variable lookup and updatedVariables so disabled variables with the same
variableName are detected rather than treated as missing. Reuse the existing
variable entry by updating its value and preserving its enabled state, or
otherwise reject the operation according to the prior behavior; only create a
new UUID-backed entry when no variable with that name exists. Verify the
upstream getVariableScope/data.variable lookup does not filter out disabled
environment variables.
In `@packages/bruno-app/src/utils/codemirror/brunoVarInfo.js`:
- Around line 246-256: Update the request branch in the scopeInfo.type switch to
dispatch addTab for targetItem before updating its request pane and focusing it,
matching the folder and collection navigation flows. Preserve the existing
targetItem fallback and uid guard, and ensure request-scoped navigation opens a
missing target tab before focusTab runs.
---
Nitpick comments:
In `@packages/bruno-app/src/utils/codemirror/brunoVarInfo.js`:
- Around line 114-160: Update the item.type === 'folder' branch to derive and
include the full ancestor folderPath, matching the request branch behavior. Add
scope options for each ancestor folder in path order while retaining the current
folder option and existing labels/data structure.
In `@packages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.js`:
- Around line 599-615: Add a request-scope go-to-definition test near the
existing “should dispatch navigation actions for request-scoped variables” case
in `brunoVarInfo.spec.js` using distinct rendered and target request items.
Trigger `.var-definition-button`, then assert `store.dispatch` receives the
target request’s `addTab` navigation action, along with the existing
request-pane navigation expectations.
🪄 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: e4d0d8b9-36f2-4e5e-9900-efca4ad4a0b1
📒 Files selected for processing (4)
packages/bruno-app/src/globalStyles.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-app/src/utils/codemirror/brunoVarInfo.jspackages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.js
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js (1)
2380-2407: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
globalcase ignoresdataentirely — recompute duplicates logic already built upstream.Unlike
environment/collection/folder/request, theglobalbranch never readsdata.environmentordata.variable; it re-derives both fromstate.globalEnvironmentsand re-runs its own.find((v) => v.name === variableName && v.enabled).getCreatableScopeOptionsinbrunoVarInfo.jsalready buildsdata: { environment: globalEnvironment, variable: null }for this exact purpose. Two independent lookups for the same thing risk silently diverging (e.g., an enabled-filter tweak applied to only one path).♻️ Suggested alignment with the `environment` case
case 'global': { - const globalEnvironments = state.globalEnvironments?.globalEnvironments || []; - const activeGlobalEnvUid = state.globalEnvironments?.activeGlobalEnvironmentUid; - - if (!activeGlobalEnvUid) { - return reject(new Error('No active global environment')); - } - - const environment = globalEnvironments.find((env) => env.uid === activeGlobalEnvUid); - - if (!environment) { - return reject(new Error('Global environment not found')); - } - - // Match script variable behavior: preserve disabled entries and create a separate enabled slot. - const variable = environment.variables.find((v) => v.name === variableName && v.enabled); + const { environment, variable } = data; + + if (!environment) { + return reject(new Error('Global environment not found')); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js` around lines 2380 - 2407, Update the `global` case to use the upstream `data.environment` and `data.variable` values, matching the existing `environment` case, instead of re-reading `state.globalEnvironments` and performing its own enabled-variable lookup. Preserve the global update behavior, including updating the provided variable or appending a new enabled entry when no variable is supplied.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 2380-2407: Update the `global` case to use the upstream
`data.environment` and `data.variable` values, matching the existing
`environment` case, instead of re-reading `state.globalEnvironments` and
performing its own enabled-variable lookup. Preserve the global update behavior,
including updating the provided variable or appending a new enabled entry when
no variable is supplied.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: cc4ff988-9deb-4a7f-86fc-2e3127d31002
📒 Files selected for processing (3)
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-app/src/utils/codemirror/brunoVarInfo.jspackages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.js
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.js
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/bruno-app/src/utils/codemirror/brunoVarInfo.js (1)
856-869: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick winPrevent
TypeErrorwhen updating variables in contexts without a collection.
renderVarInfois explicitly designed to support contexts wherecollectionis falsy (as seen in checks on lines 422, 485, and 687). However, when an edited value is saved, accessingcollection.uidwithout a safeguard throws aTypeError: Cannot read properties of null (reading 'uid').Additionally, the refresh logic currently bypasses updating
scopeInfoentirely if there's no collection, which prevents global variables from correctly re-hydrating after an edit in a collection-less context.🐛 Proposed fix to guard collection access and support global re-hydration
- dispatch(updateVariableInScope(variableName, newValue, scopeInfo, collection.uid)) + dispatch(updateVariableInScope(variableName, newValue, scopeInfo, collection?.uid)) .then(() => { originalValue = newValue; // Re-fetch scopeInfo to get the updated variable reference after save const state = store.getState(); - const freshCollection = findCollectionByUid(state.collections.collections, collection.uid); - if (collection) { - const freshItem = item ? findItemInCollectionByItemUid(freshCollection, item.uid) : null; - const updatedScopeInfo = getVariableScope(variableName, freshCollection, freshItem); - if (updatedScopeInfo) { - scopeInfo = hydrateGlobalScopeInfo(updatedScopeInfo, variableName); - } + const freshCollection = collection ? findCollectionByUid(state.collections.collections, collection.uid) : null; + const freshItem = collection && item ? findItemInCollectionByItemUid(freshCollection, item.uid) : null; + const updatedScopeInfo = getVariableScope(variableName, freshCollection, freshItem); + if (updatedScopeInfo) { + scopeInfo = hydrateGlobalScopeInfo(updatedScopeInfo, variableName); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bruno-app/src/utils/codemirror/brunoVarInfo.js` around lines 856 - 869, Update the variable-save flow around updateVariableInScope so collection-less contexts do not access collection.uid; pass the collection identifier only when collection exists. Adjust the subsequent scope refresh to re-hydrate global scope information even without a collection, while retaining collection/item lookup for collection-backed variables.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/bruno-app/src/utils/codemirror/brunoVarInfo.js`:
- Around line 856-869: Update the variable-save flow around
updateVariableInScope so collection-less contexts do not access collection.uid;
pass the collection identifier only when collection exists. Adjust the
subsequent scope refresh to re-hydrate global scope information even without a
collection, while retaining collection/item lookup for collection-backed
variables.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f3abf29e-ef0b-4074-9989-5a37af172aef
📒 Files selected for processing (3)
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-app/src/utils/codemirror/brunoVarInfo.jspackages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.js
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.js
1297781 to
611341a
Compare
|
Regarding the latest nitpick about the That lookup predates this PR and intentionally resolves the current active global environment from fresh state at save time. Existing global scope data returned by Since the current lookup is the canonical source of truth and the suggested refactor is not required for #7382, I’m leaving this out of the PR. |
611341a to
7e64337
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 2280-2295: Refresh the current environment from Redux before
constructing updatedVariables in the environment save branch, rather than
relying on the stale tooltip environment snapshot. Reuse the same state-refresh
approach as the global branch, then preserve the existing variable update/create
behavior and pass the refreshed environment data to saveEnvironment.
🪄 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: ab59cbae-bfa0-48cb-b76a-91a9188e472b
📒 Files selected for processing (4)
packages/bruno-app/src/globalStyles.jspackages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-app/src/utils/codemirror/brunoVarInfo.jspackages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.js
- include ancestor scopes from nested folder settings - open target requests before navigating to definitions - document disabled variable slot behavior
7e64337 to
342b88d
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js (1)
2284-2297: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winGuard against undefined
environment.variables.Both the
environmentandglobalblocks defensively fallback to an empty array (environment.variables || []) during variable creation, suggesting the array might be uninitialized. However, the preceding.find()calls lack this guard and will throw aTypeErrorif the array is absent.
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js#L2284-L2297: Add optional chaining (environment.variables?.find(...)) to safely query the environment scope.packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js#L2401-L2413: Add optional chaining (environment.variables?.find(...)) to safely query the global scope.🛡️ Proposed fixes
For the environment scope (around line 2284):
- const variable = environment.variables.find((v) => v.name === variableName && v.enabled); + const variable = environment.variables?.find((v) => v.name === variableName && v.enabled);For the global scope (around line 2401):
- const variable = environment.variables.find((v) => v.name === variableName && v.enabled); + const variable = environment.variables?.find((v) => v.name === variableName && v.enabled);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js` around lines 2284 - 2297, Guard both variable lookups with optional chaining so missing arrays do not throw: update the environment-scope find call near packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js:2284-2297 and the global-scope find call near packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js:2401-2413. Preserve the existing fallback-to-empty-array creation behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 2284-2297: Guard both variable lookups with optional chaining so
missing arrays do not throw: update the environment-scope find call near
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js:2284-2297
and the global-scope find call near
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js:2401-2413.
Preserve the existing fallback-to-empty-array creation behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7229a237-3649-463e-a3c8-05529c258667
📒 Files selected for processing (3)
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.jspackages/bruno-app/src/utils/codemirror/brunoVarInfo.jspackages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.js
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/bruno-app/src/utils/codemirror/brunoVarInfo.js
- packages/bruno-app/src/utils/codemirror/brunoVarInfo.spec.js
|
@coderabbitai review |
✅ Action performedReview finished.
|
…variable-scope-selector
166086f
into
usebruno:feature/variable-scope-selector-8665-internal
* feat(variables): add scope-aware variable creation (#8665) * feat(variables): scope-aware secret creation, review fixes (#8863, #8974, #8981) --------- Co-authored-by: Delta X <[email protected]> Co-authored-by: sachin-thakur-bruno <[email protected]>
Closes #7382
Description
This PR improves variable creation and navigation from the variable tooltip:
Screenshots
Select variable scope
Go to definition
Contribution Checklist:
Summary by CodeRabbit