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] New sorting feature for the datatable visualization #84435

Merged
merged 20 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2010f76
:sparkles: New sorting feature for the datatable visualization
dej611 Nov 26, 2020
9534f6a
:white_check_mark: Add some unit testing for table storting
dej611 Nov 30, 2020
f92107c
:white_check_mark: Add test for column switch
dej611 Nov 30, 2020
d786a30
Merge branch 'master' into feature/lens/table-sorting
kibanamachine Dec 1, 2020
11135c5
:bug: Fix the dimension removal scenario
dej611 Dec 2, 2020
3877af0
:label: Refactor types for edit events
dej611 Dec 2, 2020
cb5006c
:lipstick: Implement readOnly state for sorting
dej611 Dec 3, 2020
18e925c
Merge remote-tracking branch 'upstream/master' into feature/lens/tabl…
dej611 Dec 3, 2020
ea96b1a
Merge branch 'feature/lens/table-sorting' of github.com:dej611/kibana…
dej611 Dec 3, 2020
81396a4
:white_check_mark: Fix type issue + add test for readOnly mode
dej611 Dec 3, 2020
468005d
:bug: Fix bundle size issue
dej611 Dec 3, 2020
59a2715
:sparkles: Make sorting happen at the expression level
dej611 Dec 3, 2020
a5e1086
:recycle: Refactor edit event flow + vis state updater action
dej611 Dec 4, 2020
fd1e9ba
Merge branch 'master' into feature/lens/table-sorting
kibanamachine Dec 8, 2020
c531447
Merge branch 'master' into feature/lens/table-sorting
kibanamachine Dec 14, 2020
121c701
:fire: Remove IPv4 specific sorting logic for now
dej611 Dec 14, 2020
8014026
:twisted_rightwards_arrows: Merge latest master and fix conflicts
dej611 Dec 14, 2020
406dd81
Update x-pack/plugins/lens/public/editor_frame_service/editor_frame/w…
dej611 Dec 15, 2020
a421bbb
:camera_flash: Update snapshot
dej611 Dec 15, 2020
6f65ab3
:bug: Fix suggestion conflict syntax issue
dej611 Dec 15, 2020
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 103 additions & 3 deletions x-pack/plugins/lens/public/datatable_visualization/expression.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mountWithIntl } from '@kbn/test/jest';
import { datatable, DatatableComponent } from './expression';
import { getDatatable, DatatableComponent } from './expression';
import { LensMultiTable } from '../types';
import { DatatableProps } from './expression';
import { createMockExecutionContext } from '../../../../../src/plugins/expressions/common/mocks';
import { IFieldFormat } from '../../../../../src/plugins/data/public';
import { IAggType } from 'src/plugins/data/public';
import { EmptyPlaceholder } from '../shared_components';
import { LensIconChartDatatable } from '../assets/chart_datatable';
import { EuiBasicTable } from '@elastic/eui';

function sampleArgs() {
const indexPatternId = 'indexPatternId';
Expand Down Expand Up @@ -67,6 +68,8 @@ function sampleArgs() {
title: 'My fanci metric chart',
columns: {
columnIds: ['a', 'b', 'c'],
sortBy: '',
sortDirection: 'none',
type: 'lens_datatable_columns',
},
};
Expand All @@ -76,14 +79,21 @@ function sampleArgs() {

describe('datatable_expression', () => {
let onClickValue: jest.Mock;
let onEditAction: jest.Mock;

beforeEach(() => {
onClickValue = jest.fn();
onEditAction = jest.fn();
});

describe('datatable renders', () => {
test('it renders with the specified data and args', () => {
const { data, args } = sampleArgs();
const result = datatable.fn(data, args, createMockExecutionContext());
const result = getDatatable({ formatFactory: (x) => x as IFieldFormat }).fn(
data,
args,
createMockExecutionContext()
);

expect(result).toEqual({
type: 'render',
Expand All @@ -105,6 +115,7 @@ describe('datatable_expression', () => {
formatFactory={(x) => x as IFieldFormat}
onClickValue={onClickValue}
getType={jest.fn()}
renderMode="edit"
/>
)
).toMatchSnapshot();
Expand All @@ -126,6 +137,7 @@ describe('datatable_expression', () => {
formatFactory={(x) => x as IFieldFormat}
onClickValue={onClickValue}
getType={jest.fn(() => ({ type: 'buckets' } as IAggType))}
renderMode="edit"
/>
);

Expand Down Expand Up @@ -161,6 +173,7 @@ describe('datatable_expression', () => {
formatFactory={(x) => x as IFieldFormat}
onClickValue={onClickValue}
getType={jest.fn(() => ({ type: 'buckets' } as IAggType))}
renderMode="edit"
/>
);

Expand Down Expand Up @@ -214,7 +227,12 @@ describe('datatable_expression', () => {

const args: DatatableProps['args'] = {
title: '',
columns: { columnIds: ['a', 'b'], type: 'lens_datatable_columns' },
columns: {
columnIds: ['a', 'b'],
sortBy: '',
sortDirection: 'none',
type: 'lens_datatable_columns',
},
};

const wrapper = mountWithIntl(
Expand All @@ -230,6 +248,7 @@ describe('datatable_expression', () => {
formatFactory={(x) => x as IFieldFormat}
onClickValue={onClickValue}
getType={jest.fn(() => ({ type: 'buckets' } as IAggType))}
renderMode="edit"
/>
);

Expand Down Expand Up @@ -270,9 +289,90 @@ describe('datatable_expression', () => {
getType={jest.fn((type) =>
type === 'count' ? ({ type: 'metrics' } as IAggType) : ({ type: 'buckets' } as IAggType)
)}
renderMode="edit"
/>
);
expect(component.find(EmptyPlaceholder).prop('icon')).toEqual(LensIconChartDatatable);
});

test('it renders the table with the given sorting', () => {
const { data, args } = sampleArgs();

const wrapper = mountWithIntl(
<DatatableComponent
data={data}
args={{
...args,
columns: {
...args.columns,
sortBy: 'b',
sortDirection: 'desc',
},
}}
formatFactory={(x) => x as IFieldFormat}
onClickValue={onClickValue}
onEditAction={onEditAction}
getType={jest.fn()}
renderMode="edit"
/>
);

// there's currently no way to detect the sorting column via DOM
expect(
wrapper.exists('[className*="isSorted"][data-test-subj="tableHeaderSortButton"]')
).toBe(true);
// check that the sorting is passing the right next state for the same column
wrapper
.find('[className*="isSorted"][data-test-subj="tableHeaderSortButton"]')
.first()
.simulate('click');

expect(onEditAction).toHaveBeenCalledWith({
action: 'sort',
columnId: undefined,
direction: 'none',
});

// check that the sorting is passing the right next state for another column
wrapper
.find('[data-test-subj="tableHeaderSortButton"]')
.not('[className*="isSorted"]')
.first()
.simulate('click');

expect(onEditAction).toHaveBeenCalledWith({
action: 'sort',
columnId: 'a',
direction: 'asc',
});
});

test('it renders the table with the given sorting in readOnly mode', () => {
const { data, args } = sampleArgs();

const wrapper = mountWithIntl(
<DatatableComponent
data={data}
args={{
...args,
columns: {
...args.columns,
sortBy: 'b',
sortDirection: 'desc',
},
}}
formatFactory={(x) => x as IFieldFormat}
onClickValue={onClickValue}
onEditAction={onEditAction}
getType={jest.fn()}
renderMode="display"
/>
);

expect(wrapper.find(EuiBasicTable).prop('sorting')).toMatchObject({
sort: undefined,
allowNeutralSort: true,
});
});
});
});
Loading