[Lens] Fix bug with switching from subtype to subtype (#49915)

This commit is contained in:
Wylie Conlon 2019-10-31 17:14:40 -04:00 committed by GitHub
parent 96297ffae6
commit 6db835c8fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -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();
@ -397,6 +397,7 @@ describe('chart_switch', () => {
initialState: 'therebedragons',
})
);
expect(frame.removeLayers).not.toHaveBeenCalled();
});
it('should switch to the updated datasource state', () => {

View file

@ -28,6 +28,7 @@ interface VisualizationSelection {
dataLoss: 'nothing' | 'layers' | 'everything' | 'columns';
datasourceId?: string;
datasourceState?: unknown;
sameDatasources?: boolean;
}
interface Props {
@ -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));
}
};
@ -109,6 +113,7 @@ export function ChartSwitch(props: Props) {
dataLoss: 'nothing',
keptLayerIds: Object.keys(props.framePublicAPI.datasourceLayers),
getVisualizationState: () => switchVisType(subVisualizationId, props.visualizationState),
sameDatasources: true,
};
}