Skip to content

Commit

Permalink
Merge pull request #11 from stratoula/branch-byvalue-textbased
Browse files Browse the repository at this point in the history
Simplifications and solve bug on refresh
  • Loading branch information
ppisljar authored Jan 22, 2024
2 parents 663c7b2 + 7190ab5 commit 47d10f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 34 deletions.
32 changes: 0 additions & 32 deletions src/plugins/unified_histogram/public/container/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { pick } from 'lodash';
import useMount from 'react-use/lib/useMount';
import { LensSuggestionsApi } from '@kbn/lens-plugin/public';
import { Datatable } from '@kbn/expressions-plugin/common';
import { TextBasedPersistedState } from '@kbn/lens-plugin/public/datasources/text_based/types';
import { UnifiedHistogramLayout, UnifiedHistogramLayoutProps } from '../layout';
import type { UnifiedHistogramInputMessage, UnifiedHistogramRequestContext } from '../types';
import {
Expand Down Expand Up @@ -144,37 +143,6 @@ export const UnifiedHistogramContainer = forwardRef<
return null;
}

if (
containerProps.table &&
currentSuggestion &&
currentSuggestion.datasourceId === 'textBased' &&
currentSuggestion.datasourceState &&
(currentSuggestion.datasourceState as TextBasedPersistedState).layers &&
Object.values((currentSuggestion.datasourceState as TextBasedPersistedState).layers).some(
(l) => l.table && l.table !== containerProps.table
)
) {
const layerIds = Object.keys(
(currentSuggestion.datasourceState as TextBasedPersistedState).layers
);

const newLayers: TextBasedPersistedState['layers'] = {};
layerIds.forEach((layerId) => {
newLayers[layerId] = {
...(currentSuggestion!.datasourceState as TextBasedPersistedState).layers[layerId],
table: containerProps.table,
};
});

stateService?.setCurrentSuggestion({
...currentSuggestion,
datasourceState: {
...(currentSuggestion.datasourceState as TextBasedPersistedState),
layers: newLayers,
},
});
}

return (
<UnifiedHistogramLayout
{...containerProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const useLensSuggestions = ({
}, [currentSuggestion, dataView, query, timeRange, data, lensSuggestionsApi]);

useEffect(() => {
const newSuggestionsDeps = getSuggestionDeps({ dataView, query, columns });
const newSuggestionsDeps = getSuggestionDeps({ dataView, query, columns, table });

if (!isEqual(suggestionDeps.current, newSuggestionsDeps)) {
setAllSuggestions(suggestions.allSuggestions);
Expand All @@ -136,6 +136,7 @@ export const useLensSuggestions = ({
}, [
columns,
dataView,
table,
onSuggestionChange,
query,
suggestions.firstSuggestion,
Expand All @@ -155,8 +156,10 @@ const getSuggestionDeps = ({
dataView,
query,
columns,
table,
}: {
dataView: DataView;
query?: Query | AggregateQuery;
columns?: DatatableColumn[];
}) => [dataView.id, columns, query];
table?: Datatable;
}) => [dataView.id, columns, query, table];

0 comments on commit 47d10f0

Please sign in to comment.