Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Create history component #391

Merged
merged 35 commits into from
Mar 18, 2022
Merged

Create history component #391

merged 35 commits into from
Mar 18, 2022

Conversation

saranicoly
Copy link
Contributor

@saranicoly saranicoly commented Mar 15, 2022

What's the purpose of this pull request?

This PR aims to show the user's search history in base store, which is made by creating a "SearchHistory" component.

How it should look like:
image
How it is actually looking like:
image

How does it work?

  • When the user clicks on "search bar", if there are any previous searches saved in the local storage, SearchHistory must appear:
Gravacao.de.Tela.2022-03-15.as.19.35.16.mov
  • If the user has never searched anything, or if they press the "clear" button, there won't be any search saved in the local storage. In this case, the shown component will be "SuggestionsTopSearch":
Gravacao.de.Tela.2022-03-15.as.19.52.24.mov
  • When clicking any of the listed searches, the component must do another search with the same name:
Gravacao.de.Tela.2022-03-15.as.20.07.35.mov

How to test it?

Since the component will be part of the Suggestion's dropdown component, we don't have a specific place to render it yet. That said, you can test SearchHistory by following the steps below:

Supposing that you want to see it on Navbar:

  • Open the Navbar.tsx file
  • Add the following imports:
import SearchHistory from 'src/components/search/History/SearchHistory'
import useSearchHistory from 'src/sdk/search/useSeachHistory'
import { SuggestionsTopSearch } from 'src/components/search/Suggestions'
  • Add const { searchHistory, clearSearchHistory } = useSearchHistory() inside the Navbar() function:

image

  • Add the following lines to the SearchInput call:
onBlur={() => setSearchExpanded(false)}
onFocus={() => setSearchExpanded(true)}

image

  • Before closing the section tag, add the following lines:
{searchExpanded && searchHistory.length > 0 && (
    <SearchHistory onClear={() => clearSearchHistory()} />
 )}
{searchExpanded && searchHistory.length === 0 && (
    <SuggestionsTopSearch
        searchedItems={[
            {
                  href: 'http://localhost:8000/tasty-granite-towels-tasty-18643698/p',
                  name: 'Tasty Granite Towels Tasty',
            },
        ]}
    />
)}

image

  • After that, you'll be ready to test the component!

Possible issues

  • Some of the functionalities aren't working well on Desktop. This is probably because the component bar is closed before the function can work when we click it.
  • Since the actual rendering of this component will be done in another task and these issues are likely related to the way SearchHistory is being called in the Navbar, it was accorded within the team that the investigation would be done later.
  • If you face any issue related to this, try to visualize it as a mobile device.

References

Checklist

  • CHANGELOG entry added

@netlify
Copy link

netlify bot commented Mar 15, 2022

✅ Deploy Preview for basestore ready!

🔨 Explore the source changes: 2ed3b8f

🔍 Inspect the deploy log: https://app.netlify.com/sites/basestore/deploys/6234d87e3b5a7800097ca0a4

😎 Browse the preview: https://deploy-preview-391--basestore.netlify.app

@vtex-sites
Copy link

vtex-sites bot commented Mar 15, 2022

Preview is ready

This pull request generated a Preview

👀   Preview: https://preview-391--base.preview.vtex.app
🔬   Go deeper by inspecting the Build Logs
📝   based on commit fb6cbb8

@gatsby-cloud
Copy link

gatsby-cloud bot commented Mar 15, 2022

Gatsby Cloud Build Report

basestore

🎉 Your build was successful! See the Deploy preview here.

Build Details

View the build logs here.

🕐 Build time: 11m

Performance

Lighthouse report

Metric Score
Performance 💚 92
Accessibility 💚 100
Best Practices 💚 100
SEO 💚 93

🔗 View full report

@saranicoly saranicoly requested a review from sergiofontes March 15, 2022 23:41
Copy link
Contributor

@israelswf israelswf left a comment

Choose a reason for hiding this comment

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

Great job, Sara ✨

@israelswf israelswf self-requested a review March 16, 2022 16:29
Copy link
Contributor

@filipewl filipewl left a comment

Choose a reason for hiding this comment

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

Left some initial comments for us to discuss!

import useSearchHistory from 'src/sdk/search/useSeachHistory'
import { formatSearchState, initSearchState } from '@faststore/sdk'

const doSearch = (term: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Noticed we have this same function on the SearchInput component so I wonder we can how we can extract it to a single place.

const doSearch = async (term: string) => {
const { pathname, search } = formatSearchState(
initSearchState({
term,
base: '/s',
})
)

Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!
I think when we have all search-related components integrated we are going to have a more clear way about how to reuse the same function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with @eduardoformiga. How do you guys feel about adding a task to do that in the next sprint?

Copy link
Member

Choose a reason for hiding this comment

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

Agree with you!

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.

Good Job! 👏

I left some comments/suggestions regarding the row alignment.

import useSearchHistory from 'src/sdk/search/useSeachHistory'
import { formatSearchState, initSearchState } from '@faststore/sdk'

const doSearch = (term: string) => {
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!
I think when we have all search-related components integrated we are going to have a more clear way about how to reuse the same function.

sergiofontes and others added 2 commits March 17, 2022 14:33
Co-Authored-By: Sara Nicoly <saranicoly0@gmail.com>
Co-Authored-By: Sara Nicoly <saranicoly0@gmail.com>
@saranicoly saranicoly requested a review from filipewl March 17, 2022 19:28
Copy link
Contributor

@lucasfp13 lucasfp13 left a comment

Choose a reason for hiding this comment

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

Great job, LGTM! 💯

Just a small thing I noticed is that the CSS file name is not following the pattern we have in the project. Instead using SearchHistory.scss you can leave as search-history.scss to keep consistency.

Copy link
Contributor

@filipewl filipewl left a comment

Choose a reason for hiding this comment

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

LGTM! Just one more question about opening the searches in a new tab.

saranicoly and others added 3 commits March 18, 2022 16:02
Co-authored-by: Filipe W. Lima <fwl.ufpe@gmail.com>
@saranicoly saranicoly merged commit fb6cbb8 into master Mar 18, 2022
@saranicoly saranicoly deleted the feat/FSSS-193-history-component branch March 18, 2022 19:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants