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

Migrate doc view part of discover #58094

Merged
merged 19 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from 18 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 .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"src/legacy/core_plugins/data",
"src/plugins/data"
],
"discover": "src/plugins/discover",
"embeddableApi": "src/plugins/embeddable",
"embeddableExamples": "examples/embeddable_examples",
"share": "src/plugins/share",
Expand Down
6 changes: 3 additions & 3 deletions src/core/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1234,11 +1234,11 @@ This table shows where these uiExports have moved to in the New Platform. In mos
| `chromeNavControls` | [`core.chrome.navControls.register{Left,Right}`](/docs/development/core/public/kibana-plugin-public.chromenavcontrols.md) | |
| `contextMenuActions` | | Should be an API on the devTools plugin. |
| `devTools` | | |
| `docViews` | | |
| `docViews` | [`plugins.discover.docViews.addDocView`](./src/plugins/discover/public/doc_views) | Should be an API on the discover plugin. |
| `embeddableActions` | | Should be an API on the embeddables plugin. |
| `embeddableFactories` | | Should be an API on the embeddables plugin. |
| `fieldFormatEditors` | | |
| `fieldFormats` | [`plugins.data.fieldFormats`](./src/plugins/data/public/field_formats) | |
| `fieldFormatEditors` | | |
| `fieldFormats` | [`plugins.data.fieldFormats`](./src/plugins/data/public/field_formats) | |
| `hacks` | n/a | Just run the code in your plugin's `start` method. |
| `home` | [`plugins.home.featureCatalogue.register`](./src/plugins/home/public/feature_catalogue) | Must add `home` as a dependency in your kibana.json. |
| `indexManagement` | | Should be an API on the indexManagement plugin. |
Expand Down
14 changes: 8 additions & 6 deletions src/legacy/core_plugins/kibana/public/discover/build_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ import {

import { DiscoverStartPlugins } from './plugin';
import { SharePluginStart } from '../../../../../plugins/share/public';
import { DocViewsRegistry } from './np_ready/doc_views/doc_views_registry';
import { ChartsPluginStart } from '../../../../../plugins/charts/public';
import { VisualizationsStart } from '../../../visualizations/public';
import { createSavedSearchesLoader, SavedSearch } from '../../../../../plugins/discover/public';
import {
createSavedSearchesLoader,
DocViewerComponent,
SavedSearch,
} from '../../../../../plugins/discover/public';

export interface DiscoverServices {
addBasePath: (path: string) => string;
Expand All @@ -45,7 +48,7 @@ export interface DiscoverServices {
core: CoreStart;
data: DataPublicPluginStart;
docLinks: DocLinksStart;
docViewsRegistry: DocViewsRegistry;
DocViewer: DocViewerComponent;
theme: ChartsPluginStart['theme'];
filterManager: FilterManager;
indexPatterns: IndexPatternsContract;
Expand All @@ -61,8 +64,7 @@ export interface DiscoverServices {
}
export async function buildServices(
core: CoreStart,
plugins: DiscoverStartPlugins,
docViewsRegistry: DocViewsRegistry
plugins: DiscoverStartPlugins
): Promise<DiscoverServices> {
const services = {
savedObjectsClient: core.savedObjects.client,
Expand All @@ -78,7 +80,7 @@ export async function buildServices(
core,
data: plugins.data,
docLinks: core.docLinks,
docViewsRegistry,
DocViewer: plugins.discover.docViews.DocViewer,
theme: plugins.charts.theme,
filterManager: plugins.data.query.filterManager,
getSavedSearchById: async (id: string) => savedObjectService.get(id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ export { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
export { timezoneProvider } from 'ui/vis/lib/timezone';
export { tabifyAggResponse } from '../../../data/public';
export { unhashUrl } from '../../../../../plugins/kibana_utils/public';
export {
ensureDefaultIndexPattern,
formatMsg,
formatStack,
} from '../../../../../plugins/kibana_legacy/public';
export { ensureDefaultIndexPattern } from '../../../../../plugins/kibana_legacy/public';

// EXPORT types
export {
Expand All @@ -76,7 +72,6 @@ export {
EsQuerySortValue,
SortDirection,
} from '../../../../../plugins/data/public';
export { ElasticSearchHit } from './np_ready/doc_views/doc_views_types';
export { getFormat } from 'ui/visualize/loader/pipeline_helpers/utilities';
// @ts-ignore
export { buildPointSeriesData } from 'ui/agg_response/point_series/point_series';
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { FieldName } from './field_name/field_name';
import { FieldName } from '../../../../../../../../plugins/discover/public';
import { wrapInI18nContext } from '../../../kibana_services';

export function FieldNameDirectiveProvider(config, reactDirective) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
* under the License.
*/

import { DocViewer } from '../components/doc_viewer/doc_viewer';
import React from 'react';
import { getServices } from '../../kibana_services';

export function createDocViewerDirective(reactDirective: any) {
return reactDirective(
DocViewer,
(props: any) => {
const { DocViewer } = getServices();
return <DocViewer {...props} />;
},
[
'hit',
['indexPattern', { watchDepth: 'reference' }],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
@import 'fetch_error/index';
@import 'field_chooser/index';
@import 'doc_viewer/index';
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,13 @@ import { ReactWrapper } from 'enzyme';
import { findTestSubject } from '@elastic/eui/lib/test';
import { Doc, DocProps } from './doc';

jest.mock('../doc_viewer/doc_viewer', () => ({
DocViewer: () => null,
}));

jest.mock('../../../kibana_services', () => {
return {
getServices: () => ({
metadata: {
branch: 'test',
},
getDocViewsSorted: () => {
return [];
},
DocViewer: () => null,
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiCallOut, EuiLink, EuiLoadingSpinner, EuiPageContent } from '@elastic/eui';
import { IndexPatternsContract } from 'src/plugins/data/public';
import { DocViewer } from '../doc_viewer/doc_viewer';
import { ElasticRequestState, useEsDocSearch } from './use_es_doc_search';
import { ElasticSearchHit, getServices } from '../../../kibana_services';
import { getServices } from '../../../kibana_services';
import { ElasticSearchHit } from '../../../../../../../../plugins/discover/public';

export interface ElasticSearchResult {
hits: {
Expand Down Expand Up @@ -61,6 +61,7 @@ export interface DocProps {
}

export function Doc(props: DocProps) {
const { DocViewer } = getServices();
const [reqState, hit, indexPattern] = useEsDocSearch(props);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
* under the License.
*/
import { useEffect, useState } from 'react';
import { ElasticSearchHit, IndexPattern } from '../../../kibana_services';
import { IndexPattern } from '../../../kibana_services';
import { DocProps } from './doc';
import { ElasticSearchHit } from '../../../../../../../../plugins/discover/public';

export enum ElasticRequestState {
Loading,
Expand Down
46 changes: 8 additions & 38 deletions src/legacy/core_plugins/kibana/public/discover/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import { BehaviorSubject } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { i18n } from '@kbn/i18n';
import { AppMountParameters, CoreSetup, CoreStart, Plugin } from 'kibana/public';
import angular, { auto } from 'angular';
import { UiActionsSetup, UiActionsStart } from 'src/plugins/ui_actions/public';
Expand All @@ -41,33 +40,22 @@ import {
KibanaLegacySetup,
AngularRenderedAppUpdater,
} from '../../../../../plugins/kibana_legacy/public';
import { DocViewsRegistry } from './np_ready/doc_views/doc_views_registry';
import { DocViewInput, DocViewInputFn } from './np_ready/doc_views/doc_views_types';
import { DocViewTable } from './np_ready/components/table/table';
import { JsonCodeBlock } from './np_ready/components/json_code_block/json_code_block';
import { DiscoverSetup, DiscoverStart } from '../../../../../plugins/discover/public';
import { HomePublicPluginSetup } from '../../../../../plugins/home/public';
import {
VisualizationsStart,
VisualizationsSetup,
} from '../../../visualizations/public/np_ready/public';
import { createKbnUrlTracker } from '../../../../../plugins/kibana_utils/public';

/**
* These are the interfaces with your public contracts. You should export these
* for other plugins to use in _their_ `SetupDeps`/`StartDeps` interfaces.
* @public
*/
export interface DiscoverSetup {
addDocView(docViewRaw: DocViewInput | DocViewInputFn): void;
}
export type DiscoverStart = void;
export interface DiscoverSetupPlugins {
uiActions: UiActionsSetup;
embeddable: IEmbeddableSetup;
kibanaLegacy: KibanaLegacySetup;
home: HomePublicPluginSetup;
visualizations: VisualizationsSetup;
data: DataPublicPluginSetup;
discover: DiscoverSetup;
}
export interface DiscoverStartPlugins {
uiActions: UiActionsStart;
Expand All @@ -78,6 +66,7 @@ export interface DiscoverStartPlugins {
share: SharePluginStart;
inspector: any;
visualizations: VisualizationsStart;
discover: DiscoverStart;
}
const innerAngularName = 'app/discover';
const embeddableAngularName = 'app/discoverEmbeddable';
Expand All @@ -87,10 +76,9 @@ const embeddableAngularName = 'app/discoverEmbeddable';
* There are 2 kinds of Angular bootstrapped for rendering, additionally to the main Angular
* Discover provides embeddables, those contain a slimmer Angular
*/
export class DiscoverPlugin implements Plugin<DiscoverSetup, DiscoverStart> {
export class DiscoverPlugin implements Plugin<void, void> {
private servicesInitialized: boolean = false;
private innerAngularInitialized: boolean = false;
private docViewsRegistry: DocViewsRegistry | null = null;
private embeddableInjector: auto.IInjectorService | null = null;
private getEmbeddableInjector: (() => Promise<auto.IInjectorService>) | null = null;
private appStateUpdater = new BehaviorSubject<AngularRenderedAppUpdater>(() => ({}));
Expand All @@ -103,7 +91,7 @@ export class DiscoverPlugin implements Plugin<DiscoverSetup, DiscoverStart> {
public initializeInnerAngular?: () => void;
public initializeServices?: () => Promise<{ core: CoreStart; plugins: DiscoverStartPlugins }>;

setup(core: CoreSetup, plugins: DiscoverSetupPlugins): DiscoverSetup {
setup(core: CoreSetup, plugins: DiscoverSetupPlugins) {
const { appMounted, appUnMounted, stop: stopUrlTracker } = createKbnUrlTracker({
baseUrl: core.http.basePath.prepend('/app/kibana'),
defaultSubUrl: '#/discover',
Expand All @@ -130,21 +118,7 @@ export class DiscoverPlugin implements Plugin<DiscoverSetup, DiscoverStart> {
};

this.getEmbeddableInjector = this.getInjector.bind(this);
this.docViewsRegistry = new DocViewsRegistry(this.getEmbeddableInjector);
this.docViewsRegistry.addDocView({
title: i18n.translate('kbn.discover.docViews.table.tableTitle', {
defaultMessage: 'Table',
}),
order: 10,
component: DocViewTable,
});
this.docViewsRegistry.addDocView({
title: i18n.translate('kbn.discover.docViews.json.jsonTitle', {
defaultMessage: 'JSON',
}),
order: 20,
component: JsonCodeBlock,
});
plugins.discover.docViews.setAngularInjectorGetter(this.getEmbeddableInjector);
plugins.kibanaLegacy.registerLegacyApp({
id: 'discover',
title: 'Discover',
Expand Down Expand Up @@ -172,13 +146,9 @@ export class DiscoverPlugin implements Plugin<DiscoverSetup, DiscoverStart> {
},
});
registerFeature(plugins.home);

return {
addDocView: this.docViewsRegistry.addDocView.bind(this.docViewsRegistry),
};
}

start(core: CoreStart, plugins: DiscoverStartPlugins): DiscoverStart {
start(core: CoreStart, plugins: DiscoverStartPlugins) {
// we need to register the application service at setup, but to render it
// there are some start dependencies necessary, for this reason
// initializeInnerAngular + initializeServices are assigned at start and used
Expand All @@ -197,7 +167,7 @@ export class DiscoverPlugin implements Plugin<DiscoverSetup, DiscoverStart> {
if (this.servicesInitialized) {
return { core, plugins };
}
const services = await buildServices(core, plugins, this.docViewsRegistry!);
const services = await buildServices(core, plugins);
setServices(services);
this.servicesInitialized = true;

Expand Down
11 changes: 11 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ export const npSetup = {
}),
},
},
discover: {
docViews: {
addDocView: sinon.fake(),
setAngularInjectorGetter: sinon.fake(),
},
},
},
};

Expand Down Expand Up @@ -395,6 +401,11 @@ export const npStart = {
useChartsTheme: sinon.fake(),
},
},
discover: {
docViews: {
DocViewer: () => null,
},
},
},
};

Expand Down
3 changes: 3 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
NavigationPublicPluginStart,
} from '../../../../plugins/navigation/public';
import { VisTypeVegaSetup } from '../../../../plugins/vis_type_vega/public';
import { DiscoverSetup, DiscoverStart } from '../../../../plugins/discover/public';

export interface PluginsSetup {
bfetch: BfetchPublicSetup;
Expand All @@ -70,6 +71,7 @@ export interface PluginsSetup {
advancedSettings: AdvancedSettingsSetup;
management: ManagementSetup;
visTypeVega: VisTypeVegaSetup;
discover: DiscoverSetup;
telemetry?: TelemetryPluginSetup;
}

Expand All @@ -87,6 +89,7 @@ export interface PluginsStart {
share: SharePluginStart;
management: ManagementStart;
advancedSettings: AdvancedSettingsStart;
discover: DiscoverStart;
telemetry?: TelemetryPluginStart;
}

Expand Down
6 changes: 6 additions & 0 deletions src/plugins/discover/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "discover",
"version": "kibana",
"server": false,
"ui": true
}
1 change: 1 addition & 0 deletions src/plugins/discover/public/components/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'doc_viewer/index';
Loading