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 all 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);
58 changes: 58 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,58 @@
/*
* 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(start: StartObject): void {
const {
core,
plugins: {
data: { autocomplete },
},
} = start;
const libs: UMFrontendLibs = {
framework: getKibanaFrameworkAdapter(core, autocomplete),
};
// @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 @@ -6,18 +6,17 @@

import React, { useState, useEffect, useContext } from 'react';
import { uniqueId, startsWith } from 'lodash';
import { npStart } from 'ui/new_platform';
import { EuiCallOut } from '@elastic/eui';
import styled from 'styled-components';
import { FormattedMessage } from '@kbn/i18n/react';
import { StaticIndexPattern } from 'ui/index_patterns';
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
import { AutocompleteProviderRegister, AutocompleteSuggestion } from 'src/plugins/data/public';
import { StaticIndexPattern } from 'src/legacy/core_plugins/data/public/index_patterns/index_patterns';
import { Typeahead } from './typeahead';
import { getIndexPattern } from '../../../lib/adapters/index_pattern';
import { UptimeSettingsContext } from '../../../contexts';
import { useUrlParams } from '../../../hooks';
import { toStaticIndexPattern } from '../../../lib/helper';
import { AutocompleteSuggestion } from '../../../../../../../../src/plugins/data/public';

const Container = styled.div`
margin-bottom: 10px;
Expand All @@ -28,20 +27,18 @@ interface State {
isLoadingIndexPattern: boolean;
}

const getAutocompleteProvider = (language: string) =>
npStart.plugins.data.autocomplete.getProvider(language);

function convertKueryToEsQuery(kuery: string, indexPattern: StaticIndexPattern) {
function convertKueryToEsQuery(kuery: string, indexPattern: unknown) {
const ast = fromKueryExpression(kuery);
return toElasticsearchQuery(ast, indexPattern);
}

function getSuggestions(
query: string,
selectionStart: number,
apmIndexPattern: StaticIndexPattern
apmIndexPattern: StaticIndexPattern,
autocomplete: Pick<AutocompleteProviderRegister, 'getProvider'>
) {
const autocompleteProvider = getAutocompleteProvider('kuery');
const autocompleteProvider = autocomplete.getProvider('kuery');
if (!autocompleteProvider) {
return [];
}
Expand All @@ -62,7 +59,11 @@ function getSuggestions(
return suggestions;
}

export function KueryBar() {
interface Props {
autocomplete: Pick<AutocompleteProviderRegister, 'getProvider'>;
}

export function KueryBar({ autocomplete }: Props) {
const [state, setState] = useState<State>({
suggestions: [],
isLoadingIndexPattern: true,
Expand Down Expand Up @@ -94,7 +95,12 @@ export function KueryBar() {
currentRequestCheck = currentRequest;

try {
let suggestions = await getSuggestions(inputValue, selectionStart, indexPattern);
let suggestions = await getSuggestions(
inputValue,
selectionStart,
indexPattern,
autocomplete
);
suggestions = suggestions
.filter((suggestion: AutocompleteSuggestion) => !startsWith(suggestion.text, 'span.'))
.slice(0, 15);
Expand Down
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.

Loading