Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

bug: Unwanted content displayed in search suggestion box when there are no results for search #1252

Conversation

khoa-le
Copy link
Contributor

@khoa-le khoa-le commented May 17, 2019

Description

Disable render suggestion component when search query have not results.

Related Issue

Closes #1223.

Verification Steps

  1. Go to Venia store front and click on search icon.
  2. Enter search string which should not return any results. example - afgdsgedf
  3. Search suggestion box display "No results were found."

How Have YOU Tested this?

Verification steps above!

Screenshots / Screen Captures (if appropriate):

Screenshot from 2019-05-17 15-48-56

@magento-cicd2
Copy link

magento-cicd2 commented May 17, 2019

CLA assistant check
All committers have signed the CLA.

@vercel
Copy link

vercel bot commented May 17, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://venia-git-fork-khoa-le-bugfix-1223-hide-unwante-c705fb.magento-research1.now.sh

@khoa-le
Copy link
Contributor Author

khoa-le commented May 21, 2019

I see this pull request have error when run tests but I don't see any output that help me fix it. Can anyone help?

@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Jun 7, 2019

Messages
📖 We are currently working on automating the PR metadata checks. Until that time, you may see failures related to labels/description/linked issues/etc even if you have fixed the problem. Failures will persist until the next push (assuming they are fixed).

Generated by 🚫 dangerJS against 5dd816f

Copy link
Contributor

@supernova-at supernova-at left a comment

Choose a reason for hiding this comment

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

This solves the problem perfectly, thank you!

Looking at that conditional though, I'm left wondering if autocomplete.js shouldn't house this logic instead. In other words, only render <Suggestions> if we have results (data.products.items.length > 0).

Here's where autocomplete.js renders this Suggestions component:

                <Suggestions
                    products={data ? data.products : {}}
                    searchValue={value}
                    setVisible={setVisible}
                    visible={visible}
                />

And sending in an empty object as the products prop just doesn't make much sense to me. We need products to suggest both categories and other products. If we don't have any, we shouldn't render <Suggestions> at all (because we don't have any!).

That said, this code works fine and I'd still accept it if you don't want to make the change to autocomplete.js instead.

@supernova-at supernova-at added the version: Patch This changeset includes backwards compatible bug fixes. label Jun 24, 2019
Copy link
Contributor

@supernova-at supernova-at left a comment

Choose a reason for hiding this comment

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

I see this pull request have error when run tests but I don't see any output that help me fix it. Can anyone help?

Yeah, that output isn't very helpful sometimes, sorry 😬 . You can get more details locally by running yarn test.

The unit tests for this component do need to be updated to reflect this change:

Update the "renders correctly" and "renders a category list" unit tests

The products prop these tests are passing in contains an empty items array which - after your change - will satisfy the conditional and render null. Instead of updating the snapshot / assertion, please pass in some items.

Add a test for empty items array

Please add a test that ensures this component returns null when products.items is an empty array.

jimbo
jimbo previously approved these changes Jun 26, 2019
Copy link
Contributor

@jimbo jimbo left a comment

Choose a reason for hiding this comment

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

Makes sense to me. Thanks for your contribution! 👍

@jimbo
Copy link
Contributor

jimbo commented Jun 26, 2019

Wow, Github's cache really didn't show me any conversation on this one.

Looking at that conditional though, I'm left wondering if autocomplete.js shouldn't house this logic instead.

No, I wouldn't make that change. I think the logic is fine where it is.

Copy link
Contributor

@sirugh sirugh left a comment

Choose a reason for hiding this comment

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

We need to make sure the tests are updated/fixed before merging. The code looks fine, otherwise but please fix the test! If you need help with this you can always reach out to us on the community slack or you can comment here and we can try to help.

@sirugh sirugh assigned tjwiebell and unassigned tjwiebell, sirugh and supernova-at Jun 26, 2019
@sirugh
Copy link
Contributor

sirugh commented Jun 26, 2019

Assigned this to @tjwiebell to handle writing/fixing tests.

@sirugh sirugh changed the title Bugfix/1223 Unwanted content displayed in search suggestion box when there are no results for search bug: Unwanted content displayed in search suggestion box when there are no results for search Jun 26, 2019
@dpatil-magento
Copy link
Contributor

QA Pass.

@dpatil-magento dpatil-magento merged commit 1b2abc3 into magento:develop Jun 26, 2019
@khoa-le khoa-le deleted the bugfix/1223-Hide-unwanted-content-when-no-result-search branch June 27, 2019 04:33
@khoa-le
Copy link
Contributor Author

khoa-le commented Jun 27, 2019

Thank you guys helping me out.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working pkg:venia-concept version: Patch This changeset includes backwards compatible bug fixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug]: Unwanted content displayed in search suggestion box when there are no results for search
9 participants