Skip to content

Commit

Permalink
[Discover] Close inspector when switching app (#92994)
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal authored Apr 13, 2021
1 parent 6ddc4bf commit d8b4316
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
17 changes: 16 additions & 1 deletion src/plugins/discover/public/application/components/discover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { DiscoverTopNav } from './discover_topnav';
import { ElasticSearchHit } from '../doc_views/doc_views_types';
import { setBreadcrumbsTitle } from '../helpers/breadcrumbs';
import { addHelpMenuToAppChrome } from './help_menu/help_menu_util';
import { InspectorSession } from '../../../../inspector/public';

const DocTableLegacyMemoized = React.memo(DocTableLegacy);
const SidebarMemoized = React.memo(DiscoverSidebarResponsive);
Expand Down Expand Up @@ -71,6 +72,7 @@ export function Discover({
refreshAppState,
}: DiscoverProps) {
const [expandedDoc, setExpandedDoc] = useState<ElasticSearchHit | undefined>(undefined);
const [inspectorSession, setInspectorSession] = useState<InspectorSession | undefined>(undefined);
const scrollableDesktop = useRef<HTMLDivElement>(null);
const collapseIcon = useRef<HTMLButtonElement>(null);
const isMobile = () => {
Expand Down Expand Up @@ -131,7 +133,20 @@ export function Discover({
const onOpenInspector = useCallback(() => {
// prevent overlapping
setExpandedDoc(undefined);
}, [setExpandedDoc]);
const session = services.inspector.open(opts.inspectorAdapters, {
title: savedSearch.title,
});
setInspectorSession(session);
}, [setExpandedDoc, opts.inspectorAdapters, savedSearch, services.inspector]);

useEffect(() => {
return () => {
if (inspectorSession) {
// Close the inspector if this scope is destroyed (e.g. because the user navigates away).
inspectorSession.close();
}
};
}, [inspectorSession]);

const onSort = useCallback(
(sort: string[][]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const DiscoverTopNav = ({
getTopNavLinks({
getFieldCounts: opts.getFieldCounts,
indexPattern,
inspectorAdapters: opts.inspectorAdapters,
navigateTo: opts.navigateTo,
savedSearch: opts.savedSearch,
services: opts.services,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { ISearchSource } from 'src/plugins/data/public';
import { getTopNavLinks } from './get_top_nav_links';
import { inspectorPluginMock } from '../../../../../inspector/public/mocks';
import { indexPatternMock } from '../../../__mocks__/index_pattern';
import { savedSearchMock } from '../../../__mocks__/saved_search';
import { DiscoverServices } from '../../../build_services';
Expand All @@ -28,7 +27,6 @@ test('getTopNavLinks result', () => {
const topNavLinks = getTopNavLinks({
getFieldCounts: jest.fn(),
indexPattern: indexPatternMock,
inspectorAdapters: inspectorPluginMock,
navigateTo: jest.fn(),
onOpenInspector: jest.fn(),
savedSearch: savedSearchMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { showOpenSearchPanel } from './show_open_search_panel';
import { getSharingData, showPublicUrlSwitch } from '../../helpers/get_sharing_data';
import { unhashUrl } from '../../../../../kibana_utils/public';
import { DiscoverServices } from '../../../build_services';
import { Adapters } from '../../../../../inspector/common/adapters';
import { SavedSearch } from '../../../saved_searches';
import { onSaveSearch } from './on_save_search';
import { GetStateReturn } from '../../angular/discover_state';
Expand All @@ -23,7 +22,6 @@ import { IndexPattern, ISearchSource } from '../../../kibana_services';
export const getTopNavLinks = ({
getFieldCounts,
indexPattern,
inspectorAdapters,
navigateTo,
savedSearch,
services,
Expand All @@ -33,7 +31,6 @@ export const getTopNavLinks = ({
}: {
getFieldCounts: () => Promise<Record<string, number>>;
indexPattern: IndexPattern;
inspectorAdapters: Adapters;
navigateTo: (url: string) => void;
savedSearch: SavedSearch;
services: DiscoverServices;
Expand Down Expand Up @@ -127,9 +124,6 @@ export const getTopNavLinks = ({
testId: 'openInspectorButton',
run: () => {
onOpenInspector();
services.inspector.open(inspectorAdapters, {
title: savedSearch.title,
});
},
};

Expand Down

0 comments on commit d8b4316

Please sign in to comment.