Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Embeddable #41361

Merged
merged 82 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
220eefa
[lens] WIP add support for layers
wylieconlon Jul 12, 2019
26601aa
[lens] WIP switch to nested tables
wylieconlon Jul 15, 2019
152bee3
Merge remote-tracking branch 'origin/feature/lens' into lens/layers-t…
wylieconlon Jul 15, 2019
99187a7
add embeddable for lens WIP
flash1293 Jul 16, 2019
ccb6f74
Merge branch 'feature/lens' into lens/embeddable
flash1293 Jul 16, 2019
9fc03e3
work on lens embeddable
flash1293 Jul 16, 2019
84bf126
Get basic layering to work
wylieconlon Jul 16, 2019
63fb14b
Load multiple tables and render in one chart
wylieconlon Jul 16, 2019
5e60930
Merge remote-tracking branch 'origin/feature/lens' into lens/layers-t…
wylieconlon Jul 16, 2019
4aa80f2
Fix priority ordering
wylieconlon Jul 16, 2019
2e6aa45
working on embedding lens vis in dashboard
flash1293 Jul 17, 2019
201a130
continue working on embeddables
flash1293 Jul 17, 2019
d213ef4
clean up embeddable stuff
flash1293 Jul 17, 2019
6b06f76
clean up type errors
flash1293 Jul 17, 2019
8be851e
Merge remote-tracking branch 'origin/feature/lens' into lens/layers-t…
wylieconlon Jul 17, 2019
f78ce1a
Reduce quantity of linting errors
wylieconlon Jul 17, 2019
998cf81
fix test failures
flash1293 Jul 18, 2019
88466b2
rename stuff and clean up
flash1293 Jul 18, 2019
b4e0963
remove unrelated changes
flash1293 Jul 18, 2019
b1443cc
Merge branch 'feature/lens' into lens/embeddable
flash1293 Jul 18, 2019
3c56d84
Merge branch 'lens/layers-toplevel' of https://github.com/wylieconlon…
chrisdavies Jul 18, 2019
6b2454b
Ensure that new xy layer state has a split column
chrisdavies Jul 18, 2019
94c97d7
Make the "add" y / split the trailing accessor
chrisdavies Jul 18, 2019
cbea4e8
Various fixes for datasource public API and implementation
wylieconlon Jul 18, 2019
762bd44
Unify datasource deletion and accessor removal
chrisdavies Jul 18, 2019
6229db6
Merge branch 'lens/layers-toplevel' of https://github.com/wylieconlon…
chrisdavies Jul 18, 2019
5001bf2
Fix broken scss
chrisdavies Jul 18, 2019
e111fdc
Fix xy visualization TypeScript errors?
chrisdavies Jul 18, 2019
dcc243f
Build basic suggestions
wylieconlon Jul 18, 2019
d9e101a
Restore save/load and fix typescript bugs
flash1293 Jul 19, 2019
5d533c0
Merge branch 'lens/layers-toplevel' of github.com:wylieconlon/kibana …
flash1293 Jul 19, 2019
e35bc9f
simplify init routine
flash1293 Jul 19, 2019
cd90a9d
fix save tests
flash1293 Jul 19, 2019
9fac490
fix persistence tests
flash1293 Jul 19, 2019
5b997af
fix state management tests
flash1293 Jul 19, 2019
26bc89c
Ensure the data table is aligned to the top
chrisdavies Jul 19, 2019
cbcb341
Add layer support to Lens datatable
chrisdavies Jul 19, 2019
91c6881
Give xy chart a default layer initially
chrisdavies Jul 19, 2019
e263e4c
Allow deletion of layers in xy charts
chrisdavies Jul 19, 2019
a642a11
xy: Make split accessor singular
chrisdavies Jul 19, 2019
844be81
Change expression type for lens_merge_tables
wylieconlon Jul 19, 2019
142bca2
Fix XY chart rendering expression
wylieconlon Jul 19, 2019
c10b6a1
Fix type errors relating to `layerId` in table suggestions
wylieconlon Jul 19, 2019
542557c
Pass around tables for suggestions with associated layerIds
wylieconlon Jul 19, 2019
c659084
fix tests in workspace panel
flash1293 Jul 22, 2019
42302d6
fix editor_frame tests
flash1293 Jul 22, 2019
9d2ebce
Merge branch 'feature/lens' into lens/embeddable
flash1293 Jul 22, 2019
ad523b0
fix review findings and use context handler for layer compatibility
flash1293 Jul 22, 2019
a6db214
remove blank line
flash1293 Jul 22, 2019
85a7fab
fix typing bug
flash1293 Jul 22, 2019
64b2f58
Fix xy tests, skip inapplicable tests
chrisdavies Jul 22, 2019
f634f51
add some tests for multiple datasources and layers
flash1293 Jul 22, 2019
aaa320d
Merge branch 'lens/layers-toplevel' of github.com:wylieconlon/kibana …
chrisdavies Jul 22, 2019
9fb5e9d
Suggest that split series comes before X axis in XY chart
wylieconlon Jul 22, 2019
19d9a50
Get datatable suggestion working
chrisdavies Jul 22, 2019
ddab6e4
Adjust how xy axis labels are computed
chrisdavies Jul 22, 2019
c368a28
Merge branch 'lens/layers-toplevel' of github.com:wylieconlon/kibana …
chrisdavies Jul 22, 2019
3f25c93
Datasource suggestions should handle layers and have tests
wylieconlon Jul 22, 2019
0ac2c31
Fix linting in XY chart and remove commented code
wylieconlon Jul 22, 2019
61f232b
Update snapshots from earlier change
wylieconlon Jul 22, 2019
f15228a
Merge branch 'feature/lens' into lens/layers-toplevel
wylieconlon Jul 22, 2019
792935e
add comments and check whether reload is actually necessary
flash1293 Jul 23, 2019
a2ad1a4
Fix linting errors
wylieconlon Jul 23, 2019
b629292
More cleanup
wylieconlon Jul 23, 2019
a221e39
Remove commented code
wylieconlon Jul 23, 2019
765e57b
Test the multi-column editor
chrisdavies Jul 23, 2019
616d24c
XY Visualization does not need to track datasourceId
wylieconlon Jul 23, 2019
fdb1197
Fix various comments
chrisdavies Jul 23, 2019
8bdc919
Merge branch 'lens/layers-toplevel' of github.com:wylieconlon/kibana …
chrisdavies Jul 23, 2019
e432c86
Remove unused xy prop
chrisdavies Jul 23, 2019
be5ad16
Use operation labels for XY chart
wylieconlon Jul 23, 2019
6533e90
Adding and removing layers is reflected in the datasource
wylieconlon Jul 23, 2019
74e0ec9
rewrote datasource state init
flash1293 Jul 24, 2019
116d49b
clean up editor_frame frame api implementation
flash1293 Jul 24, 2019
7704e97
clean up editor frame
flash1293 Jul 24, 2019
0b6862b
Merge branch 'lens/layers-toplevel' into lens/embeddable
flash1293 Jul 24, 2019
c42d383
fix linting problems
flash1293 Jul 24, 2019
38d200a
fix typing errors
flash1293 Jul 24, 2019
35bb690
Merge remote-tracking branch 'upstream/feature/lens' into lens/embedd…
flash1293 Jul 24, 2019
03a68b4
fix tests
flash1293 Jul 24, 2019
53bd771
fix multiple index patterns for filter bar and omit series if there i…
flash1293 Jul 24, 2019
e30f734
fix linting error
flash1293 Jul 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const createRenderer = (run: ExpressionRunner): ExpressionRenderer => ({
}
});
}
}, [expression, mountpoint.current]);
}, [expression, mountpoint.current, options.context, options.getInitialContext]);

return (
<div
Expand Down
6 changes: 6 additions & 0 deletions x-pack/legacy/plugins/lens/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
*/

export const PLUGIN_ID = 'lens';

export const BASE_URL = 'app/lens';

export function getEditPath(id: string) {
return `/${BASE_URL}#/edit/${encodeURIComponent(id)}`;
}
7 changes: 4 additions & 3 deletions x-pack/legacy/plugins/lens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Server } from 'hapi';
import { resolve } from 'path';
import { LegacyPluginInitializer } from 'src/legacy/types';
import mappings from './mappings.json';
import { PLUGIN_ID } from './common';
import { PLUGIN_ID, getEditPath } from './common';

const NOT_INTERNATIONALIZED_PRODUCT_NAME = 'Lens Visualizations';

Expand All @@ -26,6 +26,7 @@ export const lens: LegacyPluginInitializer = kibana => {
description: 'Explore and visualize data.',
main: `plugins/${PLUGIN_ID}/index`,
},
embeddableFactories: ['plugins/lens/register_embeddable'],
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
mappings,
visTypes: ['plugins/lens/register_vis_type_alias'],
Expand All @@ -35,7 +36,7 @@ export const lens: LegacyPluginInitializer = kibana => {
isImportableAndExportable: true,
getTitle: (obj: { attributes: { title: string } }) => obj.attributes.title,
getInAppUrl: (obj: { id: string }) => ({
path: `/app/lens#/edit/${encodeURIComponent(obj.id)}`,
path: getEditPath(obj.id),
uiCapabilitiesPath: 'lens.show',
}),
},
Expand Down Expand Up @@ -63,7 +64,7 @@ export const lens: LegacyPluginInitializer = kibana => {
all: [],
read: [],
},
ui: ['show'],
ui: ['save', 'show'],
},
read: {
api: [PLUGIN_ID],
Expand Down
3 changes: 3 additions & 0 deletions x-pack/legacy/plugins/lens/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
},
"state": {
"type": "text"
},
"expression": {
"type": "text"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ describe('editor_frame', () => {
activeDatasourceId: 'testDatasource',
visualizationType: 'testVis',
title: '',
expression: '',
state: {
datasourceStates: {
testDatasource: datasource1State,
testDatasource2: datasource2State,
},
visualization: {},
datasourceMetaData: {
filterableIndexPatterns: [],
},
},
}}
/>
Expand Down Expand Up @@ -341,38 +345,52 @@ describe('editor_frame', () => {
instance.update();

expect(instance.find(expressionRendererMock).prop('expression')).toMatchInlineSnapshot(`
Object {
"chain": Array [
Object {
"arguments": Object {
"layerIds": Array [
"first",
],
"tables": Array [
Object {
"chain": Array [
Object {
"arguments": Object {},
"function": "datasource",
"type": "function",
},
],
"type": "expression",
},
],
Object {
"chain": Array [
Object {
"arguments": Object {},
"function": "kibana",
"type": "function",
},
Object {
"arguments": Object {
"filters": Array [],
"query": Array [],
"timeRange": Array [],
},
"function": "kibana_context",
"type": "function",
},
Object {
"arguments": Object {
"layerIds": Array [
"first",
],
"tables": Array [
Object {
"chain": Array [
Object {
"arguments": Object {},
"function": "datasource",
"type": "function",
},
"function": "lens_merge_tables",
"type": "function",
},
Object {
"arguments": Object {},
"function": "vis",
"type": "function",
},
],
"type": "expression",
}
`);
],
"type": "expression",
},
],
},
"function": "lens_merge_tables",
"type": "function",
},
Object {
"arguments": Object {},
"function": "vis",
"type": "function",
},
],
"type": "expression",
}
`);
});

it('should render individual expression for each given layer', async () => {
Expand All @@ -398,12 +416,16 @@ describe('editor_frame', () => {
activeDatasourceId: 'testDatasource',
visualizationType: 'testVis',
title: '',
expression: '',
state: {
datasourceStates: {
testDatasource: {},
testDatasource2: {},
},
visualization: {},
datasourceMetaData: {
filterableIndexPatterns: [],
},
},
}}
/>
Expand All @@ -416,6 +438,20 @@ describe('editor_frame', () => {
expect(instance.find(expressionRendererMock).prop('expression')).toMatchInlineSnapshot(`
Object {
"chain": Array [
Object {
"arguments": Object {},
"function": "kibana",
"type": "function",
},
Object {
"arguments": Object {
"filters": Array [],
"query": Array [],
"timeRange": Array [],
},
"function": "kibana_context",
"type": "function",
},
Object {
"arguments": Object {
"layerIds": Array [
Expand Down Expand Up @@ -608,12 +644,16 @@ describe('editor_frame', () => {
activeDatasourceId: 'testDatasource',
visualizationType: 'testVis',
title: '',
expression: '',
state: {
datasourceStates: {
testDatasource: {},
testDatasource2: {},
},
visualization: {},
datasourceMetaData: {
filterableIndexPatterns: [],
},
},
}}
/>
Expand Down Expand Up @@ -656,12 +696,16 @@ describe('editor_frame', () => {
activeDatasourceId: 'testDatasource',
visualizationType: 'testVis',
title: '',
expression: '',
state: {
datasourceStates: {
testDatasource: datasource1State,
testDatasource2: datasource2State,
},
visualization: {},
datasourceMetaData: {
filterableIndexPatterns: [],
},
},
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export function EditorFrame(props: EditorFrameProps) {
<nav>
<EuiLink
onClick={() => {
if (activeDatasource && visualization) {
if (state.activeDatasourceId && activeDatasource && visualization) {
save({
activeDatasources: Object.keys(state.datasourceStates).reduce(
(datasourceMap, datasourceId) => ({
Expand All @@ -176,6 +176,8 @@ export function EditorFrame(props: EditorFrameProps) {
state,
redirectTo: props.redirectTo,
store: props.store,
activeDatasourceId: state.activeDatasourceId,
framePublicAPI,
}).catch(onError);
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { TimeRange } from 'ui/timefilter/time_history';
import { Query } from 'src/legacy/core_plugins/data/public';
import { Filter } from '@kbn/es-query';
import { Ast, fromExpression, ExpressionFunctionAST } from '@kbn/interpreter/common';
import { Visualization, Datasource, FramePublicAPI } from '../../types';

Expand Down Expand Up @@ -59,6 +62,39 @@ export function prependDatasourceExpression(
};
}

export function prependKibanaContext(
expression: Ast | string | null,
{
timeRange,
query,
filters,
}: {
timeRange?: TimeRange;
query?: Query;
filters?: Filter[];
}
): Ast | null {
if (!expression) return null;
const parsedExpression = typeof expression === 'string' ? fromExpression(expression) : expression;

return {
type: 'expression',
chain: [
{ type: 'function', function: 'kibana', arguments: {} },
{
type: 'function',
function: 'kibana_context',
arguments: {
timeRange: timeRange ? [JSON.stringify(timeRange)] : [],
query: query ? [JSON.stringify(query)] : [],
filters: filters ? [JSON.stringify(filters)] : [],
},
},
...parsedExpression.chain,
],
};
}

export function buildExpression({
visualization,
visualizationState,
Expand All @@ -83,5 +119,8 @@ export function buildExpression({
}
const visualizationExpression = visualization.toExpression(visualizationState, framePublicAPI);

return prependDatasourceExpression(visualizationExpression, datasourceMap, datasourceStates);
return prependKibanaContext(
prependDatasourceExpression(visualizationExpression, datasourceMap, datasourceStates),
{}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@

import { save, Props } from './save';
import { Action } from './state_management';
import { createMockDatasource } from '../mocks';
import { createMockDatasource, createMockVisualization } from '../mocks';

describe('save editor frame state', () => {
const mockVisualization = createMockVisualization();
mockVisualization.getPersistableState.mockImplementation(x => x);
const mockDatasource = createMockDatasource();
mockDatasource.getPersistableState.mockImplementation(x => x);
const saveArgs: Props = {
dispatch: jest.fn(),
redirectTo: jest.fn(),
activeDatasources: {
indexpattern: {
getPersistableState: x => x,
},
indexpattern: mockDatasource,
},
visualization: { getPersistableState: x => x },
visualization: mockVisualization,
state: {
title: 'aaa',
datasourceStates: {
Expand All @@ -30,6 +32,14 @@ describe('save editor frame state', () => {
saving: false,
visualization: { activeId: '2', state: {} },
},
activeDatasourceId: 'indexpattern',
framePublicAPI: {
addNewLayer: jest.fn(),
removeLayer: jest.fn(),
datasourceLayers: {
first: mockDatasource.publicAPIMock,
},
},
store: {
async save() {
return { id: 'foo' };
Expand Down Expand Up @@ -92,6 +102,10 @@ describe('save editor frame state', () => {
stuff: `${state}_datasource_persisted`,
}));

const visualization = createMockVisualization();
visualization.getPersistableState.mockImplementation(state => ({
things: `${state}_vis_persisted`,
}));
await save({
...saveArgs,
activeDatasources: {
Expand All @@ -110,20 +124,17 @@ describe('save editor frame state', () => {
saving: false,
visualization: { activeId: '3', state: '4' },
},

visualization: {
getPersistableState(state) {
return {
things: `${state}_vis_persisted`,
};
},
},
visualization,
});

expect(store.save).toHaveBeenCalledWith({
activeDatasourceId: 'indexpattern',
id: undefined,
expression: '',
state: {
datasourceMetaData: {
filterableIndexPatterns: [],
},
datasourceStates: {
indexpattern: {
stuff: '2_datasource_persisted',
Expand Down
Loading