Skip to content

Commit abeb2d4

Browse files
authored
[Lens] Hides the legend actions from ES|QL charts when in dashboard (#217133)
1 parent ce10318 commit abeb2d4

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

src/platform/plugins/shared/chart_expressions/expression_xy/public/components/xy_chart.test.tsx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import React from 'react';
1111
import { mount, shallow } from 'enzyme';
1212
import { mountWithIntl } from '@kbn/test-jest-helpers';
13+
1314
import {
1415
AreaSeries,
1516
Axis,
@@ -36,6 +37,7 @@ import {
3637
import { Datatable } from '@kbn/expressions-plugin/common';
3738
import { EmptyPlaceholder } from '@kbn/charts-plugin/public';
3839
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
40+
import { ESQL_TABLE_TYPE } from '@kbn/data-plugin/common';
3941
import { eventAnnotationServiceMock } from '@kbn/event-annotation-plugin/public/mocks';
4042
import { EventAnnotationOutput } from '@kbn/event-annotation-plugin/common';
4143
import { DataLayerConfig } from '../../common';
@@ -106,6 +108,23 @@ describe('XYChart component', () => {
106108
return shallow(<XYChart {...defaultProps} args={args} />);
107109
};
108110

111+
const dataFromESQL: Datatable = {
112+
type: 'datatable',
113+
columns: [
114+
{ id: 'a', name: 'a', meta: { type: 'number' } },
115+
{ id: 'b', name: 'b', meta: { type: 'number' } },
116+
{ id: 'c', name: 'c', meta: { type: 'string' } },
117+
{ id: 'd', name: 'd', meta: { type: 'string' } },
118+
],
119+
rows: [
120+
{ a: 1, b: 2, c: 'I', d: 'Row 1' },
121+
{ a: 1, b: 5, c: 'J', d: 'Row 2' },
122+
],
123+
meta: {
124+
type: ESQL_TABLE_TYPE,
125+
},
126+
};
127+
109128
beforeEach(() => {
110129
convertSpy = jest.fn((x) => x);
111130
getFormatSpy = jest.fn();
@@ -1517,6 +1536,69 @@ describe('XYChart component', () => {
15171536
expect(wrapper.find(Settings).first().prop('legendAction')).toBeUndefined();
15181537
});
15191538

1539+
test('legendAction is not triggering event on ES|QL charts when unified search is on KQL/Lucene mode', () => {
1540+
const { args } = sampleArgs();
1541+
1542+
const newArgs = {
1543+
...args,
1544+
layers: args.layers.map((l) => ({
1545+
...l,
1546+
table: dataFromESQL,
1547+
})),
1548+
};
1549+
const dataMock = dataPluginMock.createStartContract();
1550+
const newProps = {
1551+
...defaultProps,
1552+
data: {
1553+
...dataMock,
1554+
query: {
1555+
...dataMock.query,
1556+
queryString: {
1557+
...dataMock.query.queryString,
1558+
getQuery: () => ({
1559+
language: 'kuery',
1560+
query: 'field:value',
1561+
}),
1562+
},
1563+
},
1564+
},
1565+
};
1566+
const wrapper = mountWithIntl(<XYChart {...newProps} args={newArgs} interactive={true} />);
1567+
1568+
expect(wrapper.find(Settings).first().prop('legendAction')).toBeUndefined();
1569+
});
1570+
1571+
test('legendAction is triggering event on ES|QL charts when unified search is on ES|QL mode', () => {
1572+
const { args } = sampleArgs();
1573+
1574+
const newArgs = {
1575+
...args,
1576+
layers: args.layers.map((l) => ({
1577+
...l,
1578+
table: dataFromESQL,
1579+
})),
1580+
};
1581+
const dataMock = dataPluginMock.createStartContract();
1582+
const newProps = {
1583+
...defaultProps,
1584+
data: {
1585+
...dataMock,
1586+
query: {
1587+
...dataMock.query,
1588+
queryString: {
1589+
...dataMock.query.queryString,
1590+
getQuery: () => ({
1591+
esql: 'FROM "index-pattern" WHERE "field" = "value"',
1592+
}),
1593+
},
1594+
},
1595+
},
1596+
};
1597+
const wrapper = mountWithIntl(<XYChart {...newProps} args={newArgs} interactive={true} />);
1598+
1599+
expect(wrapper.find(Settings).first().prop('legendAction')).toBeDefined();
1600+
});
1601+
15201602
test('it renders stacked bar', () => {
15211603
const { args } = sampleArgs();
15221604
const component = shallow(

src/platform/plugins/shared/chart_expressions/expression_xy/public/components/xy_chart.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
import { partition } from 'lodash';
3737
import { IconType } from '@elastic/eui';
3838
import { i18n } from '@kbn/i18n';
39+
import { isOfAggregateQueryType } from '@kbn/es-query';
3940
import { PaletteRegistry } from '@kbn/coloring';
4041
import { RenderMode } from '@kbn/expressions-plugin/common';
4142
import { useKbnPalettes } from '@kbn/palettes';
@@ -747,6 +748,11 @@ export function XYChart({
747748
formatFactory
748749
);
749750

751+
// ES|QL charts are allowed to create filters only when the unified search bar query is ES|QL (e.g. in Discover)
752+
const applicationQuery = data.query.queryString.getQuery();
753+
const canCreateFilters =
754+
!isEsqlMode || (isEsqlMode && applicationQuery && isOfAggregateQueryType(applicationQuery));
755+
750756
return (
751757
<>
752758
<GlobalXYChartStyles />
@@ -873,7 +879,7 @@ export function XYChart({
873879
onBrushEnd={interactive ? (brushHandler as BrushEndListener) : undefined}
874880
onElementClick={interactive ? clickHandler : undefined}
875881
legendAction={
876-
interactive
882+
interactive && canCreateFilters
877883
? getLegendAction(
878884
dataLayers,
879885
onClickValue,

0 commit comments

Comments
 (0)