From f112668af128702221ac16c9e7bb8ccb406f33c4 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 18 Dec 2019 11:33:00 +0100 Subject: [PATCH 1/5] move doc views registry and existing doc views into discover plugin --- src/core/MIGRATION.md | 1 + .../core_plugins/kbn_doc_views/index.js | 26 ------- .../core_plugins/kbn_doc_views/package.json | 4 -- .../kbn_doc_views/public/kbn_doc_views.js | 21 ------ .../kbn_doc_views/public/views/json.tsx | 33 --------- .../kbn_doc_views/public/views/table.ts | 31 --------- .../discover/components/doc/doc.test.tsx | 4 +- .../components/doc/use_es_doc_search.test.tsx | 8 +-- .../components/doc_viewer/doc_viewer.test.tsx | 30 ++++---- .../components/doc_viewer/doc_viewer.tsx | 4 +- .../doc_viewer/doc_viewer_render_tab.test.tsx | 2 +- .../doc_viewer/doc_viewer_render_tab.tsx | 2 +- .../components/doc_viewer/doc_viewer_tab.tsx | 2 +- .../json_code_block.test.tsx.snap | 0 .../json_code_block}/json_code_block.test.tsx | 0 .../json_code_block}/json_code_block.tsx | 4 +- .../discover/components}/table/table.test.tsx | 2 +- .../discover/components}/table/table.tsx | 2 +- .../components}/table/table_helper.test.ts | 0 .../components}/table/table_helper.tsx | 0 .../discover/components}/table/table_row.tsx | 4 +- .../table/table_row_btn_collapse.tsx | 2 +- .../table/table_row_btn_filter_add.tsx | 6 +- .../table/table_row_btn_filter_exists.tsx | 15 ++-- .../table/table_row_btn_filter_remove.tsx | 6 +- .../table/table_row_btn_toggle_column.tsx | 20 ++++-- .../table/table_row_icon_no_mapping.tsx | 20 ++++-- .../table/table_row_icon_underscore.tsx | 4 +- .../discover/doc_views}/doc_views_helpers.tsx | 2 +- .../discover/doc_views/doc_views_registry.ts | 48 +++++++++++++ .../discover/doc_views}/doc_views_types.ts | 0 .../public/discover/helpers/build_services.ts | 10 ++- .../kibana/public/discover/index.ts | 6 +- .../kibana/public/discover/kibana_services.ts | 3 +- .../kibana/public/discover/plugin.ts | 35 +++++++++- src/legacy/ui/public/registry/doc_views.ts | 69 ------------------- .../translations/translations/ja-JP.json | 38 +++++----- .../translations/translations/zh-CN.json | 40 +++++------ 38 files changed, 208 insertions(+), 296 deletions(-) delete mode 100644 src/legacy/core_plugins/kbn_doc_views/index.js delete mode 100644 src/legacy/core_plugins/kbn_doc_views/package.json delete mode 100644 src/legacy/core_plugins/kbn_doc_views/public/kbn_doc_views.js delete mode 100644 src/legacy/core_plugins/kbn_doc_views/public/views/json.tsx delete mode 100644 src/legacy/core_plugins/kbn_doc_views/public/views/table.ts rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components/json_code_block}/__snapshots__/json_code_block.test.tsx.snap (100%) rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components/json_code_block}/json_code_block.test.tsx (100%) rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components/json_code_block}/json_code_block.tsx (88%) rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components}/table/table.test.tsx (99%) rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components}/table/table.tsx (97%) rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components}/table/table_helper.test.ts (100%) rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components}/table/table_helper.tsx (100%) rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components}/table/table_row.tsx (98%) rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components}/table/table_row_btn_collapse.tsx (94%) rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components}/table/table_row_btn_filter_add.tsx (87%) rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components}/table/table_row_btn_filter_exists.tsx (80%) rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components}/table/table_row_btn_filter_remove.tsx (87%) rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components}/table/table_row_btn_toggle_column.tsx (79%) rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components}/table/table_row_icon_no_mapping.tsx (74%) rename src/legacy/core_plugins/{kbn_doc_views/public/views => kibana/public/discover/components}/table/table_row_icon_underscore.tsx (89%) rename src/legacy/{ui/public/registry => core_plugins/kibana/public/discover/doc_views}/doc_views_helpers.tsx (95%) create mode 100644 src/legacy/core_plugins/kibana/public/discover/doc_views/doc_views_registry.ts rename src/legacy/{ui/public/registry => core_plugins/kibana/public/discover/doc_views}/doc_views_types.ts (100%) delete mode 100644 src/legacy/ui/public/registry/doc_views.ts diff --git a/src/core/MIGRATION.md b/src/core/MIGRATION.md index 5bb22579d123..10e33d292816 100644 --- a/src/core/MIGRATION.md +++ b/src/core/MIGRATION.md @@ -1173,6 +1173,7 @@ import { setup, start } from '../core_plugins/visualizations/public/legacy'; | `ui/registry/field_formats` | `data.fieldFormats` | | | `ui/registry/feature_catalogue` | `home.featureCatalogue.register` | Must add `home` as a dependency in your kibana.json. | | `ui/registry/vis_types` | `visualizations.types` | -- | +| `ui/registry/doc_views` | `discover.addDocView` | Currently shimmed in the old platform - use `import { setup } from '../kibana/public/discover'; setup.addDocView(...)` | | `ui/vis` | `visualizations.types` | -- | | `ui/share` | `share` | `showShareContextMenu` is now called `toggleShareContextMenu`, `ShareContextMenuExtensionsRegistryProvider` is now called `register` | | `ui/vis/vis_factory` | `visualizations.types` | -- | diff --git a/src/legacy/core_plugins/kbn_doc_views/index.js b/src/legacy/core_plugins/kbn_doc_views/index.js deleted file mode 100644 index 9078a82d6338..000000000000 --- a/src/legacy/core_plugins/kbn_doc_views/index.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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(kibana) { - return new kibana.Plugin({ - uiExports: { - docViews: ['plugins/kbn_doc_views/kbn_doc_views'], - }, - }); -} diff --git a/src/legacy/core_plugins/kbn_doc_views/package.json b/src/legacy/core_plugins/kbn_doc_views/package.json deleted file mode 100644 index efad9ec42f1f..000000000000 --- a/src/legacy/core_plugins/kbn_doc_views/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "kbn_doc_views", - "version": "kibana" -} diff --git a/src/legacy/core_plugins/kbn_doc_views/public/kbn_doc_views.js b/src/legacy/core_plugins/kbn_doc_views/public/kbn_doc_views.js deleted file mode 100644 index 2608e60e7074..000000000000 --- a/src/legacy/core_plugins/kbn_doc_views/public/kbn_doc_views.js +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 './views/table'; -import './views/json'; diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/json.tsx b/src/legacy/core_plugins/kbn_doc_views/public/views/json.tsx deleted file mode 100644 index 73167b56bdde..000000000000 --- a/src/legacy/core_plugins/kbn_doc_views/public/views/json.tsx +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 { addDocView } from 'ui/registry/doc_views'; -import { i18n } from '@kbn/i18n'; -import { JsonCodeBlock } from './json_code_block'; - -/* - * Registration of the the doc view: json - * - used to display an ES hit as pretty printed JSON at Discover - */ -addDocView({ - title: i18n.translate('kbnDocViews.json.jsonTitle', { - defaultMessage: 'JSON', - }), - order: 20, - component: JsonCodeBlock, -}); diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/table.ts b/src/legacy/core_plugins/kbn_doc_views/public/views/table.ts deleted file mode 100644 index f90840f19500..000000000000 --- a/src/legacy/core_plugins/kbn_doc_views/public/views/table.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 _ from 'lodash'; -import { addDocView } from 'ui/registry/doc_views'; -import { i18n } from '@kbn/i18n'; -import { DocViewTable } from './table/table'; - -addDocView({ - title: i18n.translate('kbnDocViews.table.tableTitle', { - defaultMessage: 'Table', - }), - order: 10, - component: DocViewTable, -}); diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc/doc.test.tsx b/src/legacy/core_plugins/kibana/public/discover/components/doc/doc.test.tsx index 4df56483fa5c..334e897c71f4 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc/doc.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/components/doc/doc.test.tsx @@ -25,7 +25,7 @@ import { findTestSubject } from '@elastic/eui/lib/test'; import { Doc, DocProps } from './doc'; jest.mock('../doc_viewer/doc_viewer', () => ({ - DocViewer: 'test', + DocViewer: () => null, })); jest.mock('../../kibana_services', () => { @@ -67,7 +67,7 @@ async function mountDoc(search: () => void, update = false, indexPatternGetter: indexPatternService, } as DocProps; let comp!: ReactWrapper; - act(() => { + await act(async () => { comp = mountWithIntl(); if (update) comp.update(); }); diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc/use_es_doc_search.test.tsx b/src/legacy/core_plugins/kibana/public/discover/components/doc/use_es_doc_search.test.tsx index 2420eb2cd22b..a8fe8de83331 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc/use_es_doc_search.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/components/doc/use_es_doc_search.test.tsx @@ -43,7 +43,7 @@ describe('Test of helper / hook', () => { `); }); - test('useEsDocSearch', () => { + test('useEsDocSearch', async () => { const indexPattern = { getComputedFields: () => [], }; @@ -53,16 +53,16 @@ describe('Test of helper / hook', () => { const props = { id: '1', index: 'index1', - esClient: { search: jest.fn() }, + esClient: { search: jest.fn(() => new Promise(() => {})) }, indexPatternId: 'xyz', indexPatternService, } as DocProps; let hook; - act(() => { + await act(async () => { hook = renderHook((p: DocProps) => useEsDocSearch(p), { initialProps: props }); }); // @ts-ignore - expect(hook.result.current).toEqual([ElasticRequestState.Loading, null, null]); + expect(hook.result.current).toEqual([ElasticRequestState.Loading, null, indexPattern]); expect(indexPatternService.get).toHaveBeenCalled(); }); }); diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer.test.tsx b/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer.test.tsx index 158ed4ccc775..13b91b26a09a 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer.test.tsx @@ -21,34 +21,33 @@ import { mount, shallow } from 'enzyme'; import { DocViewer } from './doc_viewer'; // @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; -import { - addDocView, - emptyDocViews, - DocViewRenderProps, - getDocViewsSorted as mockGetDocViewsSorted, -} from 'ui/registry/doc_views'; +import { DocViewRenderProps } from '../../doc_views/doc_views_registry'; +import { getServices } from '../../kibana_services'; jest.mock('../../kibana_services', () => { + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { DocViewsRegistry } = require('../../doc_views/doc_views_registry'); + let registry = new DocViewsRegistry(); return { getServices: () => ({ - docViewsRegistry: { - getDocViewsSorted: (hit: any) => { - return mockGetDocViewsSorted(hit); - }, + docViewsRegistry: registry, + resetRegistry: () => { + registry = new DocViewsRegistry(); }, }), }; }); beforeEach(() => { - emptyDocViews(); + (getServices() as any).resetRegistry(); jest.clearAllMocks(); }); test('Render with 3 different tabs', () => { - addDocView({ order: 20, title: 'React component', component: () =>
test
}); - addDocView({ order: 10, title: 'Render function', render: jest.fn() }); - addDocView({ order: 30, title: 'Invalid doc view' }); + const registry = getServices().docViewsRegistry; + registry.addDocView({ order: 20, title: 'React component', component: () =>
test
}); + registry.addDocView({ order: 10, title: 'Render function', render: jest.fn() }); + registry.addDocView({ order: 30, title: 'Invalid doc view' }); const renderProps = { hit: {} } as DocViewRenderProps; @@ -63,7 +62,8 @@ test('Render with 1 tab displaying error message', () => { return null; } - addDocView({ + const registry = getServices().docViewsRegistry; + registry.addDocView({ order: 10, title: 'React component', component: SomeComponent, diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer.tsx b/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer.tsx index a2d58439ad03..640889abc593 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer.tsx @@ -17,9 +17,9 @@ * under the License. */ import React from 'react'; -import { DocView } from 'ui/registry/doc_views_types'; import { EuiTabbedContent } from '@elastic/eui'; -import { getServices, DocViewRenderProps } from '../../kibana_services'; +import { DocView, DocViewRenderProps } from '../../doc_views/doc_views_types'; +import { getServices } from '../../kibana_services'; import { DocViewerTab } from './doc_viewer_tab'; /** diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_tab.test.tsx b/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_tab.test.tsx index 476d7cef159f..79f185452164 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_tab.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_tab.test.tsx @@ -19,7 +19,7 @@ import React from 'react'; import { mount } from 'enzyme'; import { DocViewRenderTab } from './doc_viewer_render_tab'; -import { DocViewRenderProps } from '../../kibana_services'; +import { DocViewRenderProps } from '../../doc_views/doc_views_types'; test('Mounting and unmounting DocViewerRenderTab', () => { const unmountFn = jest.fn(); diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_tab.tsx b/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_tab.tsx index 8ac11caefff9..0b1a02f1987c 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_tab.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_render_tab.tsx @@ -17,7 +17,7 @@ * under the License. */ import React, { useRef, useEffect } from 'react'; -import { DocViewRenderFn, DocViewRenderProps } from '../../kibana_services'; +import { DocViewRenderFn, DocViewRenderProps } from '../../doc_views/doc_views_types'; interface Props { render: DocViewRenderFn; diff --git a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_tab.tsx b/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_tab.tsx index 19558129eae8..0c21fafc91d6 100644 --- a/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_tab.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/components/doc_viewer/doc_viewer_tab.tsx @@ -18,9 +18,9 @@ */ import React from 'react'; import { I18nProvider } from '@kbn/i18n/react'; -import { DocViewRenderProps, DocViewRenderFn } from '../../kibana_services'; import { DocViewRenderTab } from './doc_viewer_render_tab'; import { DocViewerError } from './doc_viewer_render_error'; +import { DocViewRenderFn, DocViewRenderProps } from '../../doc_views/doc_views_types'; interface Props { component?: React.ComponentType; diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/__snapshots__/json_code_block.test.tsx.snap b/src/legacy/core_plugins/kibana/public/discover/components/json_code_block/__snapshots__/json_code_block.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/kbn_doc_views/public/views/__snapshots__/json_code_block.test.tsx.snap rename to src/legacy/core_plugins/kibana/public/discover/components/json_code_block/__snapshots__/json_code_block.test.tsx.snap diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/json_code_block.test.tsx b/src/legacy/core_plugins/kibana/public/discover/components/json_code_block/json_code_block.test.tsx similarity index 100% rename from src/legacy/core_plugins/kbn_doc_views/public/views/json_code_block.test.tsx rename to src/legacy/core_plugins/kibana/public/discover/components/json_code_block/json_code_block.test.tsx diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/json_code_block.tsx b/src/legacy/core_plugins/kibana/public/discover/components/json_code_block/json_code_block.tsx similarity index 88% rename from src/legacy/core_plugins/kbn_doc_views/public/views/json_code_block.tsx rename to src/legacy/core_plugins/kibana/public/discover/components/json_code_block/json_code_block.tsx index 3f412b050052..3331969e351a 100644 --- a/src/legacy/core_plugins/kbn_doc_views/public/views/json_code_block.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/components/json_code_block/json_code_block.tsx @@ -19,10 +19,10 @@ import React from 'react'; import { EuiCodeBlock } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { DocViewRenderProps } from 'ui/registry/doc_views'; +import { DocViewRenderProps } from '../../doc_views/doc_views_types'; export function JsonCodeBlock({ hit }: DocViewRenderProps) { - const label = i18n.translate('kbnDocViews.json.codeEditorAriaLabel', { + const label = i18n.translate('kbn.discover.docViews.json.codeEditorAriaLabel', { defaultMessage: 'Read only JSON view of an elasticsearch document', }); return ( diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx b/src/legacy/core_plugins/kibana/public/discover/components/table/table.test.tsx similarity index 99% rename from src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx rename to src/legacy/core_plugins/kibana/public/discover/components/table/table.test.tsx index bad006aa8c7d..946ef326b98e 100644 --- a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/components/table/table.test.tsx @@ -21,7 +21,7 @@ import { mount } from 'enzyme'; import { IndexPattern } from 'ui/index_patterns'; // @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; -import { flattenHitWrapper } from '../../../../data/public/'; +import { flattenHitWrapper } from '../../../../../data/public'; import { DocViewTable } from './table'; // @ts-ignore diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.tsx b/src/legacy/core_plugins/kibana/public/discover/components/table/table.tsx similarity index 97% rename from src/legacy/core_plugins/kbn_doc_views/public/views/table/table.tsx rename to src/legacy/core_plugins/kibana/public/discover/components/table/table.tsx index 7158739e5d43..4bb2f83016c2 100644 --- a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/components/table/table.tsx @@ -17,9 +17,9 @@ * under the License. */ import React, { useState } from 'react'; -import { DocViewRenderProps } from 'ui/registry/doc_views'; import { DocViewTableRow } from './table_row'; import { arrayContainsObjects, trimAngularSpan } from './table_helper'; +import { DocViewRenderProps } from '../../doc_views/doc_views_types'; const COLLAPSE_LINE_LENGTH = 350; diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table_helper.test.ts b/src/legacy/core_plugins/kibana/public/discover/components/table/table_helper.test.ts similarity index 100% rename from src/legacy/core_plugins/kbn_doc_views/public/views/table/table_helper.test.ts rename to src/legacy/core_plugins/kibana/public/discover/components/table/table_helper.test.ts diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table_helper.tsx b/src/legacy/core_plugins/kibana/public/discover/components/table/table_helper.tsx similarity index 100% rename from src/legacy/core_plugins/kbn_doc_views/public/views/table/table_helper.tsx rename to src/legacy/core_plugins/kibana/public/discover/components/table/table_helper.tsx diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table_row.tsx b/src/legacy/core_plugins/kibana/public/discover/components/table/table_row.tsx similarity index 98% rename from src/legacy/core_plugins/kbn_doc_views/public/views/table/table_row.tsx rename to src/legacy/core_plugins/kibana/public/discover/components/table/table_row.tsx index 045e8093124a..6151acdc2068 100644 --- a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table_row.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/components/table/table_row.tsx @@ -16,10 +16,10 @@ * specific language governing permissions and limitations * under the License. */ +import classNames from 'classnames'; import React, { ReactNode } from 'react'; import { FieldName } from 'ui/directives/field_name/field_name'; -import { FieldMapping, DocViewFilterFn } from 'ui/registry/doc_views_types'; -import classNames from 'classnames'; +import { FieldMapping, DocViewFilterFn } from '../../doc_views/doc_views_types'; import { DocViewTableRowBtnFilterAdd } from './table_row_btn_filter_add'; import { DocViewTableRowBtnFilterRemove } from './table_row_btn_filter_remove'; import { DocViewTableRowBtnToggleColumn } from './table_row_btn_toggle_column'; diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table_row_btn_collapse.tsx b/src/legacy/core_plugins/kibana/public/discover/components/table/table_row_btn_collapse.tsx similarity index 94% rename from src/legacy/core_plugins/kbn_doc_views/public/views/table/table_row_btn_collapse.tsx rename to src/legacy/core_plugins/kibana/public/discover/components/table/table_row_btn_collapse.tsx index cb6b522ba955..e59f607329d4 100644 --- a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table_row_btn_collapse.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/components/table/table_row_btn_collapse.tsx @@ -26,7 +26,7 @@ export interface Props { } export function DocViewTableRowBtnCollapse({ onClick, isCollapsed }: Props) { - const label = i18n.translate('kbnDocViews.table.toggleFieldDetails', { + const label = i18n.translate('kbn.discover.docViews.table.toggleFieldDetails', { defaultMessage: 'Toggle field details', }); return ( diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table_row_btn_filter_add.tsx b/src/legacy/core_plugins/kibana/public/discover/components/table/table_row_btn_filter_add.tsx similarity index 87% rename from src/legacy/core_plugins/kbn_doc_views/public/views/table/table_row_btn_filter_add.tsx rename to src/legacy/core_plugins/kibana/public/discover/components/table/table_row_btn_filter_add.tsx index df4572c5bb53..8e2668e26cf0 100644 --- a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table_row_btn_filter_add.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/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 ( ) : ( ) ) : ( ); @@ -54,9 +54,12 @@ export function DocViewTableRowBtnFilterExists({ return ( ) : ( ); @@ -42,7 +42,7 @@ export function DocViewTableRowBtnFilterRemove({ onClick, disabled = false }: Pr return ( } > Index Patterns page', - }); + const ariaLabel = i18n.translate( + 'kbn.discover.docViews.table.noCachedMappingForThisFieldAriaLabel', + { + defaultMessage: 'Warning', + } + ); + const tooltipContent = i18n.translate( + 'kbn.discover.docViews.table.noCachedMappingForThisFieldTooltip', + { + defaultMessage: + 'No cached mapping for this field. Refresh field list from the Management > Index Patterns page', + } + ); return ( true; + } + this.docViews.push(docView as DocView); + } + /** + * Returns a sorted array of doc_views for rendering tabs + */ + getDocViewsSorted(hit: ElasticSearchHit) { + return this.docViews + .filter(docView => docView.shouldShow(hit)) + .sort((a, b) => (Number(a.order) > Number(b.order) ? 1 : -1)); + } +} diff --git a/src/legacy/ui/public/registry/doc_views_types.ts b/src/legacy/core_plugins/kibana/public/discover/doc_views/doc_views_types.ts similarity index 100% rename from src/legacy/ui/public/registry/doc_views_types.ts rename to src/legacy/core_plugins/kibana/public/discover/doc_views/doc_views_types.ts diff --git a/src/legacy/core_plugins/kibana/public/discover/helpers/build_services.ts b/src/legacy/core_plugins/kibana/public/discover/helpers/build_services.ts index 14ea4e99b0de..b2978852e51a 100644 --- a/src/legacy/core_plugins/kibana/public/discover/helpers/build_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/helpers/build_services.ts @@ -24,7 +24,6 @@ import { ToastsStart, IUiSettingsClient, } from 'kibana/public'; -import * as docViewsRegistry from 'ui/registry/doc_views'; import { FilterManager, TimefilterContract, IndexPatternsContract } from 'src/plugins/data/public'; // @ts-ignore import { createSavedSearchesService } from '../saved_searches/saved_searches'; @@ -34,6 +33,7 @@ import { DataStart } from '../../../../data/public'; import { EuiUtilsStart } from '../../../../../../plugins/eui_utils/public'; import { SavedSearch } from '../types'; import { SharePluginStart } from '../../../../../../plugins/share/public'; +import { DocViewsRegistry } from '../doc_views/doc_views_registry'; export interface DiscoverServices { addBasePath: (path: string) => string; @@ -42,7 +42,7 @@ export interface DiscoverServices { core: CoreStart; data: DataStart; docLinks: DocLinksStart; - docViewsRegistry: docViewsRegistry.DocViewsRegistry; + docViewsRegistry: DocViewsRegistry; eui_utils: EuiUtilsStart; filterManager: FilterManager; indexPatterns: IndexPatternsContract; @@ -55,7 +55,11 @@ export interface DiscoverServices { getSavedSearchUrlById: (id: string) => Promise; uiSettings: IUiSettingsClient; } -export async function buildServices(core: CoreStart, plugins: DiscoverStartPlugins) { +export async function buildServices( + core: CoreStart, + plugins: DiscoverStartPlugins, + docViewsRegistry: DocViewsRegistry +) { const services = { savedObjectsClient: core.savedObjects.client, indexPatterns: plugins.data.indexPatterns, diff --git a/src/legacy/core_plugins/kibana/public/discover/index.ts b/src/legacy/core_plugins/kibana/public/discover/index.ts index 6ea658682c89..cbf041f2cbab 100644 --- a/src/legacy/core_plugins/kibana/public/discover/index.ts +++ b/src/legacy/core_plugins/kibana/public/discover/index.ts @@ -28,10 +28,8 @@ export const plugin: PluginInitializer = () => { // Legacy compatiblity part - to be removed at cutover, replaced by a kibana.json file export const pluginInstance = plugin({} as PluginInitializerContext); -(async () => { - pluginInstance.setup(npSetup.core, npSetup.plugins); - pluginInstance.start(npStart.core, npStart.plugins); -})(); +export const setup = pluginInstance.setup(npSetup.core, npSetup.plugins); +export const start = pluginInstance.start(npStart.core, npStart.plugins); SavedObjectRegistryProvider.register((savedSearches: any) => { return savedSearches; 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 d13d0dc868a5..53268b1c36ef 100644 --- a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts @@ -87,6 +87,5 @@ export { IndexPattern, IFieldType, } from '../../../../../plugins/data/public'; -export { ElasticSearchHit } from 'ui/registry/doc_views_types'; -export { DocViewRenderProps, DocViewRenderFn } from 'ui/registry/doc_views'; +export { ElasticSearchHit } from './doc_views/doc_views_types'; export { Adapters } from 'ui/inspector/types'; diff --git a/src/legacy/core_plugins/kibana/public/discover/plugin.ts b/src/legacy/core_plugins/kibana/public/discover/plugin.ts index b5a8e25dc11e..2c4071fbea89 100644 --- a/src/legacy/core_plugins/kibana/public/discover/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/discover/plugin.ts @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +import { i18n } from '@kbn/i18n'; import { AppMountParameters, CoreSetup, CoreStart, Plugin } from 'kibana/public'; import angular from 'angular'; import { IUiActionsStart } from 'src/plugins/ui_actions/public'; @@ -30,13 +31,19 @@ import { EuiUtilsStart } from '../../../../../plugins/eui_utils/public'; import { buildServices } from './helpers/build_services'; import { SharePluginStart } from '../../../../../plugins/share/public'; import { KibanaLegacySetup } from '../../../../../plugins/kibana_legacy/public'; +import { DocViewsRegistry } from './doc_views/doc_views_registry'; +import { DocViewInput, DocViewInputFn } from './doc_views/doc_views_types'; +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 type DiscoverSetup = void; +export interface DiscoverSetup { + addDocView(docViewRaw: DocViewInput | DocViewInputFn): void; +} export type DiscoverStart = void; export interface DiscoverSetupPlugins { uiActions: IUiActionsStart; @@ -63,12 +70,32 @@ const embeddableAngularName = 'app/discoverEmbeddable'; export class DiscoverPlugin implements Plugin { private servicesInitialized: boolean = false; private innerAngularInitialized: boolean = false; + private readonly docViewsRegistry: DocViewsRegistry; /** * why are those functions public? they are needed for some mocha tests * can be removed once all is Jest */ public initializeInnerAngular?: () => void; public initializeServices?: () => void; + + constructor() { + 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, + }); + } + setup(core: CoreSetup, plugins: DiscoverSetupPlugins): DiscoverSetup { plugins.kibana_legacy.registerLegacyApp({ id: 'discover', @@ -88,6 +115,10 @@ export class DiscoverPlugin implements Plugin { return renderApp(innerAngularName, params.element); }, }); + + return { + addDocView: this.docViewsRegistry.addDocView.bind(this.docViewsRegistry), + }; } start(core: CoreStart, plugins: DiscoverStartPlugins): DiscoverStart { @@ -109,7 +140,7 @@ export class DiscoverPlugin implements Plugin { if (this.servicesInitialized) { return; } - const services = await buildServices(core, plugins); + const services = await buildServices(core, plugins, this.docViewsRegistry); setServices(services); this.servicesInitialized = true; }; diff --git a/src/legacy/ui/public/registry/doc_views.ts b/src/legacy/ui/public/registry/doc_views.ts deleted file mode 100644 index bf1e8416ae66..000000000000 --- a/src/legacy/ui/public/registry/doc_views.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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 { convertDirectiveToRenderFn } from './doc_views_helpers'; -import { DocView, DocViewInput, ElasticSearchHit, DocViewInputFn } from './doc_views_types'; - -export { DocViewRenderProps, DocView, DocViewRenderFn } from './doc_views_types'; - -export interface DocViewsRegistry { - docViews: DocView[]; - addDocView: (docView: DocViewInput) => void; - getDocViewsSorted: (hit: ElasticSearchHit) => DocView[]; -} - -export const docViews: DocView[] = []; - -/** - * Extends and adds the given doc view to the registry array - */ -export function addDocView(docView: DocViewInput) { - if (docView.directive) { - // convert angular directive to render function for backwards compatibility - docView.render = convertDirectiveToRenderFn(docView.directive); - } - if (typeof docView.shouldShow !== 'function') { - docView.shouldShow = () => true; - } - docViews.push(docView as DocView); -} - -/** - * Empty array of doc views for testing - */ -export function emptyDocViews() { - docViews.length = 0; -} - -/** - * Returns a sorted array of doc_views for rendering tabs - */ -export function getDocViewsSorted(hit: ElasticSearchHit): DocView[] { - return docViews - .filter(docView => docView.shouldShow(hit)) - .sort((a, b) => (Number(a.order) > Number(b.order) ? 1 : -1)); -} -/** - * Provider for compatibility with 3rd Party plugins - */ -export const DocViewsRegistryProvider = { - register: (docViewRaw: DocViewInput | DocViewInputFn) => { - const docView = typeof docViewRaw === 'function' ? docViewRaw() : docViewRaw; - addDocView(docView); - }, -}; diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index b7036399f3f7..3896f5023554 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -2492,6 +2492,25 @@ "kbn.context.olderDocumentsAriaLabel": "古いドキュメントの数", "kbn.context.olderDocumentsWarning": "アンカーよりも古いドキュメントは {docCount} 件しか見つかりませんでした。", "kbn.context.olderDocumentsWarningZero": "アンカーよりも古いドキュメントは見つかりませんでした。", + "kbn.discover.docViews.table.fieldNamesBeginningWithUnderscoreUnsupportedTooltip": "{underscoreSign} で始まるフィールド名はサポートされていません", + "kbn.discover.docViews.table.filterForFieldPresentButtonAriaLabel": "現在のフィールドのフィルター", + "kbn.discover.docViews.table.filterForFieldPresentButtonTooltip": "現在のフィールドのフィルター", + "kbn.discover.docViews.table.filterForValueButtonAriaLabel": "値でフィルタリング", + "kbn.discover.docViews.table.filterForValueButtonTooltip": "値でフィルタリング", + "kbn.discover.docViews.table.filterOutValueButtonAriaLabel": "値を除外", + "kbn.discover.docViews.table.filterOutValueButtonTooltip": "値を除外します", + "kbn.discover.docViews.table.noCachedMappingForThisFieldTooltip": "このフィールドのキャッシュされたマッピングがありません。管理 > インデックスパターンページからフィールドリストを更新してください", + "kbn.discover.docViews.table.tableTitle": "表", + "kbn.discover.docViews.table.toggleColumnInTableButtonAriaLabel": "表の列を切り替える", + "kbn.discover.docViews.table.toggleColumnInTableButtonTooltip": "表の列を切り替える", + "kbn.discover.docViews.table.unableToFilterForPresenceOfMetaFieldsTooltip": "メタフィールドの有無でフィルタリングできません", + "kbn.discover.docViews.table.unableToFilterForPresenceOfScriptedFieldsTooltip": "スクリプトフィールドの有無でフィルタリングできません", + "kbn.discover.docViews.table.unindexedFieldsCanNotBeSearchedTooltip": "インデックスされていないフィールドは検索できません", + "kbn.discover.docViews.json.codeEditorAriaLabel": "Elasticsearch ドキュメントの JSON ビューのみを読み込む", + "kbn.discover.docViews.json.jsonTitle": "JSON", + "kbn.discover.docViews.table.fieldNamesBeginningWithUnderscoreUnsupportedAriaLabel": "警告", + "kbn.discover.docViews.table.noCachedMappingForThisFieldAriaLabel": "警告", + "kbn.discover.docViews.table.toggleFieldDetails": "フィールド詳細を切り替える", "kbn.discover.fieldChooser.fieldFilterFacetButtonLabel": "フィルタリングされたフィールド", "kbn.discover.fieldChooser.indexPattern.changeLinkTooltip": "現在のインデックスパターンを変更", "kbn.discover.fieldChooser.indexPattern.changeLinkAriaLabel": "現在のインデックスパターンを変更", @@ -2514,25 +2533,6 @@ "kbn.advancedSettings.courier.batchSearchesText": "無効の場合、ダッシュボードパネルは個々に読み込まれ、検索リクエストはユーザーが移動するか\n クエリを更新すると停止します。有効の場合、ダッシュボードパネルはすべてのデータが読み込まれると同時に読み込まれ、\n 検索は停止しません。", "kbn.doc.couldNotFindDocumentsDescription": "その ID に一致するドキュメントがありません。", "kbn.doc.somethingWentWrongDescription": "{indexName} が欠けています。", - "kbnDocViews.table.fieldNamesBeginningWithUnderscoreUnsupportedTooltip": "{underscoreSign} で始まるフィールド名はサポートされていません", - "kbnDocViews.table.filterForFieldPresentButtonAriaLabel": "現在のフィールドのフィルター", - "kbnDocViews.table.filterForFieldPresentButtonTooltip": "現在のフィールドのフィルター", - "kbnDocViews.table.filterForValueButtonAriaLabel": "値でフィルタリング", - "kbnDocViews.table.filterForValueButtonTooltip": "値でフィルタリング", - "kbnDocViews.table.filterOutValueButtonAriaLabel": "値を除外", - "kbnDocViews.table.filterOutValueButtonTooltip": "値を除外します", - "kbnDocViews.table.noCachedMappingForThisFieldTooltip": "このフィールドのキャッシュされたマッピングがありません。管理 > インデックスパターンページからフィールドリストを更新してください", - "kbnDocViews.table.tableTitle": "表", - "kbnDocViews.table.toggleColumnInTableButtonAriaLabel": "表の列を切り替える", - "kbnDocViews.table.toggleColumnInTableButtonTooltip": "表の列を切り替える", - "kbnDocViews.table.unableToFilterForPresenceOfMetaFieldsTooltip": "メタフィールドの有無でフィルタリングできません", - "kbnDocViews.table.unableToFilterForPresenceOfScriptedFieldsTooltip": "スクリプトフィールドの有無でフィルタリングできません", - "kbnDocViews.table.unindexedFieldsCanNotBeSearchedTooltip": "インデックスされていないフィールドは検索できません", - "kbnDocViews.json.codeEditorAriaLabel": "Elasticsearch ドキュメントの JSON ビューのみを読み込む", - "kbnDocViews.json.jsonTitle": "JSON", - "kbnDocViews.table.fieldNamesBeginningWithUnderscoreUnsupportedAriaLabel": "警告", - "kbnDocViews.table.noCachedMappingForThisFieldAriaLabel": "警告", - "kbnDocViews.table.toggleFieldDetails": "フィールド詳細を切り替える", "kbnVislibVisTypes.area.areaDescription": "折れ線グラフの下の数量を強調します。", "kbnVislibVisTypes.area.areaTitle": "エリア", "kbnVislibVisTypes.area.groupTitle": "系列を分割", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index af4aa1f0c7bb..bbc16bd4039a 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -1528,6 +1528,25 @@ "kbn.discover.discoverDescription": "通过查询和筛选原始文档来以交互方式浏览您的数据。", "kbn.discover.discoverTitle": "Discover", "kbn.discover.documentsAriaLabel": "文档", + "kbn.discover.docViews.table.fieldNamesBeginningWithUnderscoreUnsupportedTooltip": "不支持以 {underscoreSign} 开头的字段名称", + "kbn.discover.docViews.table.filterForFieldPresentButtonAriaLabel": "筛留存在的字段", + "kbn.discover.docViews.table.filterForFieldPresentButtonTooltip": "筛留存在的字段", + "kbn.discover.docViews.table.filterForValueButtonAriaLabel": "筛留值", + "kbn.discover.docViews.table.filterForValueButtonTooltip": "筛留值", + "kbn.discover.docViews.table.filterOutValueButtonAriaLabel": "筛除值", + "kbn.discover.docViews.table.filterOutValueButtonTooltip": "筛除值", + "kbn.discover.docViews.table.noCachedMappingForThisFieldTooltip": "此字段没有任何已缓存映射。从“管理”>“索引模式”页面刷新字段列表", + "kbn.discover.docViews.table.tableTitle": "表", + "kbn.discover.docViews.table.toggleColumnInTableButtonAriaLabel": "在表中切换列", + "kbn.discover.docViews.table.toggleColumnInTableButtonTooltip": "在表中切换列", + "kbn.discover.docViews.table.unableToFilterForPresenceOfMetaFieldsTooltip": "无法筛留元数据字段", + "kbn.discover.docViews.table.unableToFilterForPresenceOfScriptedFieldsTooltip": "无法筛留脚本字段", + "kbn.discover.docViews.table.unindexedFieldsCanNotBeSearchedTooltip": "无法搜索未索引字段", + "kbn.discover.docViews.json.codeEditorAriaLabel": "Elasticsearch 文档的只读 JSON 视图", + "kbn.discover.docViews.json.jsonTitle": "JSON", + "kbn.discover.docViews.table.fieldNamesBeginningWithUnderscoreUnsupportedAriaLabel": "警告", + "kbn.discover.docViews.table.noCachedMappingForThisFieldAriaLabel": "警告", + "kbn.discover.docViews.table.toggleFieldDetails": "切换字段详细信息", "kbn.discover.errorLoadingData": "加载数据时出错", "kbn.discover.fetchError.howToAddressErrorDescription": "您可以通过编辑 “{scriptedFields}” 选项卡下 “{managementLink}” 中的 “{fetchErrorScript}” 字段来解决此错误。", "kbn.discover.fetchError.managmentLinkText": "管理 > 索引模式", @@ -2515,25 +2534,6 @@ "kbn.advancedSettings.courier.batchSearchesText": "禁用时,仪表板面板将分别加载,用户离开时或更新查询时,\n 搜索请求将终止。启用时,仪表板面板将一起加载并加载所有数据,\n 搜索将不会终止。", "kbn.doc.couldNotFindDocumentsDescription": "无文档匹配该 ID。", "kbn.doc.somethingWentWrongDescription": "{indexName} 缺失。", - "kbnDocViews.table.fieldNamesBeginningWithUnderscoreUnsupportedTooltip": "不支持以 {underscoreSign} 开头的字段名称", - "kbnDocViews.table.filterForFieldPresentButtonAriaLabel": "筛留存在的字段", - "kbnDocViews.table.filterForFieldPresentButtonTooltip": "筛留存在的字段", - "kbnDocViews.table.filterForValueButtonAriaLabel": "筛留值", - "kbnDocViews.table.filterForValueButtonTooltip": "筛留值", - "kbnDocViews.table.filterOutValueButtonAriaLabel": "筛除值", - "kbnDocViews.table.filterOutValueButtonTooltip": "筛除值", - "kbnDocViews.table.noCachedMappingForThisFieldTooltip": "此字段没有任何已缓存映射。从“管理”>“索引模式”页面刷新字段列表", - "kbnDocViews.table.tableTitle": "表", - "kbnDocViews.table.toggleColumnInTableButtonAriaLabel": "在表中切换列", - "kbnDocViews.table.toggleColumnInTableButtonTooltip": "在表中切换列", - "kbnDocViews.table.unableToFilterForPresenceOfMetaFieldsTooltip": "无法筛留元数据字段", - "kbnDocViews.table.unableToFilterForPresenceOfScriptedFieldsTooltip": "无法筛留脚本字段", - "kbnDocViews.table.unindexedFieldsCanNotBeSearchedTooltip": "无法搜索未索引字段", - "kbnDocViews.json.codeEditorAriaLabel": "Elasticsearch 文档的只读 JSON 视图", - "kbnDocViews.json.jsonTitle": "JSON", - "kbnDocViews.table.fieldNamesBeginningWithUnderscoreUnsupportedAriaLabel": "警告", - "kbnDocViews.table.noCachedMappingForThisFieldAriaLabel": "警告", - "kbnDocViews.table.toggleFieldDetails": "切换字段详细信息", "kbnVislibVisTypes.area.areaDescription": "突出折线图下方的数量", "kbnVislibVisTypes.area.areaTitle": "面积图", "kbnVislibVisTypes.area.groupTitle": "拆分序列", @@ -12810,4 +12810,4 @@ "xpack.licensing.welcomeBanner.licenseIsExpiredDescription.updateYourLicenseLinkText": "更新您的许可", "xpack.licensing.welcomeBanner.licenseIsExpiredTitle": "您的{licenseType}许可已过期" } -} \ No newline at end of file +} From e817686572ff6b71d6ff76aa82b75bdd0d4f7b60 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 18 Dec 2019 11:55:28 +0100 Subject: [PATCH 2/5] inject chrome properly --- .../discover/doc_views/doc_views_helpers.tsx | 10 ++++++---- .../discover/doc_views/doc_views_registry.ts | 6 +++++- .../public/discover/helpers/build_services.ts | 2 +- .../core_plugins/kibana/public/discover/index.ts | 8 +++++++- .../kibana/public/discover/kibana_services.ts | 1 + .../kibana/public/discover/plugin.ts | 16 ++++++++-------- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/discover/doc_views/doc_views_helpers.tsx b/src/legacy/core_plugins/kibana/public/discover/doc_views/doc_views_helpers.tsx index 34619413d44f..a2543ece48b3 100644 --- a/src/legacy/core_plugins/kibana/public/discover/doc_views/doc_views_helpers.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/doc_views/doc_views_helpers.tsx @@ -19,7 +19,6 @@ import React from 'react'; import { render } from 'react-dom'; import angular, { ICompileService } from 'angular'; -import chrome from 'ui/chrome'; import { DocViewRenderProps, AngularScope, @@ -27,6 +26,7 @@ import { AngularDirective, } from './doc_views_types'; import { DocViewerError } from '../components/doc_viewer/doc_viewer_render_error'; +import { Chrome } from '../kibana_services'; /** * Compiles and injects the give angular template into the given dom node @@ -36,7 +36,8 @@ export async function injectAngularElement( domNode: Element, template: string, scopeProps: DocViewRenderProps, - Controller: AngularController + Controller: AngularController, + chrome: Chrome ): Promise<() => void> { const $injector = await chrome.dangerouslyGetActiveInjector(); const rootScope: AngularScope = $injector.get('$rootScope'); @@ -68,7 +69,7 @@ export async function injectAngularElement( * Converts a given legacy angular directive to a render function * for usage in a react component. Note that the rendering is async */ -export function convertDirectiveToRenderFn(directive: AngularDirective) { +export function convertDirectiveToRenderFn(directive: AngularDirective, chrome: Chrome) { return (domNode: Element, props: DocViewRenderProps) => { let rejected = false; @@ -76,7 +77,8 @@ export function convertDirectiveToRenderFn(directive: AngularDirective) { domNode, directive.template, props, - directive.controller + directive.controller, + chrome ); cleanupFnPromise.catch(e => { rejected = true; diff --git a/src/legacy/core_plugins/kibana/public/discover/doc_views/doc_views_registry.ts b/src/legacy/core_plugins/kibana/public/discover/doc_views/doc_views_registry.ts index 6f866ca23a34..fc2077a611fd 100644 --- a/src/legacy/core_plugins/kibana/public/discover/doc_views/doc_views_registry.ts +++ b/src/legacy/core_plugins/kibana/public/discover/doc_views/doc_views_registry.ts @@ -18,11 +18,15 @@ */ import { convertDirectiveToRenderFn } from './doc_views_helpers'; import { DocView, DocViewInput, ElasticSearchHit, DocViewInputFn } from './doc_views_types'; +import { Chrome } from '../kibana_services'; export { DocViewRenderProps, DocView, DocViewRenderFn } from './doc_views_types'; export class DocViewsRegistry { private docViews: DocView[] = []; + + constructor(private legacyChrome: Chrome) {} + /** * Extends and adds the given doc view to the registry array */ @@ -30,7 +34,7 @@ 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); + docView.render = convertDirectiveToRenderFn(docView.directive, this.legacyChrome); } if (typeof docView.shouldShow !== 'function') { docView.shouldShow = () => true; diff --git a/src/legacy/core_plugins/kibana/public/discover/helpers/build_services.ts b/src/legacy/core_plugins/kibana/public/discover/helpers/build_services.ts index b2978852e51a..c06004ebab36 100644 --- a/src/legacy/core_plugins/kibana/public/discover/helpers/build_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/helpers/build_services.ts @@ -59,7 +59,7 @@ export async function buildServices( core: CoreStart, plugins: DiscoverStartPlugins, docViewsRegistry: DocViewsRegistry -) { +): Promise { const services = { savedObjectsClient: core.savedObjects.client, indexPatterns: plugins.data.indexPatterns, diff --git a/src/legacy/core_plugins/kibana/public/discover/index.ts b/src/legacy/core_plugins/kibana/public/discover/index.ts index cbf041f2cbab..d905f2162656 100644 --- a/src/legacy/core_plugins/kibana/public/discover/index.ts +++ b/src/legacy/core_plugins/kibana/public/discover/index.ts @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +import chrome from 'ui/chrome'; import { PluginInitializer, PluginInitializerContext } from 'kibana/public'; import { npSetup, npStart } from 'ui/new_platform'; import { SavedObjectRegistryProvider } from 'ui/saved_objects'; @@ -28,7 +29,12 @@ export const plugin: PluginInitializer = () => { // Legacy compatiblity part - to be removed at cutover, replaced by a kibana.json file export const pluginInstance = plugin({} as PluginInitializerContext); -export const setup = pluginInstance.setup(npSetup.core, npSetup.plugins); +export const setup = pluginInstance.setup(npSetup.core, { + ...npSetup.plugins, + __LEGACY: { + chrome, + }, +}); export const start = pluginInstance.start(npStart.core, npStart.plugins); SavedObjectRegistryProvider.register((savedSearches: any) => { 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 53268b1c36ef..20501afa3ba4 100644 --- a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts @@ -89,3 +89,4 @@ export { } from '../../../../../plugins/data/public'; export { ElasticSearchHit } from './doc_views/doc_views_types'; export { Adapters } from 'ui/inspector/types'; +export { Chrome } from 'ui/chrome'; diff --git a/src/legacy/core_plugins/kibana/public/discover/plugin.ts b/src/legacy/core_plugins/kibana/public/discover/plugin.ts index 2c4071fbea89..588c8bec51f9 100644 --- a/src/legacy/core_plugins/kibana/public/discover/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/discover/plugin.ts @@ -25,7 +25,7 @@ import { registerFeature } from './helpers/register_feature'; import './kibana_services'; import { IEmbeddableStart, IEmbeddableSetup } from '../../../../../plugins/embeddable/public'; import { getInnerAngularModule, getInnerAngularModuleEmbeddable } from './get_inner_angular'; -import { setAngularModule, setServices } from './kibana_services'; +import { Chrome, setAngularModule, setServices } from './kibana_services'; import { NavigationPublicPluginStart as NavigationStart } from '../../../../../plugins/navigation/public'; import { EuiUtilsStart } from '../../../../../plugins/eui_utils/public'; import { buildServices } from './helpers/build_services'; @@ -49,6 +49,9 @@ export interface DiscoverSetupPlugins { uiActions: IUiActionsStart; embeddable: IEmbeddableSetup; kibana_legacy: KibanaLegacySetup; + __LEGACY: { + chrome: Chrome; + }; } export interface DiscoverStartPlugins { uiActions: IUiActionsStart; @@ -70,7 +73,7 @@ const embeddableAngularName = 'app/discoverEmbeddable'; export class DiscoverPlugin implements Plugin { private servicesInitialized: boolean = false; private innerAngularInitialized: boolean = false; - private readonly docViewsRegistry: DocViewsRegistry; + private docViewsRegistry: DocViewsRegistry | null = null; /** * why are those functions public? they are needed for some mocha tests * can be removed once all is Jest @@ -78,8 +81,8 @@ export class DiscoverPlugin implements Plugin { public initializeInnerAngular?: () => void; public initializeServices?: () => void; - constructor() { - this.docViewsRegistry = new DocViewsRegistry(); + setup(core: CoreSetup, plugins: DiscoverSetupPlugins): DiscoverSetup { + this.docViewsRegistry = new DocViewsRegistry(plugins.__LEGACY.chrome); this.docViewsRegistry.addDocView({ title: i18n.translate('kbn.discover.docViews.table.tableTitle', { defaultMessage: 'Table', @@ -94,9 +97,6 @@ export class DiscoverPlugin implements Plugin { order: 20, component: JsonCodeBlock, }); - } - - setup(core: CoreSetup, plugins: DiscoverSetupPlugins): DiscoverSetup { plugins.kibana_legacy.registerLegacyApp({ id: 'discover', title: 'Discover', @@ -140,7 +140,7 @@ export class DiscoverPlugin implements Plugin { if (this.servicesInitialized) { return; } - const services = await buildServices(core, plugins, this.docViewsRegistry); + const services = await buildServices(core, plugins, this.docViewsRegistry!); setServices(services); this.servicesInitialized = true; }; From 52faac2039d178093c32c646ce43b4a785df05b0 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Fri, 20 Dec 2019 14:27:09 +0100 Subject: [PATCH 3/5] remove wrong migration docs and improve types --- src/core/MIGRATION.md | 1 - src/legacy/core_plugins/kibana/public/discover/index.ts | 6 +++--- src/legacy/core_plugins/kibana/public/discover/plugin.ts | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/core/MIGRATION.md b/src/core/MIGRATION.md index b1af865effec..1c78de966c46 100644 --- a/src/core/MIGRATION.md +++ b/src/core/MIGRATION.md @@ -1175,7 +1175,6 @@ import { setup, start } from '../core_plugins/visualizations/public/legacy'; | `ui/registry/field_formats` | `data.fieldFormats` | | | `ui/registry/feature_catalogue` | `home.featureCatalogue.register` | Must add `home` as a dependency in your kibana.json. | | `ui/registry/vis_types` | `visualizations.types` | -- | -| `ui/registry/doc_views` | `discover.addDocView` | Currently shimmed in the old platform - use `import { setup } from '../kibana/public/discover'; setup.addDocView(...)` | | `ui/vis` | `visualizations.types` | -- | | `ui/share` | `share` | `showShareContextMenu` is now called `toggleShareContextMenu`, `ShareContextMenuExtensionsRegistryProvider` is now called `register` | | `ui/vis/vis_factory` | `visualizations.types` | -- | diff --git a/src/legacy/core_plugins/kibana/public/discover/index.ts b/src/legacy/core_plugins/kibana/public/discover/index.ts index 0234efd0a708..7a4cd877c8fc 100644 --- a/src/legacy/core_plugins/kibana/public/discover/index.ts +++ b/src/legacy/core_plugins/kibana/public/discover/index.ts @@ -17,13 +17,13 @@ * under the License. */ import chrome from 'ui/chrome'; -import { PluginInitializer, PluginInitializerContext } from 'kibana/public'; +import { PluginInitializerContext } from 'kibana/public'; import { npSetup, npStart } from 'ui/new_platform'; import { SavedObjectRegistryProvider } from 'ui/saved_objects'; -import { DiscoverPlugin, DiscoverSetup, DiscoverStart } from './plugin'; +import { DiscoverPlugin } from './plugin'; // Core will be looking for this when loading our plugin in the new platform -export const plugin: PluginInitializer = () => { +export const plugin = (context: PluginInitializerContext) => { return new DiscoverPlugin(); }; diff --git a/src/legacy/core_plugins/kibana/public/discover/plugin.ts b/src/legacy/core_plugins/kibana/public/discover/plugin.ts index 588c8bec51f9..4d6a7dc79f2b 100644 --- a/src/legacy/core_plugins/kibana/public/discover/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/discover/plugin.ts @@ -19,7 +19,7 @@ import { i18n } from '@kbn/i18n'; import { AppMountParameters, CoreSetup, CoreStart, Plugin } from 'kibana/public'; import angular from 'angular'; -import { IUiActionsStart } from 'src/plugins/ui_actions/public'; +import { IUiActionsSetup, IUiActionsStart } from 'src/plugins/ui_actions/public'; import { DataPublicPluginStart } from 'src/plugins/data/public'; import { registerFeature } from './helpers/register_feature'; import './kibana_services'; @@ -46,7 +46,7 @@ export interface DiscoverSetup { } export type DiscoverStart = void; export interface DiscoverSetupPlugins { - uiActions: IUiActionsStart; + uiActions: IUiActionsSetup; embeddable: IEmbeddableSetup; kibana_legacy: KibanaLegacySetup; __LEGACY: { From 0b553d73ce282033010a5249a124dc8fae728e03 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Mon, 30 Dec 2019 17:34:27 +0100 Subject: [PATCH 4/5] fix imports --- .../core_plugins/kibana/public/discover/kibana_services.ts | 1 + .../components/json_code_block/json_code_block.test.tsx | 2 +- .../public/discover/np_ready/components/table/table.test.tsx | 2 +- .../public/discover/np_ready/components/table/table_row.tsx | 2 +- .../np_ready/components/table/table_row_btn_filter_add.tsx | 2 +- .../np_ready/components/table/table_row_btn_filter_exists.tsx | 2 +- .../np_ready/components/table/table_row_btn_filter_remove.tsx | 2 +- .../np_ready/components/table/table_row_btn_toggle_column.tsx | 2 +- 8 files changed, 8 insertions(+), 7 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 8bb211e3edd9..1585b2e86509 100644 --- a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts @@ -100,3 +100,4 @@ export { ElasticSearchHit } from './np_ready/doc_views/doc_views_types'; export { Adapters } from 'ui/inspector/types'; export { Chrome, IInjector } from 'ui/chrome'; export { registerTimefilterWithGlobalStateFactory } from 'ui/timefilter/setup_router'; +export { FieldName } from 'ui/directives/field_name/field_name'; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/json_code_block/json_code_block.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/json_code_block/json_code_block.test.tsx index 776971e57091..9cab7974c9eb 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/json_code_block/json_code_block.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/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 'ui/index_patterns'; +import { IndexPattern } from '../../../kibana_services'; it('returns the `JsonCodeEditor` component', () => { const props = { diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table.test.tsx index 7a645a6ae4a8..a87b78aae643 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table.test.tsx @@ -18,7 +18,7 @@ */ import React from 'react'; import { mount } from 'enzyme'; -import { IndexPattern } from 'ui/index_patterns'; +import { IndexPattern } from '../../../kibana_services'; // @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; import { flattenHitWrapper } from '../../../../../../data/public'; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row.tsx index 6151acdc2068..ffcb20f07673 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row.tsx @@ -18,7 +18,7 @@ */ import classNames from 'classnames'; import React, { ReactNode } from 'react'; -import { FieldName } from 'ui/directives/field_name/field_name'; +import { FieldName } from '../../../kibana_services'; import { FieldMapping, DocViewFilterFn } from '../../doc_views/doc_views_types'; import { DocViewTableRowBtnFilterAdd } from './table_row_btn_filter_add'; import { DocViewTableRowBtnFilterRemove } from './table_row_btn_filter_remove'; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_add.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_add.tsx index b286b0ed3e5d..8e2668e26cf0 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_add.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_add.tsx @@ -17,7 +17,7 @@ * under the License. */ import React from 'react'; -import { FormattedMessage } from '@kbn/i18n/target/types/react'; +import { FormattedMessage } from '@kbn/i18n/react'; import { EuiToolTip, EuiButtonIcon } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_exists.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_exists.tsx index 6d653e6ae06c..ba1cb4a4db4c 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_exists.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_exists.tsx @@ -17,7 +17,7 @@ * under the License. */ import React from 'react'; -import { FormattedMessage } from '@kbn/i18n/target/types/react'; +import { FormattedMessage } from '@kbn/i18n/react'; import { EuiToolTip, EuiButtonIcon } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_remove.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_remove.tsx index a58b11f4834b..78538f337ba9 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_remove.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_filter_remove.tsx @@ -17,7 +17,7 @@ * under the License. */ import React from 'react'; -import { FormattedMessage } from '@kbn/i18n/target/types/react'; +import { FormattedMessage } from '@kbn/i18n/react'; import { EuiToolTip, EuiButtonIcon } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_toggle_column.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_toggle_column.tsx index 70f09ac7ed5b..7a8fca529ec5 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_toggle_column.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row_btn_toggle_column.tsx @@ -17,7 +17,7 @@ * under the License. */ import React from 'react'; -import { FormattedMessage } from '@kbn/i18n/target/types/react'; +import { FormattedMessage } from '@kbn/i18n/react'; import { EuiToolTip, EuiButtonIcon } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; From d56a8d8b2025cbd7510ab392a40209790515d116 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Tue, 31 Dec 2019 15:08:40 +0100 Subject: [PATCH 5/5] fix unit test --- .../components/doc_viewer/doc_viewer.test.tsx | 19 ++++++++++++------- .../np_ready/doc_views/doc_views_registry.ts | 2 -- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.test.tsx index b2ed5b287833..15f0f40700ab 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/doc_viewer/doc_viewer.test.tsx @@ -21,18 +21,23 @@ import { mount, shallow } from 'enzyme'; import { DocViewer } from './doc_viewer'; // @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; -import { DocViewRenderProps } from '../../doc_views/doc_views_registry'; import { getServices } from '../../../kibana_services'; +import { DocViewRenderProps } from '../../doc_views/doc_views_types'; jest.mock('../../../kibana_services', () => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const { DocViewsRegistry } = require('../../doc_views/doc_views_registry'); - let registry = new DocViewsRegistry(); + let registry: any[] = []; return { getServices: () => ({ - docViewsRegistry: registry, + docViewsRegistry: { + addDocView(view: any) { + registry.push(view); + }, + getDocViewsSorted() { + return registry; + }, + }, resetRegistry: () => { - registry = new DocViewsRegistry(); + registry = []; }, }), formatMsg: (x: any) => String(x), @@ -47,8 +52,8 @@ beforeEach(() => { test('Render with 3 different tabs', () => { const registry = getServices().docViewsRegistry; - registry.addDocView({ order: 20, title: 'React component', component: () =>
test
}); 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' }); const renderProps = { hit: {} } as DocViewRenderProps; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_registry.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_registry.ts index b400944456bf..1952ec3af2f6 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_registry.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_registry.ts @@ -20,8 +20,6 @@ import { convertDirectiveToRenderFn } from './doc_views_helpers'; import { DocView, DocViewInput, ElasticSearchHit, DocViewInputFn } from './doc_views_types'; import { Chrome } from '../../kibana_services'; -export { DocViewRenderProps, DocView, DocViewRenderFn } from './doc_views_types'; - export class DocViewsRegistry { private docViews: DocView[] = [];