From e5392e2c00e8968d0aba01ed975b19a73f474875 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 4 Jul 2018 12:57:22 +0100 Subject: [PATCH] use TruncatedList to prevent rendering hundreds/thousands of DOM nodes Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/dialogs/DevtoolsDialog.js | 58 +++++++++++++++---- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/src/components/views/dialogs/DevtoolsDialog.js b/src/components/views/dialogs/DevtoolsDialog.js index 1566302e42..5e75d16455 100644 --- a/src/components/views/dialogs/DevtoolsDialog.js +++ b/src/components/views/dialogs/DevtoolsDialog.js @@ -242,6 +242,8 @@ class SendAccountData extends GenericEditor { } } +const INITIAL_LOAD_TILES = 20; + class FilteredList extends React.Component { static propTypes = { children: PropTypes.any, @@ -249,31 +251,65 @@ class FilteredList extends React.Component { onChange: PropTypes.func, }; + static filterChildren(children, query) { + if (!query) return children; + const lcQuery = query.toLowerCase(); + return children.filter((child) => child.key.toLowerCase().includes(lcQuery)); + } + constructor(props, context) { super(props, context); - this.onQuery = this.onQuery.bind(this); + + this.state = { + filteredChildren: FilteredList.filterChildren(this.props.children, this.props.query), + truncateAt: INITIAL_LOAD_TILES, + }; } - onQuery(ev) { + componentWillReceiveProps(nextProps) { + if (this.props.children === nextProps.children && this.props.query === nextProps.query) return; + this.setState({ + filteredChildren: FilteredList.filterChildren(nextProps.children, nextProps.query), + truncateAt: INITIAL_LOAD_TILES, + }); + } + + showAll = () => { + this.setState({ + truncateAt: -1, + }); + }; + + createOverflowElement = (overflowCount: number, totalCount: number) => { + return ; + }; + + onQuery = (ev) => { if (this.props.onChange) this.props.onChange(ev.target.value); - } + }; - filterChildren() { - if (this.props.query) { - const lowerQuery = this.props.query.toLowerCase(); - return this.props.children.filter((child) => child.key.toLowerCase().includes(lowerQuery)); - } - return this.props.children; - } + getChildren = (start: number, end: number) => { + return this.state.filteredChildren.slice(start, end); + }; + + getChildCount = (): number => { + return this.state.filteredChildren.length; + }; render() { + const TruncatedList = sdk.getComponent("elements.TruncatedList"); return