Skip to content

Commit

Permalink
[AO] use toMountPoint from react-kibana-mount for header menu portal (#…
Browse files Browse the repository at this point in the history
…167126)

Fixes #164366

### Acceptance Criteria
- use `toMountPoint` from `@kbn/react-kibana-mount` for
[kibana/x-pack/plugins/observability/public/pages/overview/components/header_menu/header_menu_portal.tsx](https://github.com/elastic/kibana/blob/fcf838e1f389cae6fcaeb9f7bce713123a01c939/x-pack/plugins/observability/public/pages/overview/components/header_menu/header_menu_portal.tsx#L10)

---------

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
mgiota and kibanamachine authored Sep 28, 2023
1 parent 8e6101e commit ba31c76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import React, { ReactNode, useEffect, useMemo } from 'react';
import { createHtmlPortalNode, InPortal, OutPortal } from 'react-reverse-portal';
import { toMountPoint } from '@kbn/kibana-react-plugin/public';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { AppMountParameters } from '@kbn/core/public';

import { useKibana } from '../../../../utils/kibana_react';
export interface HeaderMenuPortalProps {
children: ReactNode;
setHeaderActionMenu: AppMountParameters['setHeaderActionMenu'];
Expand All @@ -22,19 +22,22 @@ export default function HeaderMenuPortal({
setHeaderActionMenu,
theme$,
}: HeaderMenuPortalProps) {
const { i18n } = useKibana().services;
const portalNode = useMemo(() => createHtmlPortalNode(), []);

useEffect(() => {
setHeaderActionMenu((element) => {
const mount = toMountPoint(<OutPortal node={portalNode} />, { theme$ });
const mount = toMountPoint(<OutPortal node={portalNode} />, {
...{ theme: { theme$ }, i18n },
});
return mount(element);
});

return () => {
portalNode.unmount();
setHeaderActionMenu(undefined);
};
}, [portalNode, setHeaderActionMenu, theme$]);
}, [portalNode, setHeaderActionMenu, i18n, theme$]);

return <InPortal node={portalNode}>{children}</InPortal>;
}
1 change: 1 addition & 0 deletions x-pack/plugins/observability/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"@kbn/aiops-plugin",
"@kbn/content-management-plugin",
"@kbn/deeplinks-observability",
"@kbn/react-kibana-mount",
"@kbn/react-kibana-context-theme"
],
"exclude": [
Expand Down

0 comments on commit ba31c76

Please sign in to comment.