diff --git a/packages/jaeger-ui/src/components/TracePage/TraceTimelineViewer/VirtualizedTraceView.test.js b/packages/jaeger-ui/src/components/TracePage/TraceTimelineViewer/VirtualizedTraceView.test.js index d789c48b46..df79107432 100644 --- a/packages/jaeger-ui/src/components/TracePage/TraceTimelineViewer/VirtualizedTraceView.test.js +++ b/packages/jaeger-ui/src/components/TracePage/TraceTimelineViewer/VirtualizedTraceView.test.js @@ -305,7 +305,7 @@ describe('', () => { expect( rowWrapper.containsMatchingElement( , + detailStates: Map +): RowState[] { + return trace ? generateRowStates(trace.spans, childrenHiddenIDs, detailStates) : []; +} + function getCssClasses(currentViewRange: [number, number]) { const [zoomStart, zoomEnd] = currentViewRange; return cx({ @@ -138,28 +148,16 @@ function getCssClasses(currentViewRange: [number, number]) { }); } +const memoizedGenerateRowStates = memoizeOne(generateRowStatesFromTrace); +const memoizedViewBoundsFunc = memoizeOne(createViewedBoundsFunc, _isEqual); +const memoizedGetCssClasses = memoizeOne(getCssClasses, _isEqual); + // export from tests export class VirtualizedTraceViewImpl extends React.Component { - clippingCssClasses: string; listView: ListView | TNil; - rowStates: RowState[]; - getViewedBounds: ViewedBoundsFunctionType; - constructor(props: VirtualizedTraceViewProps) { super(props); - // keep "prop derivations" on the instance instead of calculating in - // `.render()` to avoid recalculating in every invocation of `.renderRow()` - const { currentViewRangeTime, childrenHiddenIDs, detailStates, setTrace, trace, uiFind } = props; - this.clippingCssClasses = getCssClasses(currentViewRangeTime); - const [zoomStart, zoomEnd] = currentViewRangeTime; - this.getViewedBounds = createViewedBoundsFunc({ - min: trace.startTime, - max: trace.endTime, - viewStart: zoomStart, - viewEnd: zoomEnd, - }); - this.rowStates = generateRowStates(trace.spans, childrenHiddenIDs, detailStates); - + const { setTrace, trace, uiFind } = props; setTrace(trace, uiFind); } @@ -180,14 +178,11 @@ export class VirtualizedTraceViewImpl extends React.Component) { - const { childrenHiddenIDs, detailStates, registerAccessors, trace, currentViewRangeTime } = prevProps; + const { registerAccessors, trace } = prevProps; const { shouldScrollToFirstUiFindMatch, clearShouldScrollToFirstUiFindMatch, scrollToFirstVisibleSpan, - currentViewRangeTime: nextViewRangeTime, - childrenHiddenIDs: nextHiddenIDs, - detailStates: nextDetailStates, registerAccessors: nextRegisterAccessors, setTrace, trace: nextTrace, @@ -198,21 +193,6 @@ export class VirtualizedTraceViewImpl extends React.Component { const { trace, focusUiFindMatches, location, history } = this.props; if (trace) { @@ -259,12 +261,12 @@ export class VirtualizedTraceViewImpl extends React.Component this.props.childrenHiddenIDs; - mapRowIndexToSpanIndex = (index: number) => this.rowStates[index].spanIndex; + mapRowIndexToSpanIndex = (index: number) => this.getRowStates()[index].spanIndex; mapSpanIndexToRowIndex = (index: number) => { - const max = this.rowStates.length; + const max = this.getRowStates().length; for (let i = 0; i < max; i++) { - const { spanIndex } = this.rowStates[i]; + const { spanIndex } = this.getRowStates()[i]; if (spanIndex === index) { return i; } @@ -283,7 +285,7 @@ export class VirtualizedTraceViewImpl extends React.Component { - const { isDetail, span } = this.rowStates[index]; + const { isDetail, span } = this.getRowStates()[index]; return `${span.spanID}--${isDetail ? 'detail' : 'bar'}`; }; @@ -291,9 +293,9 @@ export class VirtualizedTraceViewImpl extends React.Component { - const { span, isDetail } = this.rowStates[index]; + const { span, isDetail } = this.getRowStates()[index]; if (!isDetail) { return DEFAULT_HEIGHTS.bar; } @@ -315,7 +317,7 @@ export class VirtualizedTraceViewImpl extends React.Component getLinks(span, items, itemIndex); renderRow = (key: string, style: React.CSSProperties, index: number, attrs: {}) => { - const { isDetail, span, spanIndex } = this.rowStates[index]; + const { isDetail, span, spanIndex } = this.getRowStates()[index]; return isDetail ? this.renderSpanDetailRow(span, key, style, attrs) : this.renderSpanBarRow(span, spanIndex, key, style, attrs); @@ -348,7 +350,7 @@ export class VirtualizedTraceViewImpl extends React.Component