Skip to content
Snippets Groups Projects
Commit 11545588 authored by piotr.kupczyk@id.ethz.ch's avatar piotr.kupczyk@id.ethz.ch
Browse files

SSDM-12468 : ELN Table : poor performance of value truncating mechanism -...

SSDM-12468 : ELN Table : poor performance of value truncating mechanism - reduce a number of cell state changes
parent f3942c2e
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
...@@ -303,7 +303,7 @@ class Grid extends React.PureComponent { ...@@ -303,7 +303,7 @@ class Grid extends React.PureComponent {
renderRow(row) { renderRow(row) {
const { selectable, multiselectable, onRowClick } = this.props const { selectable, multiselectable, onRowClick } = this.props
const { selectedRow, multiselectedRows } = this.state const { selectedRow, multiselectedRows, heights } = this.state
const visibleColumns = this.controller.getVisibleColumns() const visibleColumns = this.controller.getVisibleColumns()
...@@ -312,6 +312,7 @@ class Grid extends React.PureComponent { ...@@ -312,6 +312,7 @@ class Grid extends React.PureComponent {
key={row.id} key={row.id}
columns={visibleColumns} columns={visibleColumns}
row={row} row={row}
heights={heights[row.id] || {}}
clickable={onRowClick ? true : false} clickable={onRowClick ? true : false}
selectable={selectable} selectable={selectable}
selected={selectedRow ? selectedRow.id === row.id : false} selected={selectedRow ? selectedRow.id === row.id : false}
...@@ -320,6 +321,7 @@ class Grid extends React.PureComponent { ...@@ -320,6 +321,7 @@ class Grid extends React.PureComponent {
onClick={this.controller.handleRowClick} onClick={this.controller.handleRowClick}
onSelect={this.controller.handleRowSelect} onSelect={this.controller.handleRowSelect}
onMultiselect={this.controller.handleRowMultiselect} onMultiselect={this.controller.handleRowMultiselect}
onMeasured={this.controller.handleMeasured}
/> />
) )
} }
......
...@@ -33,8 +33,7 @@ class GridCell extends React.PureComponent { ...@@ -33,8 +33,7 @@ class GridCell extends React.PureComponent {
super(props) super(props)
this.state = { this.state = {
renderMore: false, more: false
moreOpen: false
} }
this.ref = React.createRef() this.ref = React.createRef()
this.handleMoreClick = this.handleMoreClick.bind(this) this.handleMoreClick = this.handleMoreClick.bind(this)
...@@ -42,12 +41,35 @@ class GridCell extends React.PureComponent { ...@@ -42,12 +41,35 @@ class GridCell extends React.PureComponent {
componentDidMount() { componentDidMount() {
this.renderDOMValue() this.renderDOMValue()
this.maybeScheduleRenderMore()
setTimeout(() => {
if (this.ref.current) {
const { column, row, onMeasured } = this.props
const height = this.ref.current.scrollHeight
if (column.truncate && height > TRUNCATE_HEIGHT) {
onMeasured(column, row, height)
}
}
}, 1)
}
componentDidUpdate() {
this.renderDOMValue()
setTimeout(() => {
if (this.ref.current) {
const { column, row, onMeasured } = this.props
const height = this.ref.current.scrollHeight
if (column.truncate && height > TRUNCATE_HEIGHT) {
onMeasured(column, row, height)
}
}
}, 1)
} }
handleMoreClick() { handleMoreClick() {
this.setState(state => ({ this.setState(state => ({
moreOpen: !state.moreOpen more: !state.more
})) }))
} }
...@@ -55,7 +77,7 @@ class GridCell extends React.PureComponent { ...@@ -55,7 +77,7 @@ class GridCell extends React.PureComponent {
logger.log(logger.DEBUG, 'GridCell.render') logger.log(logger.DEBUG, 'GridCell.render')
const { column, className, classes } = this.props const { column, className, classes } = this.props
const { moreOpen } = this.state const { more } = this.state
const cellClasses = [classes.cell] const cellClasses = [classes.cell]
if (className) { if (className) {
...@@ -66,7 +88,7 @@ class GridCell extends React.PureComponent { ...@@ -66,7 +88,7 @@ class GridCell extends React.PureComponent {
if (column.nowrap) { if (column.nowrap) {
divClasses.push(classes.nowrap) divClasses.push(classes.nowrap)
} }
if (column.truncate && !moreOpen) { if (column.truncate && !more) {
divClasses.push(classes.truncate) divClasses.push(classes.truncate)
} }
...@@ -116,31 +138,23 @@ class GridCell extends React.PureComponent { ...@@ -116,31 +138,23 @@ class GridCell extends React.PureComponent {
} }
renderMore() { renderMore() {
const { renderMore, moreOpen } = this.state const { column, height } = this.props
const { more } = this.state
if (!renderMore) { if (!column.truncate) {
return null return
} }
return ( if (height && height > TRUNCATE_HEIGHT) {
<div> return (
<Link onClick={this.handleMoreClick}> <div>
{moreOpen ? messages.get(messages.LESS) : messages.get(messages.MORE)} <Link onClick={this.handleMoreClick}>
</Link> {more ? messages.get(messages.LESS) : messages.get(messages.MORE)}
</div> </Link>
) </div>
} )
} else {
maybeScheduleRenderMore() { return null
const { column } = this.props
if (
column.truncate &&
this.ref.current &&
this.ref.current.scrollHeight > TRUNCATE_HEIGHT
) {
setTimeout(() => {
this.setState({ renderMore: true })
}, 1)
} }
} }
} }
......
...@@ -60,6 +60,7 @@ export default class GridController { ...@@ -60,6 +60,7 @@ export default class GridController {
allRows: [], allRows: [],
selectedRow: null, selectedRow: null,
multiselectedRows: {}, multiselectedRows: {},
heights: {},
sortings: sortings, sortings: sortings,
totalCount: 0, totalCount: 0,
exportOptions: { exportOptions: {
...@@ -1136,6 +1137,26 @@ export default class GridController { ...@@ -1136,6 +1137,26 @@ export default class GridController {
await this._saveSettings() await this._saveSettings()
} }
async handleMeasured(column, row, height) {
if (!this.heights) {
this.heights = {}
}
const rowHeights = this.heights[row.id] || {}
rowHeights[column.name] = height
this.heights[row.id] = rowHeights
if (this.heightsTimeout) {
clearTimeout(this.heightsTimeout)
}
setTimeout(() => {
this.context.setState({
heights: this.heights
})
}, 500)
}
getAllColumns() { getAllColumns() {
const { allColumns, columnsSorting } = this.context.getState() const { allColumns, columnsSorting } = this.context.getState()
......
...@@ -117,7 +117,7 @@ class GridRow extends React.PureComponent { ...@@ -117,7 +117,7 @@ class GridRow extends React.PureComponent {
} }
renderCell(column, columnIndex, row) { renderCell(column, columnIndex, row) {
const { classes } = this.props const { heights, classes } = this.props
const cellClasses = [classes.cell] const cellClasses = [classes.cell]
if (columnIndex === 0) { if (columnIndex === 0) {
...@@ -128,8 +128,10 @@ class GridRow extends React.PureComponent { ...@@ -128,8 +128,10 @@ class GridRow extends React.PureComponent {
<GridCell <GridCell
key={column.name} key={column.name}
row={row} row={row}
height={heights[column.name]}
column={column} column={column}
className={cellClasses.join(' ')} className={cellClasses.join(' ')}
onMeasured={this.props.onMeasured}
/> />
) )
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment