Skip to content

Conversation

@nikolasrieble
Copy link
Contributor

@nikolasrieble nikolasrieble commented Nov 26, 2025

πŸ”— Relevant links

πŸ—’οΈ What

This PR:

  • add tests to a helper that did not have any
  • fixes a bug in the helper function
  • Boy Scout rule: Leave the campsite better and do minor improvements (listed below)

In the first commit, I only add tests and specifically add a test to reproduce the bug.
In the second I fix the bug.

And while I am already here, I decided to propose a few opinionated changes:

  • Use 'routes' in item rather than item.hasOwnProperty('routes'), because it allows for Typescript narrowing, and enables us to remove all casts ("as")
  • Switched the traversal from items.forEach to a for...of loop so we can rely on continue instead of early returns inside a callback. Clearer control flow and no extra closure per iteration.
  • Added the small includesFilter helper to centralize the lowercase/undefined guard logic, so both title and alias comparisons share a single, type-safe code path.

🀷 Why

@l2fprod found a bug:
image

and created a ticket for us to fix it. https://hashicorp.atlassian.net/browse/TF-32415

πŸ› οΈ How

πŸ“Έ Design Screenshots

πŸ§ͺ Testing

This PR adds unit tests for the helper function.

πŸ’­ Anything else?

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

  • If applicable, I've documented the impact of any changes to security controls.

    Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.

@vercel
Copy link

vercel bot commented Nov 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
dev-portal Ready Ready Preview Comment Nov 26, 2025 8:20pm

@nikolasrieble nikolasrieble enabled auto-merge (squash) November 26, 2025 20:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where items matching a filter by both title and alias were being duplicated in the filtered navigation results. The fix adds test coverage for the getFilteredNavItems helper function and refactors the implementation to use modern JavaScript patterns like in operator for type narrowing and for...of loops for clearer control flow.

Key changes:

  • Adds comprehensive unit tests for the getFilteredNavItems helper
  • Fixes duplication bug by using continue to prevent items from being added twice when both title and alias match
  • Refactors to use in operator instead of hasOwnProperty for better type safety

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/components/sidebar/helpers/get-filtered-nav-items.ts Refactored filtering logic to prevent duplicate items and improved code maintainability with clearer control flow
src/components/sidebar/helpers/tests/get-filtered-nav-items.test.ts Added comprehensive test suite covering edge cases including the title+alias duplication bug

πŸ’‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nikolasrieble nikolasrieble changed the title Nikolasrieble.sidebar.reproduce bug in test Fix: Sidebar filter produces duplicate results Nov 26, 2025
@github-actions
Copy link

github-actions bot commented Nov 26, 2025

πŸ“¦ Next.js Bundle Analysis

This analysis was generated by the next.js bundle analysis action πŸ€–

This PR introduced no changes to the javascript bundle πŸ™Œ

nikolasrieble and others added 2 commits November 26, 2025 21:06
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Collaborator

@RubenSandwich RubenSandwich left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for adding tests.

@nikolasrieble nikolasrieble merged commit 85b45a8 into main Dec 1, 2025
12 checks passed
@nikolasrieble nikolasrieble deleted the nikolasrieble.sidebar.reproduceBugInTest branch December 1, 2025 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants