Skip to content

Commit 7ee38a6

Browse files
authored
Merge pull request #608 from react-bootstrap-table/develop
20181014 release
2 parents 532581b + 01ec193 commit 7ee38a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3777
-2723
lines changed

docs/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* [hover](#hover)
1818
* [condensed](#condensed)
1919
* [id](#id)
20+
* [tabIndexCell](#tabIndexCell)
2021
* [classes](#classes)
2122
* [wrapperClasses](#wrapperClasses)
2223
* [headerClasses](#headerClasses)
@@ -112,6 +113,10 @@ Same as bootstrap `.table-condensed` class for making a table more compact by cu
112113

113114
### <a name='id'>id - [String]</a>
114115
Customize id on `table` element.
116+
117+
### <a name='tabIndexCell'>tabIndexCell - [Bool]</a>
118+
Enable the `tabIndex` attribute on `<td>` element.
119+
115120
### <a name='classes'>classes - [String]</a>
116121
Customize class on `table` element.
117122

docs/row-expand.md

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* [onExpandAll](#onExpandAll)
1515
* [showExpandColumn](#showExpandColumn)
1616
* [onlyOneExpanding](#onlyOneExpanding)
17+
* [expandByColumnOnly](#expandByColumnOnly)
1718
* [expandColumnRenderer](#expandColumnRenderer)
1819
* [expandHeaderColumnRenderer](#expandHeaderColumnRenderer)
1920

@@ -138,3 +139,14 @@ const expandRow = {
138139
onlyOneExpanding: true
139140
};
140141
```
142+
143+
### <a name='expandByColumnOnly'>expandRow.expandByColumnOnly - [Bool]</a>
144+
Default is `false`. If you want to restrict user to expand/collapse row via clicking the expand column only, you can enable it.
145+
146+
```js
147+
const expandRow = {
148+
renderer: (row) => ...,
149+
showExpandColumn: true,
150+
expandByColumnOnly: true
151+
};
152+
```

docs/row-selection.md

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [bgColor](#bgColor)
1313
* [nonSelectable)](#nonSelectable)
1414
* [clickToSelect)](#clickToSelect)
15+
* [clickToExpand)](#clickToExpand)
1516
* [clickToEdit](#clickToEdit)
1617
* [onSelect](#onSelect)
1718
* [onSelectAll](#onSelectAll)
@@ -148,6 +149,16 @@ const selectRow = {
148149
> Note: When you also enable [cellEdit](./cell-edit.md), the `selectRow.clickToSelect` will deactivate the functionality of cell editing
149150
> If you want to click on row to select row and edit cell simultaneously, you are suppose to enable [`selectRow.clickToEdit`](#clickToEdit)
150151
152+
### <a name='clickToExpand'>selectRow.clickToExpand - [Bool]</a>
153+
Default is false, enable it will let user able to expand and select row when user clicking on the row.
154+
155+
```js
156+
const selectRow = {
157+
mode: 'checkbox',
158+
clickToExpand: true
159+
};
160+
```
161+
151162
### <a name='clickToEdit'>selectRow.clickToEdit - [Bool]</a>
152163
Able to click to edit cell and select row
153164

enzyme-setup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Adapter from 'enzyme-adapter-react-16';
1+
import Adapter from 'enzyme-adapter-react-16.3';
22
import { configure } from 'enzyme';
33

44
const configureEnzyme = () => {

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
"babel-preset-stage-0": "6.24.1",
5151
"babel-register": "6.24.1",
5252
"css-loader": "0.28.1",
53-
"enzyme": "3.3.0",
54-
"enzyme-adapter-react-16": "1.1.1",
53+
"enzyme": "3.4.0",
54+
"enzyme-adapter-react-16.3": "1.0.0",
5555
"enzyme-to-json": "3.3.4",
5656
"eslint": "4.5.0",
5757
"eslint-config-airbnb": "15.1.0",
@@ -82,8 +82,8 @@
8282
"dependencies": {
8383
"classnames": "2.2.5",
8484
"prop-types": "15.5.10",
85-
"react": "16.3.2",
86-
"react-dom": "16.3.2",
85+
"react": "16.4.0",
86+
"react-dom": "16.4.0",
8787
"underscore": "1.9.1"
8888
},
8989
"jest": {

packages/react-bootstrap-table2-editor/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import createContext from './src/context';
2-
import editingCellFactory from './src/editing-cell';
2+
import withRowLevelCellEdit from './src/row-consumer';
3+
import createEditingCell from './src/editing-cell-consumer';
34
import {
45
EDITTYPE,
5-
CLICK_TO_CELL_EDIT,
66
DBCLICK_TO_CELL_EDIT,
77
DELAY_FOR_DBCLICK
88
} from './src/const';
99

1010
export default (options = {}) => ({
1111
createContext,
12-
editingCellFactory,
13-
CLICK_TO_CELL_EDIT,
12+
createEditingCell,
13+
withRowLevelCellEdit,
1414
DBCLICK_TO_CELL_EDIT,
1515
DELAY_FOR_DBCLICK,
1616
options

packages/react-bootstrap-table2-editor/src/context.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import React from 'react';
44
import PropTypes from 'prop-types';
55
import { CLICK_TO_CELL_EDIT, DBCLICK_TO_CELL_EDIT } from './const';
66

7+
const CellEditContext = React.createContext();
8+
79
export default (
810
_,
911
dataOperator,
1012
isRemoteCellEdit,
1113
handleCellChange
1214
) => {
13-
let EditingCell;
14-
const CellEditContext = React.createContext();
15-
1615
class CellEditProvider extends React.Component {
1716
static propTypes = {
1817
data: PropTypes.array.isRequired,
@@ -32,7 +31,6 @@ export default (
3231

3332
constructor(props) {
3433
super(props);
35-
EditingCell = props.cellEdit.editingCellFactory(_, props.cellEdit.options.onStartEdit);
3634
this.startEditing = this.startEditing.bind(this);
3735
this.escapeEditing = this.escapeEditing.bind(this);
3836
this.completeEditing = this.completeEditing.bind(this);
@@ -102,8 +100,6 @@ export default (
102100
const {
103101
cellEdit: {
104102
options: { nonEditableRows, errorMessage, ...optionsRest },
105-
editingCellFactory,
106-
createContext,
107103
...cellEditRest
108104
}
109105
} = this.props;
@@ -112,7 +108,6 @@ export default (
112108
...optionsRest,
113109
...cellEditRest,
114110
...this.state,
115-
EditingCell,
116111
nonEditableRows: _.isDefined(nonEditableRows) ? nonEditableRows() : [],
117112
onStart: this.startEditing,
118113
onEscape: this.escapeEditing,
@@ -121,15 +116,16 @@ export default (
121116

122117
return (
123118
<CellEditContext.Provider
124-
value={ { cellEdit: newCellEdit } }
119+
value={ { ...newCellEdit } }
125120
>
126121
{ this.props.children }
127122
</CellEditContext.Provider>
128123
);
129124
}
130125
}
131126
return {
132-
Provider: CellEditProvider,
133-
Consumer: CellEditContext.Consumer
127+
Provider: CellEditProvider
134128
};
135129
};
130+
131+
export const Consumer = CellEditContext.Consumer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* eslint react/prop-types: 0 */
2+
import React from 'react';
3+
import { Consumer } from './context';
4+
import createEditingCell from './editing-cell';
5+
6+
export default (_, onStartEdit) => {
7+
const EditingCell = createEditingCell(_, onStartEdit);
8+
const renderWithEditingCell = (props, cellEdit) => {
9+
const content = _.get(props.row, props.column.dataField);
10+
let editCellstyle = props.column.editCellStyle || {};
11+
let editCellclasses = props.column.editCellClasses;
12+
if (_.isFunction(props.column.editCellStyle)) {
13+
editCellstyle = props.column.editCellStyle(
14+
content,
15+
props.row,
16+
props.rowIndex,
17+
props.columnIndex
18+
);
19+
}
20+
if (_.isFunction(props.column.editCellClasses)) {
21+
editCellclasses = props.column.editCellClasses(
22+
content,
23+
props.row,
24+
props.rowIndex,
25+
props.columnIndex)
26+
;
27+
}
28+
29+
return (
30+
<EditingCell
31+
{ ...props }
32+
className={ editCellclasses }
33+
style={ editCellstyle }
34+
{ ...cellEdit }
35+
/>
36+
);
37+
};
38+
39+
return props => (
40+
<Consumer>
41+
{ cellEdit => renderWithEditingCell(props, cellEdit) }
42+
</Consumer>
43+
);
44+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* eslint react/prop-types: 0 */
2+
import React from 'react';
3+
import { DELAY_FOR_DBCLICK, DBCLICK_TO_CELL_EDIT, CLICK_TO_CELL_EDIT } from './const';
4+
import { Consumer } from './context';
5+
6+
export default (Component, selectRowEnabled) => {
7+
const renderWithCellEdit = (props, cellEdit) => {
8+
const key = props.value;
9+
const editableRow = !(
10+
cellEdit.nonEditableRows.length > 0 &&
11+
cellEdit.nonEditableRows.indexOf(key) > -1
12+
);
13+
14+
const attrs = {};
15+
16+
if (selectRowEnabled && cellEdit.mode === DBCLICK_TO_CELL_EDIT) {
17+
attrs.DELAY_FOR_DBCLICK = DELAY_FOR_DBCLICK;
18+
}
19+
20+
return (
21+
<Component
22+
{ ...props }
23+
{ ...attrs }
24+
editingRowIdx={ cellEdit.ridx }
25+
editingColIdx={ cellEdit.cidx }
26+
editable={ editableRow }
27+
onStart={ cellEdit.onStart }
28+
clickToEdit={ cellEdit.mode === CLICK_TO_CELL_EDIT }
29+
dbclickToEdit={ cellEdit.mode === DBCLICK_TO_CELL_EDIT }
30+
/>
31+
);
32+
};
33+
function withConsumer(props) {
34+
return (
35+
<Consumer>
36+
{ cellEdit => renderWithCellEdit(props, cellEdit) }
37+
</Consumer>
38+
);
39+
}
40+
41+
withConsumer.displayName = 'WithCellEditingRowConsumer';
42+
return withConsumer;
43+
};

packages/react-bootstrap-table2-editor/test/context.test.js

+9-24
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import React from 'react';
33
import { shallow } from 'enzyme';
44
import _ from 'react-bootstrap-table-next/src/utils';
55
import dataOperator from 'react-bootstrap-table-next/src/store/operators';
6-
import BootstrapTable from 'react-bootstrap-table-next/src/bootstrap-table';
76

87
import {
98
CLICK_TO_CELL_EDIT,
109
DBCLICK_TO_CELL_EDIT,
1110
DELAY_FOR_DBCLICK
1211
} from '../src/const';
13-
import createCellEditContext from '../src/context';
12+
import createCellEditContext, { Consumer } from '../src/context';
1413
import cellEditFactory from '../index';
1514

1615
describe('CellEditContext', () => {
@@ -42,14 +41,7 @@ describe('CellEditContext', () => {
4241

4342
const defaultSelectRow = undefined;
4443

45-
const mockBase = jest.fn((props => (
46-
<BootstrapTable
47-
data={ data }
48-
columns={ columns }
49-
keyField={ keyField }
50-
{ ...props }
51-
/>
52-
)));
44+
const mockBase = jest.fn((() => null));
5345

5446
const handleCellChange = jest.fn();
5547

@@ -75,11 +67,11 @@ describe('CellEditContext', () => {
7567
selectRow={ selectRow }
7668
data={ data }
7769
>
78-
<CellEditContext.Consumer>
70+
<Consumer>
7971
{
8072
cellEditProps => mockBase(cellEditProps)
8173
}
82-
</CellEditContext.Consumer>
74+
</Consumer>
8375
</CellEditContext.Provider>
8476
);
8577
}
@@ -94,10 +86,6 @@ describe('CellEditContext', () => {
9486
expect(CellEditContext.Provider).toBeDefined();
9587
});
9688

97-
it('should have correct Consumer property after calling createCellEditContext', () => {
98-
expect(CellEditContext.Consumer).toBeDefined();
99-
});
100-
10189
it('should have correct state.ridx', () => {
10290
expect(wrapper.state().ridx).toBeNull();
10391
});
@@ -113,14 +101,11 @@ describe('CellEditContext', () => {
113101
it('should pass correct cell editing props to children element', () => {
114102
expect(wrapper.length).toBe(1);
115103
expect(JSON.stringify(mockBase.mock.calls[0])).toEqual(JSON.stringify([{
116-
cellEdit: {
117-
...defaultCellEdit,
118-
CLICK_TO_CELL_EDIT,
119-
DBCLICK_TO_CELL_EDIT,
120-
DELAY_FOR_DBCLICK,
121-
...wrapper.state(),
122-
nonEditableRows: []
123-
}
104+
...defaultCellEdit,
105+
DBCLICK_TO_CELL_EDIT,
106+
DELAY_FOR_DBCLICK,
107+
...wrapper.state(),
108+
nonEditableRows: []
124109
}]));
125110
});
126111
});

0 commit comments

Comments
 (0)