Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions x-pack/plugins/observability/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { BehaviorSubject } from 'rxjs';
import { i18n } from '@kbn/i18n';
import {
AppMountParameters,
AppUpdater,
CoreSetup,
DEFAULT_APP_CATEGORIES,
Plugin as PluginClass,
Expand All @@ -28,6 +30,8 @@ interface SetupPlugins {
export type ObservabilityPluginStart = void;

export class Plugin implements PluginClass<ObservabilityPluginSetup, ObservabilityPluginStart> {
private readonly appUpdater$ = new BehaviorSubject<AppUpdater>(() => ({}));

constructor(context: PluginInitializerContext) {}

public setup(core: CoreSetup, plugins: SetupPlugins) {
Expand All @@ -37,6 +41,7 @@ export class Plugin implements PluginClass<ObservabilityPluginSetup, Observabili
order: 8000,
euiIconType: 'logoObservability',
appRoute: '/app/observability',
updater$: this.appUpdater$,
category: DEFAULT_APP_CATEGORIES.observability,

mount: async (params: AppMountParameters<unknown>) => {
Expand Down Expand Up @@ -79,7 +84,7 @@ export class Plugin implements PluginClass<ObservabilityPluginSetup, Observabili
dashboard: { register: registerDataHandler },
};
}
public start(core: CoreStart) {
toggleOverviewLinkInNav(core);
public start({ application }: CoreStart) {
toggleOverviewLinkInNav(this.appUpdater$, application);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,58 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { CoreStart } from 'kibana/public';

import { Subject } from 'rxjs';
import { AppUpdater, AppNavLinkStatus } from '../../../../src/core/public';
import { applicationServiceMock } from '../../../../src/core/public/mocks';

import { toggleOverviewLinkInNav } from './toggle_overview_link_in_nav';

describe('toggleOverviewLinkInNav', () => {
const update = jest.fn();
afterEach(() => {
update.mockClear();
let applicationStart: ReturnType<typeof applicationServiceMock.createStartContract>;
let subjectMock: jest.Mocked<Subject<AppUpdater>>;

beforeEach(() => {
applicationStart = applicationServiceMock.createStartContract();
subjectMock = {
next: jest.fn(),
} as any;
});

it('hides overview menu', () => {
const core = ({
application: {
capabilities: {
navLinks: {
apm: false,
logs: false,
metrics: false,
uptime: false,
},
},
applicationStart.capabilities = {
management: {},
catalogue: {},
navLinks: {
apm: false,
logs: false,
metrics: false,
uptime: false,
},
chrome: { navLinks: { update } },
} as unknown) as CoreStart;
toggleOverviewLinkInNav(core);
expect(update).toHaveBeenCalledWith('observability-overview', { hidden: true });
};

toggleOverviewLinkInNav(subjectMock, applicationStart);

expect(subjectMock.next).toHaveBeenCalledTimes(1);
const updater = subjectMock.next.mock.calls[0][0]!;
expect(updater({} as any)).toEqual({
navLinkStatus: AppNavLinkStatus.hidden,
});
});
it('shows overview menu', () => {
const core = ({
application: {
capabilities: {
navLinks: {
apm: true,
logs: false,
metrics: false,
uptime: false,
},
},
applicationStart.capabilities = {
management: {},
catalogue: {},
navLinks: {
apm: true,
logs: false,
metrics: false,
uptime: false,
},
chrome: { navLinks: { update } },
} as unknown) as CoreStart;
toggleOverviewLinkInNav(core);
expect(update).not.toHaveBeenCalled();
};

toggleOverviewLinkInNav(subjectMock, applicationStart);

expect(subjectMock.next).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { CoreStart } from 'kibana/public';
import { Subject } from 'rxjs';
import { AppNavLinkStatus, AppUpdater, ApplicationStart } from '../../../../src/core/public';

export function toggleOverviewLinkInNav(core: CoreStart) {
const { apm, logs, metrics, uptime } = core.application.capabilities.navLinks;
export function toggleOverviewLinkInNav(
updater$: Subject<AppUpdater>,
{ capabilities }: ApplicationStart
) {
const { apm, logs, metrics, uptime } = capabilities.navLinks;
const someVisible = Object.values({ apm, logs, metrics, uptime }).some((visible) => visible);
if (!someVisible) {
core.chrome.navLinks.update('observability-overview', { hidden: true });
updater$.next(() => ({
navLinkStatus: AppNavLinkStatus.hidden,
}));
}
}