Skip to content

Commit 94bbd49

Browse files
amanmahajan7malonecj
authored andcommitted
Remove Mixins (Comcast#1078)
* Remove ScrollShim mixin * Convert Canvas to class component * Fix ESLint errors * Add HOC and Keyboard utils * Remove keyboardHandlerMixin from EditorConfig * Convert EditorContainer to a class component * Remove displayName as it is inferred from the name of the class * Add scrollUtils * Remove KeyboardHandlerMixin from ReactDataGrid component * Extract ViewportScrollMixin logic into viewportUtils * Move ViewportScrollMix code to Viewport component * Remove unused flow anotation * Remove GridScrollMixin * Add mising ReactDOM import * Remove ColumnUtilsMixin from HeaderRow component * Convert HeaderRow to a class component * Remove displayName static property * Remove ColumnUtilsMixin from Row component * Revert "Remove displayName static property" This reverts commit e46a22d. * Revert "Convert HeaderRow to a class component" This reverts commit bfd939d. * Revert "Remove displayName as it is inferred from the name of the class" This reverts commit 1858fd0. * Revert "Convert EditorContainer to a class component" This reverts commit e8ce7da. * Revert "Fix ESLint errors" This reverts commit 320b843. * Revert "Add scrollUtils" This reverts commit 4c5d43d. * Revert "Convert Canvas to class component" This reverts commit 87521bb. * Add scrollUtils * Remove MetricsComputatorMixin from the Grid component (ReactDataGrid component adds the MetricsComputatorMixin so mixin methods are available to any child component via the context api, it does not need to be added to the Grid component) * Remove MetricsComputatorMixin from ReadDataGrid component * Remove ViewportScrollMixin from Viewport component * Remove ColumnMetricsMixin from ReactDataGrid component * Delete hocUtils as it is not used anywhere * Set _mounted to false on componentWillUnmount * Delete unused mixins * Delete unused getRenderedColumnCount method * Add tests for KeyboardHandlerMixins methods * Use ref instead of React.findDOMNode * Add unit tests for scrollUtils * Add unit tests for viewportUtils * Add unit tests for getRenderedColumnCount * Add unit tests for getNextScrollState * Add unit tests for keyboardUtils * Fix unit tests * Fix cel navigation for locked cells: Check if the node containes the class instead of strict equality
1 parent 6af5e9a commit 94bbd49

22 files changed

+751
-776
lines changed

packages/react-data-grid/src/Canvas.js

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
const React = require('react');
22
const createReactClass = require('create-react-class');
3-
const ReactDOM = require('react-dom');
43
const joinClasses = require('classnames');
54
import PropTypes from 'prop-types';
6-
const ScrollShim = require('./ScrollShim');
75
const Row = require('./Row');
86
const cellMetaDataShape = require('./PropTypeShapes/CellMetaDataShape');
97
const RowUtils = require('./RowUtils');
8+
import { createScrollShim } from './utils/scrollUtils';
109
require('../../../themes/react-data-grid-core.css');
1110

1211
import shallowEqual from 'fbjs/lib/shallowEqual';
@@ -15,7 +14,6 @@ import RowGroup from './RowGroup';
1514

1615
const Canvas = createReactClass({
1716
displayName: 'Canvas',
18-
mixins: [ScrollShim],
1917

2018
propTypes: {
2119
rowRenderer: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
@@ -67,6 +65,38 @@ const Canvas = createReactClass({
6765
isScrolling: PropTypes.bool
6866
},
6967

68+
appendScrollShim() {
69+
if (!this._scrollShim) {
70+
const size = this._scrollShimSize();
71+
const shim = createScrollShim(size);
72+
this.canvas.appendChild(shim);
73+
this._scrollShim = shim;
74+
}
75+
this._scheduleRemoveScrollShim();
76+
},
77+
78+
_scrollShimSize(): { width: number; height: number } {
79+
return {
80+
width: this.props.width,
81+
height: this.props.length * this.props.rowHeight
82+
};
83+
},
84+
85+
_scheduleRemoveScrollShim() {
86+
if (this._scheduleRemoveScrollShimTimer) {
87+
clearTimeout(this._scheduleRemoveScrollShimTimer);
88+
}
89+
this._scheduleRemoveScrollShimTimer = setTimeout(
90+
this._removeScrollShim, 200);
91+
},
92+
93+
_removeScrollShim() {
94+
if (this._scrollShim) {
95+
this._scrollShim.parentNode.removeChild(this._scrollShim);
96+
this._scrollShim = undefined;
97+
}
98+
},
99+
70100
getDefaultProps() {
71101
return {
72102
rowRenderer: Row,
@@ -136,7 +166,7 @@ const Canvas = createReactClass({
136166
this.setScrollLeft(this._scroll.scrollLeft);
137167
}
138168
if (this.props.scrollToRowIndex !== 0) {
139-
this.div.scrollTop = Math.min(
169+
this.canvas.scrollTop = Math.min(
140170
this.props.scrollToRowIndex * this.props.rowHeight,
141171
this.props.rowsCount * this.props.rowHeight - this.props.height
142172
);
@@ -152,7 +182,7 @@ const Canvas = createReactClass({
152182
},
153183

154184
onScroll(e: any) {
155-
if (ReactDOM.findDOMNode(this) !== e.target) {
185+
if (this.canvas !== e.target) {
156186
return;
157187
}
158188
this.appendScrollShim();
@@ -183,15 +213,13 @@ const Canvas = createReactClass({
183213
},
184214

185215
getScrollbarWidth() {
186-
let scrollbarWidth = 0;
187216
// Get the scrollbar width
188-
let canvas = ReactDOM.findDOMNode(this);
189-
scrollbarWidth = canvas.offsetWidth - canvas.clientWidth;
217+
const scrollbarWidth = this.canvas.offsetWidth - this.canvas.clientWidth;
190218
return scrollbarWidth;
191219
},
192220

193221
getScroll() {
194-
let {scrollTop, scrollLeft} = ReactDOM.findDOMNode(this);
222+
const { scrollTop, scrollLeft } = this.canvas;
195223
return { scrollTop, scrollLeft };
196224
},
197225

@@ -207,7 +235,7 @@ const Canvas = createReactClass({
207235

208236
// Else use new rowSelection props
209237
if (this.props.rowSelection) {
210-
let {keys, indexes, isSelectedKey} = this.props.rowSelection;
238+
let { keys, indexes, isSelectedKey } = this.props.rowSelection;
211239
return RowUtils.isRowSelected(keys, indexes, isSelectedKey, row, idx);
212240
}
213241

@@ -255,7 +283,7 @@ const Canvas = createReactClass({
255283
}
256284
let RowsRenderer = this.props.rowRenderer;
257285
if (typeof RowsRenderer === 'function') {
258-
return <RowsRenderer {...props}/>;
286+
return <RowsRenderer {...props} />;
259287
}
260288

261289
if (React.isValidElement(this.props.rowRenderer)) {
@@ -266,7 +294,7 @@ const Canvas = createReactClass({
266294
renderPlaceholder(key: string, height: number): ?ReactElement {
267295
// just renders empty cells
268296
// if we wanted to show gridlines, we'd need classes and position as with renderScrollingPlaceholder
269-
return (<div key={ key } style={{ height: height }}>
297+
return (<div key={key} style={{ height: height }}>
270298
{
271299
this.props.columns.map(
272300
(column, idx) => <div style={{ width: column.width }} key={idx} />
@@ -325,10 +353,10 @@ const Canvas = createReactClass({
325353

326354
return (
327355
<div
328-
ref={(div) => {this.div = div;}}
356+
ref={(div) => { this.canvas = div; }}
329357
style={style}
330358
onScroll={this.onScroll}
331-
className={joinClasses('react-grid-Canvas', this.props.className, { opaque: this.props.cellMetaData.selected && this.props.cellMetaData.selected.active }) }>
359+
className={joinClasses('react-grid-Canvas', this.props.className, { opaque: this.props.cellMetaData.selected && this.props.cellMetaData.selected.active })}>
332360
<RowsContainer
333361
width={this.props.width}
334362
rows={rows}

packages/react-data-grid/src/Cell.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ class Cell extends React.Component {
377377
};
378378

379379
isFocusedOnCell = () => {
380-
return document.activeElement && document.activeElement.className === 'react-grid-Cell';
380+
return document.activeElement && document.activeElement.className.indexOf('react-grid-Cell') !== -1;
381381
};
382382

383383
checkFocus = () => {

packages/react-data-grid/src/ColumnMetricsMixin.js

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)