Skip to content

Commit

Permalink
[Lens] "Open in Discover" from dashboard (#127355)
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon authored Mar 28, 2022
1 parent 9655416 commit 0ea741d
Show file tree
Hide file tree
Showing 16 changed files with 760 additions and 97 deletions.
2 changes: 1 addition & 1 deletion test/accessibility/apps/dashboard_panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

it('dashboard panel full screen', async () => {
const header = await dashboardPanelActions.getPanelHeading('[Flights] Flight count');
await dashboardPanelActions.toggleContextMenu(header);
await dashboardPanelActions.openContextMenuMorePanel(header);

await testSubjects.click('embeddablePanelAction-togglePanel');
await a11y.testAppSnapshot();
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/discover_enhanced/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"requiredPlugins": ["uiActions", "embeddable", "discover"],
"optionalPlugins": ["share", "usageCollection"],
"configPath": ["xpack", "discoverEnhanced"],
"requiredBundles": ["kibanaUtils", "data"],
"requiredBundles": ["kibanaUtils", "data", "lens"],
"owner": {
"name": "Data Discovery",
"githubTeam": "kibana-data-discovery"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ViewMode, IEmbeddable } from '../../../../../../src/plugins/embeddable/
import { StartServicesGetter } from '../../../../../../src/plugins/kibana_utils/public';
import { CoreStart } from '../../../../../../src/core/public';
import { KibanaLocation } from '../../../../../../src/plugins/share/public';
import { DOC_TYPE as LENS_DOC_TYPE } from '../../../../lens/common/constants';
import * as shared from './shared';

export const ACTION_EXPLORE_DATA = 'ACTION_EXPLORE_DATA';
Expand Down Expand Up @@ -41,6 +42,7 @@ export abstract class AbstractExploreDataAction<Context extends { embeddable?: I

public async isCompatible({ embeddable }: Context): Promise<boolean> {
if (!embeddable) return false;
if (embeddable.type === LENS_DOC_TYPE) return false;

const { core, plugins } = this.params.start();
const { capabilities } = core.application;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/discover_enhanced/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
{ "path": "../../../src/plugins/discover/tsconfig.json" },
{ "path": "../../../src/plugins/share/tsconfig.json" },
{ "path": "../../../src/plugins/kibana_utils/tsconfig.json" },
{ "path": "../lens/tsconfig.json" },
{ "path": "../../../src/plugins/url_forwarding/tsconfig.json" },
{ "path": "../../../src/plugins/usage_collection/tsconfig.json" },
{ "path": "../../../src/plugins/embeddable/tsconfig.json" },
Expand Down
171 changes: 160 additions & 11 deletions x-pack/plugins/lens/public/app_plugin/show_underlying_data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ import { createMockDatasource } from '../mocks';
import { combineQueryAndFilters, getLayerMetaInfo } from './show_underlying_data';
import { Filter } from '@kbn/es-query';
import { DatasourcePublicAPI } from '../types';
import { RecursiveReadonly } from '@kbn/utility-types';
import { Capabilities } from 'kibana/public';

describe('getLayerMetaInfo', () => {
const capabilities = {
navLinks: { discover: true },
discover: { show: true },
} as unknown as RecursiveReadonly<Capabilities>;
};
it('should return error in case of no data', () => {
expect(
getLayerMetaInfo(createMockDatasource('testDatasource'), {}, undefined, capabilities).error
Expand Down Expand Up @@ -85,7 +83,7 @@ describe('getLayerMetaInfo', () => {
{
navLinks: { discover: false },
discover: { show: true },
} as unknown as RecursiveReadonly<Capabilities>
}
).isVisible
).toBeFalsy();
expect(
Expand All @@ -98,7 +96,7 @@ describe('getLayerMetaInfo', () => {
{
navLinks: { discover: true },
discover: { show: false },
} as unknown as RecursiveReadonly<Capabilities>
}
).isVisible
).toBeFalsy();
});
Expand Down Expand Up @@ -178,7 +176,7 @@ describe('combineQueryAndFilters', () => {
undefined
)
).toEqual({
query: { language: 'kuery', query: '( myfield: * ) AND ( otherField: * )' },
query: { language: 'kuery', query: '( ( myfield: * ) AND ( otherField: * ) )' },
filters: [],
});
});
Expand All @@ -198,7 +196,7 @@ describe('combineQueryAndFilters', () => {
},
undefined
)
).toEqual({ query: { language: 'kuery', query: '( otherField: * )' }, filters: [] });
).toEqual({ query: { language: 'kuery', query: 'otherField: *' }, filters: [] });
});

it('should build single kuery expression from meta filters and join using OR and AND at the right level', () => {
Expand Down Expand Up @@ -238,6 +236,7 @@ describe('combineQueryAndFilters', () => {
filters: [],
});
});

it('should assign kuery meta filters to app filters if existing query is using lucene language', () => {
expect(
combineQueryAndFilters(
Expand Down Expand Up @@ -293,6 +292,7 @@ describe('combineQueryAndFilters', () => {
],
});
});

it('should append lucene meta filters to app filters even if existing filters are using kuery', () => {
expect(
combineQueryAndFilters(
Expand Down Expand Up @@ -385,7 +385,7 @@ describe('combineQueryAndFilters', () => {
must: [
{
query_string: {
query: '( anotherField )',
query: 'anotherField',
},
},
],
Expand All @@ -407,6 +407,7 @@ describe('combineQueryAndFilters', () => {
},
});
});

it('should append lucene meta filters to an existing lucene query', () => {
expect(
combineQueryAndFilters(
Expand Down Expand Up @@ -461,10 +462,158 @@ describe('combineQueryAndFilters', () => {
],
query: {
language: 'lucene',
query: '( myField ) AND ( anotherField )',
query: '( ( myField ) AND ( anotherField ) )',
},
});
});

it('should accept multiple queries (and play nice with meta filters)', () => {
const { query, filters } = combineQueryAndFilters(
[
{ language: 'lucene', query: 'myFirstField' },
{ language: 'lucene', query: 'mySecondField' },
{ language: 'kuery', query: 'myThirdField : *' },
],
[],
{
id: 'testDatasource',
columns: [],
filters: {
enabled: {
kuery: [[{ language: 'kuery', query: 'myFourthField : *' }]],
lucene: [[{ language: 'lucene', query: 'myFifthField' }]],
},
disabled: { kuery: [], lucene: [] },
},
},
undefined
);

expect(query).toEqual({
language: 'lucene',
query: '( ( myFirstField ) AND ( mySecondField ) AND ( myFifthField ) )',
});

expect(filters).toEqual([
{
$state: {
store: 'appState',
},
bool: {
filter: [
{
bool: {
filter: [
{
bool: {
minimum_should_match: 1,
should: [
{
exists: {
field: 'myThirdField',
},
},
],
},
},
{
bool: {
minimum_should_match: 1,
should: [
{
exists: {
field: 'myFourthField',
},
},
],
},
},
],
},
},
],
must: [],
must_not: [],
should: [],
},
meta: {
alias: 'Lens context (kuery)',
disabled: false,
index: 'testDatasource',
negate: false,
type: 'custom',
},
},
]);
});

it('should ignore all empty queries', () => {
const emptyQueryAndFilters = {
filters: [],
query: {
language: 'kuery',
query: '',
},
};

expect(
combineQueryAndFilters(
[{ language: 'lucene', query: '' }],
[],
{
id: 'testDatasource',
columns: [],
filters: {
enabled: {
kuery: [[{ language: 'kuery', query: '' }]],
lucene: [],
},
disabled: { kuery: [], lucene: [] },
},
},
undefined
)
).toEqual(emptyQueryAndFilters);

expect(
combineQueryAndFilters(
{ language: 'lucene', query: '' },
[],
{
id: 'testDatasource',
columns: [],
filters: {
enabled: {
kuery: [[{ language: 'kuery', query: '' }]],
lucene: [],
},
disabled: { kuery: [], lucene: [] },
},
},
undefined
)
).toEqual(emptyQueryAndFilters);

expect(
combineQueryAndFilters(
undefined,
[],
{
id: 'testDatasource',
columns: [],
filters: {
enabled: {
kuery: [[{ language: 'kuery', query: '' }]],
lucene: [],
},
disabled: { kuery: [], lucene: [] },
},
},
undefined
)
).toEqual(emptyQueryAndFilters);
});

it('should work for complex cases of nested meta filters', () => {
// scenario overview:
// A kuery query
Expand Down Expand Up @@ -596,7 +745,7 @@ describe('combineQueryAndFilters', () => {
query: {
language: 'kuery',
query:
'( myField: * ) AND ( ( bytes > 4000 ) AND ( ( memory > 5000 ) OR ( memory >= 15000 ) ) AND ( myField: * ) AND ( otherField >= 15 ) )',
'( ( myField: * ) AND ( bytes > 4000 ) AND ( ( memory > 5000 ) OR ( memory >= 15000 ) ) AND ( myField: * ) AND ( otherField >= 15 ) )',
},
});
});
Expand Down Expand Up @@ -796,7 +945,7 @@ describe('combineQueryAndFilters', () => {
],
query: {
language: 'lucene',
query: '( myField ) AND ( anotherField )',
query: '( ( myField ) AND ( anotherField ) )',
},
});
});
Expand Down
Loading

0 comments on commit 0ea741d

Please sign in to comment.