Skip to content

Commit dc9903c

Browse files
feat(react-grid): add components for the TableGroupRow plugin (#520)
1 parent f5bd4e0 commit dc9903c

File tree

9 files changed

+85
-20
lines changed

9 files changed

+85
-20
lines changed

packages/dx-react-grid-bootstrap3/src/plugins/table-group-row.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export class TableGroupRow extends React.PureComponent {
2929
}
3030
}
3131

32+
TableGroupRow.Row = TableRow;
33+
TableGroupRow.Cell = TableGroupCell;
34+
3235
TableGroupRow.propTypes = {
3336
groupRowTemplate: PropTypes.func,
3437
groupCellTemplate: PropTypes.func,

packages/dx-react-grid-bootstrap3/src/templates/table-group-row-cell.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ const handleMouseDown = (e) => { e.target.style.outline = 'none'; };
88
const handleBlur = (e) => { e.target.style.outline = ''; };
99

1010
export const TableGroupCell = ({
11-
style, colSpan, row, column, isExpanded, toggleGroupExpanded, children,
11+
style, colSpan, row, column,
12+
isExpanded, toggleGroupExpanded,
13+
children, tableRow, tableColumn,
14+
...restProps
1215
}) => {
1316
const handleClick = () => toggleGroupExpanded();
1417
const handleKeyDown = (e) => {
@@ -27,6 +30,7 @@ export const TableGroupCell = ({
2730
...style,
2831
}}
2932
onClick={handleClick}
33+
{...restProps}
3034
>
3135
<i
3236
className={`glyphicon glyphicon-triangle-${isExpanded ? 'bottom' : 'right'}`}
@@ -57,6 +61,8 @@ TableGroupCell.propTypes = {
5761
PropTypes.node,
5862
PropTypes.arrayOf(PropTypes.node),
5963
]),
64+
tableRow: PropTypes.object,
65+
tableColumn: PropTypes.object,
6066
};
6167

6268
TableGroupCell.defaultProps = {
@@ -67,4 +73,6 @@ TableGroupCell.defaultProps = {
6773
isExpanded: false,
6874
toggleGroupExpanded: () => {},
6975
children: undefined,
76+
tableRow: undefined,
77+
tableColumn: undefined,
7078
};

packages/dx-react-grid-bootstrap3/src/templates/table-group-row-cell.test.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { mount } from 'enzyme';
2+
import { mount, shallow } from 'enzyme';
33
import { setupConsole } from '@devexpress/dx-testing';
44
import { TableGroupCell } from './table-group-row-cell';
55

@@ -71,4 +71,13 @@ describe('TableCell', () => {
7171
expect(toggleGroupExpanded)
7272
.not.toHaveBeenCalled();
7373
});
74+
75+
it('should pass rest props to the root element', () => {
76+
const tree = shallow((
77+
<TableGroupCell className="custom-class" />
78+
));
79+
80+
expect(tree.is('.custom-class'))
81+
.toBeTruthy();
82+
});
7483
});

packages/dx-react-grid-bootstrap3/src/templates/table-row.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33

44
export const TableRow = ({
5-
children,
6-
style,
7-
tableRow,
5+
children, style,
6+
row, tableRow, tableColumn,
87
...restProps
98
}) => (
109
<tr
@@ -18,11 +17,15 @@ export const TableRow = ({
1817
TableRow.propTypes = {
1918
children: PropTypes.node,
2019
style: PropTypes.object,
20+
row: PropTypes.object,
21+
tableColumn: PropTypes.object,
2122
tableRow: PropTypes.object,
2223
};
2324

2425
TableRow.defaultProps = {
2526
children: null,
2627
style: null,
28+
row: undefined,
29+
tableColumn: undefined,
2730
tableRow: undefined,
2831
};

packages/dx-react-grid-material-ui/src/plugins/table-group-row.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export class TableGroupRow extends React.PureComponent {
2929
}
3030
}
3131

32+
TableGroupRow.Row = TableRow;
33+
TableGroupRow.Cell = TableGroupCell;
34+
3235
TableGroupRow.propTypes = {
3336
groupRowTemplate: PropTypes.func,
3437
groupCellTemplate: PropTypes.func,

packages/dx-react-grid-material-ui/src/templates/table-group-row-cell.jsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import classNames from 'classnames';
34
import ChevronRight from 'material-ui-icons/ChevronRight';
45
import ExpandMore from 'material-ui-icons/ExpandMore';
56
import IconButton from 'material-ui/IconButton';
@@ -29,23 +30,22 @@ const styles = theme => ({
2930
});
3031

3132
const TableGroupCellBase = ({
32-
style,
33-
colSpan,
34-
row,
35-
column,
36-
isExpanded,
33+
style, colSpan, row,
34+
column, isExpanded,
3735
toggleGroupExpanded,
38-
classes,
39-
children,
36+
classes, children,
37+
className, tableRow,
38+
tableColumn, ...restProps
4039
}) => {
4140
const handleClick = () => toggleGroupExpanded();
4241

4342
return (
4443
<TableCell
4544
colSpan={colSpan}
4645
style={style}
47-
className={classes.cell}
46+
className={classNames(classes.cell, className)}
4847
onClick={handleClick}
48+
{...restProps}
4949
>
5050
<IconButton
5151
className={classes.groupButton}
@@ -76,6 +76,9 @@ TableGroupCellBase.propTypes = {
7676
PropTypes.node,
7777
PropTypes.arrayOf(PropTypes.node),
7878
]),
79+
className: PropTypes.string,
80+
tableRow: PropTypes.object,
81+
tableColumn: PropTypes.object,
7982
};
8083

8184
TableGroupCellBase.defaultProps = {
@@ -86,6 +89,9 @@ TableGroupCellBase.defaultProps = {
8689
isExpanded: false,
8790
toggleGroupExpanded: () => {},
8891
children: undefined,
92+
className: undefined,
93+
tableRow: undefined,
94+
tableColumn: undefined,
8995
};
9096

9197
export const TableGroupCell = withStyles(styles, { name: 'TableGroupCell' })(TableGroupCellBase);

packages/dx-react-grid-material-ui/src/templates/table-group-row-cell.test.jsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import React from 'react';
2-
import { createMount, createShallow } from 'material-ui/test-utils';
3-
import { Table, TableCell } from 'material-ui';
2+
import { createMount, createShallow, getClasses } from 'material-ui/test-utils';
3+
import { TableCell } from 'material-ui';
44
import { setupConsole } from '@devexpress/dx-testing';
55
import { TableGroupCell } from './table-group-row-cell';
66

77
describe('TableCell', () => {
88
let resetConsole;
99
let mount;
1010
let shallow;
11+
let classes;
1112
beforeAll(() => {
13+
classes = getClasses(<TableGroupCell />);
1214
resetConsole = setupConsole({ ignore: ['validateDOMNesting'] });
13-
const mountMUI = createMount();
1415
shallow = createShallow({ dive: true });
15-
mount = component => mountMUI(<Table>{component}</Table>);
16+
mount = createMount({ context: { table: {} }, childContextTypes: { table: () => null } });
1617
});
1718

1819
afterAll(() => {
@@ -64,4 +65,24 @@ describe('TableCell', () => {
6465
expect(toggleGroupExpanded)
6566
.toHaveBeenCalled();
6667
});
68+
69+
it('should pass the className prop to the root element', () => {
70+
const tree = shallow((
71+
<TableGroupCell className="custom-class" />
72+
));
73+
74+
expect(tree.is('.custom-class'))
75+
.toBeTruthy();
76+
expect(tree.is(`.${classes.cell}`))
77+
.toBeTruthy();
78+
});
79+
80+
it('should pass rest props to the root element', () => {
81+
const tree = shallow((
82+
<TableGroupCell data={{ a: 1 }} />
83+
));
84+
85+
expect(tree.props().data)
86+
.toMatchObject({ a: 1 });
87+
});
6788
});

packages/dx-react-grid-material-ui/src/templates/table-row.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import PropTypes from 'prop-types';
33
import { TableRow as TableRowMUI } from 'material-ui';
44

55
export const TableRow = ({
6-
children,
7-
style,
8-
tableRow,
6+
children, style,
7+
row, tableRow, tableColumn,
98
...restProps
109
}) => (
1110
<TableRowMUI
@@ -19,11 +18,15 @@ export const TableRow = ({
1918
TableRow.propTypes = {
2019
children: PropTypes.node,
2120
style: PropTypes.object,
21+
row: PropTypes.object,
2222
tableRow: PropTypes.object,
23+
tableColumn: PropTypes.object,
2324
};
2425

2526
TableRow.defaultProps = {
2627
children: null,
2728
style: null,
29+
row: undefined,
2830
tableRow: undefined,
31+
tableColumn: undefined,
2932
};

packages/dx-react-grid/docs/reference/table-group-row.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ Field | Type | Description
7474
key | number &#124; string | The current group key.
7575
value | any | The current group value.
7676

77+
## Plugin Components
78+
79+
Name | Properties | Description
80+
-----|------------|------------
81+
TableGroupRow.Row | [GroupRowArgs](#group-row-args) | A component that renders a group row.
82+
TableGroupRow.Cell | [GroupCellArgs](#group-cell-args) | A component that renders a group cell.
83+
84+
If you specify additional properties, they are added to the component's root element.
85+
7786
## Plugin Developer Reference
7887

7988
### Imports

0 commit comments

Comments
 (0)