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

Filter link on search displays results #742

Merged
merged 12 commits into from
Oct 4, 2022
Merged

Conversation

yunakim714
Copy link
Collaborator

Description

Currently, when users search for an item and then apply a filter from the search results page, they are directed to a 404 error page that looks like this:
https://pwa-kit.mobify-storefront.com/en-GB/category/undefined?limit=25&q=dress&refine=c_refinementColor%3DBlack&sort=best-matches

This fix ensures that users can filter on search results.

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

  • If users search for an item, "categoryId" is undefined. If "categoryId" is undefined, the url is correctly built with "/search?" and the selected refinement categories

How to Test-Drive This PR

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

@yunakim714 yunakim714 requested a review from a team as a code owner September 30, 2022 20:07
@yunakim714
Copy link
Collaborator Author

Still need to write tests for this change

@echessman echessman requested a review from adamraya October 3, 2022 16:49
@@ -82,6 +82,20 @@ const MockedComponent = ({isLoading, isLoggedIn = false, searchQuery}) => {
</div>
)}
/>
<Route
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's no need to add a new <Route />, we can add the '/search' path to the existing <Route />:

path={createPathWithDefaults('/category/:categoryId')}

                path={[
                    createPathWithDefaults('/category/:categoryId'),
                    createPathWithDefaults('/search')
                ]}

@@ -108,7 +122,6 @@ const server = setupMockServer(
)

beforeEach(() => {
window.history.pushState({}, 'ProductList', '/uk/en-GB/category/mens-clothing-jackets')
Copy link
Collaborator

@adamraya adamraya Oct 3, 2022

Choose a reason for hiding this comment

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

We can leave this pushState by default for the majority of the tests.
I suggest reverting this change.

Copy link
Collaborator

@alexvuong alexvuong Oct 3, 2022

Choose a reason for hiding this comment

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

Since we are adding tests for both routes /search and /category/:id for the PLP, having module-wise navigation to the category page for all tests does not make any sense for the one that needs to navigate to the search page. I think it is better for the individual tests to handle the URL navigation instead of having a global one for all tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, currently there are two tests that need to navigate to the search page. For potential future test cases, I also suggest having the individual tests handle the URL navigation!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can see advantages for both approaches, less code vs more specific code. Either way works great in this case.
Feel free to ignore the window.history.pushState comments @yunakim714.

Copy link
Collaborator

@adamraya adamraya left a comment

Choose a reason for hiding this comment

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

Good job! I left only small comments.

CI is currently failing due to an ESLint issue, which you can fix by running npm run lint:fix.

Feel free to merge once tests pass.

Copy link
Collaborator

@alexvuong alexvuong left a comment

Choose a reason for hiding this comment

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

LGTM

@yunakim714 yunakim714 merged commit 94aa73b into develop Oct 4, 2022
@wjhsf wjhsf deleted the filter-link-on-search branch March 17, 2023 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants