diff --git a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/expression_helpers.ts b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/expression_helpers.ts index 012fc5c208fe4..e2cbcd0696238 100644 --- a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/expression_helpers.ts +++ b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/expression_helpers.ts @@ -17,7 +17,7 @@ export function getDatasourceExpressionsByLayers( nowInstant: Date, searchSessionId?: string, forceDSL?: boolean -): null | Record { +): undefined | Record { const datasourceExpressions: Array<[string, Ast | string]> = []; Object.entries(datasourceMap).forEach(([datasourceId, datasource]) => { @@ -45,7 +45,7 @@ export function getDatasourceExpressionsByLayers( }); if (datasourceExpressions.length === 0) { - return null; + return undefined; } return datasourceExpressions.reduce( @@ -107,10 +107,10 @@ export function buildExpression({ title, description, }, - datasourceExpressionsByLayers ?? undefined + datasourceExpressionsByLayers ); - if (datasourceExpressionsByLayers === null || visualizationExpression === null) { + if (!datasourceExpressionsByLayers || visualizationExpression === null) { return null; } diff --git a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_panel.tsx b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_panel.tsx index d07d1240f3488..bcae657c07dcc 100644 --- a/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_panel.tsx +++ b/x-pack/platform/plugins/shared/lens/public/editor_frame_service/editor_frame/suggestion_panel.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import { camelCase, pick } from 'lodash'; +import { camelCase } from 'lodash'; import React, { useState, useEffect, useMemo, useRef, useCallback } from 'react'; import { FormattedMessage } from '@kbn/i18n-react'; import { css } from '@emotion/react'; @@ -46,7 +46,6 @@ import { FramePublicAPI, DatasourceMap, VisualizationMap, - DatasourceLayers, UserMessagesGetter, } from '../../types'; import { getSuggestions, switchToSuggestion } from './suggestion_helpers'; @@ -708,30 +707,6 @@ function getPreviewExpression( datasourceLayers: { ...frame.datasourceLayers }, }; try { - // use current frame api and patch apis for changed datasource layers - if ( - visualizableState.keptLayerIds && - visualizableState.datasourceId && - visualizableState.datasourceState - ) { - const datasource = datasources[visualizableState.datasourceId]; - const datasourceState = visualizableState.datasourceState; - const updatedLayerApis: DatasourceLayers = pick( - frame.datasourceLayers, - visualizableState.keptLayerIds - ); - const changedLayers = datasource.getLayers(visualizableState.datasourceState); - changedLayers.forEach((layerId) => { - if (updatedLayerApis[layerId]) { - updatedLayerApis[layerId] = datasource.getPublicAPI({ - layerId, - state: datasourceState, - indexPatterns: frame.dataViews.indexPatterns, - }); - } - }); - } - const datasourceExpressionsByLayers = getDatasourceExpressionsByLayers( datasources, datasourceStates, @@ -743,7 +718,7 @@ function getPreviewExpression( return visualization.toPreviewExpression( visualizableState.visualizationState, suggestionFrameApi.datasourceLayers, - datasourceExpressionsByLayers ?? undefined + datasourceExpressionsByLayers ); } catch (error) { showMemoizedErrorNotification(error);