Skip to content

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

Add simple category page from GraphQL

Krzysztof Białogłowiczef71c62e0b29
diff --git a/saleor/static/js/category.js b/saleor/static/js/category.js
index efaf5c8311..4f16e0722c 100644
--- a/saleor/static/js/category.js
+++ b/saleor/static/js/category.js
@@ -16,7 +16,13 @@ Relay.injectNetworkLayer(
class App extends React.Component {
render() {
- return <CategoryPage products={ this.props.viewer.category.products.edges } />
+ return (
+ <CategoryPage
+ products={ this.props.viewer.category.products.edges }
+ categoryName = { this.props.viewer.category.name }
+ categories= { this.props.viewer.category.children.edges }
+ />
+ );
}
}
@@ -28,6 +34,17 @@ const RelayApp = Relay.createContainer(App, {
viewer: () => Relay.QL`
fragment on Viewer {
category(pk: $categoryId) {
+ id,
+ name,
+ children(first: 20) {
+ edges {
+ node {
+ id,
+ name,
+ slug
+ }
+ }
+ },
products(first: 20) {
edges {
node {
@@ -63,5 +80,5 @@ ReactDOM.render(
Component={RelayApp}
route={Viewer}
/>,
- document.getElementById('category-page'),
+ categoryPage,
);
diff --git a/saleor/static/js/components/CategoryPage.js b/saleor/static/js/components/CategoryPage.js
index 11fc8e895e..027b12c6ba 100644
--- a/saleor/static/js/components/CategoryPage.js
+++ b/saleor/static/js/components/CategoryPage.js
@@ -1,19 +1,23 @@
import React, { Component, PropTypes } from 'react'
import ProductList from './ProductList'
+import ProductFilters from './ProductFilters'
export default class CategoryPage extends Component {
static propTypes = {
- products: PropTypes.array
+ products: PropTypes.array,
+ categories: PropTypes.array,
+ categoryName: PropTypes.string
}
render() {
- const { products } = this.props;
+ const { products, categories, categoryName } = this.props;
return (
<div className="row">
<div className="col-md-3">
+ <ProductFilters categories={categories} categoryName={categoryName} />
</div>
<div className="col-md-9">
<div className="row">
diff --git a/saleor/static/js/components/productFilters.js b/saleor/static/js/components/productFilters.js
index 2df6b3eb67..9dc92e9ab5 100644
--- a/saleor/static/js/components/productFilters.js
+++ b/saleor/static/js/components/productFilters.js
@@ -1,18 +1,28 @@
import React, { Component, findDOMNode, PropTypes } from 'react'
-import { ProductList } from './productList'
-export class ProductFilters extends Component {
+export default class ProductFilters extends Component {
+
+ static propTypes = {
+ categories: PropTypes.array,
+ categoryName: PropTypes.string
+ };
render() {
+ const { categories, categoryName } = this.props;
return(
<div>
- <button className="btn btn-danger">Red</button>
- <button className="btn btn-success">Green</button>
- <button className="btn btn-default">Cancel</button>
+ <h2>Filters:</h2>
+ <ul className="categories list-group">
+ <li className="list-group-item active">{categoryName}</li>
+ {categories.map((item) => {
+ const category = item.node;
+ return (
+ <li key={category.id} className="list-group-item"><a href={category.name}>{category.name}</a></li>
+ );
+ })}
+ </ul>
</div>
)
-
}
-
}
\ No newline at end of file
diff --git a/templates/category/index.html b/templates/category/index.html
index 7da1767c02..035f087a06 100644
--- a/templates/category/index.html
+++ b/templates/category/index.html
@@ -25,21 +25,7 @@
{% endblock breadcrumb %}
{% block content %}
- <div id="category-page" data-category='{"id":{{category.id}},"name":"{{category}}"}'></div>
- <div class="row">
- <div class="col-md-3">
- <ul class="list-group">
- <li class="list-group-item active">
- {{ category }}
- </li>
- {% for category in children_categories %}
- <li class="list-group-item">
- <a href="{{ category.get_absolute_url }}">
- {{ category }}
- </a>
- </li>
- {% endfor %}
- </ul>
- </div>
- </div>
+
+ <div id="category-page" data-category='{"id":{{category.id}}}'></div>
+
{% endblock content %}