-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create products layout. #3
Conversation
|
||
this.state = { | ||
unbxdCore: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this object required to be on state? Can we keep it as an instance variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that the changes are passed on to children.
src/App.js
Outdated
this.state = { | ||
unbxdCore: | ||
new UnbxdSearch({ ...searchConfigurations, siteName, siteKey, callBackFn: this.unbxdCallBack }), | ||
helpers: this.helpers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, is this a dynamically changing value to be kept on state? can we just use instance variable instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is dynamic.
src/modules/Products/GridView.js
Outdated
variantMap, | ||
unbxdProductCardClickHandler } = props; | ||
|
||
return (<div className={`Unbx-product-container Unbx-grid-view grid grid-cols-${per_row} gap-4 p-4`}>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets keep the prefix as UNX-
. Will these other classes end up in the final rendered HTML?
These classnames look very generic & hence might clash with the CSS rules already defined by the customer
src/modules/Products/GridView.js
Outdated
variantMap={variantMap} | ||
per_row={per_row} | ||
key={product.uniqueId} | ||
unbxdProductCardClickHandler={unbxdProductCardClickHandler} />) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move the click to the parent so that we have only 1 click handler instead of one per product (if we show 100 products on page, we will have 100 click handlers)
src/modules/Products/GridView.js
Outdated
|
||
GridView.propTypes = { | ||
products: PropTypes.arrayOf(PropTypes.object).isRequired, | ||
per_row: PropTypes.number.isRequired, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets have a standard of camelCase props everywhere
src/modules/Products/GridView.js
Outdated
per_row: PropTypes.number.isRequired, | ||
fieldMap: PropTypes.object.isRequired, | ||
variantMap: PropTypes.object.isRequired, | ||
unbxdProductCardClickHandler: PropTypes.func.isRequired |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets keep naming standard for click handlers as per the React standards in the format on<Event>
.
For example in this case, it would be onProductClick
.
src/modules/Products/ListView.js
Outdated
|
||
const ListView = ({ products = [], fieldMap, isVariant, variantMap, unbxdProductCardClickHandler }) => { | ||
|
||
return (<div className={`Unbx-product-container Unbx-grid-view grid grid-cols-1 gap-4 p-4`}>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above, lets add prefix as UNX-
and try to remove the non-prefixed class names
src/modules/Products/ListView.js
Outdated
fieldMap: PropTypes.object.isRequired, | ||
isVariant: PropTypes.bool.isRequired, | ||
variantMap: PropTypes.object.isRequired, | ||
unbxdProductCardClickHandler: PropTypes.func.isRequired |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as the GridView props comments above
src/modules/Products/NoProducts.js
Outdated
import React from 'react'; | ||
|
||
const NoProducts = () => { | ||
return (<div className='Unbx-no-products-container'>Sorry! No products found!</div>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefix as UNX-
const GridProductCard = ({ product, fieldMap, variantMap, unbxdProductCardClickHandler }) => { | ||
|
||
//Get the datas from the product bases on fieldMap and create the card | ||
const productValues = productFieldsMapper(product, fieldMap, variantMap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name the functions with the "action" type present in the name, like mapProductFields
or getProductFields
or setProductFields
. In general, names would mostly be of the form <action><entity>
, where action
could be get
, set
, process
, map
etc.
<img className='Unbx-product-card Unbx-image' src={imageUrl[0]} /> | ||
<p className='Unbx-product-card Unbx-product-name'>{productName}</p> | ||
<p className='Unbx-product-card Unbx-price'>{price}</p> | ||
<p className='Unbx-product-card Unbx-selling-price'>{sellingPrice}</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as the parent has the -product-card
class already, do we need this in all the children elements?
<img className='Unbx-product-card Unbx-image' src={imageUrl[0]} /> | ||
<p className='Unbx-product-card Unbx-product-name'>{productName}</p> | ||
<p className='Unbx-product-card Unbx-price'>{price}</p> | ||
<p className='Unbx-product-card Unbx-selling-price'>{sellingPrice}</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as the parent has the -product-card
class already, do we need this in all the children elements?
|
||
//Add support for router as a config | ||
return (<div className='Unbx-product-card-container'> | ||
<a href={product.productUrl} className={`Unbx-product-card Unbx-grid-card`} onClick={unbxdProductCardClickHandler}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be list-card
here right instead of grid-card
?
src/modules/Products/index.js
Outdated
@@ -0,0 +1,143 @@ | |||
import React from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets use index.js
files to export all files of a folder. Rename this file as Products.js
const ProductContextConsumer = ProductContext.Consumer; | ||
|
||
export { ProductContextProvider, ProductContextConsumer } | ||
export default ProductContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets use index.js files to export all files of a folder. Rename this file as ProductContext.js
src/modules/Products/index.js
Outdated
@@ -0,0 +1,143 @@ | |||
import React from 'react'; | |||
import AppContext, { AppContextConsumer } from '../../common/context' | |||
import { ProductContextProvider } from './Context' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be ./context
with smallcase "c"
src/modules/Products/index.js
Outdated
|
||
Products.propTypes = { | ||
per_row: PropTypes.number, | ||
per_page: PropTypes.number, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use camelCase standard for prop names
src/modules/Products/index.js
Outdated
per_row: PropTypes.number, | ||
per_page: PropTypes.number, | ||
fieldMap: PropTypes.object.isRequired, | ||
ZeroResultsTemplate: PropTypes.oneOfType([PropTypes.element, PropTypes.bool, PropTypes.func]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is a React component & not a template name it as, "ZeroResultsComponent".
Also, how would bool be one of the accepted types?
src/modules/Products/index.js
Outdated
fieldMap: PropTypes.object.isRequired, | ||
ZeroResultsTemplate: PropTypes.oneOfType([PropTypes.element, PropTypes.bool, PropTypes.func]), | ||
infiniteScroll: PropTypes.bool, | ||
loadOnClick: PropTypes.bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refer to the configs sheet. Lets accept both these settings as paginationType
src/modules/Products/index.js
Outdated
ZeroResultsTemplate: PropTypes.oneOfType([PropTypes.element, PropTypes.bool, PropTypes.func]), | ||
infiniteScroll: PropTypes.bool, | ||
loadOnClick: PropTypes.bool, | ||
variants: PropTypes.bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets rename it to "showVariants" as mentioned in the configs sheet
src/modules/Products/utils/index.js
Outdated
@@ -0,0 +1,24 @@ | |||
const productFieldsMapper = (product, fieldMap, variantMap) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this file to utils.js
. The other possible files under this folder could be Constants.js
for enums/constants etc. Then we can use index.js
to export both utils.js & Constants.js exports
@@ -0,0 +1,37 @@ | |||
import React from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets keep small case beginning names for folder names. Here it would be src/modules/products/productCards/GridProductCard.js
Only component class file names should begin with a capital letter.
src/modules/Products/index.js
Outdated
static contextType = AppContext; | ||
|
||
static ViewTypes = ViewTypes; | ||
static ProductsView = ProductsView; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think any of these are required right? because they are all imported directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is was done with the intention of providing flexibility to the end user. This component can be used in following way:
src/modules/Products/index.js
Outdated
infiniteScroll, loadOnClick, fieldMap, variantMap } = this.props | ||
|
||
this.state = { | ||
isGrid: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name this variable as "viewType" instead with enum values like GRID
, LIST
etc, this will give us flexibility to add more view types in future if needed
src/modules/Products/index.js
Outdated
per_row, | ||
per_page, | ||
infiniteScroll, | ||
loadOnClick, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge both these configs in paginationType
with enum values INFINITE_SCROLL
, CLICK_N_SCROLL
or FIXED_PAGINATION
src/modules/Products/index.js
Outdated
|
||
this.state = { | ||
isGrid: true, | ||
onViewToggle: this.onViewToggle, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this required to be on the state?
2dc1a77
to
40711c1
Compare
970970d
to
080ea29
Compare
080ea29
to
f38af4f
Compare
f03d6a1
to
32c0ec0
Compare
No description provided.