Skip to content
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

Open
wants to merge 11 commits into
base: column-virtualization
Choose a base branch
from
12,680 changes: 12,680 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions src/FixedDataCellGroupFunction.js
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;
Copy link
Author

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

44 changes: 44 additions & 0 deletions src/FixedDataCellGroupLegacyFunction.js
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;
Copy link
Author

Choose a reason for hiding this comment

The 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

4 changes: 4 additions & 0 deletions src/FixedDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ class FixedDataTable extends React.Component {
fixedColumnsWidth={this.props.fixedColumnsWidth}
fixedRightColumnsWidth={this.props.fixedRightColumnsWidth}
isGroupHeader={true}
shouldUseLegacyComponents={this.props.shouldUseLegacyComponents}
/>
);
}
Expand Down Expand Up @@ -923,6 +924,7 @@ class FixedDataTable extends React.Component {
endViewportColumnIndex={this.props.endColumnIndex}
fixedColumnsWidth={this.props.fixedColumnsWidth}
fixedRightColumnsWidth={this.props.fixedRightColumnsWidth}
shouldUseLegacyComponents={this.props.shouldUseLegacyComponents}
/>
);
}
Expand Down Expand Up @@ -976,6 +978,7 @@ class FixedDataTable extends React.Component {
fixedRightColumnsWidth={this.props.fixedRightColumnsWidth}
firstViewportColumnIndex={this.props.firstColumnIndex}
endViewportColumnIndex={this.props.endColumnIndex}
shouldUseLegacyComponents={this.props.shouldUseLegacyComponents}
/>
);

Expand Down Expand Up @@ -1123,6 +1126,7 @@ class FixedDataTable extends React.Component {
fixedRightColumnsWidth={this.props.fixedRightColumnsWidth}
scrollbarYWidth={props.scrollbarYWidth}
isRTL={props.isRTL}
shouldUseLegacyComponents={this.props.shouldUseLegacyComponents}
/>
);
};
Expand Down
2 changes: 2 additions & 0 deletions src/FixedDataTableBufferedRows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
/>
);
}
}
//}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to pass shouldUseLegacyComponents to wherever needed

export default FixedDataTableBufferedRows;
115 changes: 29 additions & 86 deletions src/FixedDataTableCellGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -59,6 +59,8 @@ class FixedDataTableCellGroupImpl extends React.Component {

isHeaderOrFooter: PropTypes.bool,

offsetLeft: PropTypes.number,

isRTL: PropTypes.bool,

/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Copy link
Author

Choose a reason for hiding this comment

The 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}
/>
);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we have to render CellGroupComponent

}

Expand Down Expand Up @@ -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}
Expand All @@ -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;
1 change: 1 addition & 0 deletions src/FixedDataTableContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class FixedDataTableContainer extends React.Component {
defaultScrollbars: true,
scrollbarXHeight: Scrollbar.SIZE,
scrollbarYWidth: Scrollbar.SIZE,
shouldUseLegacyComponents: false,
};

constructor(props) {
Expand Down
Loading