-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Lens] Trigger a filter action on click in datatable visualization #63840
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
Merged
wylieconlon
merged 23 commits into
elastic:master
from
mbondyra:lens/clicking-datatable-filter
Apr 30, 2020
Merged
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
be57365
wip: datatable
mbondyra 7475198
fix: empty values
mbondyra a6183a6
fix: empty values
mbondyra abe63e1
translations
mbondyra 093c6c7
using dataPlugin to get buckets
mbondyra af89e27
one more time, passing aggs data
mbondyra 9647389
tests: added
mbondyra d6a65bc
feat: new design applied
mbondyra 632e096
remove icon
mbondyra a57d980
feat: old design
mbondyra e4c85bc
Merge branch 'master' into lens/clicking-datatable-filter
elasticmachine 7d3d93a
CR corrections
mbondyra badca7d
better name
mbondyra 6a94994
Merge remote-tracking branch 'origin/master' into datatable-click
wylieconlon fb8c322
Merge remote-tracking branch 'origin/master' into datatable-click
wylieconlon 1615f23
Fix merge issue
wylieconlon 594210d
fix: design changes
mbondyra 35deebb
feat: correction
mbondyra 3e9b878
Merge branch 'master' into lens/clicking-datatable-filter
elasticmachine dab164a
fix: copy changes
mbondyra 47d0e1b
Update x-pack/plugins/lens/public/datatable_visualization/_visualizat…
mbondyra 1dcdfa2
Update _visualization.scss
mbondyra ea231fb
Merge remote-tracking branch 'origin/master' into datatable-click
wylieconlon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
x-pack/plugins/lens/public/datatable_visualization/__snapshots__/expression.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
x-pack/plugins/lens/public/datatable_visualization/_visualization.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,14 @@ | ||||||||
| .lnsDataTable { | ||||||||
| align-self: flex-start; | ||||||||
| } | ||||||||
|
|
||||||||
| .lnsDataTable__filter { | ||||||||
| opacity: 0; | ||||||||
| transition: opacity 250ms ease-in-out; | ||||||||
| } | ||||||||
|
|
||||||||
| .lnsDataTable__cell:hover { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The icons need to reveal on focus as well.
Suggested change
|
||||||||
| .lnsDataTable__filter { | ||||||||
| opacity: 1; | ||||||||
| } | ||||||||
| } | ||||||||
156 changes: 156 additions & 0 deletions
156
x-pack/plugins/lens/public/datatable_visualization/expression.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import { shallow } from 'enzyme'; | ||
| import { mountWithIntl } from 'test_utils/enzyme_helpers'; | ||
| import { datatable, 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'; | ||
| const executeTriggerActions = jest.fn(); | ||
|
|
||
| function sampleArgs() { | ||
| const data: LensMultiTable = { | ||
| type: 'lens_multitable', | ||
| tables: { | ||
| l1: { | ||
| type: 'kibana_datatable', | ||
| columns: [ | ||
| { id: 'a', name: 'a', meta: { type: 'count' } }, | ||
| { id: 'b', name: 'b', meta: { type: 'date_histogram', aggConfigParams: { field: 'b' } } }, | ||
| { id: 'c', name: 'c', meta: { type: 'cardinality' } }, | ||
| ], | ||
| rows: [{ a: 10110, b: 1588024800000, c: 3 }], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const args: DatatableProps['args'] = { | ||
| title: 'My fanci metric chart', | ||
| columns: { | ||
| columnIds: ['a', 'b', 'c'], | ||
| type: 'lens_datatable_columns', | ||
| }, | ||
| }; | ||
|
|
||
| return { data, args }; | ||
| } | ||
|
|
||
| describe('datatable_expression', () => { | ||
| describe('datatable renders', () => { | ||
| test('it renders with the specified data and args', () => { | ||
| const { data, args } = sampleArgs(); | ||
| const result = datatable.fn(data, args, createMockExecutionContext()); | ||
|
|
||
| expect(result).toEqual({ | ||
| type: 'render', | ||
| as: 'lens_datatable_renderer', | ||
| value: { data, args }, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('DatatableComponent', () => { | ||
| test('it renders the title and value', () => { | ||
| const { data, args } = sampleArgs(); | ||
|
|
||
| expect( | ||
| shallow( | ||
| <DatatableComponent | ||
| data={data} | ||
| args={args} | ||
| formatFactory={x => x as IFieldFormat} | ||
| executeTriggerActions={executeTriggerActions} | ||
| getType={jest.fn()} | ||
| /> | ||
| ) | ||
| ).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('it invokes executeTriggerActions with correct context on click on top value', () => { | ||
| const { args, data } = sampleArgs(); | ||
|
|
||
| const wrapper = mountWithIntl( | ||
| <DatatableComponent | ||
| data={{ | ||
| ...data, | ||
| dateRange: { | ||
| fromDate: new Date('2020-04-20T05:00:00.000Z'), | ||
| toDate: new Date('2020-05-03T05:00:00.000Z'), | ||
| }, | ||
| }} | ||
| args={args} | ||
| formatFactory={x => x as IFieldFormat} | ||
| executeTriggerActions={executeTriggerActions} | ||
| getType={jest.fn(() => ({ type: 'buckets' } as IAggType))} | ||
| /> | ||
| ); | ||
|
|
||
| wrapper | ||
| .find('[data-test-subj="lensDatatableFilterOut"]') | ||
| .first() | ||
| .simulate('click'); | ||
|
|
||
| expect(executeTriggerActions).toHaveBeenCalledWith('VALUE_CLICK_TRIGGER', { | ||
| data: { | ||
| data: [ | ||
| { | ||
| column: 0, | ||
| row: 0, | ||
| table: data.tables.l1, | ||
| value: 10110, | ||
| }, | ||
| ], | ||
| negate: true, | ||
| }, | ||
| timeFieldName: undefined, | ||
| }); | ||
| }); | ||
|
|
||
| test('it invokes executeTriggerActions with correct context on click on timefield', () => { | ||
| const { args, data } = sampleArgs(); | ||
|
|
||
| const wrapper = mountWithIntl( | ||
| <DatatableComponent | ||
| data={{ | ||
| ...data, | ||
| dateRange: { | ||
| fromDate: new Date('2020-04-20T05:00:00.000Z'), | ||
| toDate: new Date('2020-05-03T05:00:00.000Z'), | ||
| }, | ||
| }} | ||
| args={args} | ||
| formatFactory={x => x as IFieldFormat} | ||
| executeTriggerActions={executeTriggerActions} | ||
| getType={jest.fn(() => ({ type: 'buckets' } as IAggType))} | ||
| /> | ||
| ); | ||
|
|
||
| wrapper | ||
| .find('[data-test-subj="lensDatatableFilterFor"]') | ||
| .at(3) | ||
| .simulate('click'); | ||
|
|
||
| expect(executeTriggerActions).toHaveBeenCalledWith('VALUE_CLICK_TRIGGER', { | ||
| data: { | ||
| data: [ | ||
| { | ||
| column: 1, | ||
| row: 0, | ||
| table: data.tables.l1, | ||
| value: 1588024800000, | ||
| }, | ||
| ], | ||
| negate: false, | ||
| }, | ||
| timeFieldName: 'b', | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other tables don't seem to have a transition on the tooltip, why add this?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Styles are aligned with inspector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.