Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function getDatasourceExpressionsByLayers(
nowInstant: Date,
searchSessionId?: string,
forceDSL?: boolean
): null | Record<string, Ast> {
): undefined | Record<string, Ast> {
const datasourceExpressions: Array<[string, Ast | string]> = [];

Object.entries(datasourceMap).forEach(([datasourceId, datasource]) => {
Expand Down Expand Up @@ -45,7 +45,7 @@ export function getDatasourceExpressionsByLayers(
});

if (datasourceExpressions.length === 0) {
return null;
return undefined;
}

return datasourceExpressions.reduce(
Expand Down Expand Up @@ -107,10 +107,10 @@ export function buildExpression({
title,
description,
},
datasourceExpressionsByLayers ?? undefined
datasourceExpressionsByLayers
);

if (datasourceExpressionsByLayers === null || visualizationExpression === null) {
if (!datasourceExpressionsByLayers || visualizationExpression === null) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -46,7 +46,6 @@ import {
FramePublicAPI,
DatasourceMap,
VisualizationMap,
DatasourceLayers,
UserMessagesGetter,
} from '../../types';
import { getSuggestions, switchToSuggestion } from './suggestion_helpers';
Expand Down Expand Up @@ -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,
});
}
});
}
Comment on lines -711 to -733
Copy link
Copy Markdown
Contributor Author

@markov00 markov00 May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none of these variables are used outside that if and I hope the getPublicAPI or the getLayers are pure functions that doesn't modifies any external state.


const datasourceExpressionsByLayers = getDatasourceExpressionsByLayers(
datasources,
datasourceStates,
Expand All @@ -743,7 +718,7 @@ function getPreviewExpression(
return visualization.toPreviewExpression(
visualizableState.visualizationState,
suggestionFrameApi.datasourceLayers,
datasourceExpressionsByLayers ?? undefined
datasourceExpressionsByLayers
);
} catch (error) {
showMemoizedErrorNotification(error);
Expand Down