Skip to content

Commit

Permalink
[Discover] Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta committed Apr 5, 2024
1 parent 531c7a7 commit b6637ba
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { addLog } from '../../../../utils/add_log';
import { useInternalStateSelector } from '../../services/discover_internal_state_container';
import type { DiscoverAppState } from '../../services/discover_app_state_container';
import { DataDocumentsMsg, RecordRawType } from '../../services/discover_data_state_container';
import { useSavedSearch } from '../../services/discover_state_provider';

const EMPTY_TEXT_BASED_COLUMNS: DatatableColumn[] = [];
const EMPTY_FILTERS: Filter[] = [];
Expand All @@ -61,7 +62,7 @@ export const useDiscoverHistogram = ({
}: UseDiscoverHistogramProps) => {
const services = useDiscoverServices();
const savedSearchData$ = stateContainer.dataState.data$;
const savedSearchState = useObservable(stateContainer.savedSearchState.getCurrent$());
const savedSearchState = useSavedSearch();

/**
* API initialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ function areSuggestionAndVisContextAndQueryParamsStillCompatible({
// requestData should match
if (
(Object.keys(requestData) as Array<keyof UnifiedHistogramVisContext['requestData']>).some(
(key) => requestData[key] !== externalVisContext.requestData[key]
(key) => !isEqual(requestData[key], externalVisContext.requestData[key])
)
) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import type { Suggestion } from '@kbn/lens-plugin/public';
import type { PieVisualizationState, Suggestion, XYState } from '@kbn/lens-plugin/public';
import { UnifiedHistogramSuggestionType, UnifiedHistogramVisContext } from '../types';
import { removeTablesFromLensAttributes } from './lens_vis_from_table';

Expand Down Expand Up @@ -77,17 +77,13 @@ export const isSuggestionShapeAndVisContextCompatible = (

if (suggestion?.visualizationId === 'lnsXY') {
return (
// @ts-expect-error visualization state has different structure between vis types
suggestion?.visualizationState?.preferredSeriesType ===
// @ts-expect-error visualization state has different structure between vis types
externalVisContext?.attributes?.state?.visualization?.preferredSeriesType
(suggestion?.visualizationState as XYState)?.preferredSeriesType ===
(externalVisContext?.attributes?.state?.visualization as XYState)?.preferredSeriesType
);
}

return (
// @ts-expect-error visualization state has different structure between vis types
suggestion?.visualizationState?.shape ===
// @ts-expect-error visualization state has different structure between vis types
externalVisContext?.attributes?.state?.visualization?.shape
(suggestion?.visualizationState as PieVisualizationState)?.shape ===
(externalVisContext?.attributes?.state?.visualization as PieVisualizationState)?.shape
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const enrichLensAttributesWithTablesData = ({

const layers = attributes.state.datasourceStates.textBased?.layers;

if (!layers) {
return attributes;
}

const updatedAttributes = {
...attributes,
state: {
Expand All @@ -37,14 +41,12 @@ export const enrichLensAttributesWithTablesData = ({
},
};

if (layers) {
for (const key of Object.keys(layers)) {
const newLayer = { ...layers[key], table };
if (!table) {
delete newLayer.table;
}
updatedAttributes.state.datasourceStates.textBased.layers[key] = newLayer;
for (const key of Object.keys(layers)) {
const newLayer = { ...layers[key], table };
if (!table) {
delete newLayer.table;
}
updatedAttributes.state.datasourceStates.textBased.layers[key] = newLayer;
}

return updatedAttributes;
Expand Down

0 comments on commit b6637ba

Please sign in to comment.