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 ;