mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
2018/04/01 release
2018/04/01 release
This commit is contained in:
commit
1d7df6819e
@ -11,6 +11,8 @@ branches:
|
|||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
- develop
|
- develop
|
||||||
|
except:
|
||||||
|
- gh-pages-src
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- curl -o- -L https://yarnpkg.com/install.sh | bash -s
|
- curl -o- -L https://yarnpkg.com/install.sh | bash -s
|
||||||
|
|||||||
@ -158,12 +158,12 @@ const selectRow = {
|
|||||||
|
|
||||||
### <a name='onSelect'>selectRow.onSelect - [Function]</a>
|
### <a name='onSelect'>selectRow.onSelect - [Function]</a>
|
||||||
This callback function will be called when a row is select/unselect and pass following three arguments:
|
This callback function will be called when a row is select/unselect and pass following three arguments:
|
||||||
`row`, `isSelect` and `rowIndex`.
|
`row`, `isSelect`, `rowIndex` and `e`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const selectRow = {
|
const selectRow = {
|
||||||
mode: 'checkbox',
|
mode: 'checkbox',
|
||||||
onSelect: (row, isSelect, rowIndex) => {
|
onSelect: (row, isSelect, rowIndex, e) => {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -175,7 +175,7 @@ This callback function will be called when select/unselect all and it only work
|
|||||||
```js
|
```js
|
||||||
const selectRow = {
|
const selectRow = {
|
||||||
mode: 'checkbox',
|
mode: 'checkbox',
|
||||||
onSelectAll: (isSelect, results) => {
|
onSelectAll: (isSelect, results, e) => {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -72,9 +72,15 @@ function styles() {
|
|||||||
.pipe(gulp.dest(PKG_PATH));
|
.pipe(gulp.dest(PKG_PATH));
|
||||||
}
|
}
|
||||||
|
|
||||||
function umd() {
|
function umd(done) {
|
||||||
return gulp.src('./webpack.prod.config.babel.js')
|
gulp.parallel(
|
||||||
.pipe(shell(['webpack --config <%= file.path %>']));
|
() => gulp.src('./webpack/next.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>'])),
|
||||||
|
() => gulp.src('./webpack/editor.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>'])),
|
||||||
|
() => gulp.src('./webpack/filter.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>'])),
|
||||||
|
() => gulp.src('./webpack/overlay.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>'])),
|
||||||
|
() => gulp.src('./webpack/paginator.umd.babel.js').pipe(shell(['webpack --config <%= file.path %>']))
|
||||||
|
)();
|
||||||
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildJS = gulp.parallel(umd, scripts);
|
const buildJS = gulp.parallel(umd, scripts);
|
||||||
|
|||||||
85
packages/react-bootstrap-table2-example/examples/column-filter/programmatically-number-filter.js
vendored
Normal file
85
packages/react-bootstrap-table2-example/examples/column-filter/programmatically-number-filter.js
vendored
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import filterFactory, { numberFilter, Comparator } from 'react-bootstrap-table2-filter';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator(8);
|
||||||
|
|
||||||
|
let priceFilter;
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
filter: numberFilter({
|
||||||
|
getFilter: (filter) => {
|
||||||
|
// pricerFilter was assigned once the component has been mounted.
|
||||||
|
priceFilter = filter;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}];
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
priceFilter({
|
||||||
|
number: 2103,
|
||||||
|
comparator: Comparator.GT
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import filterFactory, { numberFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
|
||||||
|
let priceFilter;
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
filter: numberFilter({
|
||||||
|
getFilter: (filter) => {
|
||||||
|
// pricerFilter was assigned once the component has been mounted.
|
||||||
|
priceFilter = filter;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}];
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
priceFilter({
|
||||||
|
number: 2103,
|
||||||
|
comparator: Comparator.GT
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-lg btn-primary" onClick={ handleClick }> filter all columns which is greater than 2103 </button>
|
||||||
|
|
||||||
|
<BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-lg btn-primary" onClick={ handleClick }> filter all columns which is greater than 2103 </button>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
96
packages/react-bootstrap-table2-example/examples/column-filter/programmatically-select-filter.js
vendored
Normal file
96
packages/react-bootstrap-table2-example/examples/column-filter/programmatically-select-filter.js
vendored
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import filterFactory, { selectFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsQualityGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsQualityGenerator(6);
|
||||||
|
|
||||||
|
let qualityFilter;
|
||||||
|
|
||||||
|
const selectOptions = {
|
||||||
|
0: 'good',
|
||||||
|
1: 'Bad',
|
||||||
|
2: 'unknown'
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'quality',
|
||||||
|
text: 'Product Quality',
|
||||||
|
formatter: cell => selectOptions[cell],
|
||||||
|
filter: selectFilter({
|
||||||
|
options: selectOptions,
|
||||||
|
getFilter: (filter) => {
|
||||||
|
// qualityFilter was assigned once the component has been mounted.
|
||||||
|
qualityFilter = filter;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}];
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
qualityFilter(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import filterFactory, { selectFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
|
||||||
|
let qualityFilter;
|
||||||
|
|
||||||
|
const selectOptions = {
|
||||||
|
0: 'good',
|
||||||
|
1: 'Bad',
|
||||||
|
2: 'unknown'
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'quality',
|
||||||
|
text: 'Product Quality',
|
||||||
|
formatter: cell => selectOptions[cell],
|
||||||
|
filter: selectFilter({
|
||||||
|
options: selectOptions,
|
||||||
|
getFilter: (filter) => {
|
||||||
|
// qualityFilter was assigned once the component has been mounted.
|
||||||
|
qualityFilter = filter;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}];
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
qualityFilter(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-lg btn-primary" onClick={ handleClick }>{' filter columns by option "good" '}</button>
|
||||||
|
|
||||||
|
<BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-lg btn-primary" onClick={ handleClick }>{' filter columns by option "good" '}</button>
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
81
packages/react-bootstrap-table2-example/examples/column-filter/programmatically-text-filter.js
vendored
Normal file
81
packages/react-bootstrap-table2-example/examples/column-filter/programmatically-text-filter.js
vendored
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator(8);
|
||||||
|
|
||||||
|
let nameFilter;
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
filter: textFilter({
|
||||||
|
getFilter: (filter) => {
|
||||||
|
// nameFilter was assigned once the component has been mounted.
|
||||||
|
nameFilter = filter;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
filter: textFilter()
|
||||||
|
}];
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
nameFilter(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
|
||||||
|
let nameFilter;
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
filter: textFilter({
|
||||||
|
getFilter: (filter) => {
|
||||||
|
// nameFilter was assigned once the component has been mounted.
|
||||||
|
nameFilter = filter;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
filter: textFilter()
|
||||||
|
}];
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
nameFilter(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-lg btn-primary" onClick={ handleClick }> filter columns by 0 </button>
|
||||||
|
|
||||||
|
<BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-lg btn-primary" onClick={ handleClick }> filter columns by 0 </button>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
@ -22,14 +22,16 @@ const columns = [{
|
|||||||
const selectRow = {
|
const selectRow = {
|
||||||
mode: 'checkbox',
|
mode: 'checkbox',
|
||||||
clickToSelect: true,
|
clickToSelect: true,
|
||||||
onSelect: (row, isSelect, rowIndex) => {
|
onSelect: (row, isSelect, rowIndex, e) => {
|
||||||
console.log(row.id);
|
console.log(row.id);
|
||||||
console.log(isSelect);
|
console.log(isSelect);
|
||||||
console.log(rowIndex);
|
console.log(rowIndex);
|
||||||
|
console.log(e);
|
||||||
},
|
},
|
||||||
onSelectAll: (isSelect, rows) => {
|
onSelectAll: (isSelect, rows, e) => {
|
||||||
console.log(isSelect);
|
console.log(isSelect);
|
||||||
console.log(rows);
|
console.log(rows);
|
||||||
|
console.log(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -49,7 +51,18 @@ const columns = [{
|
|||||||
|
|
||||||
const selectRow = {
|
const selectRow = {
|
||||||
mode: 'checkbox',
|
mode: 'checkbox',
|
||||||
clickToSelect: true
|
clickToSelect: true,
|
||||||
|
onSelect: (row, isSelect, rowIndex, e) => {
|
||||||
|
console.log(row.id);
|
||||||
|
console.log(isSelect);
|
||||||
|
console.log(rowIndex);
|
||||||
|
console.log(e);
|
||||||
|
},
|
||||||
|
onSelectAll: (isSelect, rows, e) => {
|
||||||
|
console.log(isSelect);
|
||||||
|
console.log(rows);
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
|
|||||||
@ -48,6 +48,9 @@ import CustomSelectFilter from 'examples/column-filter/custom-select-filter';
|
|||||||
import NumberFilter from 'examples/column-filter/number-filter';
|
import NumberFilter from 'examples/column-filter/number-filter';
|
||||||
import NumberFilterWithDefaultValue from 'examples/column-filter/number-filter-default-value';
|
import NumberFilterWithDefaultValue from 'examples/column-filter/number-filter-default-value';
|
||||||
import CustomNumberFilter from 'examples/column-filter/custom-number-filter';
|
import CustomNumberFilter from 'examples/column-filter/custom-number-filter';
|
||||||
|
import ProgrammaticallyTextFilter from 'examples/column-filter/programmatically-text-filter';
|
||||||
|
import ProgrammaticallySelectFilter from 'examples/column-filter/programmatically-select-filter';
|
||||||
|
import ProgrammaticallyNumberFilter from 'examples/column-filter/programmatically-number-filter';
|
||||||
|
|
||||||
// work on rows
|
// work on rows
|
||||||
import RowStyleTable from 'examples/rows/row-style';
|
import RowStyleTable from 'examples/rows/row-style';
|
||||||
@ -166,7 +169,10 @@ storiesOf('Column Filter', module)
|
|||||||
.add('Custom Text Filter', () => <CustomTextFilter />)
|
.add('Custom Text Filter', () => <CustomTextFilter />)
|
||||||
.add('Custom Select Filter', () => <CustomSelectFilter />)
|
.add('Custom Select Filter', () => <CustomSelectFilter />)
|
||||||
.add('Custom Number Filter', () => <CustomNumberFilter />)
|
.add('Custom Number Filter', () => <CustomNumberFilter />)
|
||||||
.add('Custom Filter Value', () => <CustomFilterValue />);
|
.add('Custom Filter Value', () => <CustomFilterValue />)
|
||||||
|
.add('Programmatically Text Filter ', () => <ProgrammaticallyTextFilter />)
|
||||||
|
.add('Programmatically Select Filter ', () => <ProgrammaticallySelectFilter />)
|
||||||
|
.add('Programmatically Number Filter ', () => <ProgrammaticallyNumberFilter />);
|
||||||
|
|
||||||
storiesOf('Work on Rows', module)
|
storiesOf('Work on Rows', module)
|
||||||
.add('Customize Row Style', () => <RowStyleTable />)
|
.add('Customize Row Style', () => <RowStyleTable />)
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint react/require-default-props: 0 */
|
||||||
/* eslint no-return-assign: 0 */
|
/* eslint no-return-assign: 0 */
|
||||||
|
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
@ -30,11 +31,25 @@ class NumberFilter extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { column, onFilter } = this.props;
|
const { column, onFilter, getFilter } = this.props;
|
||||||
const comparator = this.numberFilterComparator.value;
|
const comparator = this.numberFilterComparator.value;
|
||||||
const number = this.numberFilter.value;
|
const number = this.numberFilter.value;
|
||||||
if (comparator && number) {
|
if (comparator && number) {
|
||||||
onFilter(column, { number, comparator }, FILTER_TYPE.NUMBER);
|
onFilter(column, FILTER_TYPE.NUMBER)({ number, comparator });
|
||||||
|
}
|
||||||
|
|
||||||
|
// export onFilter function to allow users to access
|
||||||
|
if (getFilter) {
|
||||||
|
getFilter((filterVal) => {
|
||||||
|
this.setState(() => ({ isSelected: (filterVal !== '') }));
|
||||||
|
this.numberFilterComparator.value = filterVal.comparator;
|
||||||
|
this.numberFilter.value = filterVal.number;
|
||||||
|
|
||||||
|
onFilter(column, FILTER_TYPE.NUMBER)({
|
||||||
|
number: filterVal.number,
|
||||||
|
comparator: filterVal.comparator
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +68,7 @@ class NumberFilter extends Component {
|
|||||||
}
|
}
|
||||||
const filterValue = e.target.value;
|
const filterValue = e.target.value;
|
||||||
this.timeout = setTimeout(() => {
|
this.timeout = setTimeout(() => {
|
||||||
onFilter(column, { number: filterValue, comparator }, FILTER_TYPE.NUMBER);
|
onFilter(column, FILTER_TYPE.NUMBER)({ number: filterValue, comparator });
|
||||||
}, delay);
|
}, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +80,7 @@ class NumberFilter extends Component {
|
|||||||
// if (comparator === '') {
|
// if (comparator === '') {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
onFilter(column, { number: value, comparator }, FILTER_TYPE.NUMBER);
|
onFilter(column, FILTER_TYPE.NUMBER)({ number: value, comparator });
|
||||||
}
|
}
|
||||||
|
|
||||||
onChangeComparator(e) {
|
onChangeComparator(e) {
|
||||||
@ -75,7 +90,7 @@ class NumberFilter extends Component {
|
|||||||
// if (value === '') {
|
// if (value === '') {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
onFilter(column, { number: value, comparator }, FILTER_TYPE.NUMBER);
|
onFilter(column, FILTER_TYPE.NUMBER)({ number: value, comparator });
|
||||||
}
|
}
|
||||||
|
|
||||||
getComparatorOptions() {
|
getComparatorOptions() {
|
||||||
@ -116,7 +131,7 @@ class NumberFilter extends Component {
|
|||||||
this.setState(() => ({ isSelected: (number !== '') }));
|
this.setState(() => ({ isSelected: (number !== '') }));
|
||||||
this.numberFilterComparator.value = comparator;
|
this.numberFilterComparator.value = comparator;
|
||||||
this.numberFilter.value = number;
|
this.numberFilter.value = number;
|
||||||
onFilter(column, { number, comparator }, FILTER_TYPE.NUMBER);
|
onFilter(column, FILTER_TYPE.NUMBER)({ number, comparator });
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanFiltered() {
|
cleanFiltered() {
|
||||||
@ -126,7 +141,7 @@ class NumberFilter extends Component {
|
|||||||
this.setState(() => ({ isSelected: (value !== '') }));
|
this.setState(() => ({ isSelected: (value !== '') }));
|
||||||
this.numberFilterComparator.value = comparator;
|
this.numberFilterComparator.value = comparator;
|
||||||
this.numberFilter.value = value;
|
this.numberFilter.value = value;
|
||||||
onFilter(column, { number: value, comparator }, FILTER_TYPE.NUMBER);
|
onFilter(column, FILTER_TYPE.NUMBER)({ number: value, comparator });
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -224,7 +239,8 @@ NumberFilter.propTypes = {
|
|||||||
comparatorStyle: PropTypes.object,
|
comparatorStyle: PropTypes.object,
|
||||||
comparatorClassName: PropTypes.string,
|
comparatorClassName: PropTypes.string,
|
||||||
numberStyle: PropTypes.object,
|
numberStyle: PropTypes.object,
|
||||||
numberClassName: PropTypes.string
|
numberClassName: PropTypes.string,
|
||||||
|
getFilter: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
NumberFilter.defaultProps = {
|
NumberFilter.defaultProps = {
|
||||||
|
|||||||
@ -25,9 +25,21 @@ class SelectFilter extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
const { column, onFilter, getFilter } = this.props;
|
||||||
|
|
||||||
const value = this.selectInput.value;
|
const value = this.selectInput.value;
|
||||||
if (value && value !== '') {
|
if (value && value !== '') {
|
||||||
this.props.onFilter(this.props.column, value, FILTER_TYPE.SELECT);
|
onFilter(column, FILTER_TYPE.SELECT)(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// export onFilter function to allow users to access
|
||||||
|
if (getFilter) {
|
||||||
|
getFilter((filterVal) => {
|
||||||
|
this.setState(() => ({ isSelected: filterVal !== '' }));
|
||||||
|
this.selectInput.value = filterVal;
|
||||||
|
|
||||||
|
onFilter(column, FILTER_TYPE.SELECT)(filterVal);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +53,7 @@ class SelectFilter extends Component {
|
|||||||
if (needFilter) {
|
if (needFilter) {
|
||||||
const value = this.selectInput.value;
|
const value = this.selectInput.value;
|
||||||
if (value) {
|
if (value) {
|
||||||
this.props.onFilter(this.props.column, value, FILTER_TYPE.SELECT);
|
this.props.onFilter(this.props.column, FILTER_TYPE.SELECT)(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,19 +76,19 @@ class SelectFilter extends Component {
|
|||||||
const value = (this.props.defaultValue !== undefined) ? this.props.defaultValue : '';
|
const value = (this.props.defaultValue !== undefined) ? this.props.defaultValue : '';
|
||||||
this.setState(() => ({ isSelected: value !== '' }));
|
this.setState(() => ({ isSelected: value !== '' }));
|
||||||
this.selectInput.value = value;
|
this.selectInput.value = value;
|
||||||
this.props.onFilter(this.props.column, value, FILTER_TYPE.SELECT);
|
this.props.onFilter(this.props.column, FILTER_TYPE.SELECT)(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
applyFilter(value) {
|
applyFilter(value) {
|
||||||
this.selectInput.value = value;
|
this.selectInput.value = value;
|
||||||
this.setState(() => ({ isSelected: value !== '' }));
|
this.setState(() => ({ isSelected: value !== '' }));
|
||||||
this.props.onFilter(this.props.column, value, FILTER_TYPE.SELECT);
|
this.props.onFilter(this.props.column, FILTER_TYPE.SELECT)(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
filter(e) {
|
filter(e) {
|
||||||
const { value } = e.target;
|
const { value } = e.target;
|
||||||
this.setState(() => ({ isSelected: value !== '' }));
|
this.setState(() => ({ isSelected: value !== '' }));
|
||||||
this.props.onFilter(this.props.column, value, FILTER_TYPE.SELECT);
|
this.props.onFilter(this.props.column, FILTER_TYPE.SELECT)(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -90,6 +102,7 @@ class SelectFilter extends Component {
|
|||||||
comparator,
|
comparator,
|
||||||
withoutEmptyOption,
|
withoutEmptyOption,
|
||||||
caseSensitive,
|
caseSensitive,
|
||||||
|
getFilter,
|
||||||
...rest
|
...rest
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
@ -121,7 +134,8 @@ SelectFilter.propTypes = {
|
|||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
withoutEmptyOption: PropTypes.bool,
|
withoutEmptyOption: PropTypes.bool,
|
||||||
defaultValue: PropTypes.any,
|
defaultValue: PropTypes.any,
|
||||||
caseSensitive: PropTypes.bool
|
caseSensitive: PropTypes.bool,
|
||||||
|
getFilter: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
SelectFilter.defaultProps = {
|
SelectFilter.defaultProps = {
|
||||||
|
|||||||
@ -17,10 +17,21 @@ class TextFilter extends Component {
|
|||||||
value: props.defaultValue
|
value: props.defaultValue
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
const { onFilter, getFilter, column } = this.props;
|
||||||
const defaultValue = this.input.value;
|
const defaultValue = this.input.value;
|
||||||
|
|
||||||
if (defaultValue) {
|
if (defaultValue) {
|
||||||
this.props.onFilter(this.props.column, defaultValue, FILTER_TYPE.TEXT);
|
onFilter(this.props.column, FILTER_TYPE.TEXT)(defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
// export onFilter function to allow users to access
|
||||||
|
if (getFilter) {
|
||||||
|
getFilter((filterVal) => {
|
||||||
|
this.setState(() => ({ value: filterVal }));
|
||||||
|
onFilter(column, FILTER_TYPE.TEXT)(filterVal);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +51,7 @@ class TextFilter extends Component {
|
|||||||
const filterValue = e.target.value;
|
const filterValue = e.target.value;
|
||||||
this.setState(() => ({ value: filterValue }));
|
this.setState(() => ({ value: filterValue }));
|
||||||
this.timeout = setTimeout(() => {
|
this.timeout = setTimeout(() => {
|
||||||
this.props.onFilter(this.props.column, filterValue, FILTER_TYPE.TEXT);
|
this.props.onFilter(this.props.column, FILTER_TYPE.TEXT)(filterValue);
|
||||||
}, this.props.delay);
|
}, this.props.delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,12 +64,12 @@ class TextFilter extends Component {
|
|||||||
cleanFiltered() {
|
cleanFiltered() {
|
||||||
const value = this.props.defaultValue;
|
const value = this.props.defaultValue;
|
||||||
this.setState(() => ({ value }));
|
this.setState(() => ({ value }));
|
||||||
this.props.onFilter(this.props.column, value, FILTER_TYPE.TEXT);
|
this.props.onFilter(this.props.column, FILTER_TYPE.TEXT)(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
applyFilter(filterText) {
|
applyFilter(filterText) {
|
||||||
this.setState(() => ({ value: filterText }));
|
this.setState(() => ({ value: filterText }));
|
||||||
this.props.onFilter(this.props.column, filterText, FILTER_TYPE.TEXT);
|
this.props.onFilter(this.props.column, FILTER_TYPE.TEXT)(filterText);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick(e) {
|
handleClick(e) {
|
||||||
@ -77,8 +88,10 @@ class TextFilter extends Component {
|
|||||||
onFilter,
|
onFilter,
|
||||||
caseSensitive,
|
caseSensitive,
|
||||||
defaultValue,
|
defaultValue,
|
||||||
|
getFilter,
|
||||||
...rest
|
...rest
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
// stopPropagation for onClick event is try to prevent sort was triggered.
|
// stopPropagation for onClick event is try to prevent sort was triggered.
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
@ -105,7 +118,8 @@ TextFilter.propTypes = {
|
|||||||
placeholder: PropTypes.string,
|
placeholder: PropTypes.string,
|
||||||
style: PropTypes.object,
|
style: PropTypes.object,
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
caseSensitive: PropTypes.bool
|
caseSensitive: PropTypes.bool,
|
||||||
|
getFilter: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
TextFilter.defaultProps = {
|
TextFilter.defaultProps = {
|
||||||
|
|||||||
@ -6,30 +6,37 @@ import { LIKE, EQ, NE, GT, GE, LT, LE } from './comparison';
|
|||||||
export const filterByText = _ => (
|
export const filterByText = _ => (
|
||||||
data,
|
data,
|
||||||
dataField,
|
dataField,
|
||||||
{ filterVal = '', comparator = LIKE, caseSensitive },
|
{ filterVal: userInput = '', comparator = LIKE, caseSensitive },
|
||||||
customFilterValue
|
customFilterValue
|
||||||
) =>
|
) => {
|
||||||
data.filter((row) => {
|
// make sure filter value to be a string
|
||||||
let cell = _.get(row, dataField);
|
const filterVal = userInput.toString();
|
||||||
if (customFilterValue) {
|
|
||||||
cell = customFilterValue(cell, row);
|
return (
|
||||||
}
|
data.filter((row) => {
|
||||||
const cellStr = _.isDefined(cell) ? cell.toString() : '';
|
let cell = _.get(row, dataField);
|
||||||
if (comparator === EQ) {
|
if (customFilterValue) {
|
||||||
return cellStr === filterVal;
|
cell = customFilterValue(cell, row);
|
||||||
}
|
}
|
||||||
if (caseSensitive) {
|
const cellStr = _.isDefined(cell) ? cell.toString() : '';
|
||||||
return cellStr.includes(filterVal);
|
if (comparator === EQ) {
|
||||||
}
|
return cellStr === filterVal;
|
||||||
return cellStr.toLocaleUpperCase().indexOf(filterVal.toLocaleUpperCase()) !== -1;
|
}
|
||||||
});
|
if (caseSensitive) {
|
||||||
|
return cellStr.includes(filterVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cellStr.toLocaleUpperCase().indexOf(filterVal.toLocaleUpperCase()) !== -1;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const filterByNumber = _ => (
|
export const filterByNumber = _ => (
|
||||||
data,
|
data,
|
||||||
dataField,
|
dataField,
|
||||||
{ filterVal: { comparator, number } },
|
{ filterVal: { comparator, number } },
|
||||||
customFilterValue
|
customFilterValue
|
||||||
) =>
|
) => (
|
||||||
data.filter((row) => {
|
data.filter((row) => {
|
||||||
if (number === '' || !comparator) return true;
|
if (number === '' || !comparator) return true;
|
||||||
let valid = true;
|
let valid = true;
|
||||||
@ -81,7 +88,8 @@ export const filterByNumber = _ => (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return valid;
|
return valid;
|
||||||
});
|
})
|
||||||
|
);
|
||||||
|
|
||||||
export const filterFactory = _ => (filterType) => {
|
export const filterFactory = _ => (filterType) => {
|
||||||
let filterFn;
|
let filterFn;
|
||||||
|
|||||||
@ -40,33 +40,43 @@ export default (Base, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onFilter(column, filterVal, filterType) {
|
/**
|
||||||
const { store, columns } = this.props;
|
* filter the table like below:
|
||||||
const currFilters = Object.assign({}, this.state.currFilters);
|
* onFilter(column, filterType)(filterVal)
|
||||||
const { dataField, filter } = column;
|
* @param {Object} column
|
||||||
|
* @param {String} filterType
|
||||||
|
* @param {String} filterVal - user input for filtering.
|
||||||
|
*/
|
||||||
|
onFilter(column, filterType) {
|
||||||
|
return (filterVal) => {
|
||||||
|
const { store, columns } = this.props;
|
||||||
|
const currFilters = Object.assign({}, this.state.currFilters);
|
||||||
|
const { dataField, filter } = column;
|
||||||
|
|
||||||
if (!_.isDefined(filterVal) || filterVal === '') {
|
if (!_.isDefined(filterVal) || filterVal === '') {
|
||||||
delete currFilters[dataField];
|
delete currFilters[dataField];
|
||||||
} else {
|
} else {
|
||||||
// select default comparator is EQ, others are LIKE
|
// select default comparator is EQ, others are LIKE
|
||||||
const {
|
const {
|
||||||
comparator = (filterType === FILTER_TYPE.SELECT ? EQ : LIKE),
|
comparator = (filterType === FILTER_TYPE.SELECT ? EQ : LIKE),
|
||||||
caseSensitive = false
|
caseSensitive = false
|
||||||
} = filter.props;
|
} = filter.props;
|
||||||
currFilters[dataField] = { filterVal, filterType, comparator, caseSensitive };
|
currFilters[dataField] = { filterVal, filterType, comparator, caseSensitive };
|
||||||
}
|
}
|
||||||
store.filters = currFilters;
|
|
||||||
|
|
||||||
if (this.isRemoteFiltering() || this.isRemotePagination()) {
|
store.filters = currFilters;
|
||||||
this.handleRemoteFilterChange();
|
|
||||||
// when remote filtering is enable, dont set currFilters state
|
|
||||||
// in the componentWillReceiveProps,
|
|
||||||
// it's the key point that we can know the filter is changed
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
store.filteredData = filters(store, columns, _)(currFilters);
|
if (this.isRemoteFiltering() || this.isRemotePagination()) {
|
||||||
this.setState(() => ({ currFilters, isDataChanged: true }));
|
this.handleRemoteFilterChange();
|
||||||
|
// when remote filtering is enable, dont set currFilters state
|
||||||
|
// in the componentWillReceiveProps,
|
||||||
|
// it's the key point that we can know the filter is changed
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
store.filteredData = filters(store, columns, _)(currFilters);
|
||||||
|
this.setState(() => ({ currFilters, isDataChanged: true }));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@ -9,7 +9,11 @@ import * as Comparator from '../../src/comparison';
|
|||||||
|
|
||||||
describe('Number Filter', () => {
|
describe('Number Filter', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
|
// onFilter(x)(y) = filter result
|
||||||
const onFilter = sinon.stub();
|
const onFilter = sinon.stub();
|
||||||
|
const onFilterFirstReturn = sinon.stub();
|
||||||
|
|
||||||
const column = {
|
const column = {
|
||||||
dataField: 'price',
|
dataField: 'price',
|
||||||
text: 'Product Price'
|
text: 'Product Price'
|
||||||
@ -17,6 +21,9 @@ describe('Number Filter', () => {
|
|||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
onFilter.reset();
|
onFilter.reset();
|
||||||
|
onFilterFirstReturn.reset();
|
||||||
|
|
||||||
|
onFilter.returns(onFilterFirstReturn);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('initialization', () => {
|
describe('initialization', () => {
|
||||||
@ -90,6 +97,36 @@ describe('Number Filter', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when props.getFilter is defined', () => {
|
||||||
|
let programmaticallyFilter;
|
||||||
|
|
||||||
|
const comparator = Comparator.EQ;
|
||||||
|
const number = 123;
|
||||||
|
|
||||||
|
const getFilter = (filter) => {
|
||||||
|
programmaticallyFilter = filter;
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = mount(
|
||||||
|
<NumberFilter onFilter={ onFilter } column={ column } getFilter={ getFilter } />
|
||||||
|
);
|
||||||
|
|
||||||
|
programmaticallyFilter({ comparator, number });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should do onFilter correctly when exported function was executed', () => {
|
||||||
|
expect(onFilter.calledOnce).toBeTruthy();
|
||||||
|
expect(onFilter.calledWith(column, FILTER_TYPE.NUMBER)).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledWith({ comparator, number })).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should setState correctly when exported function was executed', () => {
|
||||||
|
expect(wrapper.state().isSelected).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when defaultValue.number and defaultValue.comparator props is defined', () => {
|
describe('when defaultValue.number and defaultValue.comparator props is defined', () => {
|
||||||
const number = 203;
|
const number = 203;
|
||||||
const comparator = Comparator.EQ;
|
const comparator = Comparator.EQ;
|
||||||
@ -110,8 +147,9 @@ describe('Number Filter', () => {
|
|||||||
|
|
||||||
it('should calling onFilter on componentDidMount', () => {
|
it('should calling onFilter on componentDidMount', () => {
|
||||||
expect(onFilter.calledOnce).toBeTruthy();
|
expect(onFilter.calledOnce).toBeTruthy();
|
||||||
expect(onFilter.calledWith(
|
expect(onFilter.calledWith(column, FILTER_TYPE.NUMBER)).toBeTruthy();
|
||||||
column, { number: `${number}`, comparator }, FILTER_TYPE.NUMBER)).toBeTruthy();
|
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledWith({ number: `${number}`, comparator })).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -9,19 +9,27 @@ import { FILTER_TYPE } from '../../src/const';
|
|||||||
describe('Select Filter', () => {
|
describe('Select Filter', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
let instance;
|
let instance;
|
||||||
|
|
||||||
|
// onFilter(x)(y) = filter result
|
||||||
const onFilter = sinon.stub();
|
const onFilter = sinon.stub();
|
||||||
|
const onFilterFirstReturn = sinon.stub();
|
||||||
|
|
||||||
const column = {
|
const column = {
|
||||||
dataField: 'quality',
|
dataField: 'quality',
|
||||||
text: 'Product Quality'
|
text: 'Product Quality'
|
||||||
};
|
};
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
0: 'Bad',
|
0: 'Bad',
|
||||||
1: 'Good',
|
1: 'Good',
|
||||||
2: 'Unknow'
|
2: 'Unknown'
|
||||||
};
|
};
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
onFilter.reset();
|
onFilter.reset();
|
||||||
|
onFilterFirstReturn.reset();
|
||||||
|
|
||||||
|
onFilter.returns(onFilterFirstReturn);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('initialization', () => {
|
describe('initialization', () => {
|
||||||
@ -83,11 +91,48 @@ describe('Select Filter', () => {
|
|||||||
|
|
||||||
it('should calling onFilter on componentDidMount', () => {
|
it('should calling onFilter on componentDidMount', () => {
|
||||||
expect(onFilter.calledOnce).toBeTruthy();
|
expect(onFilter.calledOnce).toBeTruthy();
|
||||||
expect(onFilter.calledWith(column, defaultValue, FILTER_TYPE.SELECT)).toBeTruthy();
|
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledWith(defaultValue)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when props.getFilter is defined', () => {
|
||||||
|
let programmaticallyFilter;
|
||||||
|
|
||||||
|
const filterValue = 'foo';
|
||||||
|
|
||||||
|
const getFilter = (filter) => {
|
||||||
|
programmaticallyFilter = filter;
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = mount(
|
||||||
|
<SelectFilter
|
||||||
|
onFilter={ onFilter }
|
||||||
|
column={ column }
|
||||||
|
options={ options }
|
||||||
|
getFilter={ getFilter }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
instance = wrapper.instance();
|
||||||
|
|
||||||
|
programmaticallyFilter(filterValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should do onFilter correctly when exported function was executed', () => {
|
||||||
|
expect(onFilter.calledOnce).toBeTruthy();
|
||||||
|
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledWith(filterValue)).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should setState correctly when exported function was executed', () => {
|
||||||
|
expect(instance.state.isSelected).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when placeholder is defined', () => {
|
describe('when placeholder is defined', () => {
|
||||||
const placeholder = 'test';
|
const placeholder = 'test';
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -170,8 +215,9 @@ describe('Select Filter', () => {
|
|||||||
|
|
||||||
it('should update', () => {
|
it('should update', () => {
|
||||||
expect(onFilter.callCount).toBe(2);
|
expect(onFilter.callCount).toBe(2);
|
||||||
expect(onFilter.calledWith(
|
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||||
column, instance.props.defaultValue, FILTER_TYPE.SELECT)).toBeTruthy();
|
expect(onFilterFirstReturn.callCount).toBe(2);
|
||||||
|
expect(onFilterFirstReturn.calledWith(instance.props.defaultValue)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -198,8 +244,9 @@ describe('Select Filter', () => {
|
|||||||
|
|
||||||
it('should update', () => {
|
it('should update', () => {
|
||||||
expect(onFilter.callCount).toBe(2);
|
expect(onFilter.callCount).toBe(2);
|
||||||
expect(onFilter.calledWith(
|
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||||
column, instance.props.defaultValue, FILTER_TYPE.SELECT)).toBeTruthy();
|
expect(onFilterFirstReturn.callCount).toBe(2);
|
||||||
|
expect(onFilterFirstReturn.calledWith(instance.props.defaultValue)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -226,7 +273,9 @@ describe('Select Filter', () => {
|
|||||||
|
|
||||||
it('should calling onFilter correctly', () => {
|
it('should calling onFilter correctly', () => {
|
||||||
expect(onFilter.callCount).toBe(2);
|
expect(onFilter.callCount).toBe(2);
|
||||||
expect(onFilter.calledWith(column, defaultValue, FILTER_TYPE.SELECT)).toBeTruthy();
|
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.callCount).toBe(2);
|
||||||
|
expect(onFilterFirstReturn.calledWith(defaultValue)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -249,6 +298,7 @@ describe('Select Filter', () => {
|
|||||||
|
|
||||||
it('should calling onFilter correctly', () => {
|
it('should calling onFilter correctly', () => {
|
||||||
expect(onFilter.callCount).toBe(1);
|
expect(onFilter.callCount).toBe(1);
|
||||||
|
expect(onFilterFirstReturn.callCount).toBe(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -268,8 +318,10 @@ describe('Select Filter', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should calling onFilter correctly', () => {
|
it('should calling onFilter correctly', () => {
|
||||||
expect(onFilter.callCount).toBe(1);
|
expect(onFilter.calledOnce).toBeTruthy();
|
||||||
expect(onFilter.calledWith(column, value, FILTER_TYPE.SELECT)).toBeTruthy();
|
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledWith(value)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -289,8 +341,10 @@ describe('Select Filter', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should calling onFilter correctly', () => {
|
it('should calling onFilter correctly', () => {
|
||||||
expect(onFilter.callCount).toBe(1);
|
expect(onFilter.calledOnce).toBeTruthy();
|
||||||
expect(onFilter.calledWith(column, event.target.value, FILTER_TYPE.SELECT)).toBeTruthy();
|
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledWith(event.target.value)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -9,7 +9,11 @@ jest.useFakeTimers();
|
|||||||
describe('Text Filter', () => {
|
describe('Text Filter', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
let instance;
|
let instance;
|
||||||
|
|
||||||
|
// onFilter(x)(y) = filter result
|
||||||
const onFilter = sinon.stub();
|
const onFilter = sinon.stub();
|
||||||
|
const onFilterFirstReturn = sinon.stub();
|
||||||
|
|
||||||
const column = {
|
const column = {
|
||||||
dataField: 'price',
|
dataField: 'price',
|
||||||
text: 'Price'
|
text: 'Price'
|
||||||
@ -17,6 +21,9 @@ describe('Text Filter', () => {
|
|||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
onFilter.reset();
|
onFilter.reset();
|
||||||
|
onFilterFirstReturn.reset();
|
||||||
|
|
||||||
|
onFilter.returns(onFilterFirstReturn);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('initialization', () => {
|
describe('initialization', () => {
|
||||||
@ -58,7 +65,39 @@ describe('Text Filter', () => {
|
|||||||
|
|
||||||
it('should calling onFilter on componentDidMount', () => {
|
it('should calling onFilter on componentDidMount', () => {
|
||||||
expect(onFilter.calledOnce).toBeTruthy();
|
expect(onFilter.calledOnce).toBeTruthy();
|
||||||
expect(onFilter.calledWith(column, defaultValue, FILTER_TYPE.TEXT)).toBeTruthy();
|
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledWith(defaultValue)).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when props.getFilter is defined', () => {
|
||||||
|
let programmaticallyFilter;
|
||||||
|
|
||||||
|
const filterValue = 'foo';
|
||||||
|
|
||||||
|
const getFilter = (filter) => {
|
||||||
|
programmaticallyFilter = filter;
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = mount(
|
||||||
|
<TextFilter onFilter={ onFilter } column={ column } getFilter={ getFilter } />
|
||||||
|
);
|
||||||
|
instance = wrapper.instance();
|
||||||
|
|
||||||
|
programmaticallyFilter(filterValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should do onFilter correctly when exported function was executed', () => {
|
||||||
|
expect(onFilter.calledOnce).toBeTruthy();
|
||||||
|
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledWith(filterValue)).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should setState correctly when exported function was executed', () => {
|
||||||
|
expect(instance.state.value).toEqual(filterValue);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -114,7 +153,9 @@ describe('Text Filter', () => {
|
|||||||
|
|
||||||
it('should calling onFilter correctly when props.defaultValue is changed', () => {
|
it('should calling onFilter correctly when props.defaultValue is changed', () => {
|
||||||
expect(onFilter.calledOnce).toBeTruthy();
|
expect(onFilter.calledOnce).toBeTruthy();
|
||||||
expect(onFilter.calledWith(column, nextDefaultValue, FILTER_TYPE.TEXT)).toBeTruthy();
|
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledWith(nextDefaultValue)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -133,8 +174,9 @@ describe('Text Filter', () => {
|
|||||||
|
|
||||||
it('should calling onFilter correctly', () => {
|
it('should calling onFilter correctly', () => {
|
||||||
expect(onFilter.calledOnce).toBeTruthy();
|
expect(onFilter.calledOnce).toBeTruthy();
|
||||||
expect(onFilter.calledWith(
|
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||||
column, instance.props.defaultValue, FILTER_TYPE.TEXT)).toBeTruthy();
|
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledWith(instance.props.defaultValue)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -154,7 +196,9 @@ describe('Text Filter', () => {
|
|||||||
|
|
||||||
it('should calling onFilter correctly', () => {
|
it('should calling onFilter correctly', () => {
|
||||||
expect(onFilter.calledOnce).toBeTruthy();
|
expect(onFilter.calledOnce).toBeTruthy();
|
||||||
expect(onFilter.calledWith(column, filterText, FILTER_TYPE.TEXT)).toBeTruthy();
|
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||||
|
expect(onFilterFirstReturn.calledWith(filterText)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -42,6 +42,19 @@ describe('filter', () => {
|
|||||||
filterFn = filters(store, columns, _);
|
filterFn = filters(store, columns, _);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when filter value is not a String', () => {
|
||||||
|
it('should transform to string and do the filter', () => {
|
||||||
|
currFilters.name = {
|
||||||
|
filterVal: 3,
|
||||||
|
filterType: FILTER_TYPE.TEXT
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = filterFn(currFilters);
|
||||||
|
expect(result).toBeDefined();
|
||||||
|
expect(result).toHaveLength(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe(`when default comparator is ${LIKE}`, () => {
|
describe(`when default comparator is ${LIKE}`, () => {
|
||||||
it('should returning correct result', () => {
|
it('should returning correct result', () => {
|
||||||
currFilters.name = {
|
currFilters.name = {
|
||||||
|
|||||||
@ -167,14 +167,14 @@ describe('Wrapper', () => {
|
|||||||
|
|
||||||
it('should setting store object correctly', () => {
|
it('should setting store object correctly', () => {
|
||||||
filterVals.forEach((filterVal) => {
|
filterVals.forEach((filterVal) => {
|
||||||
instance.onFilter(props.columns[1], filterVal, FILTER_TYPE.TEXT);
|
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||||
expect(props.store.filtering).toBeFalsy();
|
expect(props.store.filtering).toBeFalsy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should setting state correctly', () => {
|
it('should setting state correctly', () => {
|
||||||
filterVals.forEach((filterVal) => {
|
filterVals.forEach((filterVal) => {
|
||||||
instance.onFilter(props.columns[1], filterVal, FILTER_TYPE.TEXT);
|
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||||
expect(instance.state.isDataChanged).toBeTruthy();
|
expect(instance.state.isDataChanged).toBeTruthy();
|
||||||
expect(Object.keys(instance.state.currFilters)).toHaveLength(0);
|
expect(Object.keys(instance.state.currFilters)).toHaveLength(0);
|
||||||
});
|
});
|
||||||
@ -185,12 +185,12 @@ describe('Wrapper', () => {
|
|||||||
const filterVal = '3';
|
const filterVal = '3';
|
||||||
|
|
||||||
it('should setting store object correctly', () => {
|
it('should setting store object correctly', () => {
|
||||||
instance.onFilter(props.columns[1], filterVal, FILTER_TYPE.TEXT);
|
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||||
expect(props.store.filters).toEqual(instance.state.currFilters);
|
expect(props.store.filters).toEqual(instance.state.currFilters);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should setting state correctly', () => {
|
it('should setting state correctly', () => {
|
||||||
instance.onFilter(props.columns[1], filterVal, FILTER_TYPE.TEXT);
|
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||||
expect(instance.state.isDataChanged).toBeTruthy();
|
expect(instance.state.isDataChanged).toBeTruthy();
|
||||||
expect(Object.keys(instance.state.currFilters)).toHaveLength(1);
|
expect(Object.keys(instance.state.currFilters)).toHaveLength(1);
|
||||||
});
|
});
|
||||||
@ -203,7 +203,7 @@ describe('Wrapper', () => {
|
|||||||
props = createTableProps();
|
props = createTableProps();
|
||||||
props.remote = { filter: true };
|
props.remote = { filter: true };
|
||||||
createFilterWrapper(props);
|
createFilterWrapper(props);
|
||||||
instance.onFilter(props.columns[1], filterVal, FILTER_TYPE.TEXT);
|
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not setting store object correctly', () => {
|
it('should not setting store object correctly', () => {
|
||||||
@ -222,27 +222,27 @@ describe('Wrapper', () => {
|
|||||||
|
|
||||||
describe('combination', () => {
|
describe('combination', () => {
|
||||||
it('should setting store object correctly', () => {
|
it('should setting store object correctly', () => {
|
||||||
instance.onFilter(props.columns[1], '3', FILTER_TYPE.TEXT);
|
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)('3');
|
||||||
expect(props.store.filters).toEqual(instance.state.currFilters);
|
expect(props.store.filters).toEqual(instance.state.currFilters);
|
||||||
expect(instance.state.isDataChanged).toBeTruthy();
|
expect(instance.state.isDataChanged).toBeTruthy();
|
||||||
expect(Object.keys(instance.state.currFilters)).toHaveLength(1);
|
expect(Object.keys(instance.state.currFilters)).toHaveLength(1);
|
||||||
|
|
||||||
instance.onFilter(props.columns[1], '2', FILTER_TYPE.TEXT);
|
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)('2');
|
||||||
expect(props.store.filters).toEqual(instance.state.currFilters);
|
expect(props.store.filters).toEqual(instance.state.currFilters);
|
||||||
expect(instance.state.isDataChanged).toBeTruthy();
|
expect(instance.state.isDataChanged).toBeTruthy();
|
||||||
expect(Object.keys(instance.state.currFilters)).toHaveLength(1);
|
expect(Object.keys(instance.state.currFilters)).toHaveLength(1);
|
||||||
|
|
||||||
instance.onFilter(props.columns[2], '2', FILTER_TYPE.TEXT);
|
instance.onFilter(props.columns[2], FILTER_TYPE.TEXT)('2');
|
||||||
expect(props.store.filters).toEqual(instance.state.currFilters);
|
expect(props.store.filters).toEqual(instance.state.currFilters);
|
||||||
expect(instance.state.isDataChanged).toBeTruthy();
|
expect(instance.state.isDataChanged).toBeTruthy();
|
||||||
expect(Object.keys(instance.state.currFilters)).toHaveLength(2);
|
expect(Object.keys(instance.state.currFilters)).toHaveLength(2);
|
||||||
|
|
||||||
instance.onFilter(props.columns[2], '', FILTER_TYPE.TEXT);
|
instance.onFilter(props.columns[2], FILTER_TYPE.TEXT)('');
|
||||||
expect(props.store.filters).toEqual(instance.state.currFilters);
|
expect(props.store.filters).toEqual(instance.state.currFilters);
|
||||||
expect(instance.state.isDataChanged).toBeTruthy();
|
expect(instance.state.isDataChanged).toBeTruthy();
|
||||||
expect(Object.keys(instance.state.currFilters)).toHaveLength(1);
|
expect(Object.keys(instance.state.currFilters)).toHaveLength(1);
|
||||||
|
|
||||||
instance.onFilter(props.columns[1], '', FILTER_TYPE.TEXT);
|
instance.onFilter(props.columns[1], FILTER_TYPE.TEXT)('');
|
||||||
expect(props.store.filters).toEqual(instance.state.currFilters);
|
expect(props.store.filters).toEqual(instance.state.currFilters);
|
||||||
expect(instance.state.isDataChanged).toBeTruthy();
|
expect(instance.state.isDataChanged).toBeTruthy();
|
||||||
expect(Object.keys(instance.state.currFilters)).toHaveLength(0);
|
expect(Object.keys(instance.state.currFilters)).toHaveLength(0);
|
||||||
|
|||||||
@ -47,7 +47,7 @@ export default ExtendBase =>
|
|||||||
}
|
}
|
||||||
if (selectable) {
|
if (selectable) {
|
||||||
const key = _.get(row, keyField);
|
const key = _.get(row, keyField);
|
||||||
onRowSelect(key, !selected, rowIndex);
|
onRowSelect(key, !selected, rowIndex, e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ export default class SelectionCell extends Component {
|
|||||||
return nextProps.selected !== selected;
|
return nextProps.selected !== selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick() {
|
handleClick(e) {
|
||||||
const {
|
const {
|
||||||
mode: inputType,
|
mode: inputType,
|
||||||
rowKey,
|
rowKey,
|
||||||
@ -46,7 +46,7 @@ export default class SelectionCell extends Component {
|
|||||||
? true
|
? true
|
||||||
: !selected;
|
: !selected;
|
||||||
|
|
||||||
onRowSelect(rowKey, checked, rowIndex);
|
onRowSelect(rowKey, checked, rowIndex, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@ -44,10 +44,10 @@ export default class SelectionHeaderCell extends Component {
|
|||||||
return nextProps.checkedStatus !== checkedStatus;
|
return nextProps.checkedStatus !== checkedStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCheckBoxClick() {
|
handleCheckBoxClick(e) {
|
||||||
const { onAllRowsSelect } = this.props;
|
const { onAllRowsSelect } = this.props;
|
||||||
|
|
||||||
onAllRowsSelect();
|
onAllRowsSelect(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@ -41,7 +41,7 @@ export default Base =>
|
|||||||
* @param {String} rowKey - row key of what was selected.
|
* @param {String} rowKey - row key of what was selected.
|
||||||
* @param {Boolean} checked - next checked status of input button.
|
* @param {Boolean} checked - next checked status of input button.
|
||||||
*/
|
*/
|
||||||
handleRowSelect(rowKey, checked, rowIndex) {
|
handleRowSelect(rowKey, checked, rowIndex, e) {
|
||||||
const { selectRow: { mode, onSelect }, store } = this.props;
|
const { selectRow: { mode, onSelect }, store } = this.props;
|
||||||
const { ROW_SELECT_SINGLE } = Const;
|
const { ROW_SELECT_SINGLE } = Const;
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ export default Base =>
|
|||||||
|
|
||||||
if (onSelect) {
|
if (onSelect) {
|
||||||
const row = getRowByRowId(store)(rowKey);
|
const row = getRowByRowId(store)(rowKey);
|
||||||
onSelect(row, checked, rowIndex);
|
onSelect(row, checked, rowIndex, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState(() => ({
|
this.setState(() => ({
|
||||||
@ -68,18 +68,16 @@ export default Base =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* handle all rows selection on header cell by store.selected or given specific result.
|
* handle all rows selection on header cell by store.selected
|
||||||
* @param {Boolean} option - customized result for all rows selection
|
|
||||||
*/
|
*/
|
||||||
handleAllRowsSelect(option) {
|
handleAllRowsSelect(e) {
|
||||||
const { store, selectRow: {
|
const { store, selectRow: {
|
||||||
onSelectAll,
|
onSelectAll,
|
||||||
nonSelectable
|
nonSelectable
|
||||||
} } = this.props;
|
} } = this.props;
|
||||||
const selected = isAnySelectedRow(store)(nonSelectable);
|
const selected = isAnySelectedRow(store)(nonSelectable);
|
||||||
|
|
||||||
// set next status of all row selected by store.selected or customizing by user.
|
const result = !selected;
|
||||||
const result = option || !selected;
|
|
||||||
|
|
||||||
const currSelected = result ?
|
const currSelected = result ?
|
||||||
selectableKeys(store)(nonSelectable) :
|
selectableKeys(store)(nonSelectable) :
|
||||||
@ -89,7 +87,7 @@ export default Base =>
|
|||||||
store.selected = currSelected;
|
store.selected = currSelected;
|
||||||
|
|
||||||
if (onSelectAll) {
|
if (onSelectAll) {
|
||||||
onSelectAll(result, getSelectedRows(store));
|
onSelectAll(result, getSelectedRows(store), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState(() => ({
|
this.setState(() => ({
|
||||||
|
|||||||
@ -162,14 +162,6 @@ describe('RowSelectionWrapper', () => {
|
|||||||
wrapper.instance().handleAllRowsSelect();
|
wrapper.instance().handleAllRowsSelect();
|
||||||
expect(wrapper.state('selectedRowKeys')).toEqual([]);
|
expect(wrapper.state('selectedRowKeys')).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('call handleAllRowsSelect function with a bool args should setting correct state.selectedRowKeys', () => {
|
|
||||||
wrapper.instance().handleAllRowsSelect(true);
|
|
||||||
expect(wrapper.state('selectedRowKeys')).toEqual(expect.arrayContaining([firstSelectedRow, secondSelectedRow]));
|
|
||||||
|
|
||||||
wrapper.instance().handleAllRowsSelect(false);
|
|
||||||
expect(wrapper.state('selectedRowKeys')).toEqual([]);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when selectRow.onSelect is defined', () => {
|
describe('when selectRow.onSelect is defined', () => {
|
||||||
@ -219,13 +211,14 @@ describe('RowSelectionWrapper', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('selectRow.onSelect callback should be called correctly when calling handleRowSelect function', () => {
|
it('selectRow.onSelect callback should be called correctly when calling handleRowSelect function', () => {
|
||||||
wrapper.instance().handleAllRowsSelect();
|
const e = {};
|
||||||
|
wrapper.instance().handleAllRowsSelect(e);
|
||||||
expect(onSelectAllCallBack.callCount).toEqual(1);
|
expect(onSelectAllCallBack.callCount).toEqual(1);
|
||||||
expect(onSelectAllCallBack.calledWith(true, data)).toBeTruthy();
|
expect(onSelectAllCallBack.calledWith(true, data, e)).toBeTruthy();
|
||||||
|
|
||||||
wrapper.instance().handleAllRowsSelect();
|
wrapper.instance().handleAllRowsSelect(e);
|
||||||
expect(onSelectAllCallBack.callCount).toEqual(2);
|
expect(onSelectAllCallBack.callCount).toEqual(2);
|
||||||
expect(onSelectAllCallBack.calledWith(false, [])).toBeTruthy();
|
expect(onSelectAllCallBack.calledWith(false, [], e)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,64 +0,0 @@
|
|||||||
import * as path from 'path';
|
|
||||||
import webpack from 'webpack';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
entry: {
|
|
||||||
'react-bootstrap-table2/dist/react-bootstrap-table2': './packages/react-bootstrap-table2/index.js',
|
|
||||||
'react-bootstrap-table2/dist/react-bootstrap-table2.min': './packages/react-bootstrap-table2/index.js',
|
|
||||||
'react-bootstrap-table2-editor/dist/react-bootstrap-table2-editor': './packages/react-bootstrap-table2-editor/index.js',
|
|
||||||
'react-bootstrap-table2-editor/dist/react-bootstrap-table2-editor.min': './packages/react-bootstrap-table2-editor/index.js',
|
|
||||||
'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter': './packages/react-bootstrap-table2-filter/index.js',
|
|
||||||
'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min': './packages/react-bootstrap-table2-filter/index.js',
|
|
||||||
'react-bootstrap-table2-overlay/dist/react-bootstrap-table2-overlay': './packages/react-bootstrap-table2-overlay/index.js',
|
|
||||||
'react-bootstrap-table2-overlay/dist/react-bootstrap-table2-overlay.min': './packages/react-bootstrap-table2-overlay/index.js',
|
|
||||||
'react-bootstrap-table2-paginator/dist/react-bootstrap-table2-paginator': './packages/react-bootstrap-table2-paginator/index.js',
|
|
||||||
'react-bootstrap-table2-paginator/dist/react-bootstrap-table2-paginator.min': './packages/react-bootstrap-table2-paginator/index.js'
|
|
||||||
},
|
|
||||||
devtool: 'source-map',
|
|
||||||
output: {
|
|
||||||
path: path.join(__dirname, 'packages'),
|
|
||||||
filename: '[name].js',
|
|
||||||
library: 'ReactBootstrapTable',
|
|
||||||
libraryTarget: 'umd'
|
|
||||||
},
|
|
||||||
externals: [{
|
|
||||||
'react': {
|
|
||||||
root: 'React',
|
|
||||||
commonjs2: 'react',
|
|
||||||
commonjs: 'react',
|
|
||||||
amd: 'react'
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
'react-dom': {
|
|
||||||
root: 'ReactDOM',
|
|
||||||
commonjs2: 'react-dom',
|
|
||||||
commonjs: 'react-dom',
|
|
||||||
amd: 'react-dom'
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
module: {
|
|
||||||
rules: [{
|
|
||||||
enforce: 'pre',
|
|
||||||
test: /\.js?$/,
|
|
||||||
exclude: /node_modules/,
|
|
||||||
loader: 'eslint-loader'
|
|
||||||
}, {
|
|
||||||
test: /\.js?$/,
|
|
||||||
use: ['babel-loader'],
|
|
||||||
exclude: /node_modules/
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
'process.env.NODE_ENV': JSON.stringify('production')
|
|
||||||
}),
|
|
||||||
new webpack.SourceMapDevToolPlugin(),
|
|
||||||
new webpack.optimize.DedupePlugin(),
|
|
||||||
new webpack.optimize.OccurrenceOrderPlugin(),
|
|
||||||
new webpack.optimize.AggressiveMergingPlugin(),
|
|
||||||
new webpack.optimize.UglifyJsPlugin({
|
|
||||||
include: /\.min\.js$/,
|
|
||||||
compress: { warnings: false }
|
|
||||||
})
|
|
||||||
]
|
|
||||||
};
|
|
||||||
16
webpack/editor.umd.babel.js
Normal file
16
webpack/editor.umd.babel.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import * as path from 'path';
|
||||||
|
import umdConfig from './webpack.umd.babel';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
...umdConfig,
|
||||||
|
entry: {
|
||||||
|
'react-bootstrap-table2-editor/dist/react-bootstrap-table2-editor': './packages/react-bootstrap-table2-editor/index.js',
|
||||||
|
'react-bootstrap-table2-editor/dist/react-bootstrap-table2-editor.min': './packages/react-bootstrap-table2-editor/index.js'
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: path.join(__dirname, '../packages'),
|
||||||
|
filename: '[name].js',
|
||||||
|
library: 'ReactBootstrapTable2Editor',
|
||||||
|
libraryTarget: 'umd'
|
||||||
|
}
|
||||||
|
};
|
||||||
16
webpack/filter.umd.babel.js
Normal file
16
webpack/filter.umd.babel.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import * as path from 'path';
|
||||||
|
import umdConfig from './webpack.umd.babel';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
...umdConfig,
|
||||||
|
entry: {
|
||||||
|
'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter': './packages/react-bootstrap-table2-filter/index.js',
|
||||||
|
'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min': './packages/react-bootstrap-table2-filter/index.js'
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: path.join(__dirname, '../packages'),
|
||||||
|
filename: '[name].js',
|
||||||
|
library: 'ReactBootstrapTable2Filter',
|
||||||
|
libraryTarget: 'umd'
|
||||||
|
}
|
||||||
|
};
|
||||||
16
webpack/next.umd.babel.js
Normal file
16
webpack/next.umd.babel.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import * as path from 'path';
|
||||||
|
import umdConfig from './webpack.umd.babel';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
...umdConfig,
|
||||||
|
entry: {
|
||||||
|
'react-bootstrap-table2/dist/react-bootstrap-table-next': './packages/react-bootstrap-table2/index.js',
|
||||||
|
'react-bootstrap-table2/dist/react-bootstrap-table-next.min': './packages/react-bootstrap-table2/index.js'
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: path.join(__dirname, '../packages'),
|
||||||
|
filename: '[name].js',
|
||||||
|
library: 'ReactBootstrapTable2',
|
||||||
|
libraryTarget: 'umd'
|
||||||
|
}
|
||||||
|
};
|
||||||
16
webpack/overlay.umd.babel.js
Normal file
16
webpack/overlay.umd.babel.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import * as path from 'path';
|
||||||
|
import umdConfig from './webpack.umd.babel';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
...umdConfig,
|
||||||
|
entry: {
|
||||||
|
'react-bootstrap-table2-overlay/dist/react-bootstrap-table2-overlay': './packages/react-bootstrap-table2-overlay/index.js',
|
||||||
|
'react-bootstrap-table2-overlay/dist/react-bootstrap-table2-overlay.min': './packages/react-bootstrap-table2-overlay/index.js'
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: path.join(__dirname, '../packages'),
|
||||||
|
filename: '[name].js',
|
||||||
|
library: 'ReactBootstrapTable2Overlay',
|
||||||
|
libraryTarget: 'umd'
|
||||||
|
}
|
||||||
|
};
|
||||||
16
webpack/paginator.umd.babel.js
Normal file
16
webpack/paginator.umd.babel.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import * as path from 'path';
|
||||||
|
import umdConfig from './webpack.umd.babel';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
...umdConfig,
|
||||||
|
entry: {
|
||||||
|
'react-bootstrap-table2-paginator/dist/react-bootstrap-table2-paginator': './packages/react-bootstrap-table2-paginator/index.js',
|
||||||
|
'react-bootstrap-table2-paginator/dist/react-bootstrap-table2-paginator.min': './packages/react-bootstrap-table2-paginator/index.js'
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: path.join(__dirname, '../packages'),
|
||||||
|
filename: '[name].js',
|
||||||
|
library: 'ReactBootstrapTable2Paginator',
|
||||||
|
libraryTarget: 'umd'
|
||||||
|
}
|
||||||
|
};
|
||||||
45
webpack/webpack.umd.babel.js
Normal file
45
webpack/webpack.umd.babel.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import webpack from 'webpack';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
devtool: 'source-map',
|
||||||
|
externals: [{
|
||||||
|
'react': {
|
||||||
|
root: 'React',
|
||||||
|
commonjs2: 'react',
|
||||||
|
commonjs: 'react',
|
||||||
|
amd: 'react'
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
'react-dom': {
|
||||||
|
root: 'ReactDOM',
|
||||||
|
commonjs2: 'react-dom',
|
||||||
|
commonjs: 'react-dom',
|
||||||
|
amd: 'react-dom'
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
module: {
|
||||||
|
rules: [{
|
||||||
|
enforce: 'pre',
|
||||||
|
test: /\.js?$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
loader: 'eslint-loader'
|
||||||
|
}, {
|
||||||
|
test: /\.js?$/,
|
||||||
|
use: ['babel-loader'],
|
||||||
|
exclude: /node_modules/
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
'process.env.NODE_ENV': JSON.stringify('production')
|
||||||
|
}),
|
||||||
|
new webpack.SourceMapDevToolPlugin(),
|
||||||
|
new webpack.optimize.DedupePlugin(),
|
||||||
|
new webpack.optimize.OccurrenceOrderPlugin(),
|
||||||
|
new webpack.optimize.AggressiveMergingPlugin(),
|
||||||
|
new webpack.optimize.UglifyJsPlugin({
|
||||||
|
include: /\.min\.js$/,
|
||||||
|
compress: { warnings: false }
|
||||||
|
})
|
||||||
|
]
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user