Repository navigation
fix: path-param variable edit popup - #6955
Conversation
WalkthroughAdded path parameter variable support to Bruno's variable system. Changes include: a new Changes
Sequence Diagram(s)sequenceDiagram
participant User as User
participant Editor as Editor / Hover
participant VarDetect as Variable Detector
participant Redux as Redux Store
participant Request as Request Handler
User->>Editor: Hover over /:param in path
Editor->>VarDetect: Check token for variable
VarDetect->>VarDetect: Detect /:param pattern
VarDetect->>Editor: Render path param tooltip
User->>Editor: Update path parameter value
Editor->>Redux: Dispatch updateVariableInScope<br/>(type: 'pathParam')
Redux->>Redux: Locate matching path param<br/>in draft/request
Redux->>Redux: Create updated param<br/>with new value
Redux->>Redux: Dispatch updatePathParam
Redux->>Request: Save related request
Request-->>User: Changes persisted
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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
🤖 Fix all issues with AI agents
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`:
- Around line 2011-2026: The pathParam branch silently no-ops when
params.find(...) returns undefined, causing the UI to show a value that isn’t
persisted; fix by creating and persisting a new path param when not found:
inside the case 'pathParam' branch, if pathParam is falsy create a newParam = {
name: variableName, type: 'path', value: newValue, /* other defaults from
existing param shape */ } and dispatch an action to add/upsert it (use an
existing addRequestParam/addPathParam if available, otherwise dispatch
updatePathParam as an upsert), then continue to call saveRequest(item.uid,
collection.uid, true). Ensure you still return the promise chain (return
dispatch(saveRequest(...)).then(resolve).catch(reject)) so callers get the
correct success/failure outcome.
In `@packages/bruno-app/src/utils/codemirror/brunoVarInfo.js`:
- Around line 700-786: The path-param tokenizer can include trailing quotes,
commas or spaces because separators only include ['/', '?', '&', '=']; update
the separator set used in the path-param logic (the separators array used when
advancing pathValueEnd) to also include double-quote ("), single-quote ('),
whitespace characters (space, tab), comma (,) and any other common delimiters
(e.g., closing paren) so that the while loop that advances pathValueEnd stops at
these characters; this change should be applied where pathParamStart,
pathValueEnd and separators are defined before creating the token passed to
renderVarInfo/showPopup.
| case 'pathParam': { | ||
| const { item } = data; | ||
| const params = item.draft ? get(item, 'draft.request.params', []) : get(item, 'request.params', []); | ||
| const pathParam = params.find((p) => p.type === 'path' && p.name === variableName); | ||
|
|
||
| if (pathParam) { | ||
| const updatedParam = { ...pathParam, value: newValue }; | ||
| dispatch(updatePathParam({ | ||
| pathParam: updatedParam, | ||
| itemUid: item.uid, | ||
| collectionUid: collection.uid | ||
| })); | ||
| } | ||
| return dispatch(saveRequest(item.uid, collection.uid, true)) | ||
| .then(resolve) | ||
| .catch(reject); |
There was a problem hiding this comment.
Avoid silent no-op when a path param is missing.
If a URL includes a new /:param not yet in params, this branch skips updatePathParam but still saves, so the UI can reflect a value that wasn’t persisted. Consider rejecting or creating the param when it’s not found.
🛠️ Suggested fix
- const pathParam = params.find((p) => p.type === 'path' && p.name === variableName);
-
- if (pathParam) {
- const updatedParam = { ...pathParam, value: newValue };
- dispatch(updatePathParam({
- pathParam: updatedParam,
- itemUid: item.uid,
- collectionUid: collection.uid
- }));
- }
+ const pathParam = params.find((p) => p.type === 'path' && p.name === variableName);
+
+ if (!pathParam) {
+ return reject(new Error(`Path param "${variableName}" not found`));
+ }
+
+ const updatedParam = { ...pathParam, value: newValue };
+ dispatch(updatePathParam({
+ pathParam: updatedParam,
+ itemUid: item.uid,
+ collectionUid: collection.uid
+ }));🤖 Prompt for AI Agents
In `@packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js`
around lines 2011 - 2026, The pathParam branch silently no-ops when
params.find(...) returns undefined, causing the UI to show a value that isn’t
persisted; fix by creating and persisting a new path param when not found:
inside the case 'pathParam' branch, if pathParam is falsy create a newParam = {
name: variableName, type: 'path', value: newValue, /* other defaults from
existing param shape */ } and dispatch an action to add/upsert it (use an
existing addRequestParam/addPathParam if available, otherwise dispatch
updatePathParam as an upsert), then continue to call saveRequest(item.uid,
collection.uid, true). Ensure you still return the promise chain (return
dispatch(saveRequest(...)).then(resolve).catch(reject)) so callers get the
correct success/failure outcome.
| // ---------- 1) MODE: Double-Brace Variable {{ ... }} ---------- | ||
| // We check this first as it's the most common variable type. | ||
| if (line.includes('{{') && line.includes('}}')) { | ||
| // Check if the cursor is roughly between a '{{' to the left and '}}' to the right | ||
| if (line.lastIndexOf('{{', pos.ch) !== -1 && line.indexOf('}}', pos.ch) !== -1) { | ||
| let start = pos.ch; | ||
| let end = pos.ch; | ||
|
|
||
| // Scan LEFT to find the nearest '{{' | ||
| while (start > 0) { | ||
| const leftTwo = line.substring(start - 2, start); | ||
| if (leftTwo === '{{') { | ||
| start -= 2; | ||
| break; | ||
| } | ||
| // If we hit a '}}' while looking for '{{', the cursor is outside a pair | ||
| if (leftTwo === '}}') break; | ||
| start--; | ||
| } | ||
|
|
||
| // If we find opening braces, stop | ||
| if (leftTwo === '{{') { | ||
| start -= 2; | ||
| break; | ||
| } | ||
| // Validate we actually found a '{{' | ||
| if (start >= 0 && line.substring(start, start + 2) === '{{') { | ||
| // Scan RIGHT to find the nearest '}}' | ||
| while (end < line.length) { | ||
| const rightTwo = line.substring(end, end + 2); | ||
| if (rightTwo === '}}') { | ||
| end += 2; | ||
| break; | ||
| } | ||
| // If we hit another '{{' before a closing '}}', the structure is invalid | ||
| if (rightTwo === '{{') { | ||
| end = line.length + 1; | ||
| break; | ||
| } | ||
| end++; | ||
| } | ||
|
|
||
| // If we cross a closing braces before finding '{{', we're not inside a variable | ||
| if (leftTwo === '}}') { | ||
| return; | ||
| // Validate the final string and show popup | ||
| if (end <= line.length && line.substring(end - 2, end) === '}}') { | ||
| const fullVariableString = line.substring(start, end); | ||
| const inner = fullVariableString.slice(2, -2).trim(); | ||
|
|
||
| if (inner) { | ||
| const token = { string: fullVariableString, start, end }; | ||
| const brunoVarInfo = renderVarInfo(token, options); | ||
| if (brunoVarInfo) { | ||
| showPopup(cm, box, brunoVarInfo); | ||
| return; // EXIT: We found a variable, don't look for path params | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| start--; | ||
| } | ||
|
|
||
| // If we reached the start of the line and didn't match '{{', return | ||
| if (start < 0 || line.substring(start, start + 2) !== '{{') { | ||
| return; | ||
| } | ||
|
|
||
| // ---------- Find closing '}}' to the RIGHT ---------- | ||
| while (end < line.length) { | ||
| const rightTwo = line.substring(end, end + 2); | ||
| // ---------- 2) MODE: Path Parameter /:varName ---------- | ||
| // If we didn't return from the brace logic, check if cursor is on a path param | ||
| const pathParamStart = line.substring(0, pos.ch + 1).lastIndexOf('/:'); | ||
|
|
||
| // If we find closing braces, stop | ||
| if (rightTwo === '}}') { | ||
| end += 2; | ||
| break; | ||
| } | ||
| if (pathParamStart !== -1) { | ||
| let pathValueEnd = pathParamStart + 2; | ||
|
|
||
| // If we hit another '{{' before a '}}', then this isn't a valid enclosing pair | ||
| if (rightTwo === '{{') { | ||
| return; | ||
| // Path params end at the next URL separator (/, ?, &, =) or end of line | ||
| const separators = ['/', '?', '&', '=']; | ||
| while (pathValueEnd < line.length && !separators.includes(line[pathValueEnd])) { | ||
| pathValueEnd++; | ||
| } | ||
|
|
||
| end++; | ||
| } | ||
| // If we reached end-of-line without finding '}}', return | ||
| if (end > line.length || line.substring(end - 2, end) !== '}}') { | ||
| return; | ||
| } | ||
|
|
||
| const fullVariableString = line.substring(start, end); | ||
| // Check if cursor is actually inside the detected /:param range | ||
| if (pos.ch >= pathParamStart && pos.ch < pathValueEnd) { | ||
| const fullVariableString = line.substring(pathParamStart, pathValueEnd); | ||
|
|
||
| // Basic validation to ensure it's a non-empty variable | ||
| if (!fullVariableString.startsWith('{{') || !fullVariableString.endsWith('}}')) { | ||
| return; | ||
| } | ||
|
|
||
| // Prevent tooltips for empty variables like {{ }} | ||
| const inner = fullVariableString.slice(2, -2).trim(); | ||
| if (!inner) return; | ||
|
|
||
| // Build a token object compatible with renderVarInfo | ||
| const token = { | ||
| string: fullVariableString, | ||
| start: start, | ||
| end: end | ||
| }; | ||
|
|
||
| const brunoVarInfo = renderVarInfo(token, options); | ||
| if (brunoVarInfo) { | ||
| showPopup(cm, box, brunoVarInfo); | ||
| // Ensure it's not just "/:" but has a name (e.g., "/:id") | ||
| if (fullVariableString.length > 2) { | ||
| const token = { | ||
| string: fullVariableString, | ||
| start: pathParamStart, | ||
| end: pathValueEnd | ||
| }; | ||
| const brunoVarInfo = renderVarInfo(token, options); | ||
| if (brunoVarInfo) { | ||
| showPopup(cm, box, brunoVarInfo); | ||
| return; // EXIT: Popup shown | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Path-param tokenization should stop at quotes/whitespace.
In common URL strings (e.g., "/users/:id"), the current separators skip ", ', and whitespace, so the token can include trailing quotes/commas and fail validation. Add common delimiters to avoid invalid tokens.
🛠️ Suggested fix
- const separators = ['/', '?', '&', '='];
+ const separators = ['/', '?', '&', '=', '#', '"', '\'', '`', ' ', '\t', ')', '}', ']', ','];🤖 Prompt for AI Agents
In `@packages/bruno-app/src/utils/codemirror/brunoVarInfo.js` around lines 700 -
786, The path-param tokenizer can include trailing quotes, commas or spaces
because separators only include ['/', '?', '&', '=']; update the separator set
used in the path-param logic (the separators array used when advancing
pathValueEnd) to also include double-quote ("), single-quote ('), whitespace
characters (space, tab), comma (,) and any other common delimiters (e.g.,
closing paren) so that the while loop that advances pathValueEnd stops at these
characters; this change should be applied where pathParamStart, pathValueEnd and
separators are defined before creating the token passed to
renderVarInfo/showPopup.
|
Both failing tests Merging the fix in |
Co-authored-by: shubh-bruno <[email protected]>
Description
Fixes : #6933
Jira
Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.