Skip to content
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

Merged
merged 8 commits into from
Jun 8, 2020

Conversation

sanjithkumar017
Copy link
Contributor

No description provided.


this.state = {
unbxdCore:
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is dynamic.

variantMap,
unbxdProductCardClickHandler } = props;

return (<div className={`Unbx-product-container Unbx-grid-view grid grid-cols-${per_row} gap-4 p-4`}>{
Copy link
Contributor

@Anupama-Unbxd Anupama-Unbxd May 29, 2020

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

variantMap={variantMap}
per_row={per_row}
key={product.uniqueId}
unbxdProductCardClickHandler={unbxdProductCardClickHandler} />)
Copy link
Contributor

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)


GridView.propTypes = {
products: PropTypes.arrayOf(PropTypes.object).isRequired,
per_row: PropTypes.number.isRequired,
Copy link
Contributor

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

per_row: PropTypes.number.isRequired,
fieldMap: PropTypes.object.isRequired,
variantMap: PropTypes.object.isRequired,
unbxdProductCardClickHandler: PropTypes.func.isRequired
Copy link
Contributor

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.


const ListView = ({ products = [], fieldMap, isVariant, variantMap, unbxdProductCardClickHandler }) => {

return (<div className={`Unbx-product-container Unbx-grid-view grid grid-cols-1 gap-4 p-4`}>{
Copy link
Contributor

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

fieldMap: PropTypes.object.isRequired,
isVariant: PropTypes.bool.isRequired,
variantMap: PropTypes.object.isRequired,
unbxdProductCardClickHandler: PropTypes.func.isRequired
Copy link
Contributor

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

import React from 'react';

const NoProducts = () => {
return (<div className='Unbx-no-products-container'>Sorry! No products found!</div>)
Copy link
Contributor

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);
Copy link
Contributor

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>
Copy link
Contributor

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>
Copy link
Contributor

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}>
Copy link
Contributor

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 ?

@@ -0,0 +1,143 @@
import React from 'react';
Copy link
Contributor

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;
Copy link
Contributor

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

@@ -0,0 +1,143 @@
import React from 'react';
import AppContext, { AppContextConsumer } from '../../common/context'
import { ProductContextProvider } from './Context'
Copy link
Contributor

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"


Products.propTypes = {
per_row: PropTypes.number,
per_page: PropTypes.number,
Copy link
Contributor

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

per_row: PropTypes.number,
per_page: PropTypes.number,
fieldMap: PropTypes.object.isRequired,
ZeroResultsTemplate: PropTypes.oneOfType([PropTypes.element, PropTypes.bool, PropTypes.func]),
Copy link
Contributor

@Anupama-Unbxd Anupama-Unbxd May 29, 2020

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?

fieldMap: PropTypes.object.isRequired,
ZeroResultsTemplate: PropTypes.oneOfType([PropTypes.element, PropTypes.bool, PropTypes.func]),
infiniteScroll: PropTypes.bool,
loadOnClick: PropTypes.bool,
Copy link
Contributor

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

ZeroResultsTemplate: PropTypes.oneOfType([PropTypes.element, PropTypes.bool, PropTypes.func]),
infiniteScroll: PropTypes.bool,
loadOnClick: PropTypes.bool,
variants: PropTypes.bool,
Copy link
Contributor

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

@@ -0,0 +1,24 @@
const productFieldsMapper = (product, fieldMap, variantMap) => {
Copy link
Contributor

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';
Copy link
Contributor

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.

static contextType = AppContext;

static ViewTypes = ViewTypes;
static ProductsView = ProductsView;
Copy link
Contributor

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?

Copy link
Contributor Author

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:

infiniteScroll, loadOnClick, fieldMap, variantMap } = this.props

this.state = {
isGrid: true,
Copy link
Contributor

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

per_row,
per_page,
infiniteScroll,
loadOnClick,
Copy link
Contributor

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


this.state = {
isGrid: true,
onViewToggle: this.onViewToggle,
Copy link
Contributor

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?

@Anupama-Unbxd Anupama-Unbxd merged commit 593356d into unbxd:master Jun 8, 2020
@sanjithkumar017 sanjithkumar017 changed the title create products layout. swatches is pending. create products layout. Jun 19, 2020
@sanjithkumar017 sanjithkumar017 deleted the products_layout branch July 3, 2020 07:25
Anupama-Unbxd pushed a commit that referenced this pull request Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants