[Lens] Metric non-clickable if not filterable (#154212)

## Summary

Closes https://github.com/elastic/kibana/issues/153621

In case metric is not filterable the cursor should not indicate that it
is.

![1](https://user-images.githubusercontent.com/17003240/229454467-32247bc7-e38f-4486-9dc1-833238c226b0.gif)

### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
This commit is contained in:
Stratoula Kalafateli 2023-04-03 19:03:29 +03:00 committed by GitHub
parent affc44329b
commit 9bfd8b6ecb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 23 deletions

View file

@ -1103,15 +1103,27 @@ describe('MetricVisComponent', function () {
});
it('should do nothing if primary metric is not filterable', () => {
const event: MetricElementEvent = {
type: 'metricElementEvent',
rowIndex: 1,
columnIndex: 0,
const props = {
...defaultProps,
filterable: false,
};
const metricComponent = shallow(
<MetricVis
config={{
metric: {
progressDirection: 'vertical',
maxCols: 5,
},
dimensions: {
metric: basePriceColumnId,
},
}}
data={table}
{...props}
/>
);
fireFilter(event, false, true);
expect(fireEventSpy).not.toHaveBeenCalled();
expect(metricComponent.find(Settings).props().onElementClick).toBeUndefined();
});
});

View file

@ -362,22 +362,27 @@ export const MetricVis = ({
]}
baseTheme={baseTheme}
onRenderChange={onRenderChange}
onElementClick={(events) => {
if (!filterable) {
return;
}
events.forEach((event) => {
if (isMetricElementEvent(event)) {
const colIdx = breakdownByColumn
? data.columns.findIndex((col) => col === breakdownByColumn)
: data.columns.findIndex((col) => col === primaryMetricColumn);
const rowLength = grid[0].length;
fireEvent(
buildFilterEvent(event.rowIndex * rowLength + event.columnIndex, colIdx, data)
);
}
});
}}
onElementClick={
filterable
? (events) => {
events.forEach((event) => {
if (isMetricElementEvent(event)) {
const colIdx = breakdownByColumn
? data.columns.findIndex((col) => col === breakdownByColumn)
: data.columns.findIndex((col) => col === primaryMetricColumn);
const rowLength = grid[0].length;
fireEvent(
buildFilterEvent(
event.rowIndex * rowLength + event.columnIndex,
colIdx,
data
)
);
}
});
}
: undefined
}
/>
<Metric id="metric" data={grid} />
</Chart>