Skip to content

Commit

Permalink
[Lens] Fix bug with switching from subtype to subtype (#49915) (#49931)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wylie Conlon authored Oct 31, 2019
1 parent cec8702 commit 7990eb9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ describe('chart_switch', () => {
);
});

it('should not remove layers if the visualization is not changing', () => {
it('should not remove layers when switching between subtypes', () => {
const dispatch = jest.fn();
const frame = mockFrame(['a', 'b', 'c']);
const visualizations = mockVisualizations();
Expand Down Expand Up @@ -397,6 +397,7 @@ describe('chart_switch', () => {
initialState: 'therebedragons',
})
);
expect(frame.removeLayers).not.toHaveBeenCalled();
});

it('should switch to the updated datasource state', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface VisualizationSelection {
dataLoss: 'nothing' | 'layers' | 'everything' | 'columns';
datasourceId?: string;
datasourceState?: unknown;
sameDatasources?: boolean;
}

interface Props {
Expand Down Expand Up @@ -89,7 +90,10 @@ export function ChartSwitch(props: Props) {
'SWITCH_VISUALIZATION'
);

if (!selection.datasourceId || selection.dataLoss === 'everything') {
if (
(!selection.datasourceId && !selection.sameDatasources) ||
selection.dataLoss === 'everything'
) {
props.framePublicAPI.removeLayers(Object.keys(props.framePublicAPI.datasourceLayers));
}
};
Expand All @@ -109,6 +113,7 @@ export function ChartSwitch(props: Props) {
dataLoss: 'nothing',
keptLayerIds: Object.keys(props.framePublicAPI.datasourceLayers),
getVisualizationState: () => switchVisType(subVisualizationId, props.visualizationState),
sameDatasources: true,
};
}

Expand Down

0 comments on commit 7990eb9

Please sign in to comment.