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] Shim UI exports for new platform #44722

Merged
merged 33 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8b83f05
Remove depdency on legacy interface.
justinkambic Sep 3, 2019
2e64147
Remove custom interface, use common breadcrumb type.
justinkambic Sep 3, 2019
7b0bf2d
Add HTML template for app react entry point.
justinkambic Sep 3, 2019
f02a501
Update app props.
justinkambic Sep 3, 2019
97398d0
Add constant for react app entry point.
justinkambic Sep 3, 2019
cf2eb8c
Remove dependency on legacy capabilities provider.
justinkambic Sep 3, 2019
9fd78a1
Delete legacy kibana framework adapter.
justinkambic Sep 3, 2019
ee9f07e
Add New Platform adapter, reference in startup code.
justinkambic Sep 3, 2019
790c81a
Remove dependency on legacy capabilities function.
justinkambic Sep 3, 2019
1bdc942
Delete reference to obsolete interface.
justinkambic Sep 3, 2019
6e31ccc
Fix busted types in new adapter.
justinkambic Sep 4, 2019
dd10627
Merge branch 'master' into uptime_shim-ui-exports
justinkambic Sep 4, 2019
9e5c726
Merge branch 'master' into uptime_shim-ui-exports
justinkambic Sep 10, 2019
01751a0
Merge branch 'master' into uptime_shim-ui-exports
justinkambic Sep 12, 2019
597fe4e
Merge branch 'master' into uptime_shim-ui-exports
justinkambic Sep 19, 2019
f10988f
Merge branch 'master' into uptime_shim-ui-exports
justinkambic Sep 19, 2019
0bc7395
Add new plugin class, delete old bootstrap code.
justinkambic Sep 19, 2019
838175c
Merge branch 'master' into uptime_shim-ui-exports
elasticmachine Sep 23, 2019
342b945
Provide default for potentially-undefined value.
justinkambic Sep 23, 2019
1608782
Merge branch 'master' into uptime_shim-ui-exports
justinkambic Sep 23, 2019
160ecf8
Merge branch 'uptime_shim-ui-exports' of github.com:justinkambic/kiba…
justinkambic Sep 23, 2019
e5cb213
Merge branch 'master' into uptime_shim-ui-exports
justinkambic Sep 25, 2019
13297ea
Delete obsolete file.
justinkambic Sep 25, 2019
638b589
Update plugin constructor and start interfaces.
justinkambic Sep 25, 2019
d46be5f
Merge branch 'master' into uptime_shim-ui-exports
elasticmachine Sep 25, 2019
4a83b40
Merge branch 'master' into uptime_shim-ui-exports
justinkambic Sep 25, 2019
6f5da20
Add @ts-ignore for unused constructor parameter.
justinkambic Sep 25, 2019
da2e6f1
Merge branch 'uptime_shim-ui-exports' of github.com:justinkambic/kiba…
justinkambic Sep 25, 2019
7098397
Merge branch 'master' into uptime_shim-ui-exports
elasticmachine Sep 27, 2019
bb33f37
Merge branch 'master' into uptime_shim-ui-exports
justinkambic Sep 30, 2019
a9c696d
Import autocomplete provider from new platform.
justinkambic Sep 30, 2019
1d54f0b
Merge branch 'uptime_shim-ui-exports' of github.com:justinkambic/kiba…
justinkambic Sep 30, 2019
9f5577a
Merge branch 'master' into uptime_shim-ui-exports
elasticmachine Oct 2, 2019
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
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/uptime/common/constants/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

export const PLUGIN = {
APP_ROOT_ID: 'react-uptime-root',
ID: 'uptime',
ROUTER_BASE_NAME: '/app/uptime#/',
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
LOCAL_STORAGE_KEY: 'xpack.uptime',
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/uptime/public/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

import './apps/kibana_app';
import './apps/index';
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { compose } from '../lib/compose/kibana_compose';
import { startApp } from './start_app';
import chrome from 'ui/chrome';
import { npStart } from 'ui/new_platform';
import { Plugin } from './plugin';

startApp(compose());
new Plugin({ opaqueId: Symbol('uptime') }, chrome).start(npStart);
50 changes: 50 additions & 0 deletions x-pack/legacy/plugins/uptime/public/apps/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { LegacyCoreStart, PluginInitializerContext } from 'src/core/public';
import { PluginsStart } from 'ui/new_platform/new_platform';
import { Chrome } from 'ui/chrome';
import { UMFrontendLibs } from '../lib/lib';
import { PLUGIN } from '../../common/constants';
import { getKibanaFrameworkAdapter } from '../lib/adapters/framework/new_platform_adapter';
import template from './template.html';
import { UptimeApp } from '../uptime_app';
import { createApolloClient } from '../lib/adapters/framework/apollo_client_adapter';

export interface StartObject {
core: LegacyCoreStart;
plugins: PluginsStart;
}

export class Plugin {
constructor(
// @ts-ignore this is added to satisfy the New Platform typing constraint,
// but we're not leveraging any of its functionality yet.
private readonly initializerContext: PluginInitializerContext,
private readonly chrome: Chrome
) {
this.chrome = chrome;
}

public start({ core }: StartObject): void {
const libs: UMFrontendLibs = { framework: getKibanaFrameworkAdapter(core) };
// @ts-ignore improper type description
this.chrome.setRootTemplate(template);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rudolf it looks like setRootTemplate is slated as being available for 7.5... is this the case? If so we can delete the legacy ui/chrome import and rely entirely on StartObject.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I learned from #46481 that this function isn't going to be offered in the same way in the NP, so we do need this dependency for now.

const checkForRoot = () => {
return new Promise(resolve => {
const ready = !!document.getElementById(PLUGIN.APP_ROOT_ID);
if (ready) {
resolve();
} else {
setTimeout(() => resolve(checkForRoot()), 10);
}
});
};
checkForRoot().then(() => {
libs.framework.render(UptimeApp, createApolloClient);
});
}
}
19 changes: 0 additions & 19 deletions x-pack/legacy/plugins/uptime/public/apps/start_app.tsx

This file was deleted.

1 change: 1 addition & 0 deletions x-pack/legacy/plugins/uptime/public/apps/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="react-uptime-root"></div>
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/uptime/public/badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Badge } from 'ui/chrome/api/badge';
export type UMBadge = Badge | undefined;
import { ChromeBadge } from 'src/core/public';
export type UMBadge = ChromeBadge | undefined;
12 changes: 4 additions & 8 deletions x-pack/legacy/plugins/uptime/public/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@
*/

import { i18n } from '@kbn/i18n';
import { ChromeBreadcrumb } from 'src/core/public';

export interface UMBreadcrumb {
text: string;
href?: string;
}

const makeOverviewBreadcrumb = (search?: string): UMBreadcrumb => ({
const makeOverviewBreadcrumb = (search?: string): ChromeBreadcrumb => ({
text: i18n.translate('xpack.uptime.breadcrumbs.overviewBreadcrumbText', {
defaultMessage: 'Uptime',
}),
href: `#/${search ? search : ''}`,
});

export const getOverviewPageBreadcrumbs = (search?: string): UMBreadcrumb[] => [
export const getOverviewPageBreadcrumbs = (search?: string): ChromeBreadcrumb[] => [
makeOverviewBreadcrumb(search),
];

export const getMonitorPageBreadcrumb = (name: string, search?: string): UMBreadcrumb[] => [
export const getMonitorPageBreadcrumb = (name: string, search?: string): ChromeBreadcrumb[] => [
makeOverviewBreadcrumb(search),
{ text: name },
];
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { capabilities as uiCapabilities } from 'ui/capabilities';

interface IntegratedAppsAvailability {
[key: string]: boolean;
}

export const getIntegratedAppAvailability = (
capabilities: any,
integratedApps: string[]
): IntegratedAppsAvailability => {
const capabilities = uiCapabilities.get();
return integratedApps.reduce((supportedSolutions: IntegratedAppsAvailability, solutionName) => {
supportedSolutions[solutionName] =
capabilities[solutionName] && capabilities[solutionName].show === true;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { ChromeBreadcrumb, CoreStart } from 'src/core/public';
import React from 'react';
import ReactDOM from 'react-dom';
import { get } from 'lodash';
import { CreateGraphQLClient } from './framework_adapter_types';
import { UptimeApp, UptimeAppProps } from '../../../uptime_app';
import { getIntegratedAppAvailability } from './capabilities_adapter';
import { INTEGRATED_SOLUTIONS, PLUGIN } from '../../../../common/constants';
import { getTelemetryMonitorPageLogger, getTelemetryOverviewPageLogger } from '../telemetry';
import { renderUptimeKibanaGlobalHelp } from './kibana_global_help';
import { UMFrameworkAdapter, BootstrapUptimeApp } from '../../lib';
import { createApolloClient } from './apollo_client_adapter';

export const getKibanaFrameworkAdapter = (core: CoreStart): UMFrameworkAdapter => {
const {
application: { capabilities },
chrome: { setBadge, setHelpExtension },
docLinks: { DOC_LINK_VERSION, ELASTIC_WEBSITE_URL },
http: { basePath },
i18n,
} = core;
let breadcrumbs: ChromeBreadcrumb[] = [];
core.chrome.getBreadcrumbs$().subscribe((nextBreadcrumbs?: ChromeBreadcrumb[]) => {
breadcrumbs = nextBreadcrumbs || [];
});
const { apm, infrastructure, logs } = getIntegratedAppAvailability(
capabilities,
INTEGRATED_SOLUTIONS
);
const canSave = get(capabilities, 'uptime.save', false);
const props: UptimeAppProps = {
basePath: basePath.get(),
canSave,
client: createApolloClient(`${basePath.get()}/api/uptime/graphql`, 'true'),
darkMode: core.uiSettings.get('theme:darkMode'),
i18n,
isApmAvailable: apm,
isInfraAvailable: infrastructure,
isLogsAvailable: logs,
kibanaBreadcrumbs: breadcrumbs,
logMonitorPageLoad: getTelemetryMonitorPageLogger('true', basePath.get()),
logOverviewPageLoad: getTelemetryOverviewPageLogger('true', basePath.get()),
renderGlobalHelpControls: () =>
setHelpExtension((element: HTMLElement) => {
ReactDOM.render(
renderUptimeKibanaGlobalHelp(ELASTIC_WEBSITE_URL, DOC_LINK_VERSION),
element
);
return () => ReactDOM.unmountComponentAtNode(element);
}),
routerBasename: basePath.prepend(PLUGIN.ROUTER_BASE_NAME),
setBadge,
setBreadcrumbs: core.chrome.setBreadcrumbs,
};

return {
// TODO: these parameters satisfy the interface but are no longer needed
render: async (createComponent: BootstrapUptimeApp, cgc: CreateGraphQLClient) => {
const node = await document.getElementById('react-uptime-root');
if (node) {
ReactDOM.render(<UptimeApp {...props} />, node);
}
},
};
};
17 changes: 0 additions & 17 deletions x-pack/legacy/plugins/uptime/public/lib/compose/kibana_compose.ts

This file was deleted.

Loading