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
Plugins: Add fuzzy search to plugins catalogue #81001
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.
Great work! 🚀 Took it up for a spin and it works great! I have left some comments but the functionality is good.
There are also some integration tests failing in the backend due to adding keywords
to the plugin, and some frontend tests are failing too:
https://drone.grafana.net/grafana/grafana/157266
A future improvement could be sorting the fuzzy search results as well using the ufuzzy library, but that's up for discussion and can be left for a follow-up PR 👍
package.json
Outdated
@@ -251,7 +251,7 @@ | |||
"@grafana/sql": "workspace:*", | |||
"@grafana/ui": "workspace:*", | |||
"@kusto/monaco-kusto": "^7.4.0", | |||
"@leeoniya/ufuzzy": "1.0.14", | |||
"@leeoniya/ufuzzy": "^1.0.14", |
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.
Is this change from exact dependency to latest version intended?
}, {}); | ||
} | ||
export function filterByKeyword(plugins: CatalogPlugin[], query: string) { | ||
const dataArray = Object.values(getPluginDetailsForFuzzySearch(plugins)); |
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.
Since you are using only the values from the object that getPluginDetailsForFuzzySearch
returns and getPluginDetailsForFuzzySearch
is not used anywhere else, you can instead return directly an array from there instead of having to do Object.values
here
export function filterByKeyword(plugins: CatalogPlugin[], query: string) { | ||
const dataArray = Object.values(getPluginDetailsForFuzzySearch(plugins)); | ||
let opts = {}; | ||
let uf = new uFuzzy(opts); |
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.
you can pass {}
directly to the constructor and save declaring the opts
variable since we don't use it for anything else.
|
||
if (keyword && !fieldsToSearchIn.some((f) => f.includes(keyword))) { | ||
if (keyword && filteredPluginIds != null && !filteredPluginIds.includes(plugin.id)) { |
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: here we already know filteredPluginIds
is not null because is checked in the previous condition, so you can remove the check here.
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.
* WIP add fuzzysearch to plugins catalog * Add keywords to the plugins listing output * add fuzzy search to plugin catalog, add keywords to plugins at frontend side * refactor fuzzysearch function after review * review changes * change the version of uFuzzy library * change reduce result object in getPluginDetailsForFuzzySearch * fix yarn lock error * fix helpers tests * fix frontend searching test * fix frontend linting issues * fix tests --------- Co-authored-by: Esteban Beltran <esteban@academo.me> Co-authored-by: Giuseppe Guerra <giuseppe@guerra.in>
What is this feature?
Add keywords to plugins from frontend side
Fuzzy search for plugin catalog. User can use name, type, orgName, keywords or Id together to find plugin
Why do we need this feature?
Fuzzy search helps users to find results in more convenient way. User can type name, type, keyword and find what is needed. We add this search into our Plugin catalog.
Who is this feature for?
Everyone who uses plugins from plugins catalog
Which issue(s) does this PR fix?:
Fixes #80699