Skip to content

Commit 7588a09

Browse files
committed
Merge commit '410c64b14385c625dac32c4b0b657607fbd10548' into upmerge_to_v1
2 parents a0abd06 + 410c64b commit 7588a09

File tree

7 files changed

+130
-3
lines changed

7 files changed

+130
-3
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ language: node_js
22
node_js:
33
- "7"
44
- "6"
5-
before_script:
6-
- npm install react react-dom
5+
- "5"
6+
- "4"
7+
install:
8+
- yarn install

examples/LongClickExample.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* Copyright Schrodinger, LLC
3+
*/
4+
5+
'use strict';
6+
7+
const FakeObjectDataListStore = require('./helpers/FakeObjectDataListStore');
8+
const { TextCell } = require('./helpers/cells');
9+
const { Table, Column, Cell } = require('fixed-data-table-2');
10+
const React = require('react');
11+
12+
class LongClickExample extends React.Component {
13+
14+
longClickTimer = null;
15+
16+
displayColumns = {
17+
firstName: 'First Name',
18+
lastName: 'Last Name',
19+
city: 'City',
20+
street: 'zipCode',
21+
};
22+
23+
constructor(props) {
24+
super(props);
25+
26+
var dataList = new FakeObjectDataListStore(1000000);
27+
28+
this.state = {
29+
dataList,
30+
columns: this.getColumns(),
31+
longPressedRowIndex: -1,
32+
};
33+
}
34+
35+
handleRowMouseDown(rowIndex) {
36+
this.cancelLongClick();
37+
this.longClickTimer = setTimeout(() => {
38+
this.setState({
39+
longPressedRowIndex: rowIndex
40+
});
41+
}, 1000);
42+
}
43+
44+
handleRowMouseUp() {
45+
this.cancelLongClick();
46+
}
47+
48+
cancelLongClick() {
49+
if (this.longClickTimer) {
50+
clearTimeout(this.longClickTimer);
51+
this.longClickTimer = null;
52+
}
53+
}
54+
55+
getColumns() {
56+
let columns = [];
57+
58+
Object.keys(this.displayColumns).forEach(columnKey => {
59+
columns.push(
60+
<Column
61+
key={columnKey}
62+
columnKey={columnKey}
63+
flexGrow={2}
64+
header={<Cell>{columns[columnKey]}</Cell>}
65+
cell={cell => this.getCell(cell.rowIndex, cell.columnKey)}
66+
width={100}
67+
/>);
68+
});
69+
70+
return columns;
71+
}
72+
73+
getCell(rowIndex, columnKey) {
74+
let isCellHighlighted = this.state.longPressedRowIndex === rowIndex;
75+
76+
let rowStyle = {
77+
backgroundColor: isCellHighlighted ? 'yellow' : 'transparent',
78+
width: '100%',
79+
height: '100%'
80+
}
81+
82+
return <TextCell style={rowStyle}
83+
data={this.state.dataList}
84+
rowIndex={rowIndex}
85+
columnKey={columnKey} />;
86+
}
87+
88+
render() {
89+
return (
90+
<Table
91+
rowHeight={50}
92+
headerHeight={50}
93+
rowsCount={this.state.dataList.getSize()}
94+
width={1000}
95+
height={500}
96+
onRowMouseDown={(event, rowIndex) => { this.handleRowMouseDown(rowIndex); }}
97+
onRowMouseUp={(event, rowIndex) => { this.handleRowMouseUp(rowIndex); }}
98+
{...this.props}>
99+
{this.state.columns}
100+
</Table>
101+
);
102+
}
103+
}
104+
105+
module.exports = LongClickExample;

site/Constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ exports.ExamplePages = {
144144
title: 'Owner Height',
145145
description: 'A table example that displays a table footer sticking to the screen.'
146146
},
147+
LONG_CLICK_EXAMPLE: {
148+
location: 'example-long-click.html',
149+
fileName: 'LongClickExample.js',
150+
title: 'Row Long Click',
151+
description: 'A table example that highlights a row after a long click',
152+
},
147153
CONTEXT_EXAMPLE: {
148154
location: 'example-context.html',
149155
fileName: 'ContextExample.js',

site/examples/ExamplesPage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ var EXAMPLE_COMPONENTS = {
4646
[ExamplePages.FOOTER_EXAMPLE.location]: require('../../examples/FooterExample'),
4747
[ExamplePages.MAX_HEIGHT_EXAMPLE.location]: require('../../examples/MaxHeightExample'),
4848
[ExamplePages.OWNER_HEIGHT_EXAMPLE.location]: require('../../examples/OwnerHeightExample'),
49+
[ExamplePages.LONG_CLICK_EXAMPLE.location]: require('../../examples/LongClickExample'),
4950
[ExamplePages.CONTEXT_EXAMPLE.location]: require('../../examples/ContextExample'),
5051
};
5152

5253
class ExamplesPage extends React.Component {
5354
constructor(props) {
5455
super(props);
55-
56+
5657
this.state = {
5758
renderPage: false
5859
};

src/FixedDataTable.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ class FixedDataTable extends React.Component {
303303
*/
304304
onRowMouseDown: PropTypes.func,
305305

306+
/**
307+
* Callback that is called when a mouse-up event happens on a row.
308+
*/
309+
onRowMouseUp: PropTypes.func,
310+
306311
/**
307312
* Callback that is called when a mouse-enter event happens on a row.
308313
*/
@@ -703,6 +708,7 @@ class FixedDataTable extends React.Component {
703708
offsetTop={offsetTop}
704709
onRowClick={props.onRowClick}
705710
onRowDoubleClick={props.onRowDoubleClick}
711+
onRowMouseUp={props.onRowMouseUp}
706712
onRowMouseDown={props.onRowMouseDown}
707713
onRowMouseEnter={props.onRowMouseEnter}
708714
onRowMouseLeave={props.onRowMouseLeave}

src/FixedDataTableBufferedRows.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class FixedDataTableBufferedRows extends React.Component {
2626
onRowClick: PropTypes.func,
2727
onRowDoubleClick: PropTypes.func,
2828
onRowMouseDown: PropTypes.func,
29+
onRowMouseUp: PropTypes.func,
2930
onRowMouseEnter: PropTypes.func,
3031
onRowMouseLeave: PropTypes.func,
3132
rowClassNameGetter: PropTypes.func,
@@ -118,6 +119,7 @@ class FixedDataTableBufferedRows extends React.Component {
118119
onClick={props.onRowClick}
119120
onDoubleClick={props.onRowDoubleClick}
120121
onMouseDown={props.onRowMouseDown}
122+
onMouseUp={props.onRowMouseUp}
121123
onMouseEnter={props.onRowMouseEnter}
122124
onMouseLeave={props.onRowMouseLeave}
123125
className={joinClasses(

src/FixedDataTableRow.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class FixedDataTableRowImpl extends React.Component {
197197
onClick={this.props.onClick ? this._onClick : null}
198198
onDoubleClick={this.props.onDoubleClick ? this._onDoubleClick : null}
199199
onMouseDown={this.props.onMouseDown ? this._onMouseDown : null}
200+
onMouseUp={this.props.onMouseUp ? this._onMouseUp : null}
200201
onMouseEnter={this.props.onMouseEnter ? this._onMouseEnter : null}
201202
onMouseLeave={this.props.onMouseLeave ? this._onMouseLeave : null}
202203
style={style}>
@@ -271,6 +272,10 @@ class FixedDataTableRowImpl extends React.Component {
271272
this.props.onDoubleClick(event, this.props.index);
272273
};
273274

275+
_onMouseUp = (/*object*/ event) => {
276+
this.props.onMouseUp(event, this.props.index);
277+
};
278+
274279
_onMouseDown = (/*object*/ event) => {
275280
this.props.onMouseDown(event, this.props.index);
276281
};

0 commit comments

Comments
 (0)