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

[7.x] [Uptime] Shim UI exports for new platform (#44722) #47218

Merged
merged 2 commits into from
Oct 3, 2019
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
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#/',
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);
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