From a111dc95e96016d605969df4ef688eeb33d5ec86 Mon Sep 17 00:00:00 2001 From: sylenien Date: Fri, 18 Nov 2022 14:34:00 +0100 Subject: [PATCH] change(ui): add unified row height to state tab, add virt to console tab --- .../Console/ConsoleRow/ConsoleRow.tsx | 7 +- .../components/Session_/Storage/DiffRow.tsx | 14 +++- .../components/Session_/Storage/Storage.js | 75 ++++++++++--------- .../DevTools/ConsolePanel/ConsolePanel.tsx | 59 ++++++++++++--- .../shared/DevTools/ConsoleRow/ConsoleRow.tsx | 14 +++- .../app/components/ui/JSONTree/JSONTree.js | 4 +- 6 files changed, 116 insertions(+), 57 deletions(-) diff --git a/frontend/app/components/Session_/Console/ConsoleRow/ConsoleRow.tsx b/frontend/app/components/Session_/Console/ConsoleRow/ConsoleRow.tsx index c87ff3f9c..85457d6b1 100644 --- a/frontend/app/components/Session_/Console/ConsoleRow/ConsoleRow.tsx +++ b/frontend/app/components/Session_/Console/ConsoleRow/ConsoleRow.tsx @@ -9,12 +9,14 @@ interface Props { iconProps: any; jump?: any; renderWithNL?: any; + style?: any; } function ConsoleRow(props: Props) { - const { log, iconProps, jump, renderWithNL } = props; + const { log, iconProps, jump, renderWithNL, style } = props; const [expanded, setExpanded] = useState(false); const lines = log.value.split('\n').filter((l: any) => !!l); const canExpand = lines.length > 1; + return (
setExpanded(!expanded)} >
@@ -38,7 +41,7 @@ function ConsoleRow(props: Props) { )} {renderWithNL(lines.pop())}
- {canExpand && expanded && lines.map((l: any) =>
{l}
)} + {canExpand && expanded && lines.map((l: any, i: number) =>
{l}
)}
jump(log.time)} /> diff --git a/frontend/app/components/Session_/Storage/DiffRow.tsx b/frontend/app/components/Session_/Storage/DiffRow.tsx index 3ecb4f615..4e6c936a7 100644 --- a/frontend/app/components/Session_/Storage/DiffRow.tsx +++ b/frontend/app/components/Session_/Storage/DiffRow.tsx @@ -63,17 +63,27 @@ function DiffRow({ diff, path }: Props) { )} > {oldValueSafe || 'undefined'} + {diffLengths[0] > 50 + ? ( +
setShortenOldVal(!shortenOldVal)} className="cursor-pointer px-1 text-white bg-gray-light rounded text-sm w-fit"> + {!shortenOldVal ? 'collapse' : 'expand'} +
+ ) : null} {' -> '} setShortenNewVal(!shortenNewVal)} className={cn( 'whitespace-pre', newValue ? 'text-red' : 'text-green', - diffLengths[1] > 50 ? 'cursor-pointer' : '' )} > {newValueSafe || 'undefined'} + {diffLengths[1] > 50 + ? ( +
setShortenNewVal(!shortenNewVal)} className="cursor-pointer px-1 text-white bg-gray-light rounded text-sm w-fit"> + {!shortenNewVal ? 'collapse' : 'expand'} +
+ ) : null}
); diff --git a/frontend/app/components/Session_/Storage/Storage.js b/frontend/app/components/Session_/Storage/Storage.js index 882cb699a..20fa1c703 100644 --- a/frontend/app/components/Session_/Storage/Storage.js +++ b/frontend/app/components/Session_/Storage/Storage.js @@ -12,7 +12,6 @@ import { JSONTree, NoContent, Tooltip } from 'UI'; import { formatMs } from 'App/date'; import { diff } from 'deep-diff'; import { jump } from 'Player'; -import Autoscroll from '../Autoscroll'; import BottomBlock from '../BottomBlock/index'; import DiffRow from './DiffRow'; import cn from 'classnames'; @@ -22,6 +21,7 @@ import { List, CellMeasurer, CellMeasurerCache, AutoSizer } from 'react-virtuali // const STATE = 'STATE'; // const DIFF = 'DIFF'; // const TABS = [ DIFF, STATE ].map(tab => ({ text: tab, key: tab })); +const ROW_HEIGHT = 90; function getActionsName(type) { switch (type) { @@ -48,8 +48,8 @@ function getActionsName(type) { ) //@withEnumToggle('activeTab', 'setActiveTab', DIFF) export default class Storage extends React.PureComponent { - constructor(props, ctx) { - super(props, ctx); + constructor(props) { + super(props); this.lastBtnRef = React.createRef(); this._list = React.createRef(); @@ -57,8 +57,6 @@ export default class Storage extends React.PureComponent { fixedWidth: true, keyMapper: index => this.props.listNow[index] }); - this._listNowLen = this.props.listNow.length - this._listLen = this.props.list.length this._rowRenderer = this._rowRenderer.bind(this) } @@ -72,27 +70,25 @@ export default class Storage extends React.PureComponent { this.focusNextButton(); } - componentDidUpdate(prevProps) { + componentDidUpdate(prevProps, prevState) { if (prevProps.listNow.length !== this.props.listNow.length) { this.focusNextButton(); - const newRows = this.props.listNow.filter(evt => prevProps.listNow.indexOf(evt.id) < 0); - console.log(newRows, this.props.listNow) - if (newRows.length > 0) { - const newRowsIndexes = newRows.map(r => this.props.listNow.indexOf(r)) - - newRowsIndexes.forEach(ind => this.cache.clean(ind)) - this._list.recomputeRowHeights([...newRowsIndexes]) - } - - this._listNowLen = this.props.listNow.length - this._listLen = this.props.list.length + /** possible performance gain, but does not work with dynamic list insertion for some reason + * getting NaN offsets, maybe I detect changed rows wrongly + */ + // const newRows = this.props.listNow.filter(evt => prevProps.listNow.indexOf(evt._index) < 0); + // if (newRows.length > 0) { + // const newRowsIndexes = newRows.map(r => this.props.listNow.indexOf(r)) + // newRowsIndexes.forEach(ind => this.cache.clear(ind)) + // this._list.recomputeRowHeights(newRowsIndexes) + // } } } renderDiff(item, prevItem) { if (!prevItem) { // we don't have state before first action - return
; + return
; } const stateDiff = diff(prevItem.state, item.state); @@ -106,7 +102,7 @@ export default class Storage extends React.PureComponent { } return ( -
+
{stateDiff.map((d, i) => this.renderDiffs(d, i))}
); @@ -114,6 +110,7 @@ export default class Storage extends React.PureComponent { renderDiffs(diff, i) { const path = this.createPath(diff); + return ( @@ -153,7 +150,7 @@ export default class Storage extends React.PureComponent { return ; } - renderItem(item, i, prevItem, style) { + renderItem(item, i, prevItem, style, measure) { const { type } = this.props; let src; let name; @@ -179,10 +176,10 @@ export default class Storage extends React.PureComponent { return (
this._list.recomputeRowHeights(i)} + // onClick={() => {measure(); this._list.recomputeRowHeights(i)}} > {src === null ? (
@@ -190,13 +187,14 @@ export default class Storage extends React.PureComponent {
) : ( <> - {this.renderDiff(item, prevItem)} -
+ {this.renderDiff(item, prevItem, i)} +
console.log('test')} />
@@ -206,12 +204,12 @@ export default class Storage extends React.PureComponent {
{formatMs(item.duration)}
)}
- {i + 1 < this._listNowLen && ( + {i + 1 < this.props.listNow.length && ( )} - {i + 1 === this._listNowLen && i + 1 < this._listLen && ( + {i + 1 === this.props.listNow.length && i + 1 < this.props.list.length && ( @@ -227,15 +225,18 @@ export default class Storage extends React.PureComponent { // this.renderItem(item, i, i > 0 ? listNow[i - 1] : undefined, listNowLen, listLen) // ) const { listNow } = this.props; + + if (!listNow[index]) return console.warn(index, listNow) + return ( - {this.renderItem(listNow[index], index, index > 0 ? listNow[index - 1] : undefined, style)} + {({ measure }) => this.renderItem(listNow[index], index, index > 0 ? listNow[index - 1] : undefined, style, measure)} ) } @@ -345,20 +346,20 @@ export default class Storage extends React.PureComponent { )}
- {({ height, width }) => ( + {({ height, width }) => ( { this._list = element; }} deferredMeasurementCache={this.cache} - overscanRowCount={2} - rowCount={this._listNowLen} - rowHeight={this.cache.rowHeight} + overscanRowCount={1} + rowCount={Math.ceil(parseInt(this.props.listNow.length) || 1)} + rowHeight={ROW_HEIGHT} rowRenderer={this._rowRenderer} width={width} height={height} /> - )} + )}
diff --git a/frontend/app/components/shared/DevTools/ConsolePanel/ConsolePanel.tsx b/frontend/app/components/shared/DevTools/ConsolePanel/ConsolePanel.tsx index 361084221..320f76341 100644 --- a/frontend/app/components/shared/DevTools/ConsolePanel/ConsolePanel.tsx +++ b/frontend/app/components/shared/DevTools/ConsolePanel/ConsolePanel.tsx @@ -8,6 +8,12 @@ import { Tabs, Input, Icon, NoContent } from 'UI'; import cn from 'classnames'; import ConsoleRow from '../ConsoleRow'; import { getRE } from 'App/utils'; +import { + List, + CellMeasurer, + CellMeasurerCache, + AutoSizer, +} from 'react-virtualized'; const ALL = 'ALL'; const INFO = 'INFO'; @@ -62,6 +68,34 @@ function ConsolePanel(props: Props) { const [activeTab, setActiveTab] = useState(ALL); const [filter, setFilter] = useState(''); + const cache = new CellMeasurerCache({ + fixedWidth: true, + keyMapper: (index: number) => filtered[index], + }); + const _list = React.useRef(); + + const _rowRenderer = ({ index, key, parent, style }: any) => { + const item = filtered[index]; + + return ( + + {({ measure }: any) => ( + { + measure(); + (_list as any).current.recomputeRowHeights(index); + }} + /> + )} + + ); + }; + let filtered = React.useMemo(() => { const filterRE = getRE(filter, 'i'); let list = logs; @@ -105,17 +139,20 @@ function ConsolePanel(props: Props) { size="small" show={filtered.length === 0} > - {/* */} - {filtered.map((l: any, index: any) => ( - - ))} - {/* */} + + {({ height, width }: any) => ( + + )} + diff --git a/frontend/app/components/shared/DevTools/ConsoleRow/ConsoleRow.tsx b/frontend/app/components/shared/DevTools/ConsoleRow/ConsoleRow.tsx index f52be65cd..aae911d42 100644 --- a/frontend/app/components/shared/DevTools/ConsoleRow/ConsoleRow.tsx +++ b/frontend/app/components/shared/DevTools/ConsoleRow/ConsoleRow.tsx @@ -10,9 +10,11 @@ interface Props { iconProps: any; jump?: any; renderWithNL?: any; + style?: any; + recalcHeight?: () => void; } function ConsoleRow(props: Props) { - const { log, iconProps, jump, renderWithNL } = props; + const { log, iconProps, jump, renderWithNL, style, recalcHeight } = props; const { showModal } = useModal(); const [expanded, setExpanded] = useState(false); const lines = log.value.split('\n').filter((l: any) => !!l); @@ -23,8 +25,14 @@ function ConsoleRow(props: Props) { const onErrorClick = () => { showModal(, { right: true }); }; + + const toggleExpand = () => { + setExpanded(!expanded) + setTimeout(() => recalcHeight(), 0) + } return (
(!!log.errorId ? onErrorClick() : setExpanded(!expanded)) : () => {} + clickable ? () => (!!log.errorId ? onErrorClick() : toggleExpand()) : () => {} } >
@@ -49,7 +57,7 @@ function ConsoleRow(props: Props) { )} {renderWithNL(lines.pop())}
- {canExpand && expanded && lines.map((l: any) =>
{l}
)} + {canExpand && expanded && lines.map((l: string, i: number) =>
{l}
)}
jump(log.time)} />
diff --git a/frontend/app/components/ui/JSONTree/JSONTree.js b/frontend/app/components/ui/JSONTree/JSONTree.js index dc6ab786c..b94324ebd 100644 --- a/frontend/app/components/ui/JSONTree/JSONTree.js +++ b/frontend/app/components/ui/JSONTree/JSONTree.js @@ -8,7 +8,7 @@ function updateObjectLink(obj) { } export default ({ src, ...props }) => ( - ( iconStle="triangle" { ...props } /> -); \ No newline at end of file +);