From a395d27e6b1d0de1dfe4f1de778529f508714d9d Mon Sep 17 00:00:00 2001 From: Kerry Gallagher Date: Thu, 20 Oct 2022 15:05:38 +0100 Subject: [PATCH] Use a real DataView reference with derivedDataView --- .../infra/common/log_views/resolved_log_view.mock.ts | 8 ++++++++ .../infra/common/log_views/resolved_log_view.ts | 9 +++++++++ .../infra/public/components/log_stream/log_stream.tsx | 2 +- .../containers/logs/log_filter/log_filter_state.ts | 2 +- x-pack/plugins/infra/public/hooks/use_log_view.mock.ts | 5 +---- x-pack/plugins/infra/public/hooks/use_log_view.ts | 10 +++------- .../infra/public/pages/logs/stream/page_toolbar.tsx | 3 +-- 7 files changed, 24 insertions(+), 15 deletions(-) diff --git a/x-pack/plugins/infra/common/log_views/resolved_log_view.mock.ts b/x-pack/plugins/infra/common/log_views/resolved_log_view.mock.ts index 268b2f692f62a..a910205fc8366 100644 --- a/x-pack/plugins/infra/common/log_views/resolved_log_view.mock.ts +++ b/x-pack/plugins/infra/common/log_views/resolved_log_view.mock.ts @@ -10,6 +10,13 @@ import { createStubDataView } from '@kbn/data-views-plugin/common/stubs'; import { defaultLogViewsStaticConfig } from './defaults'; import { ResolvedLogView, resolveLogView } from './resolved_log_view'; import { LogViewAttributes } from './types'; +import { DataView } from '@kbn/data-views-plugin/common'; + +const dataViewMock = { + id: 'log-view-data-view-mock', + title: 'log-view-data-view-mock-title', + fields: [], +} as unknown as DataView; export const createResolvedLogViewMock = ( resolvedLogViewOverrides: Partial = {} @@ -41,6 +48,7 @@ export const createResolvedLogViewMock = ( messageColumn: { id: 'MESSAGE_COLUMN_ID' }, }, ], + dataViewReference: dataViewMock, ...resolvedLogViewOverrides, }); diff --git a/x-pack/plugins/infra/common/log_views/resolved_log_view.ts b/x-pack/plugins/infra/common/log_views/resolved_log_view.ts index d7e155172a57e..329dc948a2da0 100644 --- a/x-pack/plugins/infra/common/log_views/resolved_log_view.ts +++ b/x-pack/plugins/infra/common/log_views/resolved_log_view.ts @@ -23,6 +23,7 @@ export interface ResolvedLogView { fields: ResolvedLogViewField[]; runtimeMappings: estypes.MappingRuntimeFields; columns: LogViewColumnConfiguration[]; + dataViewReference: DataView; } export const resolveLogView = async ( @@ -60,6 +61,12 @@ const resolveLegacyReference = async ( ); }); + const dataViewReference = await dataViewsService.create({ + id: '___InfraLogsLegacyLogViewReference___', + title: logViewAttributes.logIndices.indexName, + timeFieldName: TIMESTAMP_FIELD, + }); + return { indices: logViewAttributes.logIndices.indexName, timestampField: TIMESTAMP_FIELD, @@ -70,6 +77,7 @@ const resolveLegacyReference = async ( columns: logViewAttributes.logColumns, name: logViewAttributes.name, description: logViewAttributes.description, + dataViewReference, }; }; @@ -97,6 +105,7 @@ const resolveDataViewReference = async ( columns: logViewAttributes.logColumns, name: logViewAttributes.name, description: logViewAttributes.description, + dataViewReference: dataView, }; }; diff --git a/x-pack/plugins/infra/public/components/log_stream/log_stream.tsx b/x-pack/plugins/infra/public/components/log_stream/log_stream.tsx index 2913b2cbb5ecf..e5aeefba983f1 100644 --- a/x-pack/plugins/infra/public/components/log_stream/log_stream.tsx +++ b/x-pack/plugins/infra/public/components/log_stream/log_stream.tsx @@ -7,11 +7,11 @@ import { buildEsQuery, Filter, Query } from '@kbn/es-query'; import { JsonValue } from '@kbn/utility-types'; -import { noop } from 'lodash'; import React, { useCallback, useEffect, useMemo } from 'react'; import { DataPublicPluginStart } from '@kbn/data-plugin/public'; import { euiStyled } from '@kbn/kibana-react-plugin/common'; import { useKibana } from '@kbn/kibana-react-plugin/public'; +import { noop } from 'lodash'; import { LogEntryCursor } from '../../../common/log_entry'; import { defaultLogViewsStaticConfig } from '../../../common/log_views'; import { BuiltEsQuery, useLogStream } from '../../containers/logs/log_stream'; diff --git a/x-pack/plugins/infra/public/containers/logs/log_filter/log_filter_state.ts b/x-pack/plugins/infra/public/containers/logs/log_filter/log_filter_state.ts index 65a75bcb5ce01..521e00331dd97 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_filter/log_filter_state.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_filter/log_filter_state.ts @@ -53,7 +53,7 @@ const unsupportedLanguageError = i18n.translate( } ); -export const useLogFilterState = ({ indexPattern }: { indexPattern: DataViewBase }) => { +export const useLogFilterState = ({ indexPattern }: { indexPattern?: DataViewBase }) => { const { notifications: { toasts }, data: { diff --git a/x-pack/plugins/infra/public/hooks/use_log_view.mock.ts b/x-pack/plugins/infra/public/hooks/use_log_view.mock.ts index daebfb82b4564..8bef101abe666 100644 --- a/x-pack/plugins/infra/public/hooks/use_log_view.mock.ts +++ b/x-pack/plugins/infra/public/hooks/use_log_view.mock.ts @@ -17,10 +17,7 @@ const defaultLogViewId = 'default'; export const createUninitializedUseLogViewMock = (logViewId: string = defaultLogViewId) => (): IUseLogView => ({ - derivedDataView: { - fields: [], - title: 'unknown', - }, + derivedDataView: undefined, hasFailedLoading: false, hasFailedLoadingLogView: false, hasFailedLoadingLogViewStatus: false, diff --git a/x-pack/plugins/infra/public/hooks/use_log_view.ts b/x-pack/plugins/infra/public/hooks/use_log_view.ts index b1b8bb6e33cc9..9dd0468d60b40 100644 --- a/x-pack/plugins/infra/public/hooks/use_log_view.ts +++ b/x-pack/plugins/infra/public/hooks/use_log_view.ts @@ -63,13 +63,9 @@ export const useLogView = ({ [logViews] ); - const derivedDataView = useMemo( - () => ({ - fields: resolvedLogView?.fields ?? [], - title: resolvedLogView?.indices ?? 'unknown', - }), - [resolvedLogView] - ); + const derivedDataView = useMemo(() => { + return resolvedLogView?.dataViewReference; + }, [resolvedLogView]); const isLoadingLogView = loadLogViewRequest.state === 'pending'; const isResolvingLogView = resolveLogViewRequest.state === 'pending'; diff --git a/x-pack/plugins/infra/public/pages/logs/stream/page_toolbar.tsx b/x-pack/plugins/infra/public/pages/logs/stream/page_toolbar.tsx index 2929151a1902e..cf30518f78ede 100644 --- a/x-pack/plugins/infra/public/pages/logs/stream/page_toolbar.tsx +++ b/x-pack/plugins/infra/public/pages/logs/stream/page_toolbar.tsx @@ -8,7 +8,6 @@ import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React from 'react'; -import { DataView } from '@kbn/data-views-plugin/public'; import { euiStyled } from '@kbn/kibana-react-plugin/common'; import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; import { LogCustomizationMenu } from '../../../components/logging/log_customization_menu'; @@ -62,7 +61,7 @@ export const LogsToolbar = () => { defaultMessage: 'Search for log entries… (e.g. host.name:host-1)', })} useDefaultBehaviors={true} - indexPatterns={[derivedDataView as DataView]} + indexPatterns={derivedDataView ? [derivedDataView] : undefined} showQueryInput={true} showQueryMenu={false} showFilterBar={false}