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

Migrate ContentSearch component to TS #325

Merged

Conversation

Souptik2001
Copy link
Contributor

Description of the Change

Migrate the ContentSearch component to TS.

Found two bugs in the component, which are also fixed by this PR (Please let me know if any of these are expected feature and not a bug) -

  • It displays the type of the suggestion, but that doesn’t have the actual post type. Instead we should display subtype.
  • When we click on the initial options, it doesn’t select. That’s because we have an onBlur event attached to the search bar, which hides the initial results whenever it's triggered. And when we try to click on any of those outside options, it just blurs out and the options just vanishes.

Both the bugs are demonstrated in the below video -

Screen.Recording.2024-05-16.at.1.15.27.AM.mov
  • You can see the pages show "post" as the info tag.
  • When I click on any result in the initial results list, then it doesn't click and before that only the result container vanishes. This is not very clear as the selected post is not shown anywhere in the block. Therefore in this PR, I have also added a section to display the selected post.

Related issue - #295 and #314

How to test the Change

  • Added a new block named "Post Searcher Example", which can be used to test the functionality of the component.

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

Signed-off-by: Souptik Datta <souptikdatta2001@gmail.com>
const ContentSearch = ({
onSelectItem,
placeholder,
interface QueryCache {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are many interfaces created for this component, therefore should it be better to move all the interfaces to another file say definitions.ts, and just import from there?

/>

{hasSearchString || hasInitialResults ? (
<>
<List className={`${NAMESPACE}-list`}>
{isLoading && currentPage === 1 && <StyledSpinner />}
{isLoading && currentPage === 1 && <StyledSpinner onPointerEnterCapture={null} onPointerLeaveCapture={null} />}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weirdly we have to pass these two props to Spinner (specifically to SVG-based component), to stop Typescript from complaining. Otherwise, Typescript throws an error.
There is a open issue for this on the Gutenberg repo - WordPress/gutenberg#61322

But the issue is setting these props throws warning in the console now by SVG element -

Screenshot 2024-05-16 at 1 35 12 AM

Signed-off-by: Souptik Datta <souptikdatta2001@gmail.com>
Signed-off-by: Souptik Datta <souptikdatta2001@gmail.com>
Copy link
Member

@fabiankaegy fabiankaegy left a comment

Choose a reason for hiding this comment

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

This works well in my testing :) Thanks for this enhancement!

@fabiankaegy fabiankaegy merged commit 2083983 into 10up:develop Jun 6, 2024
1 of 2 checks passed
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.

None yet

2 participants