Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Uptime] Unmount uptime app properly #66950

Merged
merged 2 commits into from
May 19, 2020
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
21 changes: 15 additions & 6 deletions x-pack/plugins/uptime/public/apps/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'kibana/public';
import { AppMountParameters, DEFAULT_APP_CATEGORIES } from '../../../../../src/core/public';
import {
CoreSetup,
CoreStart,
Plugin,
PluginInitializerContext,
AppMountParameters,
} from 'kibana/public';
import { DEFAULT_APP_CATEGORIES } from '../../../../../src/core/public';
import { UMFrontendLibs } from '../lib/lib';
import { PLUGIN } from '../../common/constants';
import { FeatureCatalogueCategory } from '../../../../../src/plugins/home/public';
Expand All @@ -23,7 +29,11 @@ export interface ClientPluginsStart {
embeddable: EmbeddableStart;
}

export class UptimePlugin implements Plugin<void, void, ClientPluginsSetup, ClientPluginsStart> {
export type ClientSetup = void;
export type ClientStart = void;

export class UptimePlugin
implements Plugin<ClientSetup, ClientStart, ClientPluginsSetup, ClientPluginsStart> {
constructor(_context: PluginInitializerContext) {}

public async setup(
Expand All @@ -49,7 +59,7 @@ export class UptimePlugin implements Plugin<void, void, ClientPluginsSetup, Clie
order: 8900,
title: PLUGIN.TITLE,
category: DEFAULT_APP_CATEGORIES.observability,
async mount(params: AppMountParameters) {
mount: async (params: AppMountParameters) => {
const [coreStart, corePlugins] = await core.getStartServices();
const { getKibanaFrameworkAdapter } = await import(
'../lib/adapters/framework/new_platform_adapter'
Expand All @@ -59,8 +69,7 @@ export class UptimePlugin implements Plugin<void, void, ClientPluginsSetup, Clie
const libs: UMFrontendLibs = {
framework: getKibanaFrameworkAdapter(coreStart, plugins, corePlugins),
};
libs.framework.render(element);
return () => {};
return libs.framework.render(element);
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ChromeBreadcrumb, CoreStart } from 'src/core/public';
import { CoreStart } from 'src/core/public';
import React from 'react';
import ReactDOM from 'react-dom';
import { get } from 'lodash';
Expand Down Expand Up @@ -46,11 +46,6 @@ export const getKibanaFrameworkAdapter = (
}
});

let breadcrumbs: ChromeBreadcrumb[] = [];
core.chrome.getBreadcrumbs$().subscribe((nextBreadcrumbs?: ChromeBreadcrumb[]) => {
breadcrumbs = nextBreadcrumbs || [];
});

const { apm, infrastructure, logs } = getIntegratedAppAvailability(
capabilities,
INTEGRATED_SOLUTIONS
Expand All @@ -68,7 +63,6 @@ export const getKibanaFrameworkAdapter = (
isApmAvailable: apm,
isInfraAvailable: infrastructure,
isLogsAvailable: logs,
kibanaBreadcrumbs: breadcrumbs,
plugins,
startPlugins,
renderGlobalHelpControls: () =>
Expand Down Expand Up @@ -97,6 +91,10 @@ export const getKibanaFrameworkAdapter = (
if (element) {
ReactDOM.render(<UptimeApp {...props} />, element);
}

return () => {
ReactDOM.unmountComponentAtNode(element);
};
},
};
};
3 changes: 2 additions & 1 deletion x-pack/plugins/uptime/public/lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { ReactElement } from 'react';
import { AppUnmount } from 'kibana/public';
import { UMBadge } from '../badge';
import { UptimeAppProps } from '../uptime_app';

Expand All @@ -17,5 +18,5 @@ export type UMUpdateBadge = (badge: UMBadge) => void;
export type BootstrapUptimeApp = (props: UptimeAppProps) => ReactElement<any>;

export interface UMFrameworkAdapter {
render(element: any): void;
render(element: any): Promise<AppUnmount>;
}
1 change: 0 additions & 1 deletion x-pack/plugins/uptime/public/uptime_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export interface UptimeAppProps {
isApmAvailable: boolean;
isInfraAvailable: boolean;
isLogsAvailable: boolean;
kibanaBreadcrumbs: ChromeBreadcrumb[];
plugins: ClientPluginsSetup;
startPlugins: ClientPluginsStart;
routerBasename: string;
Expand Down