Skip to content

Commit

Permalink
Add ProductSearchContextProvider schema to eliminate the SearchResult…
Browse files Browse the repository at this point in the history
… dependency
  • Loading branch information
estacioneto committed Sep 18, 2018
1 parent 1d0f05e commit 1f1ebce
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- `ProductSearchContextProvider` schema to eliminate the `SearchResult` dependency.

## [1.16.0] - 2018-09-18

Expand Down
35 changes: 16 additions & 19 deletions react/ProductSearchContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import React, { Component } from 'react'
import { Query } from 'react-apollo'
import { Helmet, withRuntimeContext } from 'render'

import { SORT_OPTIONS, createMap, canonicalPathFromParams } from './utils/search'
import DataLayerApolloWrapper from './components/DataLayerApolloWrapper'
import searchQuery from './queries/searchQuery.gql'
import { canonicalPathFromParams, createMap, SORT_OPTIONS } from './utils/search'

const DEFAULT_PAGE = 1
const DEFAULT_MAX_ITEMS_PER_PAGE = 1
const DEFAULT_MAX_ITEMS_PER_PAGE = 10

class ProductSearchContextProvider extends Component {
static propTypes = {
Expand All @@ -35,12 +35,19 @@ class ProductSearchContextProvider extends Component {
children: PropTypes.node.isRequired,
}

state = {
variables: {
maxItemsPerPage: DEFAULT_MAX_ITEMS_PER_PAGE,
static defaultProps = {
maxItemsPerPage: DEFAULT_MAX_ITEMS_PER_PAGE,
}

static schema = {
title: 'editor.product-search.title',
type: 'object',
properties: {
maxItemsPerPage: {
title: 'editor.product-search.maxItemsPerPage',
type: 'number',
},
},
/* Will be loading by default. The container will wait until the real data arrives */
loading: true,
}

pageCategory = products => {
Expand Down Expand Up @@ -100,17 +107,11 @@ class ProductSearchContextProvider extends Component {
]
}

handleContextVariables = variables => {
this.setState({
variables,
loading: false,
})
}

render() {
const {
nextTreePath,
params,
maxItemsPerPage,
query: {
order: orderBy = SORT_OPTIONS[0].value,
page: pageProps,
Expand All @@ -121,8 +122,6 @@ class ProductSearchContextProvider extends Component {
runtime: { page: runtimePage },
} = this.props

const { variables: { maxItemsPerPage } } = this.state

const map = mapProps || createMap(params, rest)
const page = pageProps ? parseInt(pageProps) : DEFAULT_PAGE
const from = (page - 1) * maxItemsPerPage
Expand Down Expand Up @@ -155,7 +154,7 @@ class ProductSearchContextProvider extends Component {
...search,
})
}
loading={this.state.loading || loading}
loading={loading}
>
<Helmet>
{params && (
Expand All @@ -175,8 +174,6 @@ class ProductSearchContextProvider extends Component {
...searchQueryProps,
...search,
},
loading: this.state.loading,
setContextVariables: this.handleContextVariables,
searchContext: runtimePage,
pagesPath: nextTreePath,
map,
Expand Down
4 changes: 3 additions & 1 deletion react/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"dreamstore.cart": "Cart",
"dreamstore.buy": "Buy",
"dreamstore.poweredBy": "POWERED BY",
"dreamstore.buy-success": "Your product was add to the cart!"
"dreamstore.buy-success": "Your product was add to the cart!",
"editor.product-search.title": "Product search context",
"editor.product-search.maxItemsPerPage": "Maximum number of items per page"
}
4 changes: 3 additions & 1 deletion react/locales/es-AR.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"dreamstore.cart": "Carrito",
"dreamstore.buy": "Comprar",
"dreamstore.poweredBy": "IMPULSADO POR VTEX",
"dreamstore.buy-success": "Su producto se ha agregado a la cesta!"
"dreamstore.buy-success": "Su producto se ha agregado a la cesta!",
"editor.product-search.title": "Contexto de búsqueda de productos",
"editor.product-search.maxItemsPerPage": "Número máximo de elementos por página"
}
4 changes: 3 additions & 1 deletion react/locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"dreamstore.cart": "Carrinho",
"dreamstore.buy": "Comprar",
"dreamstore.poweredBy": "FORNECIDO POR VTEX",
"dreamstore.buy-success": "Seu produto foi adicionado ao carrinho!"
"dreamstore.buy-success": "Seu produto foi adicionado ao carrinho!",
"editor.product-search.title": "Contexto de busca de produtos",
"editor.product-search.maxItemsPerPage": "Número máximo de elementos por página"
}

0 comments on commit 1f1ebce

Please sign in to comment.