Skip to content

Commit

Permalink
[Infra] Make nav react to Hosts view enabled flag changing (#140996)
Browse files Browse the repository at this point in the history
  • Loading branch information
miltonhultgren committed Oct 3, 2022
1 parent 656a48f commit 90a82ef
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions x-pack/plugins/infra/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -74,19 +80,27 @@ 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' },
{ label: 'Metrics Explorer', app: 'metrics', path: '/explorer' },
];
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
? [
Expand All @@ -106,7 +120,7 @@ export class Plugin implements InfraClientPluginClass {
{
label: 'Infrastructure',
sortKey: 300,
entries: core.uiSettings.get(enableInfrastructureHostsView)
entries: isInfrastructureHostsViewEnabled
? [hostInfraEntry, ...infraEntries]
: infraEntries,
},
Expand Down Expand Up @@ -210,8 +224,9 @@ export class Plugin implements InfraClientPluginClass {
order: 8200,
appRoute: '/app/metrics',
category: DEFAULT_APP_CATEGORIES.observability,
updater$: this.appUpdater$,
// !! Need to be kept in sync with the routes in x-pack/plugins/infra/public/pages/metrics/index.tsx
deepLinks: core.uiSettings.get(enableInfrastructureHostsView)
deepLinks: core.uiSettings.get<boolean>(enableInfrastructureHostsView)
? [hostInfraDeepLink, ...infraDeepLinks]
: infraDeepLinks,
mount: async (params: AppMountParameters) => {
Expand All @@ -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({
Expand Down

0 comments on commit 90a82ef

Please sign in to comment.