From 6271723e4403fe931bffe029ddd188e148bda147 Mon Sep 17 00:00:00 2001 From: Lou Marvin Caraig Date: Thu, 18 Apr 2019 17:57:13 +0200 Subject: [PATCH] Fixed initialization of `UASTViewer` There are two problems: 1. `UASTViewerPane` checks only for `flatUast` and not `initialFlatUast`. This means that it can work only when the `uast-viewer` is used in *controlled mode*. This has been fixed by checking `flatUast` first and then fallback to `initialFlatUast`. 2. `UASTViewer` component needs to be in *uncontrolled mode*, so it needs to use `initialFlatUast`. This has ben fixed by renaming `flatUast` into `initialFlatUast`. Signed-off-by: Lou Marvin Caraig --- frontend/src/components/UASTViewer.js | 6 +++--- frontend/src/components/UASTViewerPane.js | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/UASTViewer.js b/frontend/src/components/UASTViewer.js index a5cf9bf..1f312c1 100644 --- a/frontend/src/components/UASTViewer.js +++ b/frontend/src/components/UASTViewer.js @@ -16,7 +16,7 @@ class UASTViewer extends Component { this.state = { loading: false, - flatUast: this.transform(props.uast), + initialFlatUast: this.transform(props.uast), showLocations: false, filter: '', error: null @@ -65,9 +65,9 @@ class UASTViewer extends Component { } render() { - const { flatUast, error, loading } = this.state; + const { initialFlatUast, error, loading } = this.state; const { showLocations, filter } = this.state; - const uastViewerProps = { flatUast }; + const uastViewerProps = { initialFlatUast }; return (
diff --git a/frontend/src/components/UASTViewerPane.js b/frontend/src/components/UASTViewerPane.js index 75dee1b..2abb3bd 100644 --- a/frontend/src/components/UASTViewerPane.js +++ b/frontend/src/components/UASTViewerPane.js @@ -41,10 +41,11 @@ function UASTViewerPane({ }) { let content = null; + const uast = uastViewerProps.flatUast || uastViewerProps.initialFlatUast; if (loading) { content =
loading...
; - } else if (uastViewerProps.flatUast) { - const searchResults = getSearchResults(uastViewerProps.flatUast); + } else if (uast) { + const searchResults = getSearchResults(uast); const rootIds = searchResults || [ROOT_ID]; if (searchResults && !searchResults.length) {