From e4ea3ecec67b30a77ece349626dfeaa450144a9c Mon Sep 17 00:00:00 2001 From: Andrey Mishanin Date: Wed, 22 Apr 2020 05:14:03 -0700 Subject: [PATCH] Tree generation search Summary: Added the ability to search tree generations for a particular component. As soon as you start typing in the search bar, only relevant timeline tracks would be displayed. Currently, I'm looking for the search string in `component_class_name` of the payload and among all nodes in the tree. Reviewed By: fabiomassimo Differential Revision: D21175734 fbshipit-source-id: 642c628350192697980becd20352d303200a031e --- desktop/plugins/sections/index.js | 67 ++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/desktop/plugins/sections/index.js b/desktop/plugins/sections/index.js index 7c5d37a27..a5f93df49 100644 --- a/desktop/plugins/sections/index.js +++ b/desktop/plugins/sections/index.js @@ -33,6 +33,9 @@ import { Spacer, colors, DetailSidebar, + SearchInput, + SearchBox, + SearchIcon, } from 'flipper'; const Waiting = styled(FlexBox)((props) => ({ @@ -62,6 +65,7 @@ type State = { focusedChangeSet: ?UpdateTreeGenerationChangesetApplicationPayload, userSelectedGenerationId: ?string, selectedTreeNode: ?Object, + searchString: string, }; type PersistedState = { @@ -153,6 +157,7 @@ export default class extends FlipperPlugin { focusedChangeSet: null, userSelectedGenerationId: null, selectedTreeNode: null, + searchString: '', }; onTreeGenerationFocused = (focusedGenerationId: ?string) => { @@ -239,6 +244,54 @@ export default class extends FlipperPlugin { }); }; + onChange = (e: any) => { + this.setState({searchString: e.target.value}); + }; + + generationValues = () => { + const {generations} = this.props.persistedState; + const generationKeys = Object.keys(generations); + return (generationKeys.map( + (key) => generations[key], + ): Array); + }; + + matchesCurrentSearchString = (s: string) => { + return s.toLowerCase().includes(this.state.searchString.toLowerCase()); + }; + + matchingGenerationKeys = () => { + const matchingKeys: Array = this.generationValues() + .filter((g) => { + if (g.payload) { + const componentClassName: ?string = g.payload['component_class_name']; + if (componentClassName) { + return this.matchesCurrentSearchString(componentClassName); + } + } + return g.tree?.some((node) => { + return this.matchesCurrentSearchString(node.name); + }); + }) + .map((g) => { + return g.surface_key; + }); + + return new Set(matchingKeys); + }; + + filteredGenerations = () => { + if (this.state.searchString.length <= 0) { + return Object.values(this.props.persistedState.generations); + } + + const matchingKeys = this.matchingGenerationKeys(); + + return (this.generationValues().filter((g) => { + return matchingKeys.has(g.surface_key); + }): Array); + }; + render() { const {generations} = this.props.persistedState; if (Object.values(this.props.persistedState.generations).length === 0) { @@ -256,6 +309,18 @@ export default class extends FlipperPlugin { return ( + + + + {this.props.persistedState.recording ? (