Skip to content

Commit

Permalink
[Lens] Fix unintentional switching to pie (#93219)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra authored Mar 3, 2021
1 parent 529624d commit c42b994
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
34 changes: 32 additions & 2 deletions x-pack/plugins/lens/public/pie_visualization/visualization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const pieVisualization = getPieVisualization({
paletteService: chartPluginMock.createPaletteRegistry(),
});

function exampleState(): PieVisualizationState {
function getExampleState(): PieVisualizationState {
return {
shape: 'pie',
layers: [
Expand All @@ -38,9 +38,39 @@ function exampleState(): PieVisualizationState {
describe('pie_visualization', () => {
describe('#getErrorMessages', () => {
it('returns undefined if no error is raised', () => {
const error = pieVisualization.getErrorMessages(exampleState());
const error = pieVisualization.getErrorMessages(getExampleState());

expect(error).not.toBeDefined();
});
});
describe('#setDimension', () => {
it('returns expected state', () => {
const prevState: PieVisualizationState = {
layers: [
{
groups: ['a'],
layerId: LAYER_ID,
numberDisplay: 'percent',
categoryDisplay: 'default',
legendDisplay: 'default',
nestedLegend: false,
metric: undefined,
},
],
shape: 'donut',
};
const setDimensionResult = pieVisualization.setDimension({
prevState,
columnId: 'x',
layerId: LAYER_ID,
groupId: 'a',
});

expect(setDimensionResult).toEqual(
expect.objectContaining({
shape: 'donut',
})
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,6 @@ export const getPieVisualization = ({
setDimension({ prevState, layerId, columnId, groupId }) {
return {
...prevState,

shape:
prevState.shape === 'donut' && prevState.layers.every((l) => l.groups.length === 1)
? 'pie'
: prevState.shape,
layers: prevState.layers.map((l) => {
if (l.layerId !== layerId) {
return l;
Expand Down

0 comments on commit c42b994

Please sign in to comment.