fix: auto-expand collapsed sidebar section when clicking action buttons#6468
Conversation
WalkthroughThis PR adds auto-expand functionality to sidebar sections. When clicking actions (e.g., add-menu) on a collapsed section, the section now automatically expands instead of remaining collapsed. The implementation modifies the onClick handler and includes comprehensive test coverage for the new behavior. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 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: 0
🧹 Nitpick comments (4)
packages/bruno-app/src/components/Sidebar/SidebarSection/index.js (1)
69-74: Consider updating local state immediately for consistency.The onClick handler updates only the context via
setSectionExpanded(id, true)and relies on the useEffect (lines 20-23) to synclocalExpanded. In contrast,handleToggle(lines 25-29) updates bothlocalExpandedand the context immediately.For consistency and to avoid potential UI lag, consider updating
localExpandeddirectly:🔎 Proposed refactor for immediate state update
onClick={(e) => { e.stopPropagation(); if (!localExpanded) { + setLocalExpanded(true); setSectionExpanded(id, true); } }}tests/sidebar/section-auto-expand.spec.ts (3)
4-29: Usetest.stepto improve test readability.Per coding guidelines,
test.stepshould be used to organize test actions and make reports easier to read. Consider restructuring this test with steps like "Verify section is initially collapsed", "Click action button", and "Verify section expands".🔎 Proposed refactor with test.step
test('Clicking action button on collapsed section should expand it', async ({ page }) => { - // The api-specs section is collapsed by default (only collections is expanded) - // Find the api-specs section by its title - const apiSpecsSection = page.locator('.sidebar-section').filter({ hasText: 'API Specs' }); - - // Verify the api-specs section is initially collapsed (doesn't have 'expanded' class) - await expect(apiSpecsSection).not.toHaveClass(/expanded/); - - // Verify section-content is not visible when collapsed - const sectionContent = apiSpecsSection.locator('.section-content'); - await expect(sectionContent).not.toBeVisible(); - - // Click on the add button in the section-actions area - // This should trigger the auto-expand logic - const addButton = page.getByTestId('api-specs-header-add-menu'); - await addButton.click(); - - // Close the dropdown by pressing Escape (we just want to test the expand, not the dropdown action) - await page.keyboard.press('Escape'); - - // After clicking an action, the section should be expanded - await expect(apiSpecsSection).toHaveClass(/expanded/); - - // Verify section-content is now visible - await expect(sectionContent).toBeVisible(); + await test.step('Verify API Specs section is initially collapsed', async () => { + const apiSpecsSection = page.locator('.sidebar-section').filter({ hasText: 'API Specs' }); + await expect(apiSpecsSection).not.toHaveClass(/expanded/); + + const sectionContent = apiSpecsSection.locator('.section-content'); + await expect(sectionContent).not.toBeVisible(); + }); + + await test.step('Click action button to trigger auto-expand', async () => { + const addButton = page.getByTestId('api-specs-header-add-menu'); + await addButton.click(); + await page.keyboard.press('Escape'); + }); + + await test.step('Verify section is now expanded', async () => { + const apiSpecsSection = page.locator('.sidebar-section').filter({ hasText: 'API Specs' }); + await expect(apiSpecsSection).toHaveClass(/expanded/); + + const sectionContent = apiSpecsSection.locator('.section-content'); + await expect(sectionContent).toBeVisible(); + }); });Note: You'll need to move locator declarations to be accessible across steps or redeclare them as shown.
Based on coding guidelines: "Promote the use of
test.stepas much as possible so the generated reports are easier to read."
31-52: Usetest.stepto improve test readability.Apply the same
test.steppattern here to organize the test into logical sections: verify initial state, perform action, verify final state.Based on coding guidelines: "Promote the use of
test.stepas much as possible so the generated reports are easier to read."
54-73: Usetest.stepto improve test readability.This test would benefit from steps like "Collapse Collections section", "Click search action button", and "Verify section expands". This makes the test flow clearer in reports.
Based on coding guidelines: "Promote the use of
test.stepas much as possible so the generated reports are easier to read."
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/bruno-app/src/components/Sidebar/SidebarSection/index.js(1 hunks)tests/sidebar/section-auto-expand.spec.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (CODING_STANDARDS.md)
**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions.() => {}is good
No space between function name and parentheses.func()notfunc ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly
Files:
packages/bruno-app/src/components/Sidebar/SidebarSection/index.jstests/sidebar/section-auto-expand.spec.ts
tests/**/**.*
⚙️ CodeRabbit configuration file
tests/**/**.*: Review the following e2e test code written using the Playwright test library. Ensure that:
Follow best practices for Playwright code and e2e automation
Try to reduce usage of
page.waitForTimeout();in code unless absolutely necessary and the locator cannot be found using existingexpect()playwright callsAvoid using
page.pause()in codeUse locator variables for locators
Avoid using test.only
Use multiple assertions
Promote the use of
test.stepas much as possible so the generated reports are easier to readEnsure that the
fixtureslike the collections are nested inside thefixturesfolderFixture Example*: Here's an example of possible fixture and test pair
. ├── fixtures │ └── collection │ ├── base.bru │ ├── bruno.json │ ├── collection.bru │ ├── ws-test-request-with-headers.bru │ ├── ws-test-request-with-subproto.bru │ └── ws-test-request.bru ├── connection.spec.ts # <- Depends on the collection in ./fixtures/collection ├── headers.spec.ts ├── persistence.spec.ts ├── variable-interpolation │ ├── fixtures │ │ └── collection │ │ ├── environments │ │ ├── bruno.json │ │ └── ws-interpolation-test.bru │ ├── init-user-data │ └── variable-interpolation.spec.ts # <- Depends on the collection in ./variable-interpolation/fixtures/collection └── subproto.spec.ts
Files:
tests/sidebar/section-auto-expand.spec.ts
🧠 Learnings (2)
📚 Learning: 2025-12-17T21:41:24.730Z
Learnt from: naman-bruno
Repo: usebruno/bruno PR: 6407
File: packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.js:5-41
Timestamp: 2025-12-17T21:41:24.730Z
Learning: Do not suggest PropTypes validation for React components in the Bruno codebase. The project does not use PropTypes, so reviews should avoid proposing PropTypes and rely on the existing typing/validation approach (e.g., TypeScript or alternative runtime checks) if applicable. This guideline applies broadly to all JavaScript/JSX components in the repo.
Applied to files:
packages/bruno-app/src/components/Sidebar/SidebarSection/index.js
📚 Learning: 2025-12-05T20:31:33.005Z
Learnt from: CR
Repo: usebruno/bruno PR: 0
File: CODING_STANDARDS.md:0-0
Timestamp: 2025-12-05T20:31:33.005Z
Learning: Applies to **/*.test.{js,jsx,ts,tsx} : Add tests for any new functionality or meaningful changes. If code is added, removed, or significantly modified, corresponding tests should be updated or created
Applied to files:
tests/sidebar/section-auto-expand.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Unit Tests
- GitHub Check: SSL Tests - Windows
- GitHub Check: CLI Tests
- GitHub Check: Playwright E2E Tests
- GitHub Check: SSL Tests - macOS
- GitHub Check: SSL Tests - Linux
Description
When a sidebar section (Collections or API Specs) is collapsed and the user clicks on an action button (e.g., search, add, or menu), the section now automatically expands.
JIRA
Contribution Checklist:
Screen.Recording.2025-12-19.at.1.12.29.PM.mov
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.