Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add initial value to sorting

Krzysztof Białogłowicz1771749d5136
diff --git a/saleor/static/js/components/CategoryPage.js b/saleor/static/js/components/CategoryPage.js
index f60a29a1a4..ce9124059b 100644
--- a/saleor/static/js/components/CategoryPage.js
+++ b/saleor/static/js/components/CategoryPage.js
@@ -59,7 +59,7 @@ class CategoryPage extends Component {
});
}
- sortBy = (event) => {
+ setSorting = (event) => {
this.props.relay.setVariables({
sortBy: event.target.className
});
@@ -152,7 +152,8 @@ class CategoryPage extends Component {
<ProductList
onLoadMore={this.incrementProductsCount}
products={category.products}
- sortBy={this.sortBy}
+ sortingValue={variables.sortBy}
+ setSorting={this.setSorting}
/>
</div>
</div>
diff --git a/saleor/static/js/components/ProductList.js b/saleor/static/js/components/ProductList.js
index cbf0963179..abc0629f8f 100644
--- a/saleor/static/js/components/ProductList.js
+++ b/saleor/static/js/components/ProductList.js
@@ -8,18 +8,19 @@ class ProductList extends Component {
static propTypes = {
onLoadMore: PropTypes.func.isRequired,
- sortBy: PropTypes.func,
- products: PropTypes.object
+ products: PropTypes.object,
+ sortingValue: PropTypes.string,
+ setSorting: PropTypes.func
};
onLoadMore = () => this.props.onLoadMore();
- sortBy = (event) => this.props.sortBy(event);
+ setSorting = (event) => this.props.setSorting(event);
render() {
const { edges, pageInfo: { hasNextPage } } = this.props.products;
return (
<div>
- <SortBy sortBy={this.sortBy} />
+ <SortBy sortingValue={this.props.sortingValue} setSorting={this.setSorting} />
<div>
{edges && (edges.map((edge, i) => (
<ProductItem key={i} product={edge.node} />
diff --git a/saleor/static/js/components/SortBy.js b/saleor/static/js/components/SortBy.js
index 4b84803531..aefaaa3089 100644
--- a/saleor/static/js/components/SortBy.js
+++ b/saleor/static/js/components/SortBy.js
@@ -5,20 +5,17 @@ export default class sortBy extends Component {
constructor(props) {
super(props);
this.state = {
- sortedElement: '',
visibility: false
};
}
static propTypes = {
- sortBy: PropTypes.func,
+ setSorting: PropTypes.func,
+ sortingValue: PropTypes.string
}
setSorting = (event) => {
- this.props.sortBy(event);
- this.setState({
- sortedElement: event.target.classList
- });
+ this.props.setSorting(event);
this.changeVisibility();
}
@@ -29,11 +26,12 @@ export default class sortBy extends Component {
}
render() {
- const { sortedElement, visibility } = this.state;
+ const { sortingValue } = this.props;
+ const { visibility } = this.state;
return (
<div className="sort-by">
<button className="btn btn-link" onClick={this.changeVisibility}>
- <span>Sort by: <strong>{sortedElement}</strong></span>
+ <span>Sort by: <strong>{sortingValue}</strong></span>
</button>
{visibility ? (
<ul className="sort-list">