Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [Lens] Fix bug with switching from subtype to subtype (#49915) #49930

Merged
merged 1 commit into from
Oct 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Lens] Fix bug with switching from subtype to subtype (#49915)
Wylie Conlon authored and wylieconlon committed Oct 31, 2019
commit f4d1774412b128b874486a66d5cc16f5010027cb
Original file line number Diff line number Diff line change
@@ -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', () => {
Original file line number Diff line number Diff line change
@@ -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,
};
}