Skip to content

Commit

Permalink
[Lens] Extend explore data in Discover/open in Discover drilldown to …
Browse files Browse the repository at this point in the history
…visualizations with annotations and reference lines (elastic#147541)

## Summary

Fixes elastic#147427 

This PR extends the support of the *open in Discover* drilldown/explore
data in Discover to visualizations that have annotation and/or reference
line layers, but still a single data layer.

<img width="773" alt="Screenshot 2022-12-14 at 11 07 04"
src="https://user-images.githubusercontent.com/924948/207646747-48220db2-e3f4-46f6-b4ef-c5797e1790af.png">
<img width="702" alt="Screenshot 2022-12-14 at 11 07 16"
src="https://user-images.githubusercontent.com/924948/207646755-146f92b2-fbaa-425c-8a23-fc02198615b1.png">
<img width="739" alt="Screenshot 2022-12-14 at 11 07 25"
src="https://user-images.githubusercontent.com/924948/207646761-928983a3-6805-403c-9f17-9c789be3b784.png">



### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [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
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces&mdash;unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes&mdash;Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
  • Loading branch information
2 people authored and crespocarlos committed Dec 16, 2022
1 parent ddda422 commit 11bb6ff
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 77 deletions.
7 changes: 7 additions & 0 deletions x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx
Expand Up @@ -479,9 +479,14 @@ export const LensTopNavMenu = ({
if (!activeDatasourceId || !discoverLocator) {
return;
}
if (visualization.activeId == null) {
return;
}
return getLayerMetaInfo(
datasourceMap[activeDatasourceId],
datasourceStates[activeDatasourceId].state,
visualizationMap[visualization.activeId],
visualization.state,
activeData,
dataViews.indexPatterns,
data.query.timefilter.timefilter.getTime(),
Expand All @@ -490,8 +495,10 @@ export const LensTopNavMenu = ({
}, [
activeDatasourceId,
discoverLocator,
visualization,
datasourceMap,
datasourceStates,
visualizationMap,
activeData,
dataViews.indexPatterns,
data.query.timefilter.timefilter,
Expand Down
197 changes: 136 additions & 61 deletions x-pack/plugins/lens/public/app_plugin/show_underlying_data.test.ts
Expand Up @@ -5,11 +5,11 @@
* 2.0.
*/

import { createMockDatasource } from '../mocks';
import { createMockDatasource, createMockVisualization } from '../mocks';
import { combineQueryAndFilters, getLayerMetaInfo } from './show_underlying_data';
import { Filter } from '@kbn/es-query';
import { DatasourcePublicAPI } from '../types';
import { createMockedIndexPattern } from '../datasources/form_based/mocks';
import { LayerType } from '..';

describe('getLayerMetaInfo', () => {
const capabilities = {
Expand All @@ -21,6 +21,8 @@ describe('getLayerMetaInfo', () => {
getLayerMetaInfo(
createMockDatasource('testDatasource'),
{},
createMockVisualization('testVisualization'),
{},
undefined,
{},
undefined,
Expand All @@ -29,14 +31,17 @@ describe('getLayerMetaInfo', () => {
).toBe('Visualization has no data available to show');
});

it('should return error in case of multiple layers', () => {
it('should return error in case of multiple data layers', () => {
const mockDatasource = createMockDatasource('testDatasource');
mockDatasource.getLayers.mockReturnValue(['layer1', 'layer2']);
expect(
getLayerMetaInfo(
createMockDatasource('testDatasource'),
mockDatasource,
{},
createMockVisualization('testVisualization'),
{},
{
datatable1: { type: 'datatable', columns: [], rows: [] },
datatable2: { type: 'datatable', columns: [], rows: [] },
},
{},
undefined,
Expand All @@ -46,28 +51,118 @@ describe('getLayerMetaInfo', () => {
});

it('should return error in case of missing activeDatasource', () => {
expect(getLayerMetaInfo(undefined, {}, undefined, {}, undefined, capabilities).error).toBe(
'Visualization has no data available to show'
);
expect(
getLayerMetaInfo(
undefined,
{},
createMockVisualization('testVisualization'),
{},
undefined,
{},
undefined,
capabilities
).error
).toBe('Visualization has no data available to show');
});

it('should return error in case of missing datasource configuration/state', () => {
expect(
getLayerMetaInfo(
createMockDatasource('testDatasource'),
undefined,
createMockVisualization('testVisualization'),
{},
{},
{},
undefined,
capabilities
).error
).toBe('Visualization has no data available to show');
});

it('should return error in case of missing configuration/state', () => {
it('should return error in case of missing activeVisualization', () => {
expect(
getLayerMetaInfo(
createMockDatasource('testDatasource'),
{},
undefined,
{},
undefined,
{},
undefined,
capabilities
).error
).toBe('Visualization has no data available to show');
});

it('should return error in case of missing visualization configuration/state', () => {
expect(
getLayerMetaInfo(
createMockDatasource('testDatasource'),
{},
createMockVisualization('testVisualization'),
undefined,
{},
{},
undefined,
capabilities
).error
).toBe('Visualization has no data available to show');
});

it('should ignore the number of datatables passed, rather check the datasource and visualization configuration', () => {
expect(
getLayerMetaInfo(
createMockDatasource('testDatasource', {
getFilters: jest.fn(() => ({
enabled: { kuery: [], lucene: [] },
disabled: { kuery: [], lucene: [] },
})),
}),
{},
createMockVisualization('testVisualization'),
{},
{
datatable1: { type: 'datatable', columns: [], rows: [] },
datatable2: { type: 'datatable', columns: [], rows: [] },
},
{},
undefined,
capabilities
).error
).toBeUndefined();
});

it('should return no multiple layers error when non-data layers are used together with a single data layer', () => {
const mockDatasource = createMockDatasource('testDatasource', {
getFilters: jest.fn(() => ({
enabled: { kuery: [], lucene: [] },
disabled: { kuery: [], lucene: [] },
})),
});
mockDatasource.getLayers.mockReturnValue(['layer1', 'layer2', 'layer3']);
const mockVisualization = createMockVisualization('testVisualization');
let counter = 0;
const layerTypes: LayerType[] = ['data', 'annotations', 'referenceLine'];
mockVisualization.getLayerType.mockImplementation(() => layerTypes[counter++]);
expect(
getLayerMetaInfo(
mockDatasource,
{},
mockVisualization,
{},
{
datatable1: { type: 'datatable', columns: [], rows: [] },
},
{},
undefined,
capabilities
).error
).toBeUndefined();
});

it('should return error in case of a timeshift declared in a column', () => {
const mockDatasource = createMockDatasource('testDatasource');
const updatedPublicAPI: DatasourcePublicAPI = {
datasourceId: 'testDatasource',
const mockDatasource = createMockDatasource('testDatasource', {
getOperationForColumnId: jest.fn(() => ({
dataType: 'number',
isBucketed: false,
Expand All @@ -78,39 +173,33 @@ describe('getLayerMetaInfo', () => {
hasTimeShift: true,
hasReducedTimeRange: true,
})),
getTableSpec: jest.fn(),
getVisualDefaults: jest.fn(),
getSourceId: jest.fn(),
getMaxPossibleNumValues: jest.fn(),
getFilters: jest.fn(),
isTextBasedLanguage: jest.fn(() => false),
hasDefaultTimeField: jest.fn(() => true),
};
mockDatasource.getPublicAPI.mockReturnValue(updatedPublicAPI);
});
expect(
getLayerMetaInfo(createMockDatasource('testDatasource'), {}, {}, {}, undefined, capabilities)
.error
getLayerMetaInfo(
mockDatasource,
{},
createMockVisualization('testVisualization'),
{},
{},
{},
undefined,
capabilities
).error
).toBe('Visualization has no data available to show');
});

it('should return error in case of getFilters returning errors', () => {
const mockDatasource = createMockDatasource('testDatasource');
const updatedPublicAPI: DatasourcePublicAPI = {
const mockDatasource = createMockDatasource('testDatasource', {
datasourceId: 'formBased',
getOperationForColumnId: jest.fn(),
getTableSpec: jest.fn(() => [{ columnId: 'col1', fields: ['bytes'] }]),
getVisualDefaults: jest.fn(),
getSourceId: jest.fn(),
getMaxPossibleNumValues: jest.fn(),
getFilters: jest.fn(() => ({ error: 'filters error' })),
isTextBasedLanguage: jest.fn(() => false),
hasDefaultTimeField: jest.fn(() => true),
};
mockDatasource.getPublicAPI.mockReturnValue(updatedPublicAPI);
});
expect(
getLayerMetaInfo(
mockDatasource,
{}, // the publicAPI has been mocked, so no need for a state here
createMockVisualization('testVisualization'),
{},
{
datatable1: { type: 'datatable', columns: [], rows: [] },
},
Expand All @@ -122,24 +211,18 @@ describe('getLayerMetaInfo', () => {
});

it('should not be visible if discover is not available', () => {
const mockDatasource = createMockDatasource('testDatasource');
const updatedPublicAPI: DatasourcePublicAPI = {
const mockDatasource = createMockDatasource('testDatasource', {
datasourceId: 'indexpattern',
getOperationForColumnId: jest.fn(),
getTableSpec: jest.fn(() => [{ columnId: 'col1', fields: ['bytes'] }]),
getVisualDefaults: jest.fn(),
getSourceId: jest.fn(),
getMaxPossibleNumValues: jest.fn(),
getFilters: jest.fn(() => ({ error: 'filters error' })),
isTextBasedLanguage: jest.fn(() => false),
hasDefaultTimeField: jest.fn(() => true),
};
mockDatasource.getPublicAPI.mockReturnValue(updatedPublicAPI);
});
// both capabilities should be enabled to enable discover
expect(
getLayerMetaInfo(
mockDatasource,
{},
createMockVisualization('testVisualization'),
{},
{
datatable1: { type: 'datatable', columns: [], rows: [] },
},
Expand All @@ -155,6 +238,8 @@ describe('getLayerMetaInfo', () => {
getLayerMetaInfo(
mockDatasource,
{},
createMockVisualization('testVisualization'),
{},
{
datatable1: { type: 'datatable', columns: [], rows: [] },
},
Expand All @@ -169,31 +254,26 @@ describe('getLayerMetaInfo', () => {
});

it('should basically work collecting fields and filters in the visualization', () => {
const mockDatasource = createMockDatasource('testDatasource');
const updatedPublicAPI: DatasourcePublicAPI = {
const mockDatasource = createMockDatasource('testDatasource', {
datasourceId: 'formBased',
getOperationForColumnId: jest.fn(),
getTableSpec: jest.fn(() => [{ columnId: 'col1', fields: ['bytes'] }]),
getVisualDefaults: jest.fn(),
getSourceId: jest.fn(() => '1'),
getMaxPossibleNumValues: jest.fn(),
isTextBasedLanguage: jest.fn(() => false),
getFilters: jest.fn(() => ({
enabled: {
kuery: [[{ language: 'kuery', query: 'memory > 40000' }]],
lucene: [],
},
disabled: { kuery: [], lucene: [] },
})),
hasDefaultTimeField: jest.fn(() => true),
};
mockDatasource.getPublicAPI.mockReturnValue(updatedPublicAPI);
});
const sampleIndexPatternsFromService = {
'1': createMockedIndexPattern(),
};
const { error, meta } = getLayerMetaInfo(
mockDatasource,
{}, // the publicAPI has been mocked, so no need for a state here
createMockVisualization('testVisualization'),
{},
{
datatable1: { type: 'datatable', columns: [], rows: [] },
},
Expand All @@ -220,31 +300,26 @@ describe('getLayerMetaInfo', () => {
});

it('should order date fields first', () => {
const mockDatasource = createMockDatasource('testDatasource');
const updatedPublicAPI: DatasourcePublicAPI = {
const mockDatasource = createMockDatasource('testDatasource', {
datasourceId: 'formBased',
getOperationForColumnId: jest.fn(),
getTableSpec: jest.fn(() => [{ columnId: 'col1', fields: ['bytes', 'timestamp'] }]),
getVisualDefaults: jest.fn(),
getSourceId: jest.fn(() => '1'),
getMaxPossibleNumValues: jest.fn(),
isTextBasedLanguage: jest.fn(() => false),
getFilters: jest.fn(() => ({
enabled: {
kuery: [[{ language: 'kuery', query: 'memory > 40000' }]],
lucene: [],
},
disabled: { kuery: [], lucene: [] },
})),
hasDefaultTimeField: jest.fn(() => true),
};
mockDatasource.getPublicAPI.mockReturnValue(updatedPublicAPI);
});
const sampleIndexPatternsFromService = {
'1': createMockedIndexPattern(),
};
const { meta } = getLayerMetaInfo(
mockDatasource,
{}, // the publicAPI has been mocked, so no need for a state here
createMockVisualization('testVisualization'),
{},
{
datatable1: { type: 'datatable', columns: [], rows: [] },
},
Expand Down

0 comments on commit 11bb6ff

Please sign in to comment.