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

[Lens] Disable config axis side and color picker when groupid is breakdown and collaseFn enable #195845

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import React from 'react';
import { mountWithIntl as mount } from '@kbn/test-jest-helpers';
import { render, screen } from '@testing-library/react';
import { EuiButtonGroupProps, EuiButtonGroup } from '@elastic/eui';
import { DataDimensionEditor } from './dimension_editor';
import { FramePublicAPI, DatasourcePublicAPI } from '../../../types';
Expand Down Expand Up @@ -195,6 +196,65 @@ describe('XY Config panels', () => {

expect(component.find(EuiColorPicker).prop('color')).toEqual('red');
});
test.each<{ collapseFn?: string; shouldDisplay?: boolean }>([
// should display color picker
{ shouldDisplay: true },
// should not display color picker
{ collapseFn: 'sum', shouldDisplay: false },
])(
'should only show color picker when collapseFn is defined for breakdown group',
({ collapseFn = undefined, shouldDisplay = true }) => {
const state = {
...testState(),
layers: [
{
collapseFn,
seriesType: 'bar',
layerType: LayerTypes.DATA,
layerId: 'first',
splitAccessor: 'breakdownAccessor',
xAccessor: 'foo',
accessors: ['bar'],
yConfig: [{ forAccessor: 'bar', color: 'red' }],
},
],
} as XYState;

render(
<DataDimensionEditor
layerId={state.layers[0].layerId}
frame={{
...frame,
activeData: {
first: {
type: 'datatable',
columns: [],
rows: [{ bar: 123 }],
},
},
}}
setState={jest.fn()}
accessor="breakdownAccessor"
groupId={'breakdown'}
state={state}
formatFactory={jest.fn()}
paletteService={chartPluginMock.createPaletteRegistry()}
panelRef={React.createRef()}
addLayer={jest.fn()}
removeLayer={jest.fn()}
datasource={{} as DatasourcePublicAPI}
isDarkMode={false}
/>
);
const colorPickerUi = screen.queryByLabelText('Edit colors');

if (shouldDisplay) {
expect(colorPickerUi).toBeInTheDocument();
} else {
expect(colorPickerUi).not.toBeInTheDocument();
}
}
);
test('does not apply incorrect color', () => {
jest.useFakeTimers();
const setState = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ export function DataDimensionEditor(
const { splitAccessor } = layer;
const splitCategories = getColorCategories(table?.rows ?? [], splitAccessor);

if (props.groupId === 'breakdown' && !layer.collapseFn) {
return (
if (props.groupId === 'breakdown') {
return !layer.collapseFn ? (
<ColorMappingByTerms
isDarkMode={isDarkMode}
colorMapping={layer.colorMapping}
Expand All @@ -147,7 +147,7 @@ export function DataDimensionEditor(
panelRef={props.panelRef}
categories={splitCategories}
/>
);
) : null;
}

const isHorizontal = isHorizontalChart(state.layers);
Expand Down