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

feat: Add search history & top searches #112

Merged
merged 16 commits into from
Jun 16, 2022
Merged

Conversation

filipewl
Copy link
Contributor

@filipewl filipewl commented Jun 9, 2022

How does it work?

See vtex-sites/gatsby.store#67 for more details.

How to test it?

Because the intelligent search's top search data comes from real usage data from the last 14 days, as of today, we don't have any top search data to show for the storeframework store ID. That means the preview deploy won't display the Top Search component with data. Because of that, and for testing purposes, I've created a temporary branch where I switched the store ID for storecomponents, it has top search data and you can preview it working in this preview deploy.

NextJS Search History n Top Search

Known Issues

@vercel
Copy link

vercel bot commented Jun 9, 2022

Deployment failed with the following error:

Resource is limited - try again in 30 minutes (more than 100, code: "api-deployments-free-per-day").

@vercel
Copy link

vercel bot commented Jun 9, 2022

Deployment failed with the following error:

Resource is limited - try again in 10 minutes (more than 100, code: "api-deployments-free-per-day").

@vercel
Copy link

vercel bot commented Jun 9, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
nextjs-store-storybook ✅ Ready (Inspect) Visit Preview Jun 16, 2022 at 10:25PM (UTC)

@vercel vercel bot temporarily deployed to preview June 9, 2022 23:24 Inactive
@vercel vercel bot temporarily deployed to preview June 10, 2022 09:53 Inactive
@vtex-sites
Copy link

vtex-sites bot commented Jun 10, 2022

Preview is ready

This pull request generated a Preview

👀   Preview: https://sfj-f1a0e54--nextjs.preview.vtex.app
🔬   Go deeper by inspecting the Build Logs
📝   based on commit f1a0e54

@vtex-sites
Copy link

vtex-sites bot commented Jun 10, 2022

Lighthouse Reports

Here are the Lighthouse reports of this Pull Request

📝 Based on commit f1a0e54

Lighthouse Report by page
📎   /
📎   /apple-magic-mouse/p
📎   /office

Filipe W. Lima added 2 commits June 10, 2022 13:48
A cherry-pick from the Gatsby's merge commit of this same feature.

* Skip rendering the history if there isn't any

* Clear the history when its button is clicked

* Stop trying to open the link in a new tab

In a previous design spec we opened the links in a new tab but we are not doing this anymore

* Remove onClear prop, does not seem to be needed

* Show the search history component

* Show up to 4 search history items max

The design spec mentions 4 max:
https://www.figma.com/file/kJywgfIx8LBIzggCY5AeDy/Handoff-v3.1-(Search)?node-id=2%3A58234

* Add the top searches

* Extract a `formatSearchPath` util function

* Use a link instead of button for the suggested terms

Because the `href` is known so we can use links and not navigate programmatically with buttons.

* Fix search test

I had removed the `navigate` call because it wasn't needed for the
links, but it's also used programmatically to trigger the search in the
input.
 # Please enter the commit message for your changes. Lines
starting

* Fix SonarQube warning

* Create a context so the search dropdown can be closed

When terms, history, top search, products are clicked.

* Consider `closeSearchInputDropdown` to be null

Missed including this in the previous commit.

* Fix SonarQube warning

* Rename button from Clear to Clear History

* Adjust Loading text message spacing

* Fix link color for Top Search

* Fix grayish clock icon color in search history

* Limit search to 5 items per category

Noticed sometimes we were showing +5 and, apparently, the `first` pagination doesn't really filter the results.

* Also update the search input with the selected option

* Fix suggested terms link color

* Add the magnifying glass icon to suggested terms

* Run TS Hero extension to organize imports of touched files

* Better handle search input selections

Whenever a selection is made, be it from History, Top Search, Suggested Terms or Products, use the same logic:
- Add term to the history
- Send term to analytics
- Close dropdown
- Update the input with the term

* Do not show an empty gap when there are not results

* Move `SearchInputContext` and `useSearchInput` to `sdk/search/…`

* Fix warning about `SearchHistoryProps` type export

* Fix overflow-x when expanding the search on mobile

* Fix React key warning

* Debounce the search suggestions

* Add entries to the changelog

* Adjust `SuggestionsTopSearch` after the merged changes

* Fix Storybook search stories

* Simplify top search querying by using `useQuery`

Address [this suggestion](vtex-sites/gatsby.store#67 (comment)).

* Remove debounce package in favor of using `useDeferredValue` from React

Address [this comment](vtex-sites/gatsby.store#67 (comment)):

> can't we use React18 features like useDefferedValue to not need to implement a debounce function?

* Let TypeScript be aware of new types from React 18

So it doesn't complain when we use the new features (e.g., `useDeferredValue`).

* Let search history also record the path

Instead of using the generic search path for all the searched terms, along with the searched term, also store its path. This way, if a suggested product is selected, we store its name and its PDP path.

* Better organize by extracting `useTopSearch` to its own file

Address this comment:
vtex-sites/gatsby.store#67 (comment)

* Better organize by extracting `useSuggestions` to its own file

Address this comment:
vtex-sites/gatsby.store#67 (comment)

* Fix the missing search input (left) padding

Pointed out by this comment:
vtex-sites/gatsby.store#67 (review)

> should we add padding-left inside the input?

What happened was that the padding was being overwritten by the styles when the search input is minimized.

---

Conflicts:
- CHANGELOG.md
- src/components/common/SearchInput/SearchInput.tsx
- src/components/search/History/SearchHistory.tsx
- src/components/search/SuggestionProductCard/SuggestionProductCard.tsx
- src/components/search/Suggestions/Suggestions.tsx
- src/components/search/Suggestions/SuggestionsTopSearch.tsx
- src/components/ui/Search/Suggestions/Suggestions.stories.tsx
- src/components/ui/Search/Suggestions/Suggestions.tsx
@filipewl filipewl force-pushed the feat/search-history-n-top branch from f606e4b to 5be7614 Compare June 10, 2022 16:51
@vercel vercel bot temporarily deployed to preview June 10, 2022 16:53 Inactive
Cherry-picked from the `gatsby.store` repo.

* Fixes `useTopSearch` query

* Updates CHANGELOG.md

---

Conflicts:
- @generated/graphql/index.ts
- @generated/graphql/persisted.json
- CHANGELOG.md
@vercel vercel bot temporarily deployed to preview June 10, 2022 17:03 Inactive
I had done that to add support for types from React 18 on Gatsby but that is not needed in the NextJS case. The support for React 18 types was done in a previous PR.
@vercel vercel bot temporarily deployed to preview June 10, 2022 21:38 Inactive
@filipewl filipewl marked this pull request as ready for review June 13, 2022 16:29
Filipe W. Lima added 2 commits June 13, 2022 13:51
Part of the link had the blue color instead of light gray. That's because the light gray selector had less CSS specificity than the blue one, so I increased the specificity. I think will be addressed when
we got CSS modules working for all components.
@vercel vercel bot temporarily deployed to preview June 13, 2022 19:41 Inactive
@filipewl filipewl force-pushed the feat/search-history-n-top branch from 7b3a93f to f05d65a Compare June 13, 2022 19:45
@vercel vercel bot temporarily deployed to preview June 13, 2022 19:46 Inactive
@vercel vercel bot temporarily deployed to preview June 13, 2022 20:44 Inactive
This week querying for the top search for the storeframework account returned no results, that's because this is based on real usage data. Because of that, we were showing the "Top Search" dropdown with the heading but no data. In this scenario, let's not render anything till we decide what to do.
@vercel vercel bot temporarily deployed to preview June 13, 2022 22:15 Inactive
@filipewl filipewl self-assigned this Jun 13, 2022
@filipewl filipewl added the Features New feature or request label Jun 13, 2022
@vercel vercel bot temporarily deployed to preview June 13, 2022 22:25 Inactive
And also adjust the padding so the link covers it.

Reported by Fanny!
@vercel vercel bot temporarily deployed to preview June 14, 2022 00:06 Inactive
@vercel vercel bot temporarily deployed to preview June 14, 2022 10:02 Inactive
Copy link
Contributor

@hellofanny hellofanny left a comment

Choose a reason for hiding this comment

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

Looks good! Well done 🚀

image

Copy link
Member

@eduardoformiga eduardoformiga left a comment

Choose a reason for hiding this comment

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

Amazing! ✨

I noticed a border-radius issue that is not so important and we can deal with it afterward
29tFeTokGZ

@vercel vercel bot temporarily deployed to preview June 15, 2022 17:34 Inactive
@hellofanny
Copy link
Contributor

hellofanny commented Jun 15, 2022

Amazing! ✨

I noticed a border-radius issue that is not so important and we can deal with it afterward 29tFeTokGZ

I think this was intentional. The bottom corners should be flat (according to the prototype 🤔 )

@eduardoformiga
Copy link
Member

Amazing! ✨
I noticed a border-radius issue that is not so important and we can deal with it afterward 29tFeTokGZ

    [
      
    ](https://user-images.githubusercontent.com/11325562/173671688-e30b8bef-2ec1-4086-b7ca-bc8d68161509.gif)
    
        ![29tFeTokGZ](https://user-images.githubusercontent.com/11325562/173671688-e30b8bef-2ec1-4086-b7ca-bc8d68161509.gif)
      
    
      
        
          
        
        
          
          
        
      
      [
        
          
        
      ](https://user-images.githubusercontent.com/11325562/173671688-e30b8bef-2ec1-4086-b7ca-bc8d68161509.gif)

I think this was intentional. The bottom corners should be flat (according to the prototype 🤔 )

Even when there are no results for the search term?

@vercel vercel bot temporarily deployed to preview June 16, 2022 18:47 Inactive
@filipewl
Copy link
Contributor Author

@eduardoformiga and @hellofanny, I've created an internal task to deal with the border radius issue because I couldn't think of a very straightforward solution. Thanks for all the feedback!
🙇

@vercel vercel bot temporarily deployed to preview June 16, 2022 22:25 Inactive
@filipewl filipewl merged commit f1a0e54 into main Jun 16, 2022
@filipewl filipewl deleted the feat/search-history-n-top branch June 16, 2022 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Features New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants