From 7f63efb94147930364e92da0cda29f526f9e9d2f Mon Sep 17 00:00:00 2001 From: Jack Westbrook Date: Wed, 5 May 2021 13:55:34 +0200 Subject: [PATCH] Routing: refresh plugin module when pluginId changes (#33579) * fix(approotpage): load plugin if pluginId changes so ui updates * fix(approotpage): prevent dashboard search breaking for plugins without navmodel --- public/app/core/components/Page/Page.tsx | 12 +++++++---- public/app/features/plugins/AppRootPage.tsx | 24 ++++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/public/app/core/components/Page/Page.tsx b/public/app/core/components/Page/Page.tsx index 86c6dfb7a0f..573449ed416 100644 --- a/public/app/core/components/Page/Page.tsx +++ b/public/app/core/components/Page/Page.tsx @@ -13,7 +13,7 @@ import { css, cx } from '@emotion/css'; interface Props extends HTMLAttributes { children: React.ReactNode; - navModel: NavModel; + navModel?: NavModel; } export interface PageType extends FC { @@ -25,15 +25,19 @@ export const Page: PageType = ({ navModel, children, className, ...otherProps }) const styles = useStyles2(getStyles); useEffect(() => { - const title = getTitleFromNavModel(navModel); - document.title = title ? `${title} - ${Branding.AppTitle}` : Branding.AppTitle; + if (navModel) { + const title = getTitleFromNavModel(navModel); + document.title = title ? `${title} - ${Branding.AppTitle}` : Branding.AppTitle; + } else { + document.title = Branding.AppTitle; + } }, [navModel]); return (
- + {navModel && } {children}
diff --git a/public/app/features/plugins/AppRootPage.tsx b/public/app/features/plugins/AppRootPage.tsx index 5e7a0f12ea1..fa22100c574 100644 --- a/public/app/features/plugins/AppRootPage.tsx +++ b/public/app/features/plugins/AppRootPage.tsx @@ -49,8 +49,7 @@ class AppRootPage extends Component { shouldComponentUpdate(nextProps: Props) { return nextProps.location.pathname.startsWith('/a/'); } - - async componentDidMount() { + async loadPluginSettings() { const { params } = this.props.match; try { const app = await getPluginSettings(params.pluginId).then((info) => { @@ -62,7 +61,7 @@ class AppRootPage extends Component { } return importAppPlugin(info); }); - this.setState({ plugin: app, loading: false }); + this.setState({ plugin: app, loading: false, nav: undefined }); } catch (err) { this.setState({ plugin: null, @@ -72,6 +71,21 @@ class AppRootPage extends Component { } } + componentDidMount() { + this.loadPluginSettings(); + } + + componentDidUpdate(prevProps: Props) { + const { params } = this.props.match; + + if (prevProps.match.params.pluginId !== params.pluginId) { + this.setState({ + loading: true, + }); + this.loadPluginSettings(); + } + } + onNavChanged = (nav: NavModel) => { this.setState({ nav }); }; @@ -104,10 +118,10 @@ class AppRootPage extends Component { ) : ( - <> + {loading && } - + )} );