Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add ProductItem component; cosmetics
Marcin Gębala38d869947d3c
diff --git a/saleor/static/js/category.js b/saleor/static/js/category.jsindex 98ebc5d656..27dc784316 100644--- a/saleor/static/js/category.js+++ b/saleor/static/js/category.js@@ -1,16 +1,13 @@-import React from 'react'+import React, { PropTypes } from 'react'import ReactDOM from 'react-dom'import Relay from 'react-relay'-//import AppRoute from './components/AppRoute'-import CategoryPage from './components/CategoryPage'import ProductFilters from './components/ProductFilters'const categoryPage = document.getElementById('category-page');const categoryData = JSON.parse(categoryPage.getAttribute('data-category'));-Relay.injectNetworkLayer(new Relay.DefaultNetworkLayer('/graphql/', {credentials: 'same-origin',@@ -18,6 +15,11 @@ Relay.injectNetworkLayer();class App extends React.Component {++ static propTypes = {+ viewer: PropTypes.object+ }+render() {return (<CategoryPage@@ -46,8 +48,7 @@ const RelayApp = Relay.createContainer(App, {},});--const Viewer = {+const AppRoute = {queries: {viewer: () => Relay.QL`query { viewer }@@ -58,9 +59,6 @@ const Viewer = {};ReactDOM.render(- <Relay.RootContainer- Component={RelayApp}- route={Viewer}- />,+ <Relay.RootContainer Component={RelayApp} route={AppRoute} />,categoryPage,);diff --git a/saleor/static/js/components/CategoryPage.js b/saleor/static/js/components/CategoryPage.jsindex 302acb8f31..e073a8afe6 100644--- a/saleor/static/js/components/CategoryPage.js+++ b/saleor/static/js/components/CategoryPage.js@@ -12,11 +12,9 @@ class CategoryPage extends Component {}render() {-const category = this.props.category;const attributes = this.props.attributes;const products = this.props.category.products;-return (<div className="row">@@ -31,7 +29,6 @@ class CategoryPage extends Component {</div>)}-}export default Relay.createContainer(CategoryPage, {@@ -39,20 +36,20 @@ export default Relay.createContainer(CategoryPage, {category: () => Relay.QL`fragment on CategoryType {id,- name,- children(first: 20) {- edges {- node {- id,- name,- slug- }+ name,+ children(first: 20) {+ edges {+ node {+ id,+ name,+ slug}}- products (first: 20) {- ${ProductList.getFragment('products')}- }+ }+ products (first: 20) {+ ${ProductList.getFragment('products')}+ }}`,},-});\ No newline at end of file+});diff --git a/saleor/static/js/components/ProductFilters.js b/saleor/static/js/components/ProductFilters.jsindex 62e30a3b61..66d007d6da 100644--- a/saleor/static/js/components/ProductFilters.js+++ b/saleor/static/js/components/ProductFilters.js@@ -70,8 +70,3 @@ export default Relay.createContainer(ProductFilters, {`,},});-----diff --git a/saleor/static/js/components/ProductItem.js b/saleor/static/js/components/ProductItem.jsnew file mode 100644index 0000000000..0279afd1ed--- /dev/null+++ b/saleor/static/js/components/ProductItem.js@@ -0,0 +1,49 @@+import React, { Component, PropTypes } from 'react'+import Relay from 'react-relay'+++class ProductItem extends Component {++ static propTypes = {+ product: PropTypes.object+ };++ render() {+ const { product } = this.props;+ return (+ <div className="col-xs-12 col-sm-6 col-md-4 col-lg-3" itemScope itemType="https://schema.org/Product">+ <div className="panel panel-default text-center">+ <div className="panel-body">+ <a itemProp="url" href={product.url}>+ <img itemProp="image" className="img-responsive" src={product.imageUrl} alt="" />+ <span className="product-list-item-name" itemProp="name" title={product.name}>{product.name}</span>+ </a>+ </div>+ <div className="panel-footer">+ <span itemProp="price">+ {product.price.gross} <span className="currency"> {product.price.currency}</span>+ </span>+ </div>+ </div>+ </div>+ );+ }+}++export default Relay.createContainer(ProductItem, {+ fragments: {+ product: () => Relay.QL`+ fragment on ProductType {+ id+ name+ price {+ gross+ net+ currency+ }+ imageUrl+ url+ }+ `,+ },+});diff --git a/saleor/static/js/components/ProductList.js b/saleor/static/js/components/ProductList.jsindex 911a5b97bd..9ebbfeba2b 100644--- a/saleor/static/js/components/ProductList.js+++ b/saleor/static/js/components/ProductList.js@@ -1,5 +1,9 @@import React, { Component, PropTypes } from 'react'import Relay from 'react-relay'++import ProductItem from './ProductItem';++class ProductList extends Component {static propTypes = {@@ -7,30 +11,12 @@ class ProductList extends Component {};render() {- const products = this.props.products.edges;+ const edges = this.props.products.edges;return (<div>- {products ? (products.map((item) => {- const product = item.node;- return (- <div key={product.id} className="col-xs-12 col-sm-6 col-md-4 col-lg-3" itemScope itemType="https://schema.org/Product">- <div className="panel panel-default text-center">- <div className="panel-body">- <a itemProp="url" href={product.url}>- <img itemProp="image" className="img-responsive" src={product.imageUrl} alt="" />- <span className="product-list-item-name" itemProp="name" title={product.name}>{product.name}</span>- </a>- </div>- <div className="panel-footer">- <span itemProp="price">- {product.price.gross} <span className="currency"> {product.price.currency}</span>- </span>- </div>- </div>- </div>- );- })- ) : (null)}+ {edges && (edges.map((edge, i) => (+ <ProductItem key={i} product={edge.node} />+ )))}</div>)}@@ -40,19 +26,11 @@ export default Relay.createContainer(ProductList, {fragments: {products: () => Relay.QL`fragment on ProductTypeConnection {- edges {- node {- id- name- price {- gross- net- currency- }- imageUrl- url- }- }+ edges {+ node {+ ${ProductItem.getFragment('product')}+ }+ }}`,},