Skip to content

Commit e17919b

Browse files
smithkibanamachine
authored andcommitted
Fix bug with Observability > APM header navigation (#100845)
Call `setHeaderActionMenu(undefined)` when the HeaderMenuPortal is unmounted. Found this line in the docs: > Calling the handler with `undefined` will unmount the current mount point. Which we weren't doing before. Previous behavior: * Go to /app/observability/alerts * Click the "View in app" button for an APM alert * Click back * Click the "View in app" button for an APM alert * Get a weird toast error message and the header menu is gone forever Now: * Go to /app/observability/alerts * Click the "View in app" button for an APM alert * Click back * Click the "View in app" button for an APM alert * Get a working header menu Fixes #97140
1 parent 50e6387 commit e17919b

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { render } from '@testing-library/react';
9+
import React from 'react';
10+
import HeaderMenuPortal from './header_menu_portal';
11+
12+
describe('HeaderMenuPortal', () => {
13+
describe('when unmounted', () => {
14+
it('calls setHeaderActionMenu with undefined', () => {
15+
const setHeaderActionMenu = jest.fn();
16+
17+
const { unmount } = render(
18+
<HeaderMenuPortal setHeaderActionMenu={setHeaderActionMenu}>test</HeaderMenuPortal>
19+
);
20+
21+
unmount();
22+
23+
expect(setHeaderActionMenu).toHaveBeenCalledWith(undefined);
24+
});
25+
});
26+
});

x-pack/plugins/observability/public/components/shared/header_menu_portal.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@ export default function HeaderMenuPortal({ children, setHeaderActionMenu }: Head
1515
const portalNode = useMemo(() => createPortalNode(), []);
1616

1717
useEffect(() => {
18-
let unmount = () => {};
19-
2018
setHeaderActionMenu((element) => {
2119
const mount = toMountPoint(<OutPortal node={portalNode} />);
22-
unmount = mount(element);
23-
return unmount;
20+
return mount(element);
2421
});
2522

2623
return () => {
2724
portalNode.unmount();
28-
unmount();
25+
setHeaderActionMenu(undefined);
2926
};
3027
}, [portalNode, setHeaderActionMenu]);
3128

x-pack/plugins/observability/public/pages/alerts/alerts.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { IntlProvider } from 'react-intl';
1111
import { MemoryRouter } from 'react-router-dom';
1212
import { AlertsPage } from '.';
1313
import { HttpSetup } from '../../../../../../src/core/public';
14-
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';
14+
import {
15+
KibanaContextProvider,
16+
KibanaPageTemplate,
17+
} from '../../../../../../src/plugins/kibana_react/public';
1518
import { PluginContext, PluginContextValue } from '../../context/plugin_context';
1619
import { createObservabilityRuleTypeRegistryMock } from '../../rules/observability_rule_type_registry_mock';
1720
import { createCallObservabilityApi } from '../../services/call_observability_api';
@@ -63,6 +66,7 @@ export default {
6366
http: { basePath: { prepend: (_: string) => '' } },
6467
},
6568
observabilityRuleTypeRegistry: createObservabilityRuleTypeRegistryMock(),
69+
ObservabilityPageTemplate: KibanaPageTemplate,
6670
} as unknown) as PluginContextValue
6771
}
6872
>

0 commit comments

Comments
 (0)