Skip to content

Commit

Permalink
[7.x] [Uptime] Unmount uptime app properly (#66950) (#67287)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored May 25, 2020
1 parent 95e02f9 commit b8ba513
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
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

0 comments on commit b8ba513

Please sign in to comment.