Skip to content

Commit

Permalink
[Lens] Do not show legend actions popup when in non-interactive mode (#…
Browse files Browse the repository at this point in the history
…115804) (#115968)

* 🐛 Fix non-interactive legend issue

* ✅ Add tests

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Marco Liberati <[email protected]>
  • Loading branch information
kibanamachine and dej611 authored Oct 21, 2021
1 parent 52d87d7 commit da6b9f2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,13 @@ describe('PieVisualization component', () => {
`);
});

test('does not set click listener on non-interactive mode', () => {
test('does not set click listener and legend actions on non-interactive mode', () => {
const defaultArgs = getDefaultArgs();
const component = shallow(
<PieComponent args={{ ...args }} {...defaultArgs} interactive={false} />
);
expect(component.find(Settings).first().prop('onElementClick')).toBeUndefined();
expect(component.find(Settings).first().prop('legendAction')).toBeUndefined();
});

test('it renders the empty placeholder when metric contains only falsy data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export function PieComponent(
legendPosition={legendPosition || Position.Right}
legendMaxDepth={nestedLegend ? undefined : 1 /* Color is based only on first layer */}
onElementClick={props.interactive ?? true ? onElementClickHandler : undefined}
legendAction={getLegendAction(firstTable, onClickValue)}
legendAction={props.interactive ? getLegendAction(firstTable, onClickValue) : undefined}
theme={{
...chartTheme,
background: {
Expand Down
10 changes: 10 additions & 0 deletions x-pack/plugins/lens/public/xy_visualization/expression.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,16 @@ describe('xy_expression', () => {
expect(wrapper.find(Settings).first().prop('onElementClick')).toBeUndefined();
});

test('legendAction is not triggering event on non-interactive mode', () => {
const { args, data } = sampleArgs();

const wrapper = mountWithIntl(
<XYChart {...defaultProps} data={data} args={args} interactive={false} />
);

expect(wrapper.find(Settings).first().prop('legendAction')).toBeUndefined();
});

test('it renders stacked bar', () => {
const { data, args } = sampleArgs();
const component = shallow(
Expand Down
18 changes: 11 additions & 7 deletions x-pack/plugins/lens/public/xy_visualization/expression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,17 @@ export function XYChart({
xDomain={xDomain}
onBrushEnd={interactive ? (brushHandler as BrushEndListener) : undefined}
onElementClick={interactive ? clickHandler : undefined}
legendAction={getLegendAction(
filteredLayers,
data.tables,
onClickValue,
formatFactory,
layersAlreadyFormatted
)}
legendAction={
interactive
? getLegendAction(
filteredLayers,
data.tables,
onClickValue,
formatFactory,
layersAlreadyFormatted
)
: undefined
}
showLegendExtra={isHistogramViz && valuesInLegend}
/>

Expand Down

0 comments on commit da6b9f2

Please sign in to comment.