examples enhance

* utils for products generator

* load test for each *.test.js file in packages folder

* [test] unit test for utils/common

* refactor all products with productGenerator for all examples

* refactor folder structure

* move component <Code /> to src/components/common
* rename component file name
This commit is contained in:
ChunMing, Chen
2017-09-04 08:46:01 -05:00
committed by Allen
parent ae5c677854
commit f9ccbd0717
24 changed files with 128 additions and 296 deletions
@@ -1,23 +1,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const products = productsGenerator();
const columns = [{
dataField: 'id',
@@ -1,23 +1,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const products = productsGenerator();
const columns = [{
dataField: 'id',
@@ -1,7 +1,7 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
const columns = [{
dataField: 'id',
@@ -1,23 +1,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const products = productsGenerator();
const columns = [{
dataField: 'id',
@@ -2,23 +2,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const products = productsGenerator();
const columns = [{
dataField: 'id',
@@ -2,23 +2,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const products = productsGenerator();
const columns = [{
dataField: 'id',
@@ -3,23 +3,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const products = productsGenerator();
const columns = [{
dataField: 'id',
@@ -1,24 +1,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i,
onSale: Math.random() >= 0.5
});
}
}
addProducts(5);
const products = productsGenerator();
function priceFormatter(cell, row) {
if (row.onSale) {
@@ -2,23 +2,14 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
rank: Math.random() < 0.5 ? 'down' : 'up'
});
}
}
addProducts(5);
const products = productsGenerator(5, (value, index) => ({
id: index,
name: `User Name ${index}`,
rank: Math.random() < 0.5 ? 'down' : 'up'
}));
function rankFormatter(cell, row, rowIndex, formatExtraData) {
return (
@@ -2,23 +2,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const products = productsGenerator();
const columns = [{
dataField: 'id',
@@ -2,23 +2,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const products = productsGenerator();
const columns = [{
dataField: 'id',
@@ -2,23 +2,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const products = productsGenerator();
const columns = [{
dataField: 'id',
@@ -1,27 +1,18 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `User Name ${id}`,
phone: 21009831 + i,
address: {
city: 'New York',
postCode: '1111-4512'
}
});
const products = productsGenerator(5, (value, index) => ({
id: index,
name: `User Name ${index}`,
phone: 21009831 + index,
address: {
city: 'New York',
postCode: '1111-4512'
}
}
addProducts(5);
}));
const columns = [{
dataField: 'id',
@@ -1,26 +0,0 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
export default class extends Component {
static propTypes = {
children: PropTypes.string
}
static defaultProps = {
children: ''
}
componentDidMount() {
// code-prettify
// run the PR.prettyPrint() function once your page has finished loading
if (typeof (PR) !== 'undefined') PR.prettyPrint(); // eslint-disable-line no-undef
}
render() {
return (
<div className="highlight-text-html-basic">
<pre className="prettyprint lang-js">
{ this.props.children }
</pre>
</div>
);
}
}
@@ -2,23 +2,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const products = productsGenerator();
const columns = [{
dataField: 'id',
@@ -2,23 +2,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const products = productsGenerator();
const columns = [{
dataField: 'id',
@@ -3,23 +3,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const products = productsGenerator();
const columns = [{
dataField: 'id',
@@ -2,24 +2,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i,
onSale: Math.random() >= 0.5
});
}
}
addProducts(5);
const products = productsGenerator();
function priceFormatter(column, colIndex) {
return (
@@ -2,23 +2,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const products = productsGenerator();
const columns = [{
dataField: 'id',
@@ -2,23 +2,10 @@
import React from 'react';
import { BootstrapTableful } from 'react-bootstrap-table2';
import Code from 'common/codeBlock';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i += 1) {
const id = startId + i;
products.push({
id,
name: `Item name ${id}`,
price: 2100 + i
});
}
}
addProducts(5);
const products = productsGenerator();
const columns = [{
dataField: 'id',