-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce dom elements - Approach #3 #682
base: column-virtualization
Are you sure you want to change the base?
Changes from all commits
f7b8628
c4e8c63
fde920c
f475a20
b90f33a
4fe0bc9
4ff2935
51696af
f4af336
31fbf7e
5aabef5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
import FixedDataTableTranslateDOMPosition from './FixedDataTableTranslateDOMPosition'; | ||
import cx from './vendor_upstream/stubs/cx'; | ||
|
||
function CellGroup(props) { | ||
var style = { | ||
height: props.cellGroupWrapperHeight || props.height, | ||
position: 'absolute', | ||
width: props.contentWidth, | ||
zIndex: props.zIndex, | ||
}; | ||
|
||
FixedDataTableTranslateDOMPosition( | ||
style, | ||
-1 * props.left, | ||
0, | ||
props._initialRender, | ||
props.isRTL | ||
); | ||
|
||
if (props.isRTL) { | ||
style.right = props.offsetLeft; | ||
} else { | ||
style.left = props.offsetLeft; | ||
} | ||
return ( | ||
<div | ||
className={cx('fixedDataTableCellGroupLayout/cellGroup')} | ||
style={style} | ||
> | ||
{props.sortedCells} | ||
</div> | ||
); | ||
} | ||
export default CellGroup; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
import FixedDataTableTranslateDOMPosition from './FixedDataTableTranslateDOMPosition'; | ||
import cx from './vendor_upstream/stubs/cx'; | ||
function CellGroupLegacy(props) { | ||
var style1 = { | ||
height: props.cellGroupWrapperHeight || props.height, | ||
width: props.width, | ||
}; | ||
|
||
if (props.isRTL) { | ||
style1.right = props.offsetLeft; | ||
} else { | ||
style1.left = props.offsetLeft; | ||
} | ||
|
||
var style2 = { | ||
height: props.height, | ||
position: 'absolute', | ||
width: props.contentWidth, | ||
zIndex: props.zIndex, | ||
}; | ||
FixedDataTableTranslateDOMPosition( | ||
style2, | ||
-1 * props.left, | ||
0, | ||
props._initialRender, | ||
props.isRTL | ||
); | ||
|
||
return ( | ||
<div | ||
style={style1} | ||
className={cx('fixedDataTableCellGroupLayout/cellGroupWrapper')} | ||
> | ||
<div | ||
className={cx('fixedDataTableCellGroupLayout/cellGroup')} | ||
style={style2} | ||
> | ||
{props.sortedCells} | ||
</div> | ||
</div> | ||
); | ||
} | ||
export default CellGroupLegacy; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the legacy component .Only the difference between legacy and non-legacy is of styling and rendering of the divs |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,8 +228,10 @@ class FixedDataTableBufferedRows extends React.Component { | |
fixedRightColumnsWidth={this.props.fixedRightColumnsWidth} | ||
firstViewportColumnIndex={this.props.firstViewportColumnIndex} | ||
endViewportColumnIndex={this.props.endViewportColumnIndex} | ||
shouldUseLegacyComponents={this.props.shouldUseLegacyComponents} | ||
/> | ||
); | ||
} | ||
} | ||
//} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to pass shouldUseLegacyComponents to wherever needed |
||
export default FixedDataTableBufferedRows; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,13 @@ | |
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import cx from './vendor_upstream/stubs/cx'; | ||
import FixedDataTableCell from './FixedDataTableCell'; | ||
import FixedDataTableTranslateDOMPosition from './FixedDataTableTranslateDOMPosition'; | ||
import _ from 'lodash'; | ||
import inRange from 'lodash/inRange'; | ||
import CellGroup from './FixedDataCellGroupFunction'; | ||
import CellGroupLegacy from './FixedDataCellGroupLegacyFunction'; | ||
|
||
class FixedDataTableCellGroupImpl extends React.Component { | ||
class FixedDataTableCellGroup extends React.Component { | ||
/** | ||
* PropTypes are disabled in this component, because having them on slows | ||
* down the FixedDataTable hugely in DEV mode. You can enable them back for | ||
|
@@ -59,6 +59,8 @@ class FixedDataTableCellGroupImpl extends React.Component { | |
|
||
isHeaderOrFooter: PropTypes.bool, | ||
|
||
offsetLeft: PropTypes.number, | ||
|
||
isRTL: PropTypes.bool, | ||
|
||
/** | ||
|
@@ -114,6 +116,20 @@ class FixedDataTableCellGroupImpl extends React.Component { | |
componentDidMount() { | ||
this._initialRender = false; | ||
} | ||
shouldComponentUpdate(/*object*/ nextProps) /*boolean*/ { | ||
/// if offsets haven't changed for the same cell group while scrolling, then skip update | ||
return !( | ||
nextProps.isScrolling && | ||
this.props.rowIndex === nextProps.rowIndex && | ||
this.props.left === nextProps.left && | ||
this.props.offsetLeft === nextProps.offsetLeft | ||
); | ||
} | ||
|
||
static defaultProps = /*object*/ { | ||
left: 0, | ||
offsetLeft: 0, | ||
}; | ||
|
||
render() /*object*/ { | ||
var props = this.props; | ||
|
@@ -147,32 +163,21 @@ class FixedDataTableCellGroupImpl extends React.Component { | |
this._staticCells[i] = this._renderCell(i, columnIndex); | ||
} | ||
|
||
var style = { | ||
height: props.height, | ||
position: 'absolute', | ||
width: props.contentWidth, | ||
zIndex: props.zIndex, | ||
}; | ||
FixedDataTableTranslateDOMPosition( | ||
style, | ||
-1 * props.left, | ||
0, | ||
this._initialRender, | ||
this.props.isRTL | ||
); | ||
|
||
// NOTE (pradeep): Sort the cells by column index so that they appear with the right order in the DOM (see #221) | ||
const sortedCells = _.sortBy(this._staticCells, (cell) => | ||
_.get(cell, 'props.columnIndex', Infinity) | ||
); | ||
|
||
const CellGroupComponent = this.props.shouldUseLegacyComponents | ||
? CellGroupLegacy | ||
: CellGroup; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we will check that either I have to use the legacy components or the new ones |
||
return ( | ||
<div | ||
className={cx('fixedDataTableCellGroupLayout/cellGroup')} | ||
style={style} | ||
> | ||
{sortedCells} | ||
</div> | ||
<CellGroupComponent | ||
{...props} | ||
_initialRender={this._initialRender} | ||
sortedCells={sortedCells} | ||
/> | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then we have to render CellGroupComponent |
||
} | ||
|
||
|
@@ -207,7 +212,6 @@ class FixedDataTableCellGroupImpl extends React.Component { | |
className={className} | ||
height={this.props.rowHeight} | ||
key={key} | ||
columnIndex={columnIndex} | ||
maxWidth={columnProps.maxWidth} | ||
minWidth={columnProps.minWidth} | ||
touchEnabled={this.props.touchEnabled} | ||
|
@@ -222,71 +226,10 @@ class FixedDataTableCellGroupImpl extends React.Component { | |
isRTL={this.props.isRTL} | ||
visible={visible} | ||
cellGroupType={this.props.cellGroupType} | ||
shouldUseLegacyComponents={this.props.shouldUseLegacyComponents} | ||
/> | ||
); | ||
}; | ||
} | ||
|
||
class FixedDataTableCellGroup extends React.Component { | ||
/** | ||
* PropTypes are disabled in this component, because having them on slows | ||
* down the FixedDataTable hugely in DEV mode. You can enable them back for | ||
* development, but please don't commit this component with enabled propTypes. | ||
*/ | ||
static propTypes_DISABLED_FOR_PERFORMANCE = { | ||
isScrolling: PropTypes.bool, | ||
/** | ||
* Height of the row. | ||
*/ | ||
height: PropTypes.number.isRequired, | ||
|
||
offsetLeft: PropTypes.number, | ||
|
||
left: PropTypes.number, | ||
/** | ||
* Z-index on which the row will be displayed. Used e.g. for keeping | ||
* header and footer in front of other rows. | ||
*/ | ||
zIndex: PropTypes.number.isRequired, | ||
}; | ||
|
||
shouldComponentUpdate(/*object*/ nextProps) /*boolean*/ { | ||
/// if offsets haven't changed for the same cell group while scrolling, then skip update | ||
return !( | ||
nextProps.isScrolling && | ||
this.props.rowIndex === nextProps.rowIndex && | ||
this.props.left === nextProps.left && | ||
this.props.offsetLeft === nextProps.offsetLeft | ||
); | ||
} | ||
|
||
static defaultProps = /*object*/ { | ||
left: 0, | ||
offsetLeft: 0, | ||
}; | ||
|
||
render() /*object*/ { | ||
var { offsetLeft, ...props } = this.props; | ||
|
||
var style = { | ||
height: props.cellGroupWrapperHeight || props.height, | ||
width: props.width, | ||
}; | ||
|
||
if (this.props.isRTL) { | ||
style.right = offsetLeft; | ||
} else { | ||
style.left = offsetLeft; | ||
} | ||
|
||
return ( | ||
<div | ||
style={style} | ||
className={cx('fixedDataTableCellGroupLayout/cellGroupWrapper')} | ||
> | ||
<FixedDataTableCellGroupImpl {...props} /> | ||
</div> | ||
); | ||
} | ||
} | ||
export default FixedDataTableCellGroup; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the CellGroup Function which is the non-legacy component