UNPKG

7.5 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6
7var _class, _temp;
8
9import React from 'react';
10import PropTypes from 'prop-types';
11import classnames from 'classnames';
12import { log } from '../../util';
13import Row from '../base/row';
14
15var GroupListRow = (_temp = _class = function (_Row) {
16 _inherits(GroupListRow, _Row);
17
18 function GroupListRow() {
19 _classCallCheck(this, GroupListRow);
20
21 return _possibleConstructorReturn(this, _Row.apply(this, arguments));
22 }
23
24 GroupListRow.prototype.render = function render() {
25 var _classnames;
26
27 /* eslint-disable no-unused-vars*/
28 var _props = this.props,
29 prefix = _props.prefix,
30 className = _props.className,
31 onClick = _props.onClick,
32 onMouseEnter = _props.onMouseEnter,
33 onMouseLeave = _props.onMouseLeave,
34 columns = _props.columns,
35 Cell = _props.Cell,
36 rowIndex = _props.rowIndex,
37 __rowIndex = _props.__rowIndex,
38 record = _props.record,
39 children = _props.children,
40 primaryKey = _props.primaryKey,
41 colGroup = _props.colGroup,
42 cellRef = _props.cellRef,
43 getCellProps = _props.getCellProps,
44 locale = _props.locale,
45 wrapper = _props.wrapper,
46 rtl = _props.rtl,
47 others = _objectWithoutProperties(_props, ['prefix', 'className', 'onClick', 'onMouseEnter', 'onMouseLeave', 'columns', 'Cell', 'rowIndex', '__rowIndex', 'record', 'children', 'primaryKey', 'colGroup', 'cellRef', 'getCellProps', 'locale', 'wrapper', 'rtl']);
48
49 var cls = classnames((_classnames = {}, _classnames[prefix + 'table-row'] = true, _classnames[className] = className, _classnames));
50
51 // clear notRenderCellIndex, incase of cached data
52 this.context.notRenderCellIndex = [];
53
54 return React.createElement(
55 'table',
56 _extends({
57 className: cls,
58 role: 'row'
59 }, others, {
60 onClick: this.onClick,
61 onMouseEnter: this.onMouseEnter,
62 onMouseLeave: this.onMouseLeave
63 }),
64 colGroup,
65 React.createElement(
66 'tbody',
67 null,
68 this.renderContent('header'),
69 this.renderChildren(),
70 this.renderContent('footer')
71 )
72 );
73 };
74
75 GroupListRow.prototype.isChildrenSelection = function isChildrenSelection() {
76 return this.context.listHeader && this.context.listHeader.hasChildrenSelection;
77 };
78
79 GroupListRow.prototype.isFirstLevelDataWhenNoChildren = function isFirstLevelDataWhenNoChildren() {
80 return this.context.listHeader && this.context.listHeader.useFirstLevelDataWhenNoChildren;
81 };
82
83 GroupListRow.prototype.isSelection = function isSelection() {
84 return this.context.listHeader && this.context.listHeader.hasSelection;
85 };
86
87 GroupListRow.prototype.renderChildren = function renderChildren() {
88 var _this2 = this;
89
90 var _props2 = this.props,
91 record = _props2.record,
92 primaryKey = _props2.primaryKey;
93 var children = record.children;
94
95
96 var toRenderList = children;
97 if (this.isFirstLevelDataWhenNoChildren()) {
98 log.warning('useFirstLevelDataWhenNoChildren is deprecated, change your dataSource structure, make sure there is \'children\' in your dataSource.');
99
100 toRenderList = children || [record];
101 }
102
103 if (toRenderList) {
104 return toRenderList.map(function (child, index) {
105 var cells = _this2.renderCells(child, index);
106 if (_this2.isChildrenSelection()) {
107 if (!child[primaryKey]) {
108 log.warning('record.children/recored should contains primaryKey when childrenSelection is true.');
109 }
110 return React.createElement(
111 'tr',
112 { key: child[primaryKey] },
113 cells
114 );
115 }
116 if (_this2.context.rowSelection) {
117 cells.shift();
118 cells[0] = cells[0] && React.cloneElement(cells[0], _extends({
119 colSpan: 2
120 }, cells[0].props));
121 }
122 return React.createElement(
123 'tr',
124 { key: index },
125 cells
126 );
127 });
128 }
129 return null;
130 };
131
132 GroupListRow.prototype.renderContent = function renderContent(type) {
133 var _props3 = this.props,
134 columns = _props3.columns,
135 prefix = _props3.prefix,
136 record = _props3.record,
137 rowIndex = _props3.rowIndex;
138
139 var cameType = type.charAt(0).toUpperCase() + type.substr(1);
140 var list = this.context['list' + cameType];
141 var listNode = void 0;
142 if (list) {
143 if (React.isValidElement(list.cell)) {
144 listNode = React.cloneElement(list.cell, {
145 record: record,
146 index: rowIndex
147 });
148 } else if (typeof list.cell === 'function') {
149 listNode = list.cell(record, rowIndex);
150 }
151 if (listNode) {
152 var cells = this.renderCells(record);
153 if (type === 'header' && this.context.rowSelection && this.isSelection()) {
154 cells = cells.slice(0, 1);
155 cells.push(React.createElement(
156 'td',
157 { colSpan: columns.length - 1, key: 'listNode' },
158 React.createElement(
159 'div',
160 { className: prefix + 'table-cell-wrapper' },
161 listNode
162 )
163 ));
164 listNode = React.createElement(
165 'tr',
166 { className: prefix + 'table-group-' + type },
167 cells
168 );
169 } else {
170 listNode = React.createElement(
171 'tr',
172 { className: prefix + 'table-group-' + type },
173 React.createElement(
174 'td',
175 { colSpan: columns.length },
176 React.createElement(
177 'div',
178 { className: prefix + 'table-cell-wrapper' },
179 listNode
180 )
181 )
182 );
183 }
184 }
185 }
186 return listNode;
187 };
188
189 return GroupListRow;
190}(Row), _class.contextTypes = {
191 listHeader: PropTypes.any,
192 listFooter: PropTypes.any,
193 rowSelection: PropTypes.object,
194 notRenderCellIndex: PropTypes.array,
195 lockType: PropTypes.oneOf(['left', 'right'])
196}, _temp);
197export { GroupListRow as default };
\No newline at end of file