Skip to content

Add navbar search results preview#3578

Merged
Simrayz merged 7 commits intomasterfrom
feat/3577-navbar-search-results-preview
Oct 15, 2025
Merged

Add navbar search results preview#3578
Simrayz merged 7 commits intomasterfrom
feat/3577-navbar-search-results-preview

Conversation

@Simrayz
Copy link
Copy Markdown
Contributor

@Simrayz Simrayz commented Oct 8, 2025

Scope and purpose

Resolves #3577.

This PR adds search preview results when using the navbar search. It uses a new index_search_preview view, which reuses the search providers of the existing index view, but uses HTMX-compatible templates and result truncation to better fit a preview.

Edit 13.10.25

The existing search view (info/views.py::index) redirects to the search result if only a single result is returned. The search bar shows results as the user types, and it is slightly jarring to redirect automatically, even if the match is exact. As such, I opted to just show the results instead, even if only one is returned. However, if the reviewers think that automatic redirect should be the intended behaviour, I can add it to the preview search as well.

How to test

Edit 13.10.25: Added how to test section after code review

The search preview view handles several search result cases:

  1. An empty search bar shows no search results. You can test by clearing an input after performing an initial search. The popover should close.
  2. A search which returns no results will return a "Fallback" provider. You can test by searching for something that does not exist, e.g. "perfection".
  3. A search that only returns a single result, will display a popover. Try searching for "Trondheim", and it should show a single location result.
  4. A search that returns multiple results will display by category. Try searching for the start of a netbox name, or a location like "Teknobyen" or "Oslo".

Screenshots

If the search does not match anything, show a "No results" message

image

When a search returns a lot of results, truncate each category

image

When a search is specific enough, some result categories are not truncated

image

Contributor Checklist

Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to NAV can be found in the
Hacker's guide to NAV.

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation
  • Linted/formatted the code with ruff, easiest by using pre-commit
  • Wrote the commit message so that the first line continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See https://cbea.ms/git-commit/
  • Based this pull request on the correct upstream branch: For a patch/bugfix affecting the latest stable version, it should be based on that version's branch (<major>.<minor>.x). For a new feature or other additions, it should be based on master.
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done
  • If it's not obvious from a linked issue, described how to interact with NAV in order for a reviewer to observe the effects of this change first-hand (commands, URLs, UI interactions)
  • If this results in changes in the UI: Added screenshots of the before and after
  • If this adds a new Python source code file: Added the boilerplate header to that file

@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 8, 2025

Test results

    27 files      27 suites   44m 22s ⏱️
 2 593 tests  2 593 ✅ 0 💤 0 ❌
19 134 runs  19 134 ✅ 0 💤 0 ❌

Results for commit 8e7e444.

♻️ This comment has been updated with latest results.

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 8, 2025

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 62.23%. Comparing base (12c53ba) to head (8e7e444).
⚠️ Report is 318 commits behind head on master.

Files with missing lines Patch % Lines
python/nav/web/info/views.py 95.65% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3578      +/-   ##
==========================================
+ Coverage   62.21%   62.23%   +0.01%     
==========================================
  Files         611      611              
  Lines       44939    44962      +23     
  Branches       43       43              
==========================================
+ Hits        27960    27983      +23     
  Misses      16969    16969              
  Partials       10       10              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Simrayz Simrayz force-pushed the feat/3577-navbar-search-results-preview branch from 3dba0c7 to ac41370 Compare October 8, 2025 08:41
@Simrayz Simrayz force-pushed the feat/3577-navbar-search-results-preview branch from ac41370 to 7079547 Compare October 8, 2025 09:20
@Simrayz Simrayz changed the title Feat/3577 navbar search results preview Add navbar search results preview Oct 8, 2025
@Simrayz Simrayz requested a review from a team October 8, 2025 09:32
@Simrayz Simrayz marked this pull request as ready for review October 8, 2025 09:32
Copy link
Copy Markdown
Contributor

@johannaengland johannaengland left a comment

Choose a reason for hiding this comment

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

If I'm not imagining things, then the "search" button grew a bit bigger than before and it looks not symmetric anymore

Before:
image

After:
image

And maybe that's just my preference, but I think it would be nice if there would not be a gap between the search field and the results like this:

image

search_providers, failed_providers = process_form(form)
if has_only_one_result(search_providers) and not failed_providers:
provider = search_providers[0]
if provider.name == 'Fallback':
Copy link
Copy Markdown
Contributor

@johannaengland johannaengland Oct 13, 2025

Choose a reason for hiding this comment

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

When does this happen? Could you add an instruction for how to replicate this situation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have added a "How to test" section

@Simrayz Simrayz force-pushed the feat/3577-navbar-search-results-preview branch from ae1a484 to 7c2b089 Compare October 13, 2025 13:23
@Simrayz
Copy link
Copy Markdown
Contributor Author

Simrayz commented Oct 13, 2025

@johannaengland Made adjustments as requested

Adjusted styles to match previous search bar exactly

image

The reason that the button grew, was that I changed the search bar to use a button instead of an input, with consistent spacing above/below text. The old button has more space above than below, which is why it is slightly narrower. It also has a fixed height of 1.8rem.

Adjusted position of search results popover

Popover now has no space between itself and the input.

image

Use localhost instead of custom fixture in search_test

Copy link
Copy Markdown
Contributor

@johannaengland johannaengland left a comment

Choose a reason for hiding this comment

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

When I search for something that returns a result, then delete that input, then for a short moment between showing the results and closing the popover it is showing the "No results for ..." popover, that should be fixed

box.save()
yield box
box.delete()
def netbox(localhost):
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.

Why are you not using it directly where netbox is used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think using netbox instead of localhost increases the clarity of the tests, and if we need to create a custom netbox for the tests, it only has to be updated in one place. But I changed the tests to use localhost anyways :)

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.

I see, if you think there will be a need to customize it, then we can keep it that way as well

@sonarqubecloud
Copy link
Copy Markdown

@Simrayz
Copy link
Copy Markdown
Contributor Author

Simrayz commented Oct 14, 2025

When I search for something that returns a result, then delete that input, then for a short moment between showing the results and closing the popover it is showing the "No results for ..." popover, that should be fixed

Fixed it by showing an empty response before the popover is closed.

@Simrayz Simrayz merged commit cb569e9 into master Oct 15, 2025
19 checks passed
@Simrayz Simrayz deleted the feat/3577-navbar-search-results-preview branch October 15, 2025 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search results preview in NAVbar

3 participants