From c67b60e250af13f003dd06bc988c95a83c71c0ac Mon Sep 17 00:00:00 2001 From: Dzmitry Tamashevich Date: Thu, 25 Nov 2021 17:26:47 +0300 Subject: [PATCH 1/6] [Discover] close expanded document sidebar on index pattern change --- .../main/components/layout/discover_documents.tsx | 2 +- .../application/main/components/layout/discover_layout.tsx | 5 +++-- .../public/application/main/components/layout/types.ts | 3 +++ .../discover/public/application/main/discover_main_app.tsx | 7 ++++++- .../public/application/main/utils/use_discover_state.ts | 6 +++++- .../public/components/discover_grid/discover_grid.tsx | 2 +- .../components/discover_grid/discover_grid_context.tsx | 4 ++-- 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx index 154f83796490b..7af7192dafbc4 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx @@ -54,7 +54,7 @@ function DiscoverDocumentsComponent({ onAddFilter: DocViewFilterFn; savedSearch: SavedSearch; services: DiscoverServices; - setExpandedDoc: (doc: ElasticSearchHit | undefined) => void; + setExpandedDoc: (doc?: ElasticSearchHit) => void; state: AppState; stateContainer: GetStateReturn; }) { diff --git a/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx b/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx index 39d8268de2d0b..4b647867cf64a 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_layout.tsx @@ -29,7 +29,7 @@ import { DiscoverLayoutProps } from './types'; import { SEARCH_FIELDS_FROM_SOURCE, SHOW_FIELD_STATISTICS } from '../../../../../common'; import { popularizeField } from '../../../../utils/popularize_field'; import { DiscoverTopNav } from '../top_nav/discover_topnav'; -import { DocViewFilterFn, ElasticSearchHit } from '../../../../services/doc_views/doc_views_types'; +import { DocViewFilterFn } from '../../../../services/doc_views/doc_views_types'; import { DiscoverChart } from '../chart'; import { getResultState } from '../../utils/get_result_state'; import { InspectorSession } from '../../../../../../inspector/public'; @@ -62,9 +62,11 @@ export function DiscoverLayout({ indexPattern, indexPatternList, inspectorAdapters, + expandedDoc, navigateTo, onChangeIndexPattern, onUpdateQuery, + setExpandedDoc, savedSearchRefetch$, resetSavedSearch, savedSearchData$, @@ -86,7 +88,6 @@ export function DiscoverLayout({ spaces, } = services; const { main$, charts$, totalHits$ } = savedSearchData$; - const [expandedDoc, setExpandedDoc] = useState(undefined); const [inspectorSession, setInspectorSession] = useState(undefined); const viewMode = useMemo(() => { diff --git a/src/plugins/discover/public/application/main/components/layout/types.ts b/src/plugins/discover/public/application/main/components/layout/types.ts index 1ed34978416fa..69f41d65fde75 100644 --- a/src/plugins/discover/public/application/main/components/layout/types.ts +++ b/src/plugins/discover/public/application/main/components/layout/types.ts @@ -6,6 +6,7 @@ * Side Public License, v 1. */ +import { ElasticSearchHit } from 'src/plugins/discover/public/services/doc_views/doc_views_types'; import { IndexPattern, IndexPatternAttributes, @@ -28,6 +29,8 @@ export interface DiscoverLayoutProps { onChangeIndexPattern: (id: string) => void; onUpdateQuery: (payload: { dateRange: TimeRange; query?: Query }, isUpdate?: boolean) => void; resetSavedSearch: () => void; + expandedDoc?: ElasticSearchHit; + setExpandedDoc: (doc?: ElasticSearchHit) => void; savedSearch: SavedSearch; savedSearchData$: SavedSearchData; savedSearchRefetch$: DataRefetch$; diff --git a/src/plugins/discover/public/application/main/discover_main_app.tsx b/src/plugins/discover/public/application/main/discover_main_app.tsx index ea3f852a5290a..fcb34b32bc380 100644 --- a/src/plugins/discover/public/application/main/discover_main_app.tsx +++ b/src/plugins/discover/public/application/main/discover_main_app.tsx @@ -5,7 +5,7 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import React, { useCallback, useEffect } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import { History } from 'history'; import { DiscoverLayout } from './components/layout'; import { setBreadcrumbsTitle } from '../../utils/breadcrumbs'; @@ -15,6 +15,7 @@ import { useUrl } from './utils/use_url'; import { IndexPatternAttributes, SavedObject } from '../../../../data/common'; import { DiscoverServices } from '../../build_services'; import { SavedSearch } from '../../services/saved_searches'; +import { ElasticSearchHit } from '../../services/doc_views/doc_views_types'; const DiscoverLayoutMemoized = React.memo(DiscoverLayout); @@ -40,6 +41,7 @@ export interface DiscoverMainProps { export function DiscoverMainApp(props: DiscoverMainProps) { const { savedSearch, services, history, indexPatternList } = props; const { chrome, docLinks, uiSettings: config, data } = services; + const [expandedDoc, setExpandedDoc] = useState(undefined); const navigateTo = useCallback( (path: string) => { history.push(path); @@ -65,6 +67,7 @@ export function DiscoverMainApp(props: DiscoverMainProps) { services, history, savedSearch, + setExpandedDoc, }); /** @@ -100,9 +103,11 @@ export function DiscoverMainApp(props: DiscoverMainProps) { indexPattern={indexPattern} indexPatternList={indexPatternList} inspectorAdapters={inspectorAdapters} + expandedDoc={expandedDoc} onChangeIndexPattern={onChangeIndexPattern} onUpdateQuery={onUpdateQuery} resetSavedSearch={resetCurrentSavedSearch} + setExpandedDoc={setExpandedDoc} navigateTo={navigateTo} savedSearch={savedSearch} savedSearchData$={data$} diff --git a/src/plugins/discover/public/application/main/utils/use_discover_state.ts b/src/plugins/discover/public/application/main/utils/use_discover_state.ts index b70bcded4c608..34c32b8a2b0de 100644 --- a/src/plugins/discover/public/application/main/utils/use_discover_state.ts +++ b/src/plugins/discover/public/application/main/utils/use_discover_state.ts @@ -24,15 +24,18 @@ import { useSearchSession } from './use_search_session'; import { FetchStatus } from '../../types'; import { getSwitchIndexPatternAppState } from './get_switch_index_pattern_app_state'; import { SortPairArr } from '../../../components/doc_table/lib/get_sort'; +import { ElasticSearchHit } from '../../../services/doc_views/doc_views_types'; export function useDiscoverState({ services, history, savedSearch, + setExpandedDoc, }: { services: DiscoverServices; savedSearch: SavedSearch; history: History; + setExpandedDoc: (doc?: ElasticSearchHit) => void; }) { const { uiSettings: config, data, filterManager, indexPatterns, storage } = services; const useNewFieldsApi = useMemo(() => !config.get(SEARCH_FIELDS_FROM_SOURCE), [config]); @@ -186,8 +189,9 @@ export function useDiscoverState({ ); stateContainer.setAppState(nextAppState); } + setExpandedDoc(undefined); }, - [config, indexPattern, indexPatterns, state.columns, state.sort, stateContainer] + [config, indexPattern, indexPatterns, setExpandedDoc, state.columns, state.sort, stateContainer] ); /** * Function triggered when the user changes the query in the search bar diff --git a/src/plugins/discover/public/components/discover_grid/discover_grid.tsx b/src/plugins/discover/public/components/discover_grid/discover_grid.tsx index f0e0513c7748c..2a03732d46a9e 100644 --- a/src/plugins/discover/public/components/discover_grid/discover_grid.tsx +++ b/src/plugins/discover/public/components/discover_grid/discover_grid.tsx @@ -111,7 +111,7 @@ export interface DiscoverGridProps { /** * Function to set the expanded document, which is displayed in a flyout */ - setExpandedDoc: (doc: ElasticSearchHit | undefined) => void; + setExpandedDoc: (doc?: ElasticSearchHit) => void; /** * Grid display settings persisted in Elasticsearch (e.g. column width) */ diff --git a/src/plugins/discover/public/components/discover_grid/discover_grid_context.tsx b/src/plugins/discover/public/components/discover_grid/discover_grid_context.tsx index 49b72ef126a76..550156be760db 100644 --- a/src/plugins/discover/public/components/discover_grid/discover_grid_context.tsx +++ b/src/plugins/discover/public/components/discover_grid/discover_grid_context.tsx @@ -11,8 +11,8 @@ import type { IndexPattern } from 'src/plugins/data/common'; import { DocViewFilterFn, ElasticSearchHit } from '../../services/doc_views/doc_views_types'; export interface GridContext { - expanded: ElasticSearchHit | undefined; - setExpanded: (hit: ElasticSearchHit | undefined) => void; + expanded?: ElasticSearchHit; + setExpanded: (hit?: ElasticSearchHit) => void; rows: ElasticSearchHit[]; onFilter: DocViewFilterFn; indexPattern: IndexPattern; From 5148207bda0de5b43395bfbe598dc064d5fa7891 Mon Sep 17 00:00:00 2001 From: Dzmitry Tamashevich Date: Tue, 30 Nov 2021 11:43:08 +0300 Subject: [PATCH 2/6] [Discover] fix unit test --- .../application/main/components/layout/discover_layout.test.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/discover/public/application/main/components/layout/discover_layout.test.tsx b/src/plugins/discover/public/application/main/components/layout/discover_layout.test.tsx index c222e4038f517..dfc56ae98210e 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_layout.test.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_layout.test.tsx @@ -150,6 +150,7 @@ function getProps(indexPattern: IndexPattern, wasSidebarClosed?: boolean): Disco services, state: { columns: [] }, stateContainer: {} as GetStateReturn, + setExpandedDoc: jest.fn(), }; } From d3b6c4cbe1ecb1391821b602bd4996b70a0ae176 Mon Sep 17 00:00:00 2001 From: Dzmitry Tamashevich Date: Tue, 30 Nov 2021 12:41:34 +0300 Subject: [PATCH 3/6] [Discover] fix use_discover_state unit test --- .../public/application/main/utils/use_discover_state.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/plugins/discover/public/application/main/utils/use_discover_state.test.ts b/src/plugins/discover/public/application/main/utils/use_discover_state.test.ts index 78f742b9f7c9b..bac6d085acf05 100644 --- a/src/plugins/discover/public/application/main/utils/use_discover_state.test.ts +++ b/src/plugins/discover/public/application/main/utils/use_discover_state.test.ts @@ -37,6 +37,7 @@ describe('test useDiscoverState', () => { services: discoverServiceMock, history, savedSearch: savedSearchMock, + setExpandedDoc: jest.fn(), }); }); expect(result.current.state.index).toBe(indexPatternMock.id); @@ -53,6 +54,7 @@ describe('test useDiscoverState', () => { services: discoverServiceMock, history, savedSearch: savedSearchMock, + setExpandedDoc: jest.fn(), }); }); await act(async () => { @@ -69,6 +71,7 @@ describe('test useDiscoverState', () => { services: discoverServiceMock, history, savedSearch: savedSearchMock, + setExpandedDoc: jest.fn(), }); }); From f4bb3089883888c8528044e7cc94f63c098f67c9 Mon Sep 17 00:00:00 2001 From: Dzmitry Tamashevich Date: Tue, 30 Nov 2021 13:27:43 +0300 Subject: [PATCH 4/6] [Discover] fix linting --- .../public/application/main/utils/use_saved_search.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/discover/public/application/main/utils/use_saved_search.test.ts b/src/plugins/discover/public/application/main/utils/use_saved_search.test.ts index b3ed7ab854190..2788d63fdf983 100644 --- a/src/plugins/discover/public/application/main/utils/use_saved_search.test.ts +++ b/src/plugins/discover/public/application/main/utils/use_saved_search.test.ts @@ -59,6 +59,7 @@ describe('test useSavedSearch', () => { services: discoverServiceMock, history, savedSearch: savedSearchMock, + setExpandedDoc: jest.fn(), }); }); @@ -100,6 +101,7 @@ describe('test useSavedSearch', () => { services: discoverServiceMock, history, savedSearch: savedSearchMock, + setExpandedDoc: jest.fn(), }); }); From 8b66ea61e869a1bd66ace268f984839d19883594 Mon Sep 17 00:00:00 2001 From: Dzmitry Tamashevich Date: Wed, 1 Dec 2021 15:35:56 +0300 Subject: [PATCH 5/6] [Discover] apply suggestions --- .../application/context/context_app_content.tsx | 3 ++- .../components/layout/discover_documents.test.tsx | 2 +- .../main/components/layout/discover_documents.tsx | 3 ++- .../main/components/layout/discover_layout.test.tsx | 2 +- .../application/main/components/layout/types.ts | 2 +- .../main/components/sidebar/discover_sidebar.test.tsx | 2 +- .../sidebar/discover_sidebar_responsive.test.tsx | 2 +- .../main/components/sidebar/lib/get_details.ts | 2 +- .../public/application/main/discover_main_app.tsx | 2 +- .../application/main/utils/calc_field_counts.test.ts | 2 +- .../application/main/utils/calc_field_counts.ts | 2 +- .../application/main/utils/use_discover_state.ts | 2 +- .../public/application/main/utils/use_saved_search.ts | 2 +- .../components/discover_grid/discover_grid.test.tsx | 2 +- .../public/components/discover_grid/discover_grid.tsx | 3 ++- .../discover_grid/discover_grid_context.tsx | 3 ++- .../discover_grid_document_selection.tsx | 2 +- .../components/discover_grid/discover_grid_flyout.tsx | 3 ++- .../discover_grid/get_render_cell_value.test.tsx | 2 +- .../discover_grid/get_render_cell_value.tsx | 2 +- .../components/doc_table/components/table_row.tsx | 3 ++- .../public/embeddable/saved_search_embeddable.tsx | 2 +- .../discover/public/embeddable/saved_search_grid.tsx | 2 +- .../components/doc_viewer/doc_viewer_tab.test.tsx | 2 +- .../components/doc_viewer_table/table.test.tsx | 2 +- .../doc_views/components/doc_viewer_table/table.tsx | 3 ++- .../public/services/doc_views/doc_views_registry.ts | 3 ++- .../public/services/doc_views/doc_views_types.ts | 5 +---- src/plugins/discover/public/types.ts | 11 +++++++++++ .../discover/public/utils/use_es_doc_search.ts | 2 +- 30 files changed, 48 insertions(+), 32 deletions(-) create mode 100644 src/plugins/discover/public/types.ts diff --git a/src/plugins/discover/public/application/context/context_app_content.tsx b/src/plugins/discover/public/application/context/context_app_content.tsx index f498c6f0a244d..45bc3df77bd22 100644 --- a/src/plugins/discover/public/application/context/context_app_content.tsx +++ b/src/plugins/discover/public/application/context/context_app_content.tsx @@ -15,7 +15,7 @@ import { SortDirection } from '../../../../data/public'; import { LoadingStatus } from './services/context_query_state'; import { ActionBar } from './components/action_bar/action_bar'; import { DiscoverGrid } from '../../components/discover_grid/discover_grid'; -import { DocViewFilterFn, ElasticSearchHit } from '../../services/doc_views/doc_views_types'; +import { DocViewFilterFn } from '../../services/doc_views/doc_views_types'; import { AppState } from './services/context_state'; import { SurrDocType } from './services/context'; import { DiscoverServices } from '../../build_services'; @@ -23,6 +23,7 @@ import { MAX_CONTEXT_SIZE, MIN_CONTEXT_SIZE } from './services/constants'; import { DocTableContext } from '../../components/doc_table/doc_table_context'; import { EsHitRecordList } from '../types'; import { SortPairArr } from '../../components/doc_table/lib/get_sort'; +import { ElasticSearchHit } from '../../types'; export interface ContextAppContentProps { columns: string[]; diff --git a/src/plugins/discover/public/application/main/components/layout/discover_documents.test.tsx b/src/plugins/discover/public/application/main/components/layout/discover_documents.test.tsx index 829d88bbafd08..45c064d06c51f 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_documents.test.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_documents.test.tsx @@ -17,8 +17,8 @@ import { DataDocuments$ } from '../../utils/use_saved_search'; import { discoverServiceMock } from '../../../../__mocks__/services'; import { FetchStatus } from '../../../types'; import { DiscoverDocuments } from './discover_documents'; -import { ElasticSearchHit } from '../../../../services/doc_views/doc_views_types'; import { indexPatternMock } from '../../../../__mocks__/index_pattern'; +import { ElasticSearchHit } from 'src/plugins/discover/public/types'; jest.mock('../../../../kibana_services', () => ({ ...jest.requireActual('../../../../kibana_services'), diff --git a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx index 7af7192dafbc4..ae0f5ad670ce9 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx @@ -14,7 +14,7 @@ import { EuiScreenReaderOnly, } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; -import { DocViewFilterFn, ElasticSearchHit } from '../../../../services/doc_views/doc_views_types'; +import { DocViewFilterFn } from '../../../../services/doc_views/doc_views_types'; import { DiscoverGrid } from '../../../../components/discover_grid/discover_grid'; import { FetchStatus } from '../../../types'; import { @@ -32,6 +32,7 @@ import { AppState, GetStateReturn } from '../../services/discover_state'; import { useDataState } from '../../utils/use_data_state'; import { DocTableInfinite } from '../../../../components/doc_table/doc_table_infinite'; import { SortPairArr } from '../../../../components/doc_table/lib/get_sort'; +import { ElasticSearchHit } from '../../../../types'; const DocTableInfiniteMemoized = React.memo(DocTableInfinite); const DataGridMemoized = React.memo(DiscoverGrid); diff --git a/src/plugins/discover/public/application/main/components/layout/discover_layout.test.tsx b/src/plugins/discover/public/application/main/components/layout/discover_layout.test.tsx index dfc56ae98210e..77eeb88904100 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_layout.test.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_layout.test.tsx @@ -28,10 +28,10 @@ import { } from '../../utils/use_saved_search'; import { discoverServiceMock } from '../../../../__mocks__/services'; import { FetchStatus } from '../../../types'; -import { ElasticSearchHit } from '../../../../services/doc_views/doc_views_types'; import { RequestAdapter } from '../../../../../../inspector'; import { Chart } from '../chart/point_series'; import { DiscoverSidebar } from '../sidebar/discover_sidebar'; +import { ElasticSearchHit } from '../../../../types'; jest.mock('../../../../kibana_services', () => ({ ...jest.requireActual('../../../../kibana_services'), diff --git a/src/plugins/discover/public/application/main/components/layout/types.ts b/src/plugins/discover/public/application/main/components/layout/types.ts index 69f41d65fde75..7d0f747b9bd5a 100644 --- a/src/plugins/discover/public/application/main/components/layout/types.ts +++ b/src/plugins/discover/public/application/main/components/layout/types.ts @@ -6,7 +6,6 @@ * Side Public License, v 1. */ -import { ElasticSearchHit } from 'src/plugins/discover/public/services/doc_views/doc_views_types'; import { IndexPattern, IndexPatternAttributes, @@ -20,6 +19,7 @@ import { DataRefetch$, SavedSearchData } from '../../utils/use_saved_search'; import { DiscoverServices } from '../../../../build_services'; import { SavedSearch } from '../../../../services/saved_searches'; import { RequestAdapter } from '../../../../../../inspector'; +import { ElasticSearchHit } from '../../../../types'; export interface DiscoverLayoutProps { indexPattern: IndexPattern; diff --git a/src/plugins/discover/public/application/main/components/sidebar/discover_sidebar.test.tsx b/src/plugins/discover/public/application/main/components/sidebar/discover_sidebar.test.tsx index 9dd7ef19ffc07..a4d7107a7f15c 100644 --- a/src/plugins/discover/public/application/main/components/sidebar/discover_sidebar.test.tsx +++ b/src/plugins/discover/public/application/main/components/sidebar/discover_sidebar.test.tsx @@ -19,10 +19,10 @@ import { flattenHit, IndexPatternAttributes } from '../../../../../../data/commo import { SavedObject } from '../../../../../../../core/types'; import { getDefaultFieldFilter } from './lib/field_filter'; import { DiscoverSidebarComponent as DiscoverSidebar } from './discover_sidebar'; -import { ElasticSearchHit } from '../../../../services/doc_views/doc_views_types'; import { discoverServiceMock as mockDiscoverServices } from '../../../../__mocks__/services'; import { stubLogstashIndexPattern } from '../../../../../../data/common/stubs'; import { VIEW_MODE } from '../../../../components/view_mode_toggle'; +import { ElasticSearchHit } from '../../../../types'; jest.mock('../../../../kibana_services', () => ({ getServices: () => mockDiscoverServices, diff --git a/src/plugins/discover/public/application/main/components/sidebar/discover_sidebar_responsive.test.tsx b/src/plugins/discover/public/application/main/components/sidebar/discover_sidebar_responsive.test.tsx index b412cd69c82af..c65d0b0a4ec2c 100644 --- a/src/plugins/discover/public/application/main/components/sidebar/discover_sidebar_responsive.test.tsx +++ b/src/plugins/discover/public/application/main/components/sidebar/discover_sidebar_responsive.test.tsx @@ -22,11 +22,11 @@ import { DiscoverSidebarResponsiveProps, } from './discover_sidebar_responsive'; import { DiscoverServices } from '../../../../build_services'; -import { ElasticSearchHit } from '../../../../services/doc_views/doc_views_types'; import { FetchStatus } from '../../../types'; import { DataDocuments$ } from '../../utils/use_saved_search'; import { stubLogstashIndexPattern } from '../../../../../../data/common/stubs'; import { VIEW_MODE } from '../../../../components/view_mode_toggle'; +import { ElasticSearchHit } from '../../../../types'; const mockServices = { history: () => ({ diff --git a/src/plugins/discover/public/application/main/components/sidebar/lib/get_details.ts b/src/plugins/discover/public/application/main/components/sidebar/lib/get_details.ts index b5beebf6fb8d4..0715c7377da7d 100644 --- a/src/plugins/discover/public/application/main/components/sidebar/lib/get_details.ts +++ b/src/plugins/discover/public/application/main/components/sidebar/lib/get_details.ts @@ -9,7 +9,7 @@ // @ts-expect-error import { fieldCalculator } from './field_calculator'; import { IndexPattern, IndexPatternField } from '../../../../../../../data/public'; -import { ElasticSearchHit } from '../../../../../services/doc_views/doc_views_types'; +import { ElasticSearchHit } from '../../../../../types'; export function getDetails( field: IndexPatternField, diff --git a/src/plugins/discover/public/application/main/discover_main_app.tsx b/src/plugins/discover/public/application/main/discover_main_app.tsx index fcb34b32bc380..1ef6641e9bc72 100644 --- a/src/plugins/discover/public/application/main/discover_main_app.tsx +++ b/src/plugins/discover/public/application/main/discover_main_app.tsx @@ -15,7 +15,7 @@ import { useUrl } from './utils/use_url'; import { IndexPatternAttributes, SavedObject } from '../../../../data/common'; import { DiscoverServices } from '../../build_services'; import { SavedSearch } from '../../services/saved_searches'; -import { ElasticSearchHit } from '../../services/doc_views/doc_views_types'; +import { ElasticSearchHit } from '../../types'; const DiscoverLayoutMemoized = React.memo(DiscoverLayout); diff --git a/src/plugins/discover/public/application/main/utils/calc_field_counts.test.ts b/src/plugins/discover/public/application/main/utils/calc_field_counts.test.ts index 9d198947e06c7..28d814b871104 100644 --- a/src/plugins/discover/public/application/main/utils/calc_field_counts.test.ts +++ b/src/plugins/discover/public/application/main/utils/calc_field_counts.test.ts @@ -8,7 +8,7 @@ import { calcFieldCounts } from './calc_field_counts'; import { indexPatternMock } from '../../../__mocks__/index_pattern'; -import { ElasticSearchHit } from '../../../services/doc_views/doc_views_types'; +import { ElasticSearchHit } from '../../../types'; describe('calcFieldCounts', () => { test('returns valid field count data', async () => { diff --git a/src/plugins/discover/public/application/main/utils/calc_field_counts.ts b/src/plugins/discover/public/application/main/utils/calc_field_counts.ts index 08d1a2639fa0b..9a7f68550d840 100644 --- a/src/plugins/discover/public/application/main/utils/calc_field_counts.ts +++ b/src/plugins/discover/public/application/main/utils/calc_field_counts.ts @@ -7,7 +7,7 @@ */ import { flattenHit, IndexPattern } from '../../../../../data/common'; -import { ElasticSearchHit } from '../../../services/doc_views/doc_views_types'; +import { ElasticSearchHit } from '../../../types'; /** * This function is recording stats of the available fields, for usage in sidebar and sharing diff --git a/src/plugins/discover/public/application/main/utils/use_discover_state.ts b/src/plugins/discover/public/application/main/utils/use_discover_state.ts index 34c32b8a2b0de..a4ef9382b4995 100644 --- a/src/plugins/discover/public/application/main/utils/use_discover_state.ts +++ b/src/plugins/discover/public/application/main/utils/use_discover_state.ts @@ -24,7 +24,7 @@ import { useSearchSession } from './use_search_session'; import { FetchStatus } from '../../types'; import { getSwitchIndexPatternAppState } from './get_switch_index_pattern_app_state'; import { SortPairArr } from '../../../components/doc_table/lib/get_sort'; -import { ElasticSearchHit } from '../../../services/doc_views/doc_views_types'; +import { ElasticSearchHit } from '../../../types'; export function useDiscoverState({ services, diff --git a/src/plugins/discover/public/application/main/utils/use_saved_search.ts b/src/plugins/discover/public/application/main/utils/use_saved_search.ts index bfd6f1daa4bc0..0f4b9058316a0 100644 --- a/src/plugins/discover/public/application/main/utils/use_saved_search.ts +++ b/src/plugins/discover/public/application/main/utils/use_saved_search.ts @@ -11,7 +11,6 @@ import { DiscoverServices } from '../../../build_services'; import { DiscoverSearchSessionManager } from '../services/discover_search_session'; import { ISearchSource } from '../../../../../data/common'; import { GetStateReturn } from '../services/discover_state'; -import { ElasticSearchHit } from '../../../services/doc_views/doc_views_types'; import { RequestAdapter } from '../../../../../inspector/public'; import type { AutoRefreshDoneFn } from '../../../../../data/public'; import { validateTimeRange } from './validate_time_range'; @@ -23,6 +22,7 @@ import { fetchAll } from './fetch_all'; import { useBehaviorSubject } from './use_behavior_subject'; import { sendResetMsg } from './use_saved_search_messages'; import { getFetch$ } from './get_fetch_observable'; +import { ElasticSearchHit } from '../../../types'; export interface SavedSearchData { main$: DataMain$; diff --git a/src/plugins/discover/public/components/discover_grid/discover_grid.test.tsx b/src/plugins/discover/public/components/discover_grid/discover_grid.test.tsx index 4a0e472f17455..d1a1f2dcdbe8a 100644 --- a/src/plugins/discover/public/components/discover_grid/discover_grid.test.tsx +++ b/src/plugins/discover/public/components/discover_grid/discover_grid.test.tsx @@ -16,8 +16,8 @@ import { mountWithIntl } from '@kbn/test/jest'; import { DiscoverGrid, DiscoverGridProps } from './discover_grid'; import { uiSettingsMock } from '../../__mocks__/ui_settings'; import { DiscoverServices } from '../../build_services'; -import { ElasticSearchHit } from '../../services/doc_views/doc_views_types'; import { getDocId } from './discover_grid_document_selection'; +import { ElasticSearchHit } from '../../types'; jest.mock('../../kibana_services', () => ({ ...jest.requireActual('../../kibana_services'), diff --git a/src/plugins/discover/public/components/discover_grid/discover_grid.tsx b/src/plugins/discover/public/components/discover_grid/discover_grid.tsx index 2a03732d46a9e..815a9aeefe77e 100644 --- a/src/plugins/discover/public/components/discover_grid/discover_grid.tsx +++ b/src/plugins/discover/public/components/discover_grid/discover_grid.tsx @@ -22,7 +22,7 @@ import { EuiIcon, } from '@elastic/eui'; import { flattenHit, IndexPattern } from '../../../../data/common'; -import { DocViewFilterFn, ElasticSearchHit } from '../../services/doc_views/doc_views_types'; +import { DocViewFilterFn } from '../../services/doc_views/doc_views_types'; import { getSchemaDetectors } from './discover_grid_schema'; import { DiscoverGridFlyout } from './discover_grid_flyout'; import { DiscoverGridContext } from './discover_grid_context'; @@ -44,6 +44,7 @@ import { import { DiscoverGridDocumentToolbarBtn, getDocId } from './discover_grid_document_selection'; import { SortPairArr } from '../doc_table/lib/get_sort'; import { getFieldsToShow } from '../../utils/get_fields_to_show'; +import { ElasticSearchHit } from '../../types'; interface SortObj { id: string; diff --git a/src/plugins/discover/public/components/discover_grid/discover_grid_context.tsx b/src/plugins/discover/public/components/discover_grid/discover_grid_context.tsx index 550156be760db..3bf80872b0685 100644 --- a/src/plugins/discover/public/components/discover_grid/discover_grid_context.tsx +++ b/src/plugins/discover/public/components/discover_grid/discover_grid_context.tsx @@ -8,7 +8,8 @@ import React from 'react'; import type { IndexPattern } from 'src/plugins/data/common'; -import { DocViewFilterFn, ElasticSearchHit } from '../../services/doc_views/doc_views_types'; +import { DocViewFilterFn } from '../../services/doc_views/doc_views_types'; +import { ElasticSearchHit } from '../../types'; export interface GridContext { expanded?: ElasticSearchHit; diff --git a/src/plugins/discover/public/components/discover_grid/discover_grid_document_selection.tsx b/src/plugins/discover/public/components/discover_grid/discover_grid_document_selection.tsx index c517d3a65b6b9..6fb614327d2af 100644 --- a/src/plugins/discover/public/components/discover_grid/discover_grid_document_selection.tsx +++ b/src/plugins/discover/public/components/discover_grid/discover_grid_document_selection.tsx @@ -21,8 +21,8 @@ import { euiLightVars as themeLight, euiDarkVars as themeDark, } from '@kbn/ui-shared-deps-src/theme'; -import { ElasticSearchHit } from '../../services/doc_views/doc_views_types'; import { DiscoverGridContext } from './discover_grid_context'; +import { ElasticSearchHit } from '../../types'; /** * Returning a generated id of a given ES document, since `_id` can be the same diff --git a/src/plugins/discover/public/components/discover_grid/discover_grid_flyout.tsx b/src/plugins/discover/public/components/discover_grid/discover_grid_flyout.tsx index d5b2248162b2f..30e0cf24f7d52 100644 --- a/src/plugins/discover/public/components/discover_grid/discover_grid_flyout.tsx +++ b/src/plugins/discover/public/components/discover_grid/discover_grid_flyout.tsx @@ -25,10 +25,11 @@ import { keys, } from '@elastic/eui'; import { DocViewer } from '../../services/doc_views/components/doc_viewer/doc_viewer'; -import { DocViewFilterFn, ElasticSearchHit } from '../../services/doc_views/doc_views_types'; +import { DocViewFilterFn } from '../../services/doc_views/doc_views_types'; import { DiscoverServices } from '../../build_services'; import { getContextUrl } from '../../utils/get_context_url'; import { getSingleDocUrl } from '../../utils/get_single_doc_url'; +import { ElasticSearchHit } from '../../types'; interface Props { columns: string[]; diff --git a/src/plugins/discover/public/components/discover_grid/get_render_cell_value.test.tsx b/src/plugins/discover/public/components/discover_grid/get_render_cell_value.test.tsx index e97a2b2901f33..b81dda5c27915 100644 --- a/src/plugins/discover/public/components/discover_grid/get_render_cell_value.test.tsx +++ b/src/plugins/discover/public/components/discover_grid/get_render_cell_value.test.tsx @@ -10,8 +10,8 @@ import React from 'react'; import { ReactWrapper, shallow } from 'enzyme'; import { getRenderCellValueFn } from './get_render_cell_value'; import { indexPatternMock } from '../../__mocks__/index_pattern'; -import { ElasticSearchHit } from '../../services/doc_views/doc_views_types'; import { flattenHit } from 'src/plugins/data/common'; +import { ElasticSearchHit } from '../../types'; jest.mock('../../../../kibana_react/public', () => ({ useUiSetting: () => true, diff --git a/src/plugins/discover/public/components/discover_grid/get_render_cell_value.tsx b/src/plugins/discover/public/components/discover_grid/get_render_cell_value.tsx index 8fd5f73701932..c1673dad7eaa7 100644 --- a/src/plugins/discover/public/components/discover_grid/get_render_cell_value.tsx +++ b/src/plugins/discover/public/components/discover_grid/get_render_cell_value.tsx @@ -19,13 +19,13 @@ import { EuiDescriptionListTitle, EuiDescriptionListDescription, } from '@elastic/eui'; -import { ElasticSearchHit } from '../../services/doc_views/doc_views_types'; import { DiscoverGridContext } from './discover_grid_context'; import { JsonCodeEditor } from '../json_code_editor/json_code_editor'; import { defaultMonacoEditorWidth } from './constants'; import { EsHitRecord } from '../../application/types'; import { formatFieldValue } from '../../utils/format_value'; import { formatHit } from '../../utils/format_hit'; +import { ElasticSearchHit } from '../../types'; export const getRenderCellValueFn = ( diff --git a/src/plugins/discover/public/components/doc_table/components/table_row.tsx b/src/plugins/discover/public/components/doc_table/components/table_row.tsx index 8a980cc4160d8..2eee9a177e4f8 100644 --- a/src/plugins/discover/public/components/doc_table/components/table_row.tsx +++ b/src/plugins/discover/public/components/doc_table/components/table_row.tsx @@ -15,11 +15,12 @@ import { flattenHit } from '../../../../../data/common'; import { DocViewer } from '../../../services/doc_views/components/doc_viewer/doc_viewer'; import { FilterManager, IndexPattern } from '../../../../../data/public'; import { TableCell } from './table_row/table_cell'; -import { ElasticSearchHit, DocViewFilterFn } from '../../../services/doc_views/doc_views_types'; +import { DocViewFilterFn } from '../../../services/doc_views/doc_views_types'; import { getContextUrl } from '../../../utils/get_context_url'; import { getSingleDocUrl } from '../../../utils/get_single_doc_url'; import { TableRowDetails } from './table_row_details'; import { formatRow, formatTopLevelObject } from '../lib/row_formatter'; +import { ElasticSearchHit } from '../../../types'; export type DocTableRow = ElasticSearchHit & { isAnchor?: boolean; diff --git a/src/plugins/discover/public/embeddable/saved_search_embeddable.tsx b/src/plugins/discover/public/embeddable/saved_search_embeddable.tsx index 7146f84e194e2..4a7f0b1c36868 100644 --- a/src/plugins/discover/public/embeddable/saved_search_embeddable.tsx +++ b/src/plugins/discover/public/embeddable/saved_search_embeddable.tsx @@ -26,7 +26,6 @@ import { Query, TimeRange, } from '../../../data/common'; -import { ElasticSearchHit } from '../services/doc_views/doc_views_types'; import { SavedSearchEmbeddableComponent } from './saved_search_embeddable_component'; import { UiActionsStart } from '../../../ui_actions/public'; import { getServices } from '../kibana_services'; @@ -48,6 +47,7 @@ import { SortOrder } from '../components/doc_table/components/table_header/helpe import { VIEW_MODE } from '../components/view_mode_toggle'; import { updateSearchSource } from './utils/update_search_source'; import { FieldStatsTableSavedSearchEmbeddable } from '../application/main/components/field_stats_table'; +import { ElasticSearchHit } from '../types'; export type SearchProps = Partial & Partial & { diff --git a/src/plugins/discover/public/embeddable/saved_search_grid.tsx b/src/plugins/discover/public/embeddable/saved_search_grid.tsx index a28e509d3ba72..aa15ccb79da8b 100644 --- a/src/plugins/discover/public/embeddable/saved_search_grid.tsx +++ b/src/plugins/discover/public/embeddable/saved_search_grid.tsx @@ -10,8 +10,8 @@ import { I18nProvider } from '@kbn/i18n-react'; import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { DiscoverGrid, DiscoverGridProps } from '../components/discover_grid/discover_grid'; import { getServices } from '../kibana_services'; -import { ElasticSearchHit } from '../services/doc_views/doc_views_types'; import { TotalDocuments } from '../application/main/components/total_documents/total_documents'; +import { ElasticSearchHit } from '../types'; export interface DiscoverGridEmbeddableProps extends DiscoverGridProps { totalHitCount: number; diff --git a/src/plugins/discover/public/services/doc_views/components/doc_viewer/doc_viewer_tab.test.tsx b/src/plugins/discover/public/services/doc_views/components/doc_viewer/doc_viewer_tab.test.tsx index 3537699e4fe20..8eab6b1e12c8c 100644 --- a/src/plugins/discover/public/services/doc_views/components/doc_viewer/doc_viewer_tab.test.tsx +++ b/src/plugins/discover/public/services/doc_views/components/doc_viewer/doc_viewer_tab.test.tsx @@ -9,8 +9,8 @@ import React from 'react'; import { shallow } from 'enzyme'; import { DocViewerTab } from './doc_viewer_tab'; -import { ElasticSearchHit } from '../../doc_views_types'; import { indexPatternMock } from '../../../../__mocks__/index_pattern'; +import { ElasticSearchHit } from 'src/plugins/discover/public/types'; describe('DocViewerTab', () => { test('changing columns triggers an update', () => { diff --git a/src/plugins/discover/public/services/doc_views/components/doc_viewer_table/table.test.tsx b/src/plugins/discover/public/services/doc_views/components/doc_viewer_table/table.test.tsx index 5133ca46015a0..c956b36b62594 100644 --- a/src/plugins/discover/public/services/doc_views/components/doc_viewer_table/table.test.tsx +++ b/src/plugins/discover/public/services/doc_views/components/doc_viewer_table/table.test.tsx @@ -11,13 +11,13 @@ import { mountWithIntl } from '@kbn/test/jest'; import { findTestSubject } from '@elastic/eui/lib/test'; import { DocViewerTable, DocViewerTableProps } from './table'; import { IndexPattern } from '../../../../../../data/public'; -import { ElasticSearchHit } from '../../doc_views_types'; jest.mock('../../../../kibana_services', () => ({ getServices: jest.fn(), })); import { getServices } from '../../../../kibana_services'; +import { ElasticSearchHit } from '../../../../types'; (getServices as jest.Mock).mockImplementation(() => ({ uiSettings: { diff --git a/src/plugins/discover/public/services/doc_views/components/doc_viewer_table/table.tsx b/src/plugins/discover/public/services/doc_views/components/doc_viewer_table/table.tsx index 707a98d87c924..433227133370e 100644 --- a/src/plugins/discover/public/services/doc_views/components/doc_viewer_table/table.tsx +++ b/src/plugins/discover/public/services/doc_views/components/doc_viewer_table/table.tsx @@ -13,12 +13,13 @@ import { IndexPattern, IndexPatternField } from '../../../../../../data/public'; import { flattenHit } from '../../../../../../data/common'; import { SHOW_MULTIFIELDS } from '../../../../../common'; import { getServices } from '../../../../kibana_services'; -import { DocViewFilterFn, ElasticSearchHit, DocViewRenderProps } from '../../doc_views_types'; +import { DocViewFilterFn, DocViewRenderProps } from '../../doc_views_types'; import { ACTIONS_COLUMN, MAIN_COLUMNS } from './table_columns'; import { getFieldsToShow } from '../../../../utils/get_fields_to_show'; import { getIgnoredReason, IgnoredReason } from '../../../../utils/get_ignored_reason'; import { formatFieldValue } from '../../../../utils/format_value'; import { isNestedFieldParent } from '../../../../application/main/utils/nested_fields'; +import { ElasticSearchHit } from '../../../../types'; export interface DocViewerTableProps { columns?: string[]; diff --git a/src/plugins/discover/public/services/doc_views/doc_views_registry.ts b/src/plugins/discover/public/services/doc_views/doc_views_registry.ts index 26b5016881b85..8ee8741d73d3f 100644 --- a/src/plugins/discover/public/services/doc_views/doc_views_registry.ts +++ b/src/plugins/discover/public/services/doc_views/doc_views_registry.ts @@ -6,7 +6,8 @@ * Side Public License, v 1. */ -import { DocView, DocViewInput, ElasticSearchHit, DocViewInputFn } from './doc_views_types'; +import { ElasticSearchHit } from '../../types'; +import { DocView, DocViewInput, DocViewInputFn } from './doc_views_types'; export class DocViewsRegistry { private docViews: DocView[] = []; diff --git a/src/plugins/discover/public/services/doc_views/doc_views_types.ts b/src/plugins/discover/public/services/doc_views/doc_views_types.ts index e8faa51bbab40..ef2600b4d04df 100644 --- a/src/plugins/discover/public/services/doc_views/doc_views_types.ts +++ b/src/plugins/discover/public/services/doc_views/doc_views_types.ts @@ -7,11 +7,8 @@ */ import { ComponentType } from 'react'; - -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { IndexPattern } from '../../../../data/public'; - -export type ElasticSearchHit = estypes.SearchHit; +import { ElasticSearchHit } from '../../types'; export interface FieldMapping { filterable?: boolean; diff --git a/src/plugins/discover/public/types.ts b/src/plugins/discover/public/types.ts new file mode 100644 index 0000000000000..f6872e9951c37 --- /dev/null +++ b/src/plugins/discover/public/types.ts @@ -0,0 +1,11 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; + +export type ElasticSearchHit = estypes.SearchHit; diff --git a/src/plugins/discover/public/utils/use_es_doc_search.ts b/src/plugins/discover/public/utils/use_es_doc_search.ts index 10c97c53b3fb3..c8b870b1a1dae 100644 --- a/src/plugins/discover/public/utils/use_es_doc_search.ts +++ b/src/plugins/discover/public/utils/use_es_doc_search.ts @@ -11,9 +11,9 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { IndexPattern } from '../../../data/common'; import { DocProps } from '../application/doc/components/doc'; import { ElasticRequestState } from '../application/doc/types'; -import { ElasticSearchHit } from '../services/doc_views/doc_views_types'; import { getServices } from '../kibana_services'; import { SEARCH_FIELDS_FROM_SOURCE } from '../../common'; +import { ElasticSearchHit } from '../types'; type RequestBody = Pick; From 8fc12226fd8818c2de1f8822478e7dd7858c65e6 Mon Sep 17 00:00:00 2001 From: Dzmitry Tamashevich Date: Thu, 2 Dec 2021 12:43:20 +0300 Subject: [PATCH 6/6] [Discover] fix linting --- .../application/main/components/sidebar/discover_sidebar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/discover/public/application/main/components/sidebar/discover_sidebar.tsx b/src/plugins/discover/public/application/main/components/sidebar/discover_sidebar.tsx index 3b4ff997f324e..78aee49d1b288 100644 --- a/src/plugins/discover/public/application/main/components/sidebar/discover_sidebar.tsx +++ b/src/plugins/discover/public/application/main/components/sidebar/discover_sidebar.tsx @@ -39,8 +39,8 @@ import { FieldFilterState, getDefaultFieldFilter, setFieldFilterProp } from './l import { getIndexPatternFieldList } from './lib/get_index_pattern_field_list'; import { DiscoverSidebarResponsiveProps } from './discover_sidebar_responsive'; import { DiscoverIndexPatternManagement } from './discover_index_pattern_management'; -import { ElasticSearchHit } from '../../../../services/doc_views/doc_views_types'; import { VIEW_MODE } from '../../../../components/view_mode_toggle'; +import { ElasticSearchHit } from '../../../../types'; /** * Default number of available fields displayed and added on scroll