[Log Explorer] Remove beta badge when leaving the app (#167065)

## 📓  Summary

Closes #167011 

This implementation fixes the persisted beta badge after leaving the Log
Explorer profile, restoring any existing element on the mount point as a
clean-up action.


3214e097-2c82-4b09-8310-ad09eb4c5a18

Co-authored-by: Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>
This commit is contained in:
Marco Antonio Ghiani 2023-09-27 13:08:08 +02:00 committed by GitHub
parent 7d92c16ec0
commit 7f796659a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,10 +5,10 @@
* 2.0.
*/
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import deepEqual from 'fast-deep-equal';
import useObservable from 'react-use/lib/useObservable';
import { type BehaviorSubject, distinctUntilChanged } from 'rxjs';
import { type BehaviorSubject, distinctUntilChanged, filter, take } from 'rxjs';
import { HeaderMenuPortal } from '@kbn/observability-shared-plugin/public';
import { AppMountParameters } from '@kbn/core-application-browser';
import {
@ -111,6 +111,16 @@ const StatefulTopNav = ({
}: LogExplorerTopNavMenuProps) => {
const { euiTheme } = useEuiTheme();
/**
* Since the breadcrumbsAppendExtension might be set only during a plugin start (e.g. search session)
* we retrieve the latest valid extension in order to restore it once we unmount the beta badge.
*/
const [previousAppendExtension$] = useState(() =>
services.chrome.getBreadcrumbsAppendExtension$().pipe(filter(Boolean), take(1))
);
const previousAppendExtension = useObservable(previousAppendExtension$);
useEffect(() => {
const { chrome, i18n, theme } = services;
@ -137,7 +147,13 @@ const StatefulTopNav = ({
),
});
}
}, [euiTheme, services]);
return () => {
if (chrome) {
chrome.setBreadcrumbsAppendExtension(previousAppendExtension);
}
};
}, [euiTheme, services, previousAppendExtension]);
return (
<HeaderMenuPortal setHeaderActionMenu={setHeaderActionMenu} theme$={theme$}>