Skip to content
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

LibraryPanelSearch: Refactor and fix hyphen issue #55314

Merged
merged 2 commits into from Sep 21, 2022
Merged

Conversation

kaydelaney
Copy link
Contributor

What this PR does / why we need it:
Adds a new prop to FilterInput to disable regex escaping/unescaping for cases where it isn't needed, fixing an issue where search queries including special characters wouldn't return library panels that include those same characters.

Which issue(s) this PR fixes:
Closes #55312

Special notes for your reviewer:
Hopefully some of the refactoring I did on LibraryPanelsSearch is uncontroversial. I changed how state was handled from using useReducer to managing the state inline as I didn't really feel like there was an advantage compared to just using useState, but I'm more than happy to undo that change if someone can make a good argument for it.

I did a bit more work than is seen here in this PR refactoring some of the related components, but I'll probably make a separate PR with those changes to avoid overloading this one.

@kaydelaney kaydelaney added this to the 9.1.6 milestone Sep 16, 2022
@kaydelaney kaydelaney requested a review from a team September 16, 2022 15:18
@kaydelaney kaydelaney self-assigned this Sep 16, 2022
@kaydelaney kaydelaney requested review from joshhunt and a team as code owners September 16, 2022 15:18
@kaydelaney kaydelaney requested review from a team, ashharrison90, academo, codeincarnate and oscarkilhed and removed request for a team September 16, 2022 15:18
@grafanabot
Copy link
Contributor

@xlson xlson modified the milestones: 9.1.6, 9.1.7 Sep 20, 2022
Copy link
Contributor

@ivanortegaalba ivanortegaalba left a comment

Choose a reason for hiding this comment

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

Thank you so much for the refactor @kaydelaney, it looks great!

While reproducing the issue, I cannot do it I cannot reproduce it in play. Am I doing something wrong? I tried also adding a panel and I got the same result.

2022-09-20 15 43 32


return (
<div className={styles.container}>
{showSort && <SortPicker value={sortDirection} onChange={onSortChange} filter={['alpha-asc', 'alpha-desc']} />}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we extract the filter strings to an enum here? WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

It is indeed not otherwise obvious that those two are part of the options SortPicker has after receiving its response from the api /api/search/sorting.

@polibb
Copy link
Contributor

polibb commented Sep 20, 2022

Thank you so much for the refactor @kaydelaney, it looks great!

While reproducing the issue, I cannot do it I cannot reproduce it in play. Am I doing something wrong? I tried also adding a panel and I got the same result.

@ivanortegaalba Me neither, but I do reproduce it locally and it is fixed on this PR. I also don't know why it's okay in Play 👾.

@grafanabot
Copy link
Contributor

}

export const FilterInput = React.forwardRef<HTMLInputElement, Props>(
({ value, width, onChange, ...restProps }, ref) => {
({ value, width, onChange, escapeRegex = true, ...restProps }, ref) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Because FilterInput is in grafana-ui should we make the naming of the prop more clear about its purpose in general, like escapeSpecialChars?
escapeRegex makes me wonder which regex, what is the regex if not the one inside FilterInput and what does escaping it mean if it is?

Copy link
Contributor

@polibb polibb left a comment

Choose a reason for hiding this comment

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

Very neat refactoring 🙏

Copy link
Contributor

@ivanortegaalba ivanortegaalba left a comment

Choose a reason for hiding this comment

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

Tested locally, and it works perfectly fine! I can now use special characters as part of the search. The original issue was only in main but not in play, for the records ;P

Thanks, @kaydelaney for the cool refactor!

@kaydelaney kaydelaney merged commit 9e0d349 into main Sep 21, 2022
@kaydelaney kaydelaney deleted the lib-panel-search branch September 21, 2022 17:37
@grafanabot
Copy link
Contributor

The backport to v9.1.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-55314-to-v9.1.x origin/v9.1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x 9e0d349bf95dfcb962da1b91294898495eca492a
# Push it to GitHub
git push --set-upstream origin backport-55314-to-v9.1.x
git switch main
# Remove the local backport branch
git branch -D backport-55314-to-v9.1.x

Then, create a pull request where the base branch is v9.1.x and the compare/head branch is backport-55314-to-v9.1.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

LibraryPanelsSearch: Searching Library Panels with hyphens does not return results
5 participants