From 6f36031fcff5b744404462b3908dd1c29473a2b4 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 10 Nov 2018 14:54:20 +0100 Subject: [PATCH 1/2] fix duplicate loading of plugins --- scm-ui/src/containers/Index.js | 23 ++++++++++++++++++-- scm-ui/src/containers/PluginLoader.js | 30 +++++++++++++-------------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/scm-ui/src/containers/Index.js b/scm-ui/src/containers/Index.js index 0fe6364f6e..71bd6b35c2 100644 --- a/scm-ui/src/containers/Index.js +++ b/scm-ui/src/containers/Index.js @@ -27,13 +27,32 @@ type Props = { t: string => string }; -class Index extends Component { +type State = { + pluginsLoaded: boolean +}; + +class Index extends Component { + + constructor(props: Props) { + super(props); + this.state = { + pluginsLoaded: false + }; + } + componentDidMount() { this.props.fetchIndexResources(); } + pluginLoaderCallback = () => { + this.setState({ + pluginsLoaded: true + }); + }; + render() { const { indexResources, loading, error, t } = this.props; + const { pluginsLoaded } = this.state; if (error) { return ( @@ -47,7 +66,7 @@ class Index extends Component { return ; } else { return ( - + ); diff --git a/scm-ui/src/containers/PluginLoader.js b/scm-ui/src/containers/PluginLoader.js index 8e44a1d427..308f532270 100644 --- a/scm-ui/src/containers/PluginLoader.js +++ b/scm-ui/src/containers/PluginLoader.js @@ -5,12 +5,13 @@ import { getUiPluginsLink } from "../modules/indexResource"; import { connect } from "react-redux"; type Props = { + loaded: boolean, children: React.Node, - link: string + link: string, + callback: () => void }; type State = { - finished: boolean, message: string }; @@ -23,17 +24,19 @@ class PluginLoader extends React.Component { constructor(props: Props) { super(props); this.state = { - finished: false, message: "booting" }; } componentDidMount() { - this.setState({ - message: "loading plugin information" - }); - - this.getPlugins(this.props.link); + const { loaded } = this.props; + if (!loaded) { + this.setState({ + message: "loading plugin information" + }); + + this.getPlugins(this.props.link); + } } getPlugins = (link: string): Promise => { @@ -43,11 +46,7 @@ class PluginLoader extends React.Component { .then(JSON.parse) .then(pluginCollection => pluginCollection._embedded.plugins) .then(this.loadPlugins) - .then(() => { - this.setState({ - finished: true - }); - }); + .then(this.props.callback); }; loadPlugins = (plugins: Plugin[]) => { @@ -87,8 +86,9 @@ class PluginLoader extends React.Component { }; render() { - const { message, finished } = this.state; - if (finished) { + const { loaded } = this.props; + const { message } = this.state; + if (loaded) { return
{this.props.children}
; } return ; From d68b07c255381b5d54ef5c68c5732737fd1eb86e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maren=20S=C3=BCwer?= Date: Tue, 13 Nov 2018 10:03:08 +0100 Subject: [PATCH 2/2] Close branch bugfix/duplicate_loading_of_plugins