mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
* [Infra] Make nav react to Hosts view enabled flag changing (#140996)
* Move comment to more relevant location
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit d60acf8774
)
Co-authored-by: Milton Hultgren <milton.hultgren@elastic.co>
This commit is contained in:
parent
ae18bf11f1
commit
30b43ff67f
1 changed files with 39 additions and 11 deletions
|
@ -5,12 +5,17 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import {
|
||||
AppMountParameters,
|
||||
AppUpdater,
|
||||
CoreStart,
|
||||
DEFAULT_APP_CATEGORIES,
|
||||
PluginInitializerContext,
|
||||
} from '@kbn/core/public';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { AppMountParameters, PluginInitializerContext } from '@kbn/core/public';
|
||||
import { from } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { DEFAULT_APP_CATEGORIES } from '@kbn/core/public';
|
||||
import { enableInfrastructureHostsView } from '@kbn/observability-plugin/public';
|
||||
import { BehaviorSubject, combineLatest, from } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { defaultLogViewsStaticConfig } from '../common/log_views';
|
||||
import { InfraPublicConfig } from '../common/plugin_config_types';
|
||||
import { createInventoryMetricRuleType } from './alerting/inventory';
|
||||
|
@ -38,6 +43,7 @@ import { getLogsHasDataFetcher, getLogsOverviewDataFetcher } from './utils/logs_
|
|||
export class Plugin implements InfraClientPluginClass {
|
||||
public config: InfraPublicConfig;
|
||||
private logViews: LogViewsService;
|
||||
private readonly appUpdater$ = new BehaviorSubject<AppUpdater>(() => ({}));
|
||||
|
||||
constructor(context: PluginInitializerContext<InfraPublicConfig>) {
|
||||
this.config = context.config.get();
|
||||
|
@ -74,6 +80,11 @@ export class Plugin implements InfraClientPluginClass {
|
|||
fetchData: createMetricsFetchData(core.getStartServices),
|
||||
});
|
||||
|
||||
const startDep$AndHostViewFlag$ = combineLatest([
|
||||
from(core.getStartServices()),
|
||||
core.uiSettings.get$<boolean>(enableInfrastructureHostsView),
|
||||
]);
|
||||
|
||||
/** !! Need to be kept in sync with the deepLinks in x-pack/plugins/infra/public/plugin.ts */
|
||||
const infraEntries = [
|
||||
{ label: 'Inventory', app: 'metrics', path: '/inventory' },
|
||||
|
@ -81,12 +92,15 @@ export class Plugin implements InfraClientPluginClass {
|
|||
];
|
||||
const hostInfraEntry = { label: 'Hosts', app: 'metrics', path: '/hosts' };
|
||||
pluginsSetup.observability.navigation.registerSections(
|
||||
from(core.getStartServices()).pipe(
|
||||
startDep$AndHostViewFlag$.pipe(
|
||||
map(
|
||||
([
|
||||
{
|
||||
application: { capabilities },
|
||||
},
|
||||
[
|
||||
{
|
||||
application: { capabilities },
|
||||
},
|
||||
],
|
||||
isInfrastructureHostsViewEnabled,
|
||||
]) => [
|
||||
...(capabilities.logs.show
|
||||
? [
|
||||
|
@ -106,7 +120,7 @@ export class Plugin implements InfraClientPluginClass {
|
|||
{
|
||||
label: 'Infrastructure',
|
||||
sortKey: 300,
|
||||
entries: core.uiSettings.get(enableInfrastructureHostsView)
|
||||
entries: isInfrastructureHostsViewEnabled
|
||||
? [hostInfraEntry, ...infraEntries]
|
||||
: infraEntries,
|
||||
},
|
||||
|
@ -171,6 +185,7 @@ export class Plugin implements InfraClientPluginClass {
|
|||
},
|
||||
});
|
||||
|
||||
// !! Need to be kept in sync with the routes in x-pack/plugins/infra/public/pages/metrics/index.tsx
|
||||
const infraDeepLinks = [
|
||||
{
|
||||
id: 'inventory',
|
||||
|
@ -210,8 +225,8 @@ export class Plugin implements InfraClientPluginClass {
|
|||
order: 8200,
|
||||
appRoute: '/app/metrics',
|
||||
category: DEFAULT_APP_CATEGORIES.observability,
|
||||
// !! Need to be kept in sync with the routes in x-pack/plugins/infra/public/pages/metrics/index.tsx
|
||||
deepLinks: core.uiSettings.get(enableInfrastructureHostsView)
|
||||
updater$: this.appUpdater$,
|
||||
deepLinks: core.uiSettings.get<boolean>(enableInfrastructureHostsView)
|
||||
? [hostInfraDeepLink, ...infraDeepLinks]
|
||||
: infraDeepLinks,
|
||||
mount: async (params: AppMountParameters) => {
|
||||
|
@ -223,6 +238,19 @@ export class Plugin implements InfraClientPluginClass {
|
|||
},
|
||||
});
|
||||
|
||||
startDep$AndHostViewFlag$.subscribe(
|
||||
([_startServices, isInfrastructureHostsViewEnabled]: [
|
||||
[CoreStart, InfraClientStartDeps, InfraClientStartExports],
|
||||
boolean
|
||||
]) => {
|
||||
this.appUpdater$.next(() => ({
|
||||
deepLinks: isInfrastructureHostsViewEnabled
|
||||
? [hostInfraDeepLink, ...infraDeepLinks]
|
||||
: infraDeepLinks,
|
||||
}));
|
||||
}
|
||||
);
|
||||
|
||||
/* This exists purely to facilitate URL redirects from the old App ID ("infra"),
|
||||
to our new App IDs ("metrics" and "logs"). With version 8.0.0 we can remove this. */
|
||||
core.application.register({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue