mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
compute row height on-the-fly
This commit is contained in:
committed by
Marliana Lara
parent
474a2a48bb
commit
40560e962f
@@ -1,5 +1,10 @@
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { List, AutoSizer } from 'react-virtualized';
|
import {
|
||||||
|
AutoSizer,
|
||||||
|
CellMeasurer,
|
||||||
|
CellMeasurerCache,
|
||||||
|
List,
|
||||||
|
} from 'react-virtualized';
|
||||||
|
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { CardBody } from '@patternfly/react-core';
|
import { CardBody } from '@patternfly/react-core';
|
||||||
@@ -46,12 +51,18 @@ class JobOutput extends Component {
|
|||||||
stopIndex: 0,
|
stopIndex: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.cache = new CellMeasurerCache({
|
||||||
|
fixedWidth: true,
|
||||||
|
defaultHeight: 25,
|
||||||
|
});
|
||||||
|
|
||||||
this.loadJobEvents = this.loadJobEvents.bind(this);
|
this.loadJobEvents = this.loadJobEvents.bind(this);
|
||||||
this.renderRow = this.renderRow.bind(this);
|
this.renderRow = this.renderRow.bind(this);
|
||||||
this.handleScrollTop = this.handleScrollTop.bind(this);
|
this.handleScrollTop = this.handleScrollTop.bind(this);
|
||||||
this.handleScrollBottom = this.handleScrollBottom.bind(this);
|
this.handleScrollBottom = this.handleScrollBottom.bind(this);
|
||||||
this.handleScrollNext = this.handleScrollNext.bind(this);
|
this.handleScrollNext = this.handleScrollNext.bind(this);
|
||||||
this.handleScrollPrevious = this.handleScrollPrevious.bind(this);
|
this.handleScrollPrevious = this.handleScrollPrevious.bind(this);
|
||||||
|
this.handleResize = this.handleResize.bind(this);
|
||||||
this.onRowsRendered = this.onRowsRendered.bind(this);
|
this.onRowsRendered = this.onRowsRendered.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,19 +89,26 @@ class JobOutput extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderRow({ index, key, style }) {
|
renderRow({ index, parent, key, style }) {
|
||||||
const { results } = this.state;
|
const { results } = this.state;
|
||||||
const { created, event, stdout, start_line } = results[index];
|
const { created, event, stdout, start_line } = results[index];
|
||||||
return (
|
return (
|
||||||
<JobEvent
|
<CellMeasurer
|
||||||
className="row"
|
|
||||||
key={key}
|
key={key}
|
||||||
style={style}
|
cache={this.cache}
|
||||||
created={created}
|
parent={parent}
|
||||||
event={event}
|
rowIndex={index}
|
||||||
start_line={start_line}
|
columnIndex={0}
|
||||||
stdout={stdout}
|
>
|
||||||
/>
|
<JobEvent
|
||||||
|
className="row"
|
||||||
|
style={style}
|
||||||
|
created={created}
|
||||||
|
event={event}
|
||||||
|
start_line={start_line}
|
||||||
|
stdout={stdout}
|
||||||
|
/>
|
||||||
|
</CellMeasurer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,6 +136,14 @@ class JobOutput extends Component {
|
|||||||
this.setState({ scrollToIndex: results.length - 1 });
|
this.setState({ scrollToIndex: results.length - 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleResize({ width }) {
|
||||||
|
if (width !== this._previousWidth) {
|
||||||
|
this.cache.clearAll();
|
||||||
|
this.listRef.current.recomputeRowHeights();
|
||||||
|
}
|
||||||
|
this._previousWidth = width;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { job } = this.props;
|
const { job } = this.props;
|
||||||
const {
|
const {
|
||||||
@@ -149,7 +175,7 @@ class JobOutput extends Component {
|
|||||||
/>
|
/>
|
||||||
</OutputToolbar>
|
</OutputToolbar>
|
||||||
<OutputWrapper>
|
<OutputWrapper>
|
||||||
<AutoSizer>
|
<AutoSizer onResize={this.handleResize}>
|
||||||
{({ width, height }) => {
|
{({ width, height }) => {
|
||||||
console.log('scroll to index', scrollToIndex);
|
console.log('scroll to index', scrollToIndex);
|
||||||
console.log('start index', startIndex);
|
console.log('start index', startIndex);
|
||||||
@@ -159,7 +185,8 @@ class JobOutput extends Component {
|
|||||||
ref={this.listRef}
|
ref={this.listRef}
|
||||||
width={width}
|
width={width}
|
||||||
height={height}
|
height={height}
|
||||||
rowHeight={25}
|
deferredMeasurementCache={this.cache}
|
||||||
|
rowHeight={this.cache.rowHeight}
|
||||||
rowRenderer={this.renderRow}
|
rowRenderer={this.renderRow}
|
||||||
rowCount={results.length}
|
rowCount={results.length}
|
||||||
overscanRowCount={50}
|
overscanRowCount={50}
|
||||||
|
|||||||
Reference in New Issue
Block a user