[Lens] Fix bug with switching from subtype to subtype (#49915)
This commit is contained in:
parent
96297ffae6
commit
6db835c8fb
|
@ -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', () => {
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue