Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 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
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
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
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
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
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
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
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/lens/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"visualizationType": {
"type": "keyword"
},
"datasourceType": {
"activeDatasourceId": {
"type": "keyword"
},
"state": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ReactDOM from 'react-dom';
import { i18n } from '@kbn/i18n';
import { EuiBasicTable } from '@elastic/eui';
import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/types';
import { KibanaDatatable } from '../types';
import { KibanaDatatable, LensMultiTable } from '../types';
import { RenderFunction } from '../interpreter_types';

export interface DatatableColumns {
Expand All @@ -22,7 +22,7 @@ interface Args {
}

export interface DatatableProps {
data: KibanaDatatable;
data: LensMultiTable;
args: Args;
}

Expand Down Expand Up @@ -56,7 +56,7 @@ export const datatable: ExpressionFunction<
},
},
context: {
types: ['kibana_datatable'],
types: ['lens_multitable'],
},
fn(data: KibanaDatatable, args: Args) {
return {
Expand Down Expand Up @@ -106,11 +106,6 @@ export const datatableColumns: ExpressionFunction<
},
};

export interface DatatableProps {
data: KibanaDatatable;
args: Args;
}

export const datatableRenderer: RenderFunction<DatatableProps> = {
name: 'lens_datatable_renderer',
displayName: i18n.translate('xpack.lens.datatable.visualizationName', {
Expand All @@ -125,17 +120,20 @@ export const datatableRenderer: RenderFunction<DatatableProps> = {
};

function DatatableComponent(props: DatatableProps) {
const [firstTable] = Object.values(props.data.tables);

return (
<EuiBasicTable
className="lnsDataTable"
columns={props.args.columns.columnIds
.map((id, index) => {
.map((field, index) => {
return {
field: props.args.columns.columnIds[index],
field,
name: props.args.columns.labels[index],
};
})
.filter(({ field }) => !!field)}
items={props.data.rows}
items={firstTable ? firstTable.rows : []}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.lnsDataTable {
align-self: flex-start;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,79 +8,81 @@ import React from 'react';
import { createMockDatasource } from '../editor_frame_plugin/mocks';
import {
DatatableVisualizationState,
DatatableConfigPanel,
datatableVisualization,
DataTableLayer,
} from './visualization';
import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import { Operation, DataType } from '../types';
import { Operation, DataType, FramePublicAPI } from '../types';
import { generateId } from '../id_generator';

jest.mock('../id_generator');

function mockFrame(): FramePublicAPI {
return {
addNewLayer: () => 'aaa',
removeLayer: () => {},
datasourceLayers: {},
};
}

describe('Datatable Visualization', () => {
describe('#initialize', () => {
it('should initialize from the empty state', () => {
const datasource = createMockDatasource();
(generateId as jest.Mock).mockReturnValueOnce('id');
expect(datatableVisualization.initialize(datasource.publicAPIMock)).toEqual({
columns: [{ id: 'id', label: '' }],
expect(datatableVisualization.initialize(mockFrame(), undefined)).toEqual({
layers: [
{
layerId: 'aaa',
columns: ['id'],
},
],
});
});

it('should initialize from a persisted state', () => {
const datasource = createMockDatasource();
const expectedState: DatatableVisualizationState = {
columns: [{ id: 'saved', label: 'label' }],
layers: [
{
layerId: 'foo',
columns: ['saved'],
},
],
};
expect(datatableVisualization.initialize(datasource.publicAPIMock, expectedState)).toEqual(
expectedState
);
expect(datatableVisualization.initialize(mockFrame(), expectedState)).toEqual(expectedState);
});
});

describe('#getPersistableState', () => {
it('should persist the internal state', () => {
const expectedState: DatatableVisualizationState = {
columns: [{ id: 'saved', label: 'label' }],
layers: [
{
layerId: 'baz',
columns: ['a', 'b', 'c'],
},
],
};
expect(datatableVisualization.getPersistableState(expectedState)).toEqual(expectedState);
});
});

describe('DatatableConfigPanel', () => {
it('should update the column label', () => {
const setState = jest.fn();
const wrapper = mount(
<DatatableConfigPanel
dragDropContext={{ dragging: undefined, setDragging: () => {} }}
datasource={createMockDatasource().publicAPIMock}
setState={setState}
state={{ columns: [{ id: 'saved', label: 'label' }] }}
/>
);

const labelEditor = wrapper.find('[data-test-subj="lnsDatatable-columnLabel"]').at(1);

act(() => {
labelEditor.simulate('change', { target: { value: 'New Label' } });
});

expect(setState).toHaveBeenCalledWith({
columns: [{ id: 'saved', label: 'New Label' }],
});
});

it('should allow all operations to be shown', () => {
describe('DataTableLayer', () => {
it('allows all kinds of operations', () => {
const setState = jest.fn();
const datasource = createMockDatasource();
const layer = { layerId: 'a', columns: ['b', 'c'] };

mount(
<DatatableConfigPanel
<DataTableLayer
dragDropContext={{ dragging: undefined, setDragging: () => {} }}
datasource={datasource.publicAPIMock}
frame={{
addNewLayer: jest.fn(),
removeLayer: jest.fn(),
datasourceLayers: { a: datasource.publicAPIMock },
}}
layer={layer}
setState={setState}
state={{ columns: [{ id: 'saved', label: 'label' }] }}
state={{ layers: [layer] }}
/>
);

Expand All @@ -105,52 +107,74 @@ describe('Datatable Visualization', () => {
);
});

it('should remove a column', () => {
it('allows columns to be removed', () => {
const setState = jest.fn();
const wrapper = mount(
<DatatableConfigPanel
const datasource = createMockDatasource();
const layer = { layerId: 'a', columns: ['b', 'c'] };
const component = mount(
<DataTableLayer
dragDropContext={{ dragging: undefined, setDragging: () => {} }}
datasource={createMockDatasource().publicAPIMock}
frame={{
addNewLayer: jest.fn(),
removeLayer: jest.fn(),
datasourceLayers: { a: datasource.publicAPIMock },
}}
layer={layer}
setState={setState}
state={{ columns: [{ id: 'saved', label: '' }, { id: 'second', label: '' }] }}
state={{ layers: [layer] }}
/>
);

act(() => {
wrapper
.find('[data-test-subj="lnsDatatable_dimensionPanelRemove_saved"]')
.first()
.simulate('click');
});
const onRemove = component
.find('[data-test-subj="datatable_multicolumnEditor"]')
.first()
.prop('onRemove') as (k: string) => {};

onRemove('b');

expect(setState).toHaveBeenCalledWith({
columns: [{ id: 'second', label: '' }],
layers: [
{
layerId: 'a',
columns: ['c'],
},
],
});
});

it('should be able to add more columns', () => {
it('allows columns to be added', () => {
(generateId as jest.Mock).mockReturnValueOnce('d');
const setState = jest.fn();
const datasource = createMockDatasource();
const wrapper = mount(
<DatatableConfigPanel
const layer = { layerId: 'a', columns: ['b', 'c'] };
const component = mount(
<DataTableLayer
dragDropContext={{ dragging: undefined, setDragging: () => {} }}
datasource={datasource.publicAPIMock}
frame={{
addNewLayer: jest.fn(),
removeLayer: jest.fn(),
datasourceLayers: { a: datasource.publicAPIMock },
}}
layer={layer}
setState={setState}
state={{ columns: [{ id: 'saved', label: 'label' }] }}
state={{ layers: [layer] }}
/>
);

(generateId as jest.Mock).mockReturnValueOnce('newId');
const onAdd = component
.find('[data-test-subj="datatable_multicolumnEditor"]')
.first()
.prop('onAdd') as () => {};

act(() => {
wrapper
.find('[data-test-subj="lnsDatatable_dimensionPanel_add"]')
.first()
.simulate('click');
});
onAdd();

expect(setState).toHaveBeenCalledWith({
columns: [{ id: 'saved', label: 'label' }, { id: 'newId', label: '' }],
layers: [
{
layerId: 'a',
columns: ['b', 'c', 'd'],
},
],
});
});
});
Expand Down
Loading