-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Dashboard: Library Panels - Add ability to search by folder name #106997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dashboard: Library Panels - Add ability to search by folder name #106997
Conversation
There was a problem hiding this 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
Co-authored-by: Ezequiel Victorero <ezequiel.victorero@grafana.com>
…ch-by-folder-title
builder.Write(" OR "+sql, param) | ||
|
||
// Include ALL elements from folders whose titles match the search string | ||
hasFolderFilter := len(strings.TrimSpace(query.FolderFilterUIDs)) > 0 |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
var foldersWithMatchingTitles []string | ||
if len(strings.TrimSpace(query.SearchString)) > 0 { |
There was a problem hiding this comment.
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.
var foldersWithMatchingTitles []string | |
if len(strings.TrimSpace(query.SearchString)) > 0 { | |
if len(strings.TrimSpace(query.SearchString)) <= 0 { | |
return nil, nil | |
} |
Co-authored-by: Ezequiel Victorero <ezequiel.victorero@grafana.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!
…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>
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:
Tasks: