Skip to content

Commit

Permalink
component-only menu for apm
Browse files Browse the repository at this point in the history
  • Loading branch information
smith committed Nov 9, 2020
1 parent 6670f78 commit 4e6fa5d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 46 deletions.
15 changes: 7 additions & 8 deletions x-pack/plugins/apm/public/application/action_menu/index.tsx
Expand Up @@ -6,7 +6,7 @@

import { EuiHeaderLink, EuiHeaderLinks } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { useEffect } from 'react';
import React, { useEffect, useMemo } from 'react';
import { unmountComponentAtNode } from 'react-dom';
import { createPortalNode, InPortal, OutPortal } from 'react-reverse-portal';
import { useParams } from 'react-router-dom';
Expand All @@ -32,7 +32,7 @@ export function ActionMenu() {
canSaveAlerts,
canReadAnomalies,
} = getAlertingCapabilities(plugins, capabilities);
const portalNode = createPortalNode();
const portalNode = useMemo(() => createPortalNode(), []);

function apmHref(path: string) {
return getAPMHref({ basePath, path, search });
Expand All @@ -43,17 +43,16 @@ export function ActionMenu() {
}

useEffect(() => {
let mountPointElement: HTMLElement;
let unmount = () => {};

setHeaderActionMenu((element) => {
mountPointElement = element;
return toMountPoint(<OutPortal node={portalNode} />)(mountPointElement);
const mount = toMountPoint(<OutPortal node={portalNode} />);
unmount = mount(element);
});

return () => {
if (mountPointElement) {
unmountComponentAtNode(mountPointElement);
}
portalNode.unmount();
unmount();
};
}, [portalNode, setHeaderActionMenu]);

Expand Down
38 changes: 0 additions & 38 deletions x-pack/plugins/apm/public/hooks/use_action_menu.tsx

This file was deleted.

0 comments on commit 4e6fa5d

Please sign in to comment.