From 2e917c9ef5412b6901847b3fdb4e6189be2eb9a1 Mon Sep 17 00:00:00 2001 From: Devon Thomson Date: Mon, 15 Mar 2021 18:40:47 -0400 Subject: [PATCH] [Dashboard] Clear Add Panel On App Leave (#94530) (#94633) * cleared add panel in useEffect cleanup function --- .../public/application/top_nav/dashboard_top_nav.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/plugins/dashboard/public/application/top_nav/dashboard_top_nav.tsx b/src/plugins/dashboard/public/application/top_nav/dashboard_top_nav.tsx index 4c67acbfc79df..6230a16f10491 100644 --- a/src/plugins/dashboard/public/application/top_nav/dashboard_top_nav.tsx +++ b/src/plugins/dashboard/public/application/top_nav/dashboard_top_nav.tsx @@ -10,6 +10,7 @@ import { i18n } from '@kbn/i18n'; import angular from 'angular'; import React, { useCallback, useEffect, useMemo, useState } from 'react'; +import UseUnmount from 'react-use/lib/useUnmount'; import { useKibana } from '../../services/kibana_react'; import { IndexPattern, SavedQuery, TimefilterContract } from '../../services/data'; import { @@ -114,7 +115,9 @@ export function DashboardTopNav({ id || DASHBOARD_PANELS_UNSAVED_ID ); } - return () => visibleSubscription.unsubscribe(); + return () => { + visibleSubscription.unsubscribe(); + }; }, [chrome, allowByValueEmbeddables, dashboardStateManager, savedDashboard]); const addFromLibrary = useCallback(() => { @@ -458,6 +461,10 @@ export function DashboardTopNav({ share, ]); + UseUnmount(() => { + clearAddPanel(); + }); + const getNavBarProps = () => { const shouldShowNavBarComponent = (forceShow: boolean): boolean => (forceShow || state.chromeIsVisible) && !dashboardStateManager.getFullScreenMode();