From 216a37949b311b00e1acfa7ad8be552fd183a8e6 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 19 Feb 2020 18:37:53 +0100 Subject: [PATCH 01/11] wip --- .../kibana/public/discover/build_services.ts | 2 +- .../kibana/public/discover/kibana_services.ts | 2 +- .../discover/np_ready/angular/doc_viewer.ts | 2 +- .../discover/np_ready/components/_index.scss | 1 - .../discover/np_ready/components/doc/doc.tsx | 2 +- .../kibana/public/discover/plugin.ts | 8 +-- src/plugins/discover/kibana.json | 6 ++ .../__snapshots__/doc_viewer.test.tsx.snap | 0 .../doc_viewer_render_tab.test.tsx.snap | 0 .../components/doc_viewer/_doc_viewer.scss | 0 .../public}/components/doc_viewer/_index.scss | 0 .../components/doc_viewer/doc_viewer.test.tsx | 2 +- .../components/doc_viewer/doc_viewer.tsx | 2 +- .../doc_viewer/doc_viewer_render_error.tsx | 2 +- .../doc_viewer/doc_viewer_render_tab.test.tsx | 0 .../doc_viewer/doc_viewer_render_tab.tsx | 0 .../components/doc_viewer/doc_viewer_tab.tsx | 0 .../json_code_block.test.tsx.snap | 0 .../json_code_block/json_code_block.test.tsx | 2 +- .../json_code_block/json_code_block.tsx | 0 .../public}/components/table/table.test.tsx | 2 +- .../public}/components/table/table.tsx | 0 .../components/table/table_helper.test.ts | 0 .../public}/components/table/table_helper.tsx | 0 .../public}/components/table/table_row.tsx | 2 +- .../table/table_row_btn_collapse.tsx | 0 .../table/table_row_btn_filter_add.tsx | 0 .../table/table_row_btn_filter_exists.tsx | 0 .../table/table_row_btn_filter_remove.tsx | 0 .../table/table_row_btn_toggle_column.tsx | 0 .../table/table_row_icon_no_mapping.tsx | 0 .../table/table_row_icon_underscore.tsx | 0 .../public}/doc_views/doc_views_helpers.tsx | 0 .../public}/doc_views/doc_views_registry.ts | 11 ++- .../public}/doc_views/doc_views_types.ts | 2 +- src/plugins/discover/public/index.ts | 24 +++++++ src/plugins/discover/public/plugin.ts | 71 +++++++++++++++++++ 37 files changed, 125 insertions(+), 18 deletions(-) create mode 100644 src/plugins/discover/kibana.json rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/doc_viewer/__snapshots__/doc_viewer.test.tsx.snap (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/doc_viewer/__snapshots__/doc_viewer_render_tab.test.tsx.snap (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/doc_viewer/_doc_viewer.scss (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/doc_viewer/_index.scss (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/doc_viewer/doc_viewer.test.tsx (96%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/doc_viewer/doc_viewer.tsx (95%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/doc_viewer/doc_viewer_render_error.tsx (91%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/doc_viewer/doc_viewer_render_tab.test.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/doc_viewer/doc_viewer_render_tab.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/doc_viewer/doc_viewer_tab.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/json_code_block/__snapshots__/json_code_block.test.tsx.snap (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/json_code_block/json_code_block.test.tsx (92%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/json_code_block/json_code_block.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/table/table.test.tsx (98%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/table/table.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/table/table_helper.test.ts (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/table/table_helper.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/table/table_row.tsx (96%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/table/table_row_btn_collapse.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/table/table_row_btn_filter_add.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/table/table_row_btn_filter_exists.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/table/table_row_btn_filter_remove.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/table/table_row_btn_toggle_column.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/table/table_row_icon_no_mapping.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/components/table/table_row_icon_underscore.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/doc_views/doc_views_helpers.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/doc_views/doc_views_registry.ts (84%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready => plugins/discover/public}/doc_views/doc_views_types.ts (95%) create mode 100644 src/plugins/discover/public/index.ts create mode 100644 src/plugins/discover/public/plugin.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/build_services.ts b/src/legacy/core_plugins/kibana/public/discover/build_services.ts index 81f1c911f1cc9..0e0df24457f66 100644 --- a/src/legacy/core_plugins/kibana/public/discover/build_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/build_services.ts @@ -34,7 +34,7 @@ import { createSavedSearchesLoader } from './saved_searches'; import { DiscoverStartPlugins } from './plugin'; import { SharePluginStart } from '../../../../../plugins/share/public'; import { SavedSearch } from './np_ready/types'; -import { DocViewsRegistry } from './np_ready/doc_views/doc_views_registry'; +import { DocViewsRegistry } from '../../../../../plugins/discover/public/doc_views/doc_views_registry'; import { ChartsPluginStart } from '../../../../../plugins/charts/public'; import { VisualizationsStart } from '../../../visualizations/public'; diff --git a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts index b0bb17ce1ac7f..a667fb2562b43 100644 --- a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts @@ -81,7 +81,7 @@ export { EsQuerySortValue, SortDirection, } from '../../../../../plugins/data/public'; -export { ElasticSearchHit } from './np_ready/doc_views/doc_views_types'; +export { ElasticSearchHit } from '../../../../../plugins/discover/public/doc_views/doc_views_types'; export { registerTimefilterWithGlobalStateFactory } from 'ui/timefilter/setup_router'; export { getFormat } from 'ui/visualize/loader/pipeline_helpers/utilities'; // @ts-ignore diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_viewer.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_viewer.ts index 6ba47b839563b..3cc8345efc332 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_viewer.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_viewer.ts @@ -17,7 +17,7 @@ * under the License. */ -import { DocViewer } from '../components/doc_viewer/doc_viewer'; +import { DocViewer } from '../../../../../../../plugins/discover/public/components/doc_viewer/doc_viewer'; export function createDocViewerDirective(reactDirective: any) { return reactDirective( diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/_index.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/_index.scss index 0491430e5fddd..7161560f8fda4 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/_index.scss +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/_index.scss @@ -1,3 +1,2 @@ @import 'fetch_error/index'; @import 'field_chooser/index'; -@import 'doc_viewer/index'; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.tsx index 819eb9df592bd..8cac364302712 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.tsx @@ -20,7 +20,7 @@ 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 { DocViewer } from '../../../../../../../../plugins/discover/public/components/doc_viewer/doc_viewer'; import { ElasticRequestState, useEsDocSearch } from './use_es_doc_search'; import { ElasticSearchHit, getServices } from '../../../kibana_services'; diff --git a/src/legacy/core_plugins/kibana/public/discover/plugin.ts b/src/legacy/core_plugins/kibana/public/discover/plugin.ts index e8ded9d99f892..e8db920667656 100644 --- a/src/legacy/core_plugins/kibana/public/discover/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/discover/plugin.ts @@ -40,10 +40,10 @@ 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 { DocViewsRegistry } from '../../../../../plugins/discover/public/doc_views/doc_views_registry'; +import { DocViewInput, DocViewInputFn } from '../../../../../plugins/discover/public/doc_views/doc_views_types'; +import { DocViewTable } from '../../../../../plugins/discover/public/components/table/table'; +import { JsonCodeBlock } from '../../../../../plugins/discover/public/components/json_code_block/json_code_block'; import { HomePublicPluginSetup } from '../../../../../plugins/home/public'; import { VisualizationsStart, diff --git a/src/plugins/discover/kibana.json b/src/plugins/discover/kibana.json new file mode 100644 index 0000000000000..91d6358d44c18 --- /dev/null +++ b/src/plugins/discover/kibana.json @@ -0,0 +1,6 @@ +{ + "id": "discover", + "version": "kibana", + "server": false, + "ui": true +} diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/__snapshots__/doc_viewer.test.tsx.snap b/src/plugins/discover/public/components/doc_viewer/__snapshots__/doc_viewer.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/__snapshots__/doc_viewer.test.tsx.snap rename to src/plugins/discover/public/components/doc_viewer/__snapshots__/doc_viewer.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/__snapshots__/doc_viewer_render_tab.test.tsx.snap b/src/plugins/discover/public/components/doc_viewer/__snapshots__/doc_viewer_render_tab.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/__snapshots__/doc_viewer_render_tab.test.tsx.snap rename to src/plugins/discover/public/components/doc_viewer/__snapshots__/doc_viewer_render_tab.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/_doc_viewer.scss b/src/plugins/discover/public/components/doc_viewer/_doc_viewer.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/_doc_viewer.scss rename to src/plugins/discover/public/components/doc_viewer/_doc_viewer.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/_index.scss b/src/plugins/discover/public/components/doc_viewer/_index.scss similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/_index.scss rename to src/plugins/discover/public/components/doc_viewer/_index.scss diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.test.tsx b/src/plugins/discover/public/components/doc_viewer/doc_viewer.test.tsx similarity index 96% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.test.tsx rename to src/plugins/discover/public/components/doc_viewer/doc_viewer.test.tsx index 15f0f40700abc..7f2e0e527c44b 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.test.tsx +++ b/src/plugins/discover/public/components/doc_viewer/doc_viewer.test.tsx @@ -21,7 +21,7 @@ import { mount, shallow } from 'enzyme'; import { DocViewer } from './doc_viewer'; // @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; -import { getServices } from '../../../kibana_services'; +import { getServices } from '../../../../../legacy/core_plugins/kibana/public/discover/kibana_services'; import { DocViewRenderProps } from '../../doc_views/doc_views_types'; jest.mock('../../../kibana_services', () => { diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.tsx b/src/plugins/discover/public/components/doc_viewer/doc_viewer.tsx similarity index 95% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.tsx rename to src/plugins/discover/public/components/doc_viewer/doc_viewer.tsx index a177d8c29304c..b80bffdbc4fed 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.tsx +++ b/src/plugins/discover/public/components/doc_viewer/doc_viewer.tsx @@ -18,7 +18,7 @@ */ import React from 'react'; import { EuiTabbedContent } from '@elastic/eui'; -import { getServices } from '../../../kibana_services'; +import { getServices } from '../../../../../legacy/core_plugins/kibana/public/discover/kibana_services'; import { DocViewerTab } from './doc_viewer_tab'; import { DocView, DocViewRenderProps } from '../../doc_views/doc_views_types'; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_error.tsx b/src/plugins/discover/public/components/doc_viewer/doc_viewer_render_error.tsx similarity index 91% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_error.tsx rename to src/plugins/discover/public/components/doc_viewer/doc_viewer_render_error.tsx index 075217add7b52..c647a779fd430 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_error.tsx +++ b/src/plugins/discover/public/components/doc_viewer/doc_viewer_render_error.tsx @@ -18,7 +18,7 @@ */ import React from 'react'; import { EuiCallOut, EuiCodeBlock } from '@elastic/eui'; -import { formatMsg, formatStack } from '../../../kibana_services'; +import { formatMsg, formatStack } from '../../../../../legacy/core_plugins/kibana/public/discover/kibana_services'; interface Props { error: Error | string; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_tab.test.tsx b/src/plugins/discover/public/components/doc_viewer/doc_viewer_render_tab.test.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_tab.test.tsx rename to src/plugins/discover/public/components/doc_viewer/doc_viewer_render_tab.test.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_tab.tsx b/src/plugins/discover/public/components/doc_viewer/doc_viewer_render_tab.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_render_tab.tsx rename to src/plugins/discover/public/components/doc_viewer/doc_viewer_render_tab.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_tab.tsx b/src/plugins/discover/public/components/doc_viewer/doc_viewer_tab.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer_tab.tsx rename to src/plugins/discover/public/components/doc_viewer/doc_viewer_tab.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/json_code_block/__snapshots__/json_code_block.test.tsx.snap b/src/plugins/discover/public/components/json_code_block/__snapshots__/json_code_block.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/json_code_block/__snapshots__/json_code_block.test.tsx.snap rename to src/plugins/discover/public/components/json_code_block/__snapshots__/json_code_block.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/json_code_block/json_code_block.test.tsx b/src/plugins/discover/public/components/json_code_block/json_code_block.test.tsx similarity index 92% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/json_code_block/json_code_block.test.tsx rename to src/plugins/discover/public/components/json_code_block/json_code_block.test.tsx index 9cab7974c9eb2..7c832e89fe2f6 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/json_code_block/json_code_block.test.tsx +++ b/src/plugins/discover/public/components/json_code_block/json_code_block.test.tsx @@ -19,7 +19,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import { JsonCodeBlock } from './json_code_block'; -import { IndexPattern } from '../../../kibana_services'; +import { IndexPattern } from '../../../../../legacy/core_plugins/kibana/public/discover/kibana_services'; it('returns the `JsonCodeEditor` component', () => { const props = { diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/json_code_block/json_code_block.tsx b/src/plugins/discover/public/components/json_code_block/json_code_block.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/json_code_block/json_code_block.tsx rename to src/plugins/discover/public/components/json_code_block/json_code_block.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table.test.tsx b/src/plugins/discover/public/components/table/table.test.tsx similarity index 98% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table.test.tsx rename to src/plugins/discover/public/components/table/table.test.tsx index 386f405544a61..5f50c1abae879 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table.test.tsx +++ b/src/plugins/discover/public/components/table/table.test.tsx @@ -22,7 +22,7 @@ import { mount } from 'enzyme'; import { findTestSubject } from '@elastic/eui/lib/test'; import { DocViewTable } from './table'; -import { IndexPattern, indexPatterns } from '../../../kibana_services'; +import { IndexPattern, indexPatterns } from '../../../../../legacy/core_plugins/kibana/public/discover/kibana_services'; jest.mock('ui/new_platform'); diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table.tsx b/src/plugins/discover/public/components/table/table.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table.tsx rename to src/plugins/discover/public/components/table/table.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_helper.test.ts b/src/plugins/discover/public/components/table/table_helper.test.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_helper.test.ts rename to src/plugins/discover/public/components/table/table_helper.test.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_helper.tsx b/src/plugins/discover/public/components/table/table_helper.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_helper.tsx rename to src/plugins/discover/public/components/table/table_helper.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row.tsx b/src/plugins/discover/public/components/table/table_row.tsx similarity index 96% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row.tsx rename to src/plugins/discover/public/components/table/table_row.tsx index 7a78e89416361..61ef3627bf9df 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row.tsx +++ b/src/plugins/discover/public/components/table/table_row.tsx @@ -26,7 +26,7 @@ import { DocViewTableRowBtnCollapse } from './table_row_btn_collapse'; import { DocViewTableRowBtnFilterExists } from './table_row_btn_filter_exists'; import { DocViewTableRowIconNoMapping } from './table_row_icon_no_mapping'; import { DocViewTableRowIconUnderscore } from './table_row_icon_underscore'; -import { FieldName } from '../../angular/directives/field_name/field_name'; +import { FieldName } from '../../../../../legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/field_name'; export interface Props { field: string; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_collapse.tsx b/src/plugins/discover/public/components/table/table_row_btn_collapse.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_collapse.tsx rename to src/plugins/discover/public/components/table/table_row_btn_collapse.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_add.tsx b/src/plugins/discover/public/components/table/table_row_btn_filter_add.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_add.tsx rename to src/plugins/discover/public/components/table/table_row_btn_filter_add.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_exists.tsx b/src/plugins/discover/public/components/table/table_row_btn_filter_exists.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_exists.tsx rename to src/plugins/discover/public/components/table/table_row_btn_filter_exists.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_remove.tsx b/src/plugins/discover/public/components/table/table_row_btn_filter_remove.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_remove.tsx rename to src/plugins/discover/public/components/table/table_row_btn_filter_remove.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_toggle_column.tsx b/src/plugins/discover/public/components/table/table_row_btn_toggle_column.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_toggle_column.tsx rename to src/plugins/discover/public/components/table/table_row_btn_toggle_column.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_icon_no_mapping.tsx b/src/plugins/discover/public/components/table/table_row_icon_no_mapping.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_icon_no_mapping.tsx rename to src/plugins/discover/public/components/table/table_row_icon_no_mapping.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_icon_underscore.tsx b/src/plugins/discover/public/components/table/table_row_icon_underscore.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_icon_underscore.tsx rename to src/plugins/discover/public/components/table/table_row_icon_underscore.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_helpers.tsx b/src/plugins/discover/public/doc_views/doc_views_helpers.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_helpers.tsx rename to src/plugins/discover/public/doc_views/doc_views_helpers.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_registry.ts b/src/plugins/discover/public/doc_views/doc_views_registry.ts similarity index 84% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_registry.ts rename to src/plugins/discover/public/doc_views/doc_views_registry.ts index 91acf1c7ac4ae..78044e2e43e59 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_registry.ts +++ b/src/plugins/discover/public/doc_views/doc_views_registry.ts @@ -17,14 +17,19 @@ * under the License. */ +import { Subject } from 'rxjs'; import { auto } from 'angular'; import { convertDirectiveToRenderFn } from './doc_views_helpers'; import { DocView, DocViewInput, ElasticSearchHit, DocViewInputFn } from './doc_views_types'; export class DocViewsRegistry { private docViews: DocView[] = []; + private angularInjector: Subject = new Subject(); - constructor(private getInjector: () => Promise) {} + setAngularInjector(injector: auto.IInjectorService) { + this.angularInjector.next(injector); + this.angularInjector.complete(); + } /** * Extends and adds the given doc view to the registry array @@ -33,7 +38,9 @@ export class DocViewsRegistry { const docView = typeof docViewRaw === 'function' ? docViewRaw() : docViewRaw; if (docView.directive) { // convert angular directive to render function for backwards compatibility - docView.render = convertDirectiveToRenderFn(docView.directive, this.getInjector); + docView.render = convertDirectiveToRenderFn(docView.directive, () => + this.angularInjector.asObservable().toPromise() + ); } if (typeof docView.shouldShow !== 'function') { docView.shouldShow = () => true; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_types.ts b/src/plugins/discover/public/doc_views/doc_views_types.ts similarity index 95% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_types.ts rename to src/plugins/discover/public/doc_views/doc_views_types.ts index a7828f9f0e7ed..9a9e379d38d94 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_types.ts +++ b/src/plugins/discover/public/doc_views/doc_views_types.ts @@ -18,7 +18,7 @@ */ import { ComponentType } from 'react'; import { IScope } from 'angular'; -import { IndexPattern } from '../../kibana_services'; +import { IndexPattern } from '../../../../legacy/core_plugins/kibana/public/discover/kibana_services'; export interface AngularDirective { controller: (scope: AngularScope) => void; diff --git a/src/plugins/discover/public/index.ts b/src/plugins/discover/public/index.ts new file mode 100644 index 0000000000000..a452cadf03b06 --- /dev/null +++ b/src/plugins/discover/public/index.ts @@ -0,0 +1,24 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { DiscoverPlugin } from './plugin'; + +export function plugin() { + return new DiscoverPlugin(); +} diff --git a/src/plugins/discover/public/plugin.ts b/src/plugins/discover/public/plugin.ts new file mode 100644 index 0000000000000..8e68148760d64 --- /dev/null +++ b/src/plugins/discover/public/plugin.ts @@ -0,0 +1,71 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { i18n } from '@kbn/i18n'; +import { auto } from 'angular'; +import { CoreSetup, Plugin } from 'kibana/public'; +import { DocViewInput, DocViewInputFn } from './doc_views/doc_views_types'; +import { DocViewsRegistry } from './doc_views/doc_views_registry'; +import { DocViewTable } from './components/table/table'; +import { JsonCodeBlock } from './components/json_code_block/json_code_block'; + +/** + * 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; + setAngularInjector(injector: auto.IInjectorService): void; +} +export type DiscoverStart = void; + +/** + * Contains Discover, one of the oldest parts of Kibana + * 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 { + private docViewsRegistry: DocViewsRegistry | null = null; + + setup(core: CoreSetup): DiscoverSetup { + this.docViewsRegistry = new DocViewsRegistry(); + 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, + }); + + return { + addDocView: this.docViewsRegistry.addDocView.bind(this.docViewsRegistry), + setAngularInjector: this.docViewsRegistry.setAngularInjector.bind(this.docViewsRegistry), + }; + } + + start() {} +} From 6d7a10bb1b1ee7381aabdbafdc35c6ecf263f7eb Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Fri, 21 Feb 2020 09:58:19 +0100 Subject: [PATCH 02/11] wip --- .../kibana/public/discover/build_services.ts | 9 ++- .../kibana/public/discover/kibana_services.ts | 2 - .../np_ready/angular/directives/field_name.js | 2 +- .../angular/{doc_viewer.ts => doc_viewer.tsx} | 8 ++- .../np_ready/components/doc/doc.test.tsx | 4 +- .../discover/np_ready/components/doc/doc.tsx | 2 +- .../kibana/public/discover/plugin.ts | 46 +++------------ .../new_platform/new_platform.karma_mock.js | 6 ++ .../ui/public/new_platform/new_platform.ts | 3 + src/plugins/discover/public/_index.scss | 1 + .../discover/public/components/_index.scss | 1 + .../components/doc_viewer/doc_viewer.test.tsx | 26 ++++----- .../components/doc_viewer/doc_viewer.tsx | 4 +- .../doc_viewer/doc_viewer_render_error.tsx | 2 +- .../__snapshots__/field_name.test.tsx.snap | 0 .../field_name/field_name.test.tsx | 0 .../components}/field_name/field_name.tsx | 4 +- .../components}/field_name/field_type_name.ts | 0 .../json_code_block/json_code_block.test.tsx | 2 +- .../public/components/table/table.test.tsx | 5 +- .../public/components/table/table_row.tsx | 2 +- .../public/doc_views/doc_views_registry.ts | 14 +++-- .../public/doc_views/doc_views_types.ts | 5 +- src/plugins/discover/public/index.ts | 6 ++ src/plugins/discover/public/plugin.ts | 57 ++++++++++++++++--- src/plugins/discover/public/services.ts | 25 ++++++++ 26 files changed, 142 insertions(+), 94 deletions(-) rename src/legacy/core_plugins/kibana/public/discover/np_ready/angular/{doc_viewer.ts => doc_viewer.tsx} (87%) create mode 100644 src/plugins/discover/public/_index.scss create mode 100644 src/plugins/discover/public/components/_index.scss rename src/{legacy/core_plugins/kibana/public/discover/np_ready/angular/directives => plugins/discover/public/components}/field_name/__snapshots__/field_name.test.tsx.snap (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready/angular/directives => plugins/discover/public/components}/field_name/field_name.test.tsx (100%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready/angular/directives => plugins/discover/public/components}/field_name/field_name.tsx (92%) rename src/{legacy/core_plugins/kibana/public/discover/np_ready/angular/directives => plugins/discover/public/components}/field_name/field_type_name.ts (100%) create mode 100644 src/plugins/discover/public/services.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/build_services.ts b/src/legacy/core_plugins/kibana/public/discover/build_services.ts index 0e0df24457f66..8c3c41a0cecf8 100644 --- a/src/legacy/core_plugins/kibana/public/discover/build_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/build_services.ts @@ -34,9 +34,9 @@ import { createSavedSearchesLoader } from './saved_searches'; import { DiscoverStartPlugins } from './plugin'; import { SharePluginStart } from '../../../../../plugins/share/public'; import { SavedSearch } from './np_ready/types'; -import { DocViewsRegistry } from '../../../../../plugins/discover/public/doc_views/doc_views_registry'; import { ChartsPluginStart } from '../../../../../plugins/charts/public'; import { VisualizationsStart } from '../../../visualizations/public'; +import { DocViewerComponent } from '../../../../../plugins/discover/public'; export interface DiscoverServices { addBasePath: (path: string) => string; @@ -45,7 +45,7 @@ export interface DiscoverServices { core: CoreStart; data: DataPublicPluginStart; docLinks: DocLinksStart; - docViewsRegistry: DocViewsRegistry; + DocViewer: DocViewerComponent; theme: ChartsPluginStart['theme']; filterManager: FilterManager; indexPatterns: IndexPatternsContract; @@ -61,8 +61,7 @@ export interface DiscoverServices { } export async function buildServices( core: CoreStart, - plugins: DiscoverStartPlugins, - docViewsRegistry: DocViewsRegistry + plugins: DiscoverStartPlugins ): Promise { const services = { savedObjectsClient: core.savedObjects.client, @@ -78,7 +77,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), diff --git a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts index a667fb2562b43..c8327408d61b7 100644 --- a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts @@ -64,8 +64,6 @@ export { unhashUrl } from '../../../../../plugins/kibana_utils/public'; export { migrateLegacyQuery, ensureDefaultIndexPattern, - formatMsg, - formatStack, } from '../../../../../plugins/kibana_legacy/public'; // EXPORT types diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name.js index 4bc498928be52..ff85e35e328e8 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name.js @@ -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/components/field_name/field_name'; import { wrapInI18nContext } from '../../../kibana_services'; export function FieldNameDirectiveProvider(config, reactDirective) { diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_viewer.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_viewer.tsx similarity index 87% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_viewer.ts rename to src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_viewer.tsx index 3cc8345efc332..90e061ac1aa05 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_viewer.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/doc_viewer.tsx @@ -17,11 +17,15 @@ * under the License. */ -import { DocViewer } from '../../../../../../../plugins/discover/public/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 ; + }, [ 'hit', ['indexPattern', { watchDepth: 'reference' }], diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.test.tsx index e09f26311e4e3..da1749afbc987 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.test.tsx @@ -34,9 +34,7 @@ jest.mock('../../../kibana_services', () => { metadata: { branch: 'test', }, - getDocViewsSorted: () => { - return []; - }, + DocViewer: () => null, }), }; }); diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.tsx index 8cac364302712..e945ad8935030 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.tsx @@ -20,7 +20,6 @@ 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 '../../../../../../../../plugins/discover/public/components/doc_viewer/doc_viewer'; import { ElasticRequestState, useEsDocSearch } from './use_es_doc_search'; import { ElasticSearchHit, getServices } from '../../../kibana_services'; @@ -61,6 +60,7 @@ export interface DocProps { } export function Doc(props: DocProps) { + const { DocViewer } = getServices(); const [reqState, hit, indexPattern] = useEsDocSearch(props); return ( diff --git a/src/legacy/core_plugins/kibana/public/discover/plugin.ts b/src/legacy/core_plugins/kibana/public/discover/plugin.ts index e8db920667656..20e97270515ca 100644 --- a/src/legacy/core_plugins/kibana/public/discover/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/discover/plugin.ts @@ -18,7 +18,6 @@ */ import { BehaviorSubject } from 'rxjs'; -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'; @@ -40,10 +39,7 @@ import { KibanaLegacySetup, AngularRenderedAppUpdater, } from '../../../../../plugins/kibana_legacy/public'; -import { DocViewsRegistry } from '../../../../../plugins/discover/public/doc_views/doc_views_registry'; -import { DocViewInput, DocViewInputFn } from '../../../../../plugins/discover/public/doc_views/doc_views_types'; -import { DocViewTable } from '../../../../../plugins/discover/public/components/table/table'; -import { JsonCodeBlock } from '../../../../../plugins/discover/public/components/json_code_block/json_code_block'; +import { DiscoverSetup, DiscoverStart } from '../../../../../plugins/discover/public'; import { HomePublicPluginSetup } from '../../../../../plugins/home/public'; import { VisualizationsStart, @@ -51,15 +47,6 @@ import { } 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; @@ -67,6 +54,7 @@ export interface DiscoverSetupPlugins { home: HomePublicPluginSetup; visualizations: VisualizationsSetup; data: DataPublicPluginSetup; + discover: DiscoverSetup; } export interface DiscoverStartPlugins { uiActions: UiActionsStart; @@ -77,6 +65,7 @@ export interface DiscoverStartPlugins { share: SharePluginStart; inspector: any; visualizations: VisualizationsStart; + discover: DiscoverStart; } const innerAngularName = 'app/discover'; const embeddableAngularName = 'app/discoverEmbeddable'; @@ -86,10 +75,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 { +export class DiscoverPlugin implements Plugin { private servicesInitialized: boolean = false; private innerAngularInitialized: boolean = false; - private docViewsRegistry: DocViewsRegistry | null = null; private embeddableInjector: auto.IInjectorService | null = null; private getEmbeddableInjector: (() => Promise) | null = null; private appStateUpdater = new BehaviorSubject(() => ({})); @@ -102,7 +90,7 @@ export class DiscoverPlugin implements Plugin { public initializeInnerAngular?: () => void; public initializeServices?: () => Promise<{ core: CoreStart; plugins: DiscoverStartPlugins }>; - setup(core: CoreSetup, plugins: DiscoverSetupPlugins): DiscoverSetup { + setup(core: CoreSetup, plugins: DiscoverSetupPlugins) { const { querySyncStateContainer, stop: stopQuerySyncStateContainer } = getQueryStateContainer( plugins.data.query ); @@ -125,21 +113,7 @@ export class DiscoverPlugin implements Plugin { }; 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', @@ -167,13 +141,9 @@ export class DiscoverPlugin implements Plugin { }, }); 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 @@ -192,7 +162,7 @@ export class DiscoverPlugin implements Plugin { 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; diff --git a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js index 38b3434ef9c48..f555ed994a03b 100644 --- a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js +++ b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js @@ -226,6 +226,12 @@ export const npSetup = { }), }, }, + discover: { + docViews: { + addDocView: sinon.fake(), + setAngularInjector: sinon.fake(), + }, + } }, }; diff --git a/src/legacy/ui/public/new_platform/new_platform.ts b/src/legacy/ui/public/new_platform/new_platform.ts index b7994c7f68afb..0cbf0687e21f9 100644 --- a/src/legacy/ui/public/new_platform/new_platform.ts +++ b/src/legacy/ui/public/new_platform/new_platform.ts @@ -45,6 +45,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; @@ -63,6 +64,7 @@ export interface PluginsSetup { advancedSettings: AdvancedSettingsSetup; management: ManagementSetup; visTypeVega: VisTypeVegaSetup; + discover: DiscoverSetup; telemetry?: TelemetryPluginSetup; } @@ -81,6 +83,7 @@ export interface PluginsStart { share: SharePluginStart; management: ManagementStart; advancedSettings: AdvancedSettingsStart; + discover: DiscoverStart; telemetry?: TelemetryPluginStart; } diff --git a/src/plugins/discover/public/_index.scss b/src/plugins/discover/public/_index.scss new file mode 100644 index 0000000000000..bafefcccd752b --- /dev/null +++ b/src/plugins/discover/public/_index.scss @@ -0,0 +1 @@ +@import 'components/_index'; diff --git a/src/plugins/discover/public/components/_index.scss b/src/plugins/discover/public/components/_index.scss new file mode 100644 index 0000000000000..ff50d4b5dca93 --- /dev/null +++ b/src/plugins/discover/public/components/_index.scss @@ -0,0 +1 @@ +@import 'doc_viewer/index'; diff --git a/src/plugins/discover/public/components/doc_viewer/doc_viewer.test.tsx b/src/plugins/discover/public/components/doc_viewer/doc_viewer.test.tsx index 7f2e0e527c44b..6f29f10ddd026 100644 --- a/src/plugins/discover/public/components/doc_viewer/doc_viewer.test.tsx +++ b/src/plugins/discover/public/components/doc_viewer/doc_viewer.test.tsx @@ -21,37 +21,33 @@ import { mount, shallow } from 'enzyme'; import { DocViewer } from './doc_viewer'; // @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; -import { getServices } from '../../../../../legacy/core_plugins/kibana/public/discover/kibana_services'; +import { getDocViewsRegistry } from '../../services'; import { DocViewRenderProps } from '../../doc_views/doc_views_types'; -jest.mock('../../../kibana_services', () => { +jest.mock('../../services', () => { let registry: any[] = []; return { - getServices: () => ({ - docViewsRegistry: { - addDocView(view: any) { - registry.push(view); - }, - getDocViewsSorted() { - return registry; - }, + getDocViewsRegistry: () => ({ + addDocView(view: any) { + registry.push(view); + }, + getDocViewsSorted() { + return registry; }, resetRegistry: () => { registry = []; }, }), - formatMsg: (x: any) => String(x), - formatStack: (x: any) => String(x), }; }); beforeEach(() => { - (getServices() as any).resetRegistry(); + (getDocViewsRegistry() as any).resetRegistry(); jest.clearAllMocks(); }); test('Render with 3 different tabs', () => { - const registry = getServices().docViewsRegistry; + const registry = getDocViewsRegistry(); registry.addDocView({ order: 10, title: 'Render function', render: jest.fn() }); registry.addDocView({ order: 20, title: 'React component', component: () =>
test
}); registry.addDocView({ order: 30, title: 'Invalid doc view' }); @@ -69,7 +65,7 @@ test('Render with 1 tab displaying error message', () => { return null; } - const registry = getServices().docViewsRegistry; + const registry = getDocViewsRegistry(); registry.addDocView({ order: 10, title: 'React component', diff --git a/src/plugins/discover/public/components/doc_viewer/doc_viewer.tsx b/src/plugins/discover/public/components/doc_viewer/doc_viewer.tsx index b80bffdbc4fed..792d9c44400d7 100644 --- a/src/plugins/discover/public/components/doc_viewer/doc_viewer.tsx +++ b/src/plugins/discover/public/components/doc_viewer/doc_viewer.tsx @@ -18,7 +18,7 @@ */ import React from 'react'; import { EuiTabbedContent } from '@elastic/eui'; -import { getServices } from '../../../../../legacy/core_plugins/kibana/public/discover/kibana_services'; +import { getDocViewsRegistry } from '../../services'; import { DocViewerTab } from './doc_viewer_tab'; import { DocView, DocViewRenderProps } from '../../doc_views/doc_views_types'; @@ -29,7 +29,7 @@ import { DocView, DocViewRenderProps } from '../../doc_views/doc_views_types'; * a `render` function. */ export function DocViewer(renderProps: DocViewRenderProps) { - const { docViewsRegistry } = getServices(); + const docViewsRegistry = getDocViewsRegistry(); const tabs = docViewsRegistry .getDocViewsSorted(renderProps.hit) .map(({ title, render, component }: DocView, idx: number) => { diff --git a/src/plugins/discover/public/components/doc_viewer/doc_viewer_render_error.tsx b/src/plugins/discover/public/components/doc_viewer/doc_viewer_render_error.tsx index c647a779fd430..387e57dc8a7e3 100644 --- a/src/plugins/discover/public/components/doc_viewer/doc_viewer_render_error.tsx +++ b/src/plugins/discover/public/components/doc_viewer/doc_viewer_render_error.tsx @@ -18,7 +18,7 @@ */ import React from 'react'; import { EuiCallOut, EuiCodeBlock } from '@elastic/eui'; -import { formatMsg, formatStack } from '../../../../../legacy/core_plugins/kibana/public/discover/kibana_services'; +import { formatMsg, formatStack } from '../../../../kibana_legacy/public'; interface Props { error: Error | string; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/__snapshots__/field_name.test.tsx.snap b/src/plugins/discover/public/components/field_name/__snapshots__/field_name.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/__snapshots__/field_name.test.tsx.snap rename to src/plugins/discover/public/components/field_name/__snapshots__/field_name.test.tsx.snap diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/field_name.test.tsx b/src/plugins/discover/public/components/field_name/field_name.test.tsx similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/field_name.test.tsx rename to src/plugins/discover/public/components/field_name/field_name.test.tsx diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/field_name.tsx b/src/plugins/discover/public/components/field_name/field_name.tsx similarity index 92% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/field_name.tsx rename to src/plugins/discover/public/components/field_name/field_name.tsx index 95720bee38df8..c85d3f4fc485c 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/field_name.tsx +++ b/src/plugins/discover/public/components/field_name/field_name.tsx @@ -18,8 +18,8 @@ */ import React from 'react'; import classNames from 'classnames'; -import { FieldIcon } from '../../../../../../../../../plugins/kibana_react/public'; -import { shortenDottedString } from '../../../../../../../../../plugins/data/common/utils'; +import { FieldIcon } from '../../../../kibana_react/public'; +import { shortenDottedString } from '../../../../data/common/utils'; import { getFieldTypeName } from './field_type_name'; // property field is provided at discover's field chooser diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/field_type_name.ts b/src/plugins/discover/public/components/field_name/field_type_name.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/field_type_name.ts rename to src/plugins/discover/public/components/field_name/field_type_name.ts diff --git a/src/plugins/discover/public/components/json_code_block/json_code_block.test.tsx b/src/plugins/discover/public/components/json_code_block/json_code_block.test.tsx index 7c832e89fe2f6..7e7f80c6aaa56 100644 --- a/src/plugins/discover/public/components/json_code_block/json_code_block.test.tsx +++ b/src/plugins/discover/public/components/json_code_block/json_code_block.test.tsx @@ -19,7 +19,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import { JsonCodeBlock } from './json_code_block'; -import { IndexPattern } from '../../../../../legacy/core_plugins/kibana/public/discover/kibana_services'; +import { IndexPattern } from '../../../../data/public'; it('returns the `JsonCodeEditor` component', () => { const props = { diff --git a/src/plugins/discover/public/components/table/table.test.tsx b/src/plugins/discover/public/components/table/table.test.tsx index 5f50c1abae879..91e116c4c6696 100644 --- a/src/plugins/discover/public/components/table/table.test.tsx +++ b/src/plugins/discover/public/components/table/table.test.tsx @@ -21,10 +21,7 @@ import { mount } from 'enzyme'; // @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; import { DocViewTable } from './table'; - -import { IndexPattern, indexPatterns } from '../../../../../legacy/core_plugins/kibana/public/discover/kibana_services'; - -jest.mock('ui/new_platform'); +import { indexPatterns, IndexPattern } from '../../../../data/public'; const indexPattern = { fields: [ diff --git a/src/plugins/discover/public/components/table/table_row.tsx b/src/plugins/discover/public/components/table/table_row.tsx index 61ef3627bf9df..26f6011bae842 100644 --- a/src/plugins/discover/public/components/table/table_row.tsx +++ b/src/plugins/discover/public/components/table/table_row.tsx @@ -26,7 +26,7 @@ import { DocViewTableRowBtnCollapse } from './table_row_btn_collapse'; import { DocViewTableRowBtnFilterExists } from './table_row_btn_filter_exists'; import { DocViewTableRowIconNoMapping } from './table_row_icon_no_mapping'; import { DocViewTableRowIconUnderscore } from './table_row_icon_underscore'; -import { FieldName } from '../../../../../legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/field_name'; +import { FieldName } from '../field_name/field_name'; export interface Props { field: string; diff --git a/src/plugins/discover/public/doc_views/doc_views_registry.ts b/src/plugins/discover/public/doc_views/doc_views_registry.ts index 78044e2e43e59..9dc04dee07254 100644 --- a/src/plugins/discover/public/doc_views/doc_views_registry.ts +++ b/src/plugins/discover/public/doc_views/doc_views_registry.ts @@ -24,11 +24,12 @@ import { DocView, DocViewInput, ElasticSearchHit, DocViewInputFn } from './doc_v export class DocViewsRegistry { private docViews: DocView[] = []; - private angularInjector: Subject = new Subject(); + private angularInjectorGetter: Subject<() => Promise> = new Subject< + () => Promise + >(); - setAngularInjector(injector: auto.IInjectorService) { - this.angularInjector.next(injector); - this.angularInjector.complete(); + setAngularInjectorGetter(injectorGetter: () => Promise) { + this.angularInjectorGetter.next(injectorGetter); } /** @@ -39,7 +40,10 @@ export class DocViewsRegistry { if (docView.directive) { // convert angular directive to render function for backwards compatibility docView.render = convertDirectiveToRenderFn(docView.directive, () => - this.angularInjector.asObservable().toPromise() + this.angularInjectorGetter + .asObservable() + .toPromise() + .then(getter => getter()) ); } if (typeof docView.shouldShow !== 'function') { diff --git a/src/plugins/discover/public/doc_views/doc_views_types.ts b/src/plugins/discover/public/doc_views/doc_views_types.ts index 9a9e379d38d94..49910cbb50804 100644 --- a/src/plugins/discover/public/doc_views/doc_views_types.ts +++ b/src/plugins/discover/public/doc_views/doc_views_types.ts @@ -18,7 +18,7 @@ */ import { ComponentType } from 'react'; import { IScope } from 'angular'; -import { IndexPattern } from '../../../../legacy/core_plugins/kibana/public/discover/kibana_services'; +import { IndexPattern } from '../../../data/public'; export interface AngularDirective { controller: (scope: AngularScope) => void; @@ -51,13 +51,14 @@ export interface DocViewRenderProps { onAddColumn?: (columnName: string) => void; onRemoveColumn?: (columnName: string) => void; } +export type DocViewerComponent = ComponentType; export type DocViewRenderFn = ( domeNode: HTMLDivElement, renderProps: DocViewRenderProps ) => () => void; export interface DocViewInput { - component?: ComponentType; + component?: DocViewerComponent; directive?: AngularDirective; order: number; render?: DocViewRenderFn; diff --git a/src/plugins/discover/public/index.ts b/src/plugins/discover/public/index.ts index a452cadf03b06..53f29d6f81d8c 100644 --- a/src/plugins/discover/public/index.ts +++ b/src/plugins/discover/public/index.ts @@ -19,6 +19,12 @@ import { DiscoverPlugin } from './plugin'; +export { DiscoverSetup, DiscoverStart } from './plugin'; +export { DocViewTable } from './components/table/table'; +export { JsonCodeBlock } from './components/json_code_block/json_code_block'; +export { DocViewInput, DocViewInputFn, DocViewerComponent } from './doc_views/doc_views_types'; +export { FieldName } from './components/field_name/field_name'; + export function plugin() { return new DiscoverPlugin(); } diff --git a/src/plugins/discover/public/plugin.ts b/src/plugins/discover/public/plugin.ts index 8e68148760d64..bd6dea79c3e4a 100644 --- a/src/plugins/discover/public/plugin.ts +++ b/src/plugins/discover/public/plugin.ts @@ -17,24 +17,52 @@ * under the License. */ +import React from 'react'; import { i18n } from '@kbn/i18n'; import { auto } from 'angular'; import { CoreSetup, Plugin } from 'kibana/public'; -import { DocViewInput, DocViewInputFn } from './doc_views/doc_views_types'; +import { DocViewInput, DocViewInputFn, DocViewRenderProps } from './doc_views/doc_views_types'; import { DocViewsRegistry } from './doc_views/doc_views_registry'; import { DocViewTable } from './components/table/table'; import { JsonCodeBlock } from './components/json_code_block/json_code_block'; +import { DocViewer } from './components/doc_viewer/doc_viewer'; +import { setDocViewsRegistry } from './services'; + +import './_index.scss'; /** - * 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; - setAngularInjector(injector: auto.IInjectorService): void; + docViews: { + /** + * Add new doc view shown along with table view and json view in the details of each document in Discover. + * Both react and angular doc views are supported. + * @param docViewRaw + */ + addDocView(docViewRaw: DocViewInput | DocViewInputFn): void; + /** + * Set the angular injector for bootstrapping angular doc views. This is only exposed temporarily to aid + * migration to the new platform and will be removed soon. + * @deprecated + * @param injectorGetter + */ + setAngularInjectorGetter(injectorGetter: () => Promise): void; + }; +} +/** + * @public + */ +export interface DiscoverStart { + docViews: { + /** + * Component rendering all the doc views for a given document. + * This is only exposed temporarily to aid migration to the new platform and will be removed soon. + * @deprecated + */ + DocViewer: React.ComponentType; + }; } -export type DiscoverStart = void; /** * Contains Discover, one of the oldest parts of Kibana @@ -46,6 +74,7 @@ export class DiscoverPlugin implements Plugin { setup(core: CoreSetup): DiscoverSetup { this.docViewsRegistry = new DocViewsRegistry(); + setDocViewsRegistry(this.docViewsRegistry); this.docViewsRegistry.addDocView({ title: i18n.translate('kbn.discover.docViews.table.tableTitle', { defaultMessage: 'Table', @@ -62,10 +91,20 @@ export class DiscoverPlugin implements Plugin { }); return { - addDocView: this.docViewsRegistry.addDocView.bind(this.docViewsRegistry), - setAngularInjector: this.docViewsRegistry.setAngularInjector.bind(this.docViewsRegistry), + docViews: { + addDocView: this.docViewsRegistry.addDocView.bind(this.docViewsRegistry), + setAngularInjectorGetter: this.docViewsRegistry.setAngularInjectorGetter.bind( + this.docViewsRegistry + ), + }, }; } - start() {} + start() { + return { + docViews: { + DocViewer, + }, + }; + } } diff --git a/src/plugins/discover/public/services.ts b/src/plugins/discover/public/services.ts new file mode 100644 index 0000000000000..3a28759d82b71 --- /dev/null +++ b/src/plugins/discover/public/services.ts @@ -0,0 +1,25 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { createGetterSetter } from '../../kibana_utils/common'; +import { DocViewsRegistry } from './doc_views/doc_views_registry'; + +export const [getDocViewsRegistry, setDocViewsRegistry] = createGetterSetter( + 'DocViewsRegistry' +); From 12250747e46c668d8f72901b3cb453d28d0dcd2f Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Fri, 21 Feb 2020 10:53:51 +0100 Subject: [PATCH 03/11] fix scss import --- src/plugins/discover/public/_index.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/discover/public/_index.scss b/src/plugins/discover/public/_index.scss index bafefcccd752b..841415620d691 100644 --- a/src/plugins/discover/public/_index.scss +++ b/src/plugins/discover/public/_index.scss @@ -1 +1 @@ -@import 'components/_index'; +@import 'components/index'; From ea3cbf94f66ab7919068f6b018ae8c40d3724efe Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Fri, 21 Feb 2020 11:21:27 +0100 Subject: [PATCH 04/11] start doc views test plugin --- .../plugins/doc_views_plugin/kibana.json | 7 +++ .../plugins/doc_views_plugin/package.json | 17 +++++++ .../plugins/doc_views_plugin/public/index.ts | 22 +++++++++ .../doc_views_plugin/public/plugin.tsx | 48 +++++++++++++++++++ .../plugins/doc_views_plugin/tsconfig.json | 14 ++++++ 5 files changed, 108 insertions(+) create mode 100644 test/plugin_functional/plugins/doc_views_plugin/kibana.json create mode 100644 test/plugin_functional/plugins/doc_views_plugin/package.json create mode 100644 test/plugin_functional/plugins/doc_views_plugin/public/index.ts create mode 100644 test/plugin_functional/plugins/doc_views_plugin/public/plugin.tsx create mode 100644 test/plugin_functional/plugins/doc_views_plugin/tsconfig.json diff --git a/test/plugin_functional/plugins/doc_views_plugin/kibana.json b/test/plugin_functional/plugins/doc_views_plugin/kibana.json new file mode 100644 index 0000000000000..5b861ec852175 --- /dev/null +++ b/test/plugin_functional/plugins/doc_views_plugin/kibana.json @@ -0,0 +1,7 @@ +{ + "id": "docViewPlugin", + "version": "0.0.1", + "kibanaVersion": "kibana", + "server": false, + "ui": true +} diff --git a/test/plugin_functional/plugins/doc_views_plugin/package.json b/test/plugin_functional/plugins/doc_views_plugin/package.json new file mode 100644 index 0000000000000..0cef1bf65c0e8 --- /dev/null +++ b/test/plugin_functional/plugins/doc_views_plugin/package.json @@ -0,0 +1,17 @@ +{ + "name": "docViewPlugin", + "version": "1.0.0", + "main": "target/test/plugin_functional/plugins/doc_views_plugin", + "kibana": { + "version": "kibana", + "templateVersion": "1.0.0" + }, + "license": "Apache-2.0", + "scripts": { + "kbn": "node ../../../../scripts/kbn.js", + "build": "rm -rf './target' && tsc" + }, + "devDependencies": { + "typescript": "3.7.2" + } +} diff --git a/test/plugin_functional/plugins/doc_views_plugin/public/index.ts b/test/plugin_functional/plugins/doc_views_plugin/public/index.ts new file mode 100644 index 0000000000000..8097226180763 --- /dev/null +++ b/test/plugin_functional/plugins/doc_views_plugin/public/index.ts @@ -0,0 +1,22 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { DocViewsPlugin } from './plugin'; + +export const plugin = () => new DocViewsPlugin(); diff --git a/test/plugin_functional/plugins/doc_views_plugin/public/plugin.tsx b/test/plugin_functional/plugins/doc_views_plugin/public/plugin.tsx new file mode 100644 index 0000000000000..c24e561e4f9a8 --- /dev/null +++ b/test/plugin_functional/plugins/doc_views_plugin/public/plugin.tsx @@ -0,0 +1,48 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import React from 'react'; +import { Plugin, CoreSetup } from 'kibana/public'; +import { DiscoverSetup } from '../../../../../src/plugins/discover/public'; +import { AngularScope } from '../../../../../src/plugins/discover/public/doc_views/doc_views_types'; + +export class DocViewsPlugin implements Plugin { + public setup(core: CoreSetup, { discover }: { discover: DiscoverSetup }) { + discover.docViews.addDocView({ + directive: { + controller($scope: AngularScope) { + ($scope as any).abc = 123; + }, + template: `

{{abc}}

`, + }, + order: 10, + title: 'Angular doc view', + }); + + discover.docViews.addDocView({ + component: props => { + return

Test

; + }, + order: 11, + title: 'React doc view', + }); + } + + public start() {} +} diff --git a/test/plugin_functional/plugins/doc_views_plugin/tsconfig.json b/test/plugin_functional/plugins/doc_views_plugin/tsconfig.json new file mode 100644 index 0000000000000..4a564ee1e5578 --- /dev/null +++ b/test/plugin_functional/plugins/doc_views_plugin/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../../../../tsconfig.json", + "compilerOptions": { + "outDir": "./target", + "skipLibCheck": true + }, + "include": [ + "index.ts", + "public/**/*.ts", + "public/**/*.tsx", + "../../../../typings/**/*" + ], + "exclude": [] +} From 47b94012a62aedc4a32c95da278c80ef614e01a7 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Fri, 21 Feb 2020 18:05:44 +0100 Subject: [PATCH 05/11] wip --- .../np_ready/angular/directives/field_name.js | 2 +- .../new_platform/new_platform.karma_mock.js | 4 +- .../public/doc_views/doc_views_registry.ts | 19 ++++---- .../plugins/doc_views_plugin/kibana.json | 3 +- .../doc_views_plugin/public/plugin.tsx | 5 ++- .../test_suites/doc_views/doc_views.js | 44 +++++++++++++++++++ .../test_suites/doc_views/index.js | 30 +++++++++++++ 7 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 test/plugin_functional/test_suites/doc_views/doc_views.js create mode 100644 test/plugin_functional/test_suites/doc_views/index.js diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name.js index ff85e35e328e8..6c76f3f194ee9 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name.js @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { FieldName } from '../../../../../../../../plugins/discover/public/components/field_name/field_name'; +import { FieldName } from '../../../../../../../../plugins/discover/public'; import { wrapInI18nContext } from '../../../kibana_services'; export function FieldNameDirectiveProvider(config, reactDirective) { diff --git a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js index 2a88a3f6211da..a1ebafb6e0025 100644 --- a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js +++ b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js @@ -232,9 +232,9 @@ export const npSetup = { discover: { docViews: { addDocView: sinon.fake(), - setAngularInjector: sinon.fake(), + setAngularInjectorGetter: sinon.fake(), }, - } + }, }, }; diff --git a/src/plugins/discover/public/doc_views/doc_views_registry.ts b/src/plugins/discover/public/doc_views/doc_views_registry.ts index 9dc04dee07254..8f4518538be72 100644 --- a/src/plugins/discover/public/doc_views/doc_views_registry.ts +++ b/src/plugins/discover/public/doc_views/doc_views_registry.ts @@ -17,19 +17,16 @@ * under the License. */ -import { Subject } from 'rxjs'; import { auto } from 'angular'; import { convertDirectiveToRenderFn } from './doc_views_helpers'; import { DocView, DocViewInput, ElasticSearchHit, DocViewInputFn } from './doc_views_types'; export class DocViewsRegistry { private docViews: DocView[] = []; - private angularInjectorGetter: Subject<() => Promise> = new Subject< - () => Promise - >(); + private angularInjectorGetter: (() => Promise) | null = null; setAngularInjectorGetter(injectorGetter: () => Promise) { - this.angularInjectorGetter.next(injectorGetter); + this.angularInjectorGetter = injectorGetter; } /** @@ -39,12 +36,12 @@ export class DocViewsRegistry { const docView = typeof docViewRaw === 'function' ? docViewRaw() : docViewRaw; if (docView.directive) { // convert angular directive to render function for backwards compatibility - docView.render = convertDirectiveToRenderFn(docView.directive, () => - this.angularInjectorGetter - .asObservable() - .toPromise() - .then(getter => getter()) - ); + docView.render = convertDirectiveToRenderFn(docView.directive, () => { + if (!this.angularInjectorGetter) { + throw new Error('Angular was not initialized'); + } + return this.angularInjectorGetter(); + }); } if (typeof docView.shouldShow !== 'function') { docView.shouldShow = () => true; diff --git a/test/plugin_functional/plugins/doc_views_plugin/kibana.json b/test/plugin_functional/plugins/doc_views_plugin/kibana.json index 5b861ec852175..f8596aad01e87 100644 --- a/test/plugin_functional/plugins/doc_views_plugin/kibana.json +++ b/test/plugin_functional/plugins/doc_views_plugin/kibana.json @@ -3,5 +3,6 @@ "version": "0.0.1", "kibanaVersion": "kibana", "server": false, - "ui": true + "ui": true, + "requiredPlugins": ["discover"] } diff --git a/test/plugin_functional/plugins/doc_views_plugin/public/plugin.tsx b/test/plugin_functional/plugins/doc_views_plugin/public/plugin.tsx index c24e561e4f9a8..9ab927a09b61f 100644 --- a/test/plugin_functional/plugins/doc_views_plugin/public/plugin.tsx +++ b/test/plugin_functional/plugins/doc_views_plugin/public/plugin.tsx @@ -26,10 +26,11 @@ export class DocViewsPlugin implements Plugin { public setup(core: CoreSetup, { discover }: { discover: DiscoverSetup }) { discover.docViews.addDocView({ directive: { - controller($scope: AngularScope) { + controller: function MyController($scope: AngularScope, $injector: any) { + debugger; ($scope as any).abc = 123; }, - template: `

{{abc}}

`, + template: `

{{hit._id}} {{abc}}

`, }, order: 10, title: 'Angular doc view', diff --git a/test/plugin_functional/test_suites/doc_views/doc_views.js b/test/plugin_functional/test_suites/doc_views/doc_views.js new file mode 100644 index 0000000000000..cb6a5aeeda384 --- /dev/null +++ b/test/plugin_functional/test_suites/doc_views/doc_views.js @@ -0,0 +1,44 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import expect from '@kbn/expect'; + +export default function({ getService, getPageObjects }) { + const testSubjects = getService('testSubjects'); + const PageObjects = getPageObjects(['common', 'discover', 'timePicker']); + + async function getCounterValue() { + return await testSubjects.getVisibleText('counter'); + } + + async function getEditorValue() { + return await testSubjects.getAttribute('counterEditor', 'value'); + } + + describe('custom doc views', function() { + before(async () => { + await PageObjects.common.navigateToApp('discover'); + await PageObjects.timePicker.setDefaultAbsoluteRange(); + }); + + it('should show custom doc views', async () => { + + }); + }); +} diff --git a/test/plugin_functional/test_suites/doc_views/index.js b/test/plugin_functional/test_suites/doc_views/index.js new file mode 100644 index 0000000000000..de895701ee492 --- /dev/null +++ b/test/plugin_functional/test_suites/doc_views/index.js @@ -0,0 +1,30 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export default function({ getService, loadTestFile }) { + const esArchiver = getService('esArchiver'); + + describe('custom visualizations', function() { + before(async () => { + await esArchiver.loadIfNeeded('discover'); + }); + + loadTestFile(require.resolve('./doc_views')); + }); +} From 7d8959b570886488275c3390218abab94e066a45 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Mon, 9 Mar 2020 17:03:30 +0100 Subject: [PATCH 06/11] fix import and add doc views tests --- src/core/MIGRATION.md | 6 ++-- .../components/field_name/field_name.tsx | 4 +-- .../public/doc_views/doc_views_types.ts | 2 +- .../public/{_index.scss => index.scss} | 0 src/plugins/discover/public/plugin.ts | 2 +- test/plugin_functional/config.js | 1 + .../doc_views_plugin/public/plugin.tsx | 27 +++++++++++----- .../doc_views/{doc_views.js => doc_views.ts} | 31 +++++++++++++------ .../doc_views/{index.js => index.ts} | 7 +++-- 9 files changed, 53 insertions(+), 27 deletions(-) rename src/plugins/discover/public/{_index.scss => index.scss} (100%) rename test/plugin_functional/test_suites/doc_views/{doc_views.js => doc_views.ts} (51%) rename test/plugin_functional/test_suites/doc_views/{index.js => index.ts} (77%) diff --git a/src/core/MIGRATION.md b/src/core/MIGRATION.md index c5e649f7d9d5c..3331f5c610432 100644 --- a/src/core/MIGRATION.md +++ b/src/core/MIGRATION.md @@ -1233,11 +1233,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. | diff --git a/src/plugins/discover/public/components/field_name/field_name.tsx b/src/plugins/discover/public/components/field_name/field_name.tsx index e2aa33179f632..4f5e9b6112599 100644 --- a/src/plugins/discover/public/components/field_name/field_name.tsx +++ b/src/plugins/discover/public/components/field_name/field_name.tsx @@ -20,8 +20,8 @@ import React from 'react'; import classNames from 'classnames'; import { EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui'; -import { FieldIcon, FieldIconProps } from '../../../../../../../../../plugins/kibana_react/public'; -import { shortenDottedString } from '../../../../../../../../../plugins/data/common/utils'; +import { FieldIcon, FieldIconProps } from '../../../../kibana_react/public'; +import { shortenDottedString } from '../../../../data/common/utils'; import { getFieldTypeName } from './field_type_name'; // property field is provided at discover's field chooser diff --git a/src/plugins/discover/public/doc_views/doc_views_types.ts b/src/plugins/discover/public/doc_views/doc_views_types.ts index 49910cbb50804..0a4b5bb570bd7 100644 --- a/src/plugins/discover/public/doc_views/doc_views_types.ts +++ b/src/plugins/discover/public/doc_views/doc_views_types.ts @@ -21,7 +21,7 @@ import { IScope } from 'angular'; import { IndexPattern } from '../../../data/public'; export interface AngularDirective { - controller: (scope: AngularScope) => void; + controller: (...injectedServices: any[]) => void; template: string; } diff --git a/src/plugins/discover/public/_index.scss b/src/plugins/discover/public/index.scss similarity index 100% rename from src/plugins/discover/public/_index.scss rename to src/plugins/discover/public/index.scss diff --git a/src/plugins/discover/public/plugin.ts b/src/plugins/discover/public/plugin.ts index bd6dea79c3e4a..24b1b6b6ea0c3 100644 --- a/src/plugins/discover/public/plugin.ts +++ b/src/plugins/discover/public/plugin.ts @@ -28,7 +28,7 @@ import { JsonCodeBlock } from './components/json_code_block/json_code_block'; import { DocViewer } from './components/doc_viewer/doc_viewer'; import { setDocViewsRegistry } from './services'; -import './_index.scss'; +import './index.scss'; /** * @public diff --git a/test/plugin_functional/config.js b/test/plugin_functional/config.js index e63054f1b6912..7017c01cc5634 100644 --- a/test/plugin_functional/config.js +++ b/test/plugin_functional/config.js @@ -39,6 +39,7 @@ export default async function({ readConfigFile }) { require.resolve('./test_suites/core_plugins'), require.resolve('./test_suites/management'), require.resolve('./test_suites/bfetch_explorer'), + require.resolve('./test_suites/doc_views'), ], services: { ...functionalConfig.get('services'), diff --git a/test/plugin_functional/plugins/doc_views_plugin/public/plugin.tsx b/test/plugin_functional/plugins/doc_views_plugin/public/plugin.tsx index 9ab927a09b61f..4b9823fda3673 100644 --- a/test/plugin_functional/plugins/doc_views_plugin/public/plugin.tsx +++ b/test/plugin_functional/plugins/doc_views_plugin/public/plugin.tsx @@ -17,30 +17,41 @@ * under the License. */ +import angular from 'angular'; import React from 'react'; import { Plugin, CoreSetup } from 'kibana/public'; import { DiscoverSetup } from '../../../../../src/plugins/discover/public'; -import { AngularScope } from '../../../../../src/plugins/discover/public/doc_views/doc_views_types'; + +angular.module('myDocView', []).directive('myHit', () => ({ + restrict: 'E', + scope: { + hit: '=hit', + }, + template: '

{{hit._index}}

', +})); + +function MyHit(props: { index: string }) { + return

{props.index}

; +} export class DocViewsPlugin implements Plugin { public setup(core: CoreSetup, { discover }: { discover: DiscoverSetup }) { discover.docViews.addDocView({ directive: { - controller: function MyController($scope: AngularScope, $injector: any) { - debugger; - ($scope as any).abc = 123; + controller: function MyController($injector: any) { + $injector.loadNewModules(['myDocView']); }, - template: `

{{hit._id}} {{abc}}

`, + template: ``, }, - order: 10, + order: 1, title: 'Angular doc view', }); discover.docViews.addDocView({ component: props => { - return

Test

; + return ; }, - order: 11, + order: 2, title: 'React doc view', }); } diff --git a/test/plugin_functional/test_suites/doc_views/doc_views.js b/test/plugin_functional/test_suites/doc_views/doc_views.ts similarity index 51% rename from test/plugin_functional/test_suites/doc_views/doc_views.js rename to test/plugin_functional/test_suites/doc_views/doc_views.ts index cb6a5aeeda384..8764f45c2c076 100644 --- a/test/plugin_functional/test_suites/doc_views/doc_views.js +++ b/test/plugin_functional/test_suites/doc_views/doc_views.ts @@ -18,19 +18,14 @@ */ import expect from '@kbn/expect'; +import { PluginFunctionalProviderContext } from '../../services'; -export default function({ getService, getPageObjects }) { +// eslint-disable-next-line import/no-default-export +export default function({ getService, getPageObjects }: PluginFunctionalProviderContext) { const testSubjects = getService('testSubjects'); + const find = getService('find'); const PageObjects = getPageObjects(['common', 'discover', 'timePicker']); - async function getCounterValue() { - return await testSubjects.getVisibleText('counter'); - } - - async function getEditorValue() { - return await testSubjects.getAttribute('counterEditor', 'value'); - } - describe('custom doc views', function() { before(async () => { await PageObjects.common.navigateToApp('discover'); @@ -38,7 +33,25 @@ export default function({ getService, getPageObjects }) { }); it('should show custom doc views', async () => { + await testSubjects.click('docTableExpandToggleColumn'); + const angularTab = await find.byButtonText('Angular doc view'); + const reactTab = await find.byButtonText('React doc view'); + expect(await angularTab.isDisplayed()).to.be(true); + expect(await reactTab.isDisplayed()).to.be(true); + }); + + it('should render angular doc view', async () => { + const angularTab = await find.byButtonText('Angular doc view'); + await angularTab.click(); + const angularContent = await testSubjects.find('angular-docview'); + expect(await angularContent.getVisibleText()).to.be('logstash-2015.09.22'); + }); + it('should render react doc view', async () => { + const reactTab = await find.byButtonText('React doc view'); + await reactTab.click(); + const reactContent = await testSubjects.find('react-docview'); + expect(await reactContent.getVisibleText()).to.be('logstash-2015.09.22'); }); }); } diff --git a/test/plugin_functional/test_suites/doc_views/index.js b/test/plugin_functional/test_suites/doc_views/index.ts similarity index 77% rename from test/plugin_functional/test_suites/doc_views/index.js rename to test/plugin_functional/test_suites/doc_views/index.ts index de895701ee492..dee3a72e3f2c6 100644 --- a/test/plugin_functional/test_suites/doc_views/index.js +++ b/test/plugin_functional/test_suites/doc_views/index.ts @@ -16,13 +16,14 @@ * specific language governing permissions and limitations * under the License. */ +import { PluginFunctionalProviderContext } from '../../services'; -export default function({ getService, loadTestFile }) { +export default function({ getService, loadTestFile }: PluginFunctionalProviderContext) { const esArchiver = getService('esArchiver'); - describe('custom visualizations', function() { + describe('doc views', function() { before(async () => { - await esArchiver.loadIfNeeded('discover'); + await esArchiver.loadIfNeeded('../functional/fixtures/es_archiver/discover'); }); loadTestFile(require.resolve('./doc_views')); From f9283792a79b06df394fd8a0457ffcc6cc37fdb0 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Mon, 9 Mar 2020 18:24:43 +0100 Subject: [PATCH 07/11] fix type errors --- .../core_plugins/kibana/public/discover/build_services.ts | 6 +++++- src/legacy/core_plugins/kibana/public/discover/plugin.ts | 2 +- .../discover/public/saved_searches/_saved_search.ts | 8 ++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/discover/build_services.ts b/src/legacy/core_plugins/kibana/public/discover/build_services.ts index 777fc5586fec3..9cb37bbabe42c 100644 --- a/src/legacy/core_plugins/kibana/public/discover/build_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/build_services.ts @@ -35,7 +35,11 @@ import { DiscoverStartPlugins } from './plugin'; import { SharePluginStart } from '../../../../../plugins/share/public'; 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; diff --git a/src/legacy/core_plugins/kibana/public/discover/plugin.ts b/src/legacy/core_plugins/kibana/public/discover/plugin.ts index e08a9fe43da82..91f92ac218fd7 100644 --- a/src/legacy/core_plugins/kibana/public/discover/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/discover/plugin.ts @@ -91,7 +91,7 @@ export class DiscoverPlugin implements Plugin { 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', diff --git a/src/plugins/discover/public/saved_searches/_saved_search.ts b/src/plugins/discover/public/saved_searches/_saved_search.ts index 72983b7835eee..56360b04a49c8 100644 --- a/src/plugins/discover/public/saved_searches/_saved_search.ts +++ b/src/plugins/discover/public/saved_searches/_saved_search.ts @@ -16,7 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -import { createSavedObjectClass, SavedObjectKibanaServices } from '../../../saved_objects/public'; +import { + createSavedObjectClass, + SavedObject, + SavedObjectKibanaServices, +} from '../../../saved_objects/public'; export function createSavedSearchClass(services: SavedObjectKibanaServices) { const SavedObjectClass = createSavedObjectClass(services); @@ -66,5 +70,5 @@ export function createSavedSearchClass(services: SavedObjectKibanaServices) { } } - return SavedSearch; + return SavedSearch as new (id: string) => SavedObject; } From 997a15c624a53b4d4ac5c83b87cce4d8747739bd Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Tue, 10 Mar 2020 09:41:56 +0100 Subject: [PATCH 08/11] fix i18n --- .i18nrc.json | 1 + .../components/field_name/field_type_name.ts | 24 +++++++++---------- .../json_code_block/json_code_block.tsx | 2 +- .../table/table_row_btn_collapse.tsx | 2 +- .../table/table_row_btn_filter_add.tsx | 6 ++--- .../table/table_row_btn_filter_exists.tsx | 8 +++---- .../table/table_row_btn_filter_remove.tsx | 6 ++--- .../table/table_row_btn_toggle_column.tsx | 6 ++--- .../table/table_row_icon_no_mapping.tsx | 4 ++-- .../table/table_row_icon_underscore.tsx | 4 ++-- src/plugins/discover/public/plugin.ts | 4 ++-- .../translations/translations/ja-JP.json | 22 ++++++++--------- .../translations/translations/zh-CN.json | 22 ++++++++--------- 13 files changed, 56 insertions(+), 55 deletions(-) diff --git a/.i18nrc.json b/.i18nrc.json index 6874d02304e49..8d6889bbd17cf 100644 --- a/.i18nrc.json +++ b/.i18nrc.json @@ -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", diff --git a/src/plugins/discover/public/components/field_name/field_type_name.ts b/src/plugins/discover/public/components/field_name/field_type_name.ts index 0cf428ee48b9d..a67c20fc4f353 100644 --- a/src/plugins/discover/public/components/field_name/field_type_name.ts +++ b/src/plugins/discover/public/components/field_name/field_type_name.ts @@ -21,52 +21,52 @@ import { i18n } from '@kbn/i18n'; export function getFieldTypeName(type: string) { switch (type) { case 'boolean': - return i18n.translate('kbn.discover.fieldNameIcons.booleanAriaLabel', { + return i18n.translate('discover.fieldNameIcons.booleanAriaLabel', { defaultMessage: 'Boolean field', }); case 'conflict': - return i18n.translate('kbn.discover.fieldNameIcons.conflictFieldAriaLabel', { + return i18n.translate('discover.fieldNameIcons.conflictFieldAriaLabel', { defaultMessage: 'Conflicting field', }); case 'date': - return i18n.translate('kbn.discover.fieldNameIcons.dateFieldAriaLabel', { + return i18n.translate('discover.fieldNameIcons.dateFieldAriaLabel', { defaultMessage: 'Date field', }); case 'geo_point': - return i18n.translate('kbn.discover.fieldNameIcons.geoPointFieldAriaLabel', { + return i18n.translate('discover.fieldNameIcons.geoPointFieldAriaLabel', { defaultMessage: 'Geo point field', }); case 'geo_shape': - return i18n.translate('kbn.discover.fieldNameIcons.geoShapeFieldAriaLabel', { + return i18n.translate('discover.fieldNameIcons.geoShapeFieldAriaLabel', { defaultMessage: 'Geo shape field', }); case 'ip': - return i18n.translate('kbn.discover.fieldNameIcons.ipAddressFieldAriaLabel', { + return i18n.translate('discover.fieldNameIcons.ipAddressFieldAriaLabel', { defaultMessage: 'IP address field', }); case 'murmur3': - return i18n.translate('kbn.discover.fieldNameIcons.murmur3FieldAriaLabel', { + return i18n.translate('discover.fieldNameIcons.murmur3FieldAriaLabel', { defaultMessage: 'Murmur3 field', }); case 'number': - return i18n.translate('kbn.discover.fieldNameIcons.numberFieldAriaLabel', { + return i18n.translate('discover.fieldNameIcons.numberFieldAriaLabel', { defaultMessage: 'Number field', }); case 'source': // Note that this type is currently not provided, type for _source is undefined - return i18n.translate('kbn.discover.fieldNameIcons.sourceFieldAriaLabel', { + return i18n.translate('discover.fieldNameIcons.sourceFieldAriaLabel', { defaultMessage: 'Source field', }); case 'string': - return i18n.translate('kbn.discover.fieldNameIcons.stringFieldAriaLabel', { + return i18n.translate('discover.fieldNameIcons.stringFieldAriaLabel', { defaultMessage: 'String field', }); case 'nested': - return i18n.translate('kbn.discover.fieldNameIcons.nestedFieldAriaLabel', { + return i18n.translate('discover.fieldNameIcons.nestedFieldAriaLabel', { defaultMessage: 'Nested field', }); default: - return i18n.translate('kbn.discover.fieldNameIcons.unknownFieldAriaLabel', { + return i18n.translate('discover.fieldNameIcons.unknownFieldAriaLabel', { defaultMessage: 'Unknown field', }); } diff --git a/src/plugins/discover/public/components/json_code_block/json_code_block.tsx b/src/plugins/discover/public/components/json_code_block/json_code_block.tsx index 3331969e351ab..9297ab0dfcf4d 100644 --- a/src/plugins/discover/public/components/json_code_block/json_code_block.tsx +++ b/src/plugins/discover/public/components/json_code_block/json_code_block.tsx @@ -22,7 +22,7 @@ import { i18n } from '@kbn/i18n'; import { DocViewRenderProps } from '../../doc_views/doc_views_types'; export function JsonCodeBlock({ hit }: DocViewRenderProps) { - const label = i18n.translate('kbn.discover.docViews.json.codeEditorAriaLabel', { + const label = i18n.translate('discover.docViews.json.codeEditorAriaLabel', { defaultMessage: 'Read only JSON view of an elasticsearch document', }); return ( diff --git a/src/plugins/discover/public/components/table/table_row_btn_collapse.tsx b/src/plugins/discover/public/components/table/table_row_btn_collapse.tsx index e59f607329d4a..bb5ea4bd20f07 100644 --- a/src/plugins/discover/public/components/table/table_row_btn_collapse.tsx +++ b/src/plugins/discover/public/components/table/table_row_btn_collapse.tsx @@ -26,7 +26,7 @@ export interface Props { } export function DocViewTableRowBtnCollapse({ onClick, isCollapsed }: Props) { - const label = i18n.translate('kbn.discover.docViews.table.toggleFieldDetails', { + const label = i18n.translate('discover.docViews.table.toggleFieldDetails', { defaultMessage: 'Toggle field details', }); return ( diff --git a/src/plugins/discover/public/components/table/table_row_btn_filter_add.tsx b/src/plugins/discover/public/components/table/table_row_btn_filter_add.tsx index 8e2668e26cf08..bd842eb5c6f72 100644 --- a/src/plugins/discover/public/components/table/table_row_btn_filter_add.tsx +++ b/src/plugins/discover/public/components/table/table_row_btn_filter_add.tsx @@ -29,12 +29,12 @@ export interface Props { export function DocViewTableRowBtnFilterAdd({ onClick, disabled = false }: Props) { const tooltipContent = disabled ? ( ) : ( ); @@ -42,7 +42,7 @@ export function DocViewTableRowBtnFilterAdd({ onClick, disabled = false }: Props return ( ) : ( ) ) : ( ); @@ -55,7 +55,7 @@ export function DocViewTableRowBtnFilterExists({ ) : ( ); @@ -42,7 +42,7 @@ export function DocViewTableRowBtnFilterRemove({ onClick, disabled = false }: Pr return ( } > Index Patterns page', diff --git a/src/plugins/discover/public/components/table/table_row_icon_underscore.tsx b/src/plugins/discover/public/components/table/table_row_icon_underscore.tsx index 724b5712cf1fe..791ab18de5175 100644 --- a/src/plugins/discover/public/components/table/table_row_icon_underscore.tsx +++ b/src/plugins/discover/public/components/table/table_row_icon_underscore.tsx @@ -22,13 +22,13 @@ import { i18n } from '@kbn/i18n'; export function DocViewTableRowIconUnderscore() { const ariaLabel = i18n.translate( - 'kbn.discover.docViews.table.fieldNamesBeginningWithUnderscoreUnsupportedAriaLabel', + 'discover.docViews.table.fieldNamesBeginningWithUnderscoreUnsupportedAriaLabel', { defaultMessage: 'Warning', } ); const tooltipContent = i18n.translate( - 'kbn.discover.docViews.table.fieldNamesBeginningWithUnderscoreUnsupportedTooltip', + 'discover.docViews.table.fieldNamesBeginningWithUnderscoreUnsupportedTooltip', { defaultMessage: 'Field names beginning with {underscoreSign} are not supported', values: { underscoreSign: '_' }, diff --git a/src/plugins/discover/public/plugin.ts b/src/plugins/discover/public/plugin.ts index 24b1b6b6ea0c3..d2797586bfdfb 100644 --- a/src/plugins/discover/public/plugin.ts +++ b/src/plugins/discover/public/plugin.ts @@ -76,14 +76,14 @@ export class DiscoverPlugin implements Plugin { this.docViewsRegistry = new DocViewsRegistry(); setDocViewsRegistry(this.docViewsRegistry); this.docViewsRegistry.addDocView({ - title: i18n.translate('kbn.discover.docViews.table.tableTitle', { + title: i18n.translate('discover.docViews.table.tableTitle', { defaultMessage: 'Table', }), order: 10, component: DocViewTable, }); this.docViewsRegistry.addDocView({ - title: i18n.translate('kbn.discover.docViews.json.jsonTitle', { + title: i18n.translate('discover.docViews.json.jsonTitle', { defaultMessage: 'JSON', }), order: 20, diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 5635bb19b7e83..ee747af1bb310 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -470,6 +470,17 @@ "data.search.searchBar.savedQueryPopoverSavedQueryListItemDescriptionAriaLabel": "{savedQueryName} の説明", "data.search.searchBar.savedQueryPopoverSavedQueryListItemSelectedButtonAriaLabel": "選択されたクエリボタン {savedQueryName} を保存しました。変更を破棄するには押してください。", "data.search.searchBar.savedQueryPopoverTitleText": "保存されたクエリ", + "discover.fieldNameIcons.booleanAriaLabel": "ブールフィールド", + "discover.fieldNameIcons.conflictFieldAriaLabel": "矛盾フィールド", + "discover.fieldNameIcons.dateFieldAriaLabel": "日付フィールド", + "discover.fieldNameIcons.geoPointFieldAriaLabel": "地理ポイント", + "discover.fieldNameIcons.geoShapeFieldAriaLabel": "地理情報図形", + "discover.fieldNameIcons.ipAddressFieldAriaLabel": "IP アドレスフィールド", + "discover.fieldNameIcons.murmur3FieldAriaLabel": "Murmur3 フィールド", + "discover.fieldNameIcons.numberFieldAriaLabel": "数値フィールド", + "discover.fieldNameIcons.sourceFieldAriaLabel": "ソースフィールド", + "discover.fieldNameIcons.stringFieldAriaLabel": "文字列フィールド", + "discover.fieldNameIcons.unknownFieldAriaLabel": "不明なフィールド", "charts.colormaps.bluesText": "青", "charts.colormaps.greensText": "緑", "charts.colormaps.greenToRedText": "緑から赤", @@ -1082,17 +1093,6 @@ "kbn.discover.fieldChooser.searchPlaceHolder": "検索フィールド", "kbn.discover.fieldChooser.toggleFieldFilterButtonHideAriaLabel": "フィールド設定を非表示", "kbn.discover.fieldChooser.toggleFieldFilterButtonShowAriaLabel": "フィールド設定を表示", - "kbn.discover.fieldNameIcons.booleanAriaLabel": "ブールフィールド", - "kbn.discover.fieldNameIcons.conflictFieldAriaLabel": "矛盾フィールド", - "kbn.discover.fieldNameIcons.dateFieldAriaLabel": "日付フィールド", - "kbn.discover.fieldNameIcons.geoPointFieldAriaLabel": "地理ポイント", - "kbn.discover.fieldNameIcons.geoShapeFieldAriaLabel": "地理情報図形", - "kbn.discover.fieldNameIcons.ipAddressFieldAriaLabel": "IP アドレスフィールド", - "kbn.discover.fieldNameIcons.murmur3FieldAriaLabel": "Murmur3 フィールド", - "kbn.discover.fieldNameIcons.numberFieldAriaLabel": "数値フィールド", - "kbn.discover.fieldNameIcons.sourceFieldAriaLabel": "ソースフィールド", - "kbn.discover.fieldNameIcons.stringFieldAriaLabel": "文字列フィールド", - "kbn.discover.fieldNameIcons.unknownFieldAriaLabel": "不明なフィールド", "kbn.discover.histogram.partialData.bucketTooltipText": "選択された時間範囲にはこのバケット全体は含まれていませんが、一部データが含まれている可能性があります。", "kbn.discover.histogramOfFoundDocumentsAriaLabel": "発見されたドキュメントのヒストグラム", "kbn.discover.hitsPluralTitle": "{hits, plural, one {ヒット} other {ヒット}}", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 0523021046167..d53e06057a02f 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -470,6 +470,17 @@ "data.search.searchBar.savedQueryPopoverSavedQueryListItemDescriptionAriaLabel": "{savedQueryName} 描述", "data.search.searchBar.savedQueryPopoverSavedQueryListItemSelectedButtonAriaLabel": "已保存查询按钮已选择 {savedQueryName}。按下可清除任何更改。", "data.search.searchBar.savedQueryPopoverTitleText": "已保存查询", + "discover.fieldNameIcons.booleanAriaLabel": "布尔字段", + "discover.fieldNameIcons.conflictFieldAriaLabel": "冲突字段", + "discover.fieldNameIcons.dateFieldAriaLabel": "日期字段", + "discover.fieldNameIcons.geoPointFieldAriaLabel": "地理位置点字段", + "discover.fieldNameIcons.geoShapeFieldAriaLabel": "几何形状字段", + "discover.fieldNameIcons.ipAddressFieldAriaLabel": "IP 地址字段", + "discover.fieldNameIcons.murmur3FieldAriaLabel": "Murmur3 字段", + "discover.fieldNameIcons.numberFieldAriaLabel": "数字字段", + "discover.fieldNameIcons.sourceFieldAriaLabel": "源字段", + "discover.fieldNameIcons.stringFieldAriaLabel": "字符串字段", + "discover.fieldNameIcons.unknownFieldAriaLabel": "未知字段", "charts.colormaps.bluesText": "蓝色", "charts.colormaps.greensText": "绿色", "charts.colormaps.greenToRedText": "绿到红", @@ -1082,17 +1093,6 @@ "kbn.discover.fieldChooser.searchPlaceHolder": "搜索字段", "kbn.discover.fieldChooser.toggleFieldFilterButtonHideAriaLabel": "隐藏字段设置", "kbn.discover.fieldChooser.toggleFieldFilterButtonShowAriaLabel": "显示字段设置", - "kbn.discover.fieldNameIcons.booleanAriaLabel": "布尔字段", - "kbn.discover.fieldNameIcons.conflictFieldAriaLabel": "冲突字段", - "kbn.discover.fieldNameIcons.dateFieldAriaLabel": "日期字段", - "kbn.discover.fieldNameIcons.geoPointFieldAriaLabel": "地理位置点字段", - "kbn.discover.fieldNameIcons.geoShapeFieldAriaLabel": "几何形状字段", - "kbn.discover.fieldNameIcons.ipAddressFieldAriaLabel": "IP 地址字段", - "kbn.discover.fieldNameIcons.murmur3FieldAriaLabel": "Murmur3 字段", - "kbn.discover.fieldNameIcons.numberFieldAriaLabel": "数字字段", - "kbn.discover.fieldNameIcons.sourceFieldAriaLabel": "源字段", - "kbn.discover.fieldNameIcons.stringFieldAriaLabel": "字符串字段", - "kbn.discover.fieldNameIcons.unknownFieldAriaLabel": "未知字段", "kbn.discover.histogram.partialData.bucketTooltipText": "选定的时间范围不包括此整个存储桶,其可能包含部分数据。", "kbn.discover.histogramOfFoundDocumentsAriaLabel": "已找到文档的直方图", "kbn.discover.hitsPluralTitle": "{hits, plural, one {次命中} other {次命中}}", From 9269039cfbd2c5af3108df79d9f6fc13a82613ae Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Tue, 10 Mar 2020 11:52:31 +0100 Subject: [PATCH 09/11] fix eslint errors --- .../kibana/public/discover/kibana_services.ts | 4 +--- .../table/table_row_btn_filter_exists.tsx | 9 +++------ .../table/table_row_btn_toggle_column.tsx | 18 ++++++------------ .../table/table_row_icon_no_mapping.tsx | 9 +++------ 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts index 1fb13c1314ed3..b7a3974a58865 100644 --- a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts @@ -58,9 +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, -} from '../../../../../plugins/kibana_legacy/public'; +export { ensureDefaultIndexPattern } from '../../../../../plugins/kibana_legacy/public'; // EXPORT types export { diff --git a/src/plugins/discover/public/components/table/table_row_btn_filter_exists.tsx b/src/plugins/discover/public/components/table/table_row_btn_filter_exists.tsx index 2106bc816c283..dab22c103bc48 100644 --- a/src/plugins/discover/public/components/table/table_row_btn_filter_exists.tsx +++ b/src/plugins/discover/public/components/table/table_row_btn_filter_exists.tsx @@ -54,12 +54,9 @@ export function DocViewTableRowBtnFilterExists({ return ( Date: Tue, 10 Mar 2020 15:21:41 +0100 Subject: [PATCH 10/11] fix legacy tests --- .../public/discover/np_ready/components/doc/doc.test.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.test.tsx index a1942e18f5991..1d19dc112d193 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc/doc.test.tsx @@ -24,10 +24,6 @@ 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: () => ({ From 70fad9bbacfd12532989a7955e151534e3b161bb Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 11 Mar 2020 09:35:48 +0100 Subject: [PATCH 11/11] complete karma mock and add jest mocks for later user --- .../new_platform/new_platform.karma_mock.js | 5 ++ src/plugins/discover/public/mocks.ts | 47 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/plugins/discover/public/mocks.ts diff --git a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js index aa18004f91073..fc35e0545fc5f 100644 --- a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js +++ b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js @@ -401,6 +401,11 @@ export const npStart = { useChartsTheme: sinon.fake(), }, }, + discover: { + docViews: { + DocViewer: () => null, + }, + }, }, }; diff --git a/src/plugins/discover/public/mocks.ts b/src/plugins/discover/public/mocks.ts new file mode 100644 index 0000000000000..bb05e3d412001 --- /dev/null +++ b/src/plugins/discover/public/mocks.ts @@ -0,0 +1,47 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { DiscoverSetup, DiscoverStart } from '.'; + +export type Setup = jest.Mocked; +export type Start = jest.Mocked; + +const createSetupContract = (): Setup => { + const setupContract: Setup = { + docViews: { + addDocView: jest.fn(), + setAngularInjectorGetter: jest.fn(), + }, + }; + return setupContract; +}; + +const createStartContract = (): Start => { + const startContract: Start = { + docViews: { + DocViewer: jest.fn(() => null), + }, + }; + return startContract; +}; + +export const discoverPluginMock = { + createSetupContract, + createStartContract, +};