Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change indent to spaces
Krzysztof Białogłowicz623ab69f1470
diff --git a/saleor/static/js/components/CategoryPage.js b/saleor/static/js/components/CategoryPage.jsindex 478fedcdeb..8d0b52d051 100644--- a/saleor/static/js/components/CategoryPage.js+++ b/saleor/static/js/components/CategoryPage.js@@ -8,11 +8,11 @@ const PAGINATE_BY = 20;class CategoryPage extends Component {- static propTypes = {- attributes: PropTypes.array,- category: PropTypes.object,+ static propTypes = {+ attributes: PropTypes.array,+ category: PropTypes.object,relay: PropTypes.object- }+ }onFilterChanged = (attributes) => {if (attributes) {@@ -35,31 +35,31 @@ class CategoryPage extends Component {})}- render() {- const category = this.props.category;- const attributes = this.props.attributes;+ render() {+ const category = this.props.category;+ const attributes = this.props.attributes;- return (- <div className="row">- <div className="col-md-3">- <ProductFilters+ return (+ <div className="row">+ <div className="col-md-3">+ <ProductFiltersattributes={attributes}categories={category}onFilterChanged={this.onFilterChanged}onPriceFilterChanged={this.onPriceFilterChanged}/>- </div>- <div className="col-md-9">- <div className="row">- <ProductList+ </div>+ <div className="col-md-9">+ <div className="row">+ <ProductListonLoadMore={this.onLoadMore}products={category.products}/>- </div>- </div>- </div>- )- }+ </div>+ </div>+ </div>+ )+ }}export default Relay.createContainer(CategoryPage, {diff --git a/saleor/static/js/components/ProductFilters.js b/saleor/static/js/components/ProductFilters.jsindex 01d1163632..aa777441e0 100644--- a/saleor/static/js/components/ProductFilters.js+++ b/saleor/static/js/components/ProductFilters.js@@ -7,154 +7,154 @@ import PriceFilter from './PriceFilter';class ProductFilters extends Component {- static propTypes = {- attributes: PropTypes.array,- categories: PropTypes.object,- onFilterChanged: PropTypes.func.isRequired,- onPriceFilterChanged: PropTypes.func.isRequired- };-- constructor(props) {+ static propTypes = {+ attributes: PropTypes.array,+ categories: PropTypes.object,+ onFilterChanged: PropTypes.func.isRequired,+ onPriceFilterChanged: PropTypes.func.isRequired+ };++ constructor(props) {super(props);this.state = {filters: {}- };+ };}- onClick = (attribute, value, event) => {- const attrValue = `${attribute}:${value}`;- let url = '';- const element = event.target;-- this.setState({- filters: Object.assign(- this.state.filters,- {[attrValue]: !this.state.filters[attrValue]})- });- const enabled = Object.keys(this.state.filters).filter(key => this.state.filters[key] === true);- this.props.onFilterChanged(enabled);-- enabled.map((param, index) => {- param = param.replace(':', '=');- if (index == 0) {- url += '?' + param;- } else {- url += '&' + param;- }- });-- if (enabled.length == 0) {- url = location.href.split('?')[0];- }-- history.pushState({}, null , url);-- if (element.classList.contains('active')) {- element.classList.remove('active');- } else {- element.classList.add('active');- }- }-- componentDidMount() {- let url_params = queryString.parse(location.search);- Object.keys(url_params).map((params) => {- let attrValue = '';- if (Array.isArray(url_params[params])) {- url_params[params].map((param) => {- attrValue = `${params}:${param}`;- this.setState({- filters: Object.assign(- this.state.filters,- {[attrValue]: true})- });- const elementID = 'attr'+params+param;- document.getElementById(elementID).classList.add('active');- })- } else {- attrValue = `${params}:${url_params[params]}`;- this.setState({- filters: Object.assign(- this.state.filters,- {[attrValue]: true})- });- const elementID = 'attr'+params+url_params[params];- document.getElementById(elementID).classList.add('active');- }- })-- const enabled = Object.keys(this.state.filters).filter(key => this.state.filters[key] === true);- this.props.onFilterChanged(enabled);- }-- onPriceFilterChanged = (minPrice, maxPrice) => {- this.props.onPriceFilterChanged(minPrice, maxPrice)- }-- render() {- const categoryName = this.props.categories.name;- const subCategories = this.props.categories.children.edges;- const { attributes } = this.props;-- return (- <div className="product-filters">- <h2>Filters:</h2>- <ul className="categories list-group">- <li className="list-group-item active">{categoryName}</li>- {subCategories && (subCategories.map((item) => {- const category = item.node;- return (- <li key={category.id} className="list-group-item"><a href={category.url}>{category.name}</a></li>- );- })- )}- </ul>- {attributes && (attributes.map((attribute) => {- return (- <div key={attribute.id} className="attribute">- <ul className={attribute.name}>- <h3>{attribute.display}</h3>- {attribute.values.map((value) => {- const colorStyle = {- backgroundColor: value.color- }- return (- <button+ onClick = (attribute, value, event) => {+ const attrValue = `${attribute}:${value}`;+ let url = '';+ const element = event.target;++ this.setState({+ filters: Object.assign(+ this.state.filters,+ {[attrValue]: !this.state.filters[attrValue]})+ });+ const enabled = Object.keys(this.state.filters).filter(key => this.state.filters[key] === true);+ this.props.onFilterChanged(enabled);++ enabled.map((param, index) => {+ param = param.replace(':', '=');+ if (index == 0) {+ url += '?' + param;+ } else {+ url += '&' + param;+ }+ });++ if (enabled.length == 0) {+ url = location.href.split('?')[0];+ }++ history.pushState({}, null , url);++ if (element.classList.contains('active')) {+ element.classList.remove('active');+ } else {+ element.classList.add('active');+ }+ }++ componentDidMount() {+ let url_params = queryString.parse(location.search);+ Object.keys(url_params).map((params) => {+ let attrValue = '';+ if (Array.isArray(url_params[params])) {+ url_params[params].map((param) => {+ attrValue = `${params}:${param}`;+ this.setState({+ filters: Object.assign(+ this.state.filters,+ {[attrValue]: true})+ });+ const elementID = 'attr'+params+param;+ document.getElementById(elementID).classList.add('active');+ })+ } else {+ attrValue = `${params}:${url_params[params]}`;+ this.setState({+ filters: Object.assign(+ this.state.filters,+ {[attrValue]: true})+ });+ const elementID = 'attr'+params+url_params[params];+ document.getElementById(elementID).classList.add('active');+ }+ })++ const enabled = Object.keys(this.state.filters).filter(key => this.state.filters[key] === true);+ this.props.onFilterChanged(enabled);+ }++ onPriceFilterChanged = (minPrice, maxPrice) => {+ this.props.onPriceFilterChanged(minPrice, maxPrice)+ }++ render() {+ const categoryName = this.props.categories.name;+ const subCategories = this.props.categories.children.edges;+ const { attributes } = this.props;++ return (+ <div className="product-filters">+ <h2>Filters:</h2>+ <ul className="categories list-group">+ <li className="list-group-item active">{categoryName}</li>+ {subCategories && (subCategories.map((item) => {+ const category = item.node;+ return (+ <li key={category.id} className="list-group-item"><a href={category.url}>{category.name}</a></li>+ );+ })+ )}+ </ul>+ {attributes && (attributes.map((attribute) => {+ return (+ <div key={attribute.id} className="attribute">+ <ul className={attribute.name}>+ <h3>{attribute.display}</h3>+ {attribute.values.map((value) => {+ const colorStyle = {+ backgroundColor: value.color+ }+ return (+ <buttonid={'attr' + attribute.pk+value.pk}key={value.id}className="item"style={colorStyle}onClick={(event) => this.onClick(attribute.pk, value.pk, event)}>- {value.display}- </button>- )- })}- </ul>- </div>- )- }))}- <h3>Price range</h3>- <PriceFilter onFilterChanged={this.onPriceFilterChanged} />- </div>- )- }+ {value.display}+ </button>+ )+ })}+ </ul>+ </div>+ )+ }))}+ <h3>Price range</h3>+ <PriceFilter onFilterChanged={this.onPriceFilterChanged} />+ </div>+ )+ }}export default Relay.createContainer(ProductFilters, {fragments: {attributes: () => Relay.QL`fragment on ProductAttributeType @relay(plural: true) {- id- pk- name- display- values {- id- pk- display- color- }+ id+ pk+ name+ display+ values {+ id+ pk+ display+ color+ }}`,},diff --git a/saleor/static/js/components/ProductList.js b/saleor/static/js/components/ProductList.jsindex dc46ed0387..44b2504a19 100644--- a/saleor/static/js/components/ProductList.js+++ b/saleor/static/js/components/ProductList.js@@ -6,44 +6,44 @@ import ProductItem from './ProductItem';class ProductList extends Component {- static propTypes = {- onLoadMore: PropTypes.func.isRequired,- products: PropTypes.object- };+ static propTypes = {+ onLoadMore: PropTypes.func.isRequired,+ products: PropTypes.object+ };- onLoadMore = () => this.props.onLoadMore();+ onLoadMore = () => this.props.onLoadMore();- render() {- const { edges, pageInfo: { hasNextPage } } = this.props.products;- return (- <div>- <div>- {edges && (edges.map((edge, i) => (- <ProductItem key={i} product={edge.node} />- )))}- </div>- <div>- {hasNextPage && (- <button onClick={this.onLoadMore}>Load more</button>- )}- </div>- </div>- )- }+ render() {+ const { edges, pageInfo: { hasNextPage } } = this.props.products;+ return (+ <div>+ <div>+ {edges && (edges.map((edge, i) => (+ <ProductItem key={i} product={edge.node} />+ )))}+ </div>+ <div>+ {hasNextPage && (+ <button onClick={this.onLoadMore}>Load more</button>+ )}+ </div>+ </div>+ )+ }}export default Relay.createContainer(ProductList, {fragments: {products: () => Relay.QL`fragment on ProductTypeConnection {- edges {- node {- ${ProductItem.getFragment('product')}- }- }- pageInfo {- hasNextPage- }+ edges {+ node {+ ${ProductItem.getFragment('product')}+ }+ }+ pageInfo {+ hasNextPage+ }}`,},