From 147000ebfdd46ab7aad7f677f47c5eb2cfad1085 Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Mon, 21 Sep 2020 16:20:00 +0200 Subject: [PATCH] fix: unmount map when switching dashboard mode or changing active type [DHIS2-9558] (#1083) * fix: call unmount when Plugin unmounts * fix: unmount already called when switching vis --- .../Item/VisualizationItem/DefaultPlugin.js | 13 ++++++++++++- src/components/Item/VisualizationItem/Item.js | 9 ++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/components/Item/VisualizationItem/DefaultPlugin.js b/src/components/Item/VisualizationItem/DefaultPlugin.js index 8415526e8..eb28df41c 100644 --- a/src/components/Item/VisualizationItem/DefaultPlugin.js +++ b/src/components/Item/VisualizationItem/DefaultPlugin.js @@ -95,6 +95,17 @@ class DefaultPlugin extends Component { this.reloadPlugin(prevProps) } + componentWillUnmount() { + if ( + pluginManager.pluginIsAvailable( + this.props.item, + this.props.visualization + ) + ) { + pluginManager.unmount(this.props.item, this.getActiveType()) + } + } + getActiveType = () => this.props.visualization.activeType || this.props.item.type @@ -121,11 +132,11 @@ DefaultPlugin.contextTypes = { DefaultPlugin.propTypes = { classes: PropTypes.object, - useActiveType: PropTypes.bool, item: PropTypes.object, itemFilters: PropTypes.object, options: PropTypes.object, style: PropTypes.object, + useActiveType: PropTypes.bool, visualization: PropTypes.object, } diff --git a/src/components/Item/VisualizationItem/Item.js b/src/components/Item/VisualizationItem/Item.js index 0a09f0c73..c0e374b0b 100644 --- a/src/components/Item/VisualizationItem/Item.js +++ b/src/components/Item/VisualizationItem/Item.js @@ -254,13 +254,8 @@ export class Item extends Component { } onSelectActiveType = type => { - if (type === this.getActiveType()) { - return - } - - pluginManager.unmount(this.props.item, this.getActiveType()) - - this.props.onSelectActiveType(this.props.visualization.id, type) + type !== this.getActiveType() && + this.props.onSelectActiveType(this.props.visualization.id, type) } getActiveType = () =>