Skip to content

Conversation

axelavargas
Copy link
Member

@axelavargas axelavargas commented Jun 19, 2025

What is this feature?

Enables searching library panels by folder name besides panel name and description. Users can now type a folder name to find all panels contained within that folder.

Why do we need this feature?

Currently, users can only search library panels by panel name or description. When users remember which folder contains the panel they need but not the specific panel name, they have to manually browse through folders to find it.

This is not very user friendly, especially with orgs having a lot of library panels

Who is this feature for?

Everyone that uses the library panels search widget

For Admins

libraryPanelsAbilityToSearchByFolderName.mp4

For Viewers with limited access to folders

libPanelSearchByFolderNameWithPermissions.mp4

Which issue(s) does this PR fix?:

Fixes #62865

Special notes for your reviewer:

My Go coding skills are rough 😬. I did my best to consider security aspects, such as preventing users from accessing folders they shouldn't have access to, and implemented the logic by following patterns similar to those I saw in the library panels code.

Please check that:

  • It works as expected from a user's perspective.
  • It follows Grafana go patterns
  • It's secure

Tasks:

  • Implement logic that adds that support
  • Add unit tests

@axelavargas axelavargas self-assigned this Jun 19, 2025
@github-project-automation github-project-automation bot moved this to 🗂️ Needs Triage / Escalation in Sharing squad Jun 19, 2025
@axelavargas axelavargas moved this from 🗂️ Needs Triage / Escalation to 👩‍💻 Development in Sharing squad Jun 19, 2025
@axelavargas axelavargas marked this pull request as ready for review June 20, 2025 12:59
@axelavargas axelavargas requested review from a team and grafanabot as code owners June 20, 2025 12:59
@axelavargas axelavargas requested review from mdvictor and removed request for a team June 20, 2025 12:59
@github-actions github-actions bot added this to the 12.1.x milestone Jun 20, 2025
Copy link
Contributor

@evictorero evictorero left a comment

Choose a reason for hiding this comment

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

I left some comments about the approach.
The search works as expected. I found an unexpected case.
When selecting the general folder in the old dashboard filter, it lists children folders. But when I type in a child folder name it disappears.

Screen.Recording.2025-06-25.at.6.11.51.PM.mov

@axelavargas axelavargas requested a review from a team as a code owner June 30, 2025 09:06
@axelavargas axelavargas requested review from juanicabanas and nmarrs and removed request for a team June 30, 2025 09:06
@axelavargas axelavargas requested a review from evictorero June 30, 2025 09:14
@axelavargas axelavargas requested a review from evictorero July 7, 2025 14:27
builder.Write(" OR "+sql, param)

// Include ALL elements from folders whose titles match the search string
hasFolderFilter := len(strings.TrimSpace(query.FolderFilterUIDs)) > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have this condition !hasFolderFilter ? In my mind, if the folder filter has FolderA, FolderB, FolderC selected and I type in the search folder FolderA, I would expect only to see FolderA.

Copy link
Member Author

Choose a reason for hiding this comment

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

the condition is here to narrow the search to filter by "name" and "description" only if the user set the folder filter.

Think in this use case:
->Folder: Alexa
---> library panels title: "alexa lib panel", "eze lib panel"

->Folder: Alexa2
---> library panels title: "alexa 2 lib panel", "eze 2 lib panel"

->Dashboards (this is the fake general folder)
---> library panels title: "alexa 3 lib panel", "eze 2 lib panel"

If a user search by "alexa" and set the folder filter to "alexa"
The output should be: alexa lib panel

If a user search by "alexa" and doesn't use any folder filter
The output should be:

  • alexa lib panel
  • eze lib panel
  • alexa 2 lib panel
  • eze 2 lib panel
  • alexa 3 lib panel

This is returning all the library panels from the folder matching "alexa" and the library panels title that match as well

useCaseFolderSearch.mp4

Comment on lines 893 to 894
var foldersWithMatchingTitles []string
if len(strings.TrimSpace(query.SearchString)) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: In Go we try to keep the code aligned to the left. To do so, we prefer to have more than one return statement and return as soon as possible. In this case, for example, it would be better this approach to remove the nested if/else condition.

Suggested change
var foldersWithMatchingTitles []string
if len(strings.TrimSpace(query.SearchString)) > 0 {
if len(strings.TrimSpace(query.SearchString)) <= 0 {
return nil, nil
}

axelavargas and others added 3 commits July 8, 2025 12:32
Co-authored-by: Ezequiel Victorero <ezequiel.victorero@grafana.com>
Copy link
Contributor

@evictorero evictorero left a comment

Choose a reason for hiding this comment

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

LGTM!!

@axelavargas axelavargas merged commit e33047b into main Jul 8, 2025
98 checks passed
@axelavargas axelavargas deleted the axelav/lib-panel-feat-search-by-folder-title branch July 8, 2025 13:07
YannickAlex07 pushed a commit to YannickAlex07/grafana that referenced this pull request Jul 11, 2025
…fana#106997)

* Dashboard: Add ability to search by folder name in library panels

* restore to main to fix linting issues

* restore from main to avoid go linting issues

* add logic to the writers.go that search by folder title if folder is not passed

* add missing left joing from the folder table

* Add extra logic to prevent folder searches without permission

* fix go linting issue about memory

* Add test when searching by folder name

* Refactor tests to include a bit more validation

* apply feedback and use SearchFolder from search folder service

* clean up comments

* Update pkg/services/libraryelements/database.go

Co-authored-by: Ezequiel Victorero <ezequiel.victorero@grafana.com>

* Fix logic of early return

* Extract into a function and remove the left join

* Apply feedback to be aligned with idiomatic go

* Apply suggestion from @evictorero

Co-authored-by: Ezequiel Victorero <ezequiel.victorero@grafana.com>

* fix liting

---------

Co-authored-by: Ezequiel Victorero <ezequiel.victorero@grafana.com>
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.

Dashboard: Library Panel - Add support to search by folder name
2 participants