-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Allow visualizations to provide a dimension editor #67560
Merged
wylieconlon
merged 11 commits into
elastic:master
from
wylieconlon:lens/extra-dimension-panel
Jun 1, 2020
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4bee7a1
[Lens] Allow visualizations to provide a dimension editor
wylieconlon 5b89017
Merge branch 'master' into lens/extra-dimension-panel
elasticmachine f196c88
Update to tab style
wylieconlon a81f9ff
Merge branch 'lens/extra-dimension-panel' of github.com:wylieconlon/k…
wylieconlon 4aecbda
Remove table update
wylieconlon 247e713
Update class name
wylieconlon 810d7cc
Merge remote-tracking branch 'origin/master' into lens/extra-dimensio…
wylieconlon 7658cf1
typecheck fix
mbondyra 582105c
Add test
wylieconlon 8b1787b
Require each dimension group to enable editor
wylieconlon 6833b1c
Merge remote-tracking branch 'origin/master' into lens/extra-dimensio…
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
This file contains 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 |
---|---|---|
|
@@ -31,3 +31,6 @@ | |
min-height: $euiSizeXXL; | ||
} | ||
|
||
.lnsVisualizationDimensionEditor { | ||
width: $euiSize * 28; | ||
} |
This file contains 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
273 changes: 273 additions & 0 deletions
273
...k/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.test.tsx
This file contains 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,273 @@ | ||
/* | ||
* 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 { act } from 'react-dom/test-utils'; | ||
import { | ||
createMockVisualization, | ||
createMockFramePublicAPI, | ||
createMockDatasource, | ||
DatasourceMock, | ||
} from '../../mocks'; | ||
import { EuiFormRow, EuiPopover } from '@elastic/eui'; | ||
import { mount } from 'enzyme'; | ||
import { mountWithIntl } from 'test_utils/enzyme_helpers'; | ||
import { Visualization } from '../../../types'; | ||
import { LayerPanel } from './layer_panel'; | ||
import { coreMock } from 'src/core/public/mocks'; | ||
import { generateId } from '../../../id_generator'; | ||
|
||
jest.mock('../../../id_generator'); | ||
|
||
describe('LayerPanel', () => { | ||
let mockVisualization: jest.Mocked<Visualization>; | ||
let mockDatasource: DatasourceMock; | ||
|
||
function getDefaultProps() { | ||
const frame = createMockFramePublicAPI(); | ||
frame.datasourceLayers = { | ||
first: mockDatasource.publicAPIMock, | ||
}; | ||
return { | ||
layerId: 'first', | ||
activeVisualizationId: 'vis1', | ||
visualizationMap: { | ||
vis1: mockVisualization, | ||
}, | ||
activeDatasourceId: 'ds1', | ||
datasourceMap: { | ||
ds1: mockDatasource, | ||
}, | ||
datasourceStates: { | ||
ds1: { | ||
isLoading: false, | ||
state: 'state', | ||
}, | ||
}, | ||
visualizationState: 'state', | ||
updateVisualization: jest.fn(), | ||
updateDatasource: jest.fn(), | ||
updateAll: jest.fn(), | ||
framePublicAPI: frame, | ||
isOnlyLayer: true, | ||
onRemoveLayer: jest.fn(), | ||
dispatch: jest.fn(), | ||
core: coreMock.createStart(), | ||
}; | ||
} | ||
|
||
beforeEach(() => { | ||
mockVisualization = { | ||
...createMockVisualization(), | ||
id: 'testVis', | ||
visualizationTypes: [ | ||
{ | ||
icon: 'empty', | ||
id: 'testVis', | ||
label: 'TEST1', | ||
}, | ||
], | ||
}; | ||
|
||
mockVisualization.getLayerIds.mockReturnValue(['first']); | ||
mockDatasource = createMockDatasource('ds1'); | ||
}); | ||
|
||
it('should fail to render if the public API is out of date', () => { | ||
const props = getDefaultProps(); | ||
props.framePublicAPI.datasourceLayers = {}; | ||
const component = mountWithIntl(<LayerPanel {...props} />); | ||
expect(component.isEmptyRender()).toBe(true); | ||
}); | ||
|
||
it('should fail to render if the active visualization is missing', () => { | ||
const component = mountWithIntl( | ||
<LayerPanel {...getDefaultProps()} activeVisualizationId="missing" /> | ||
); | ||
expect(component.isEmptyRender()).toBe(true); | ||
}); | ||
|
||
describe('layer reset and remove', () => { | ||
it('should show the reset button when single layer', () => { | ||
const component = mountWithIntl(<LayerPanel {...getDefaultProps()} />); | ||
expect(component.find('[data-test-subj="lns_layer_remove"]').first().text()).toContain( | ||
'Reset layer' | ||
); | ||
}); | ||
|
||
it('should show the delete button when multiple layers', () => { | ||
const component = mountWithIntl(<LayerPanel {...getDefaultProps()} isOnlyLayer={false} />); | ||
expect(component.find('[data-test-subj="lns_layer_remove"]').first().text()).toContain( | ||
'Delete layer' | ||
); | ||
}); | ||
|
||
it('should call the clear callback', () => { | ||
const cb = jest.fn(); | ||
const component = mountWithIntl(<LayerPanel {...getDefaultProps()} onRemoveLayer={cb} />); | ||
act(() => { | ||
component.find('[data-test-subj="lns_layer_remove"]').first().simulate('click'); | ||
}); | ||
expect(cb).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('single group', () => { | ||
it('should render the non-editable state', () => { | ||
mockVisualization.getConfiguration.mockReturnValue({ | ||
groups: [ | ||
{ | ||
groupLabel: 'A', | ||
groupId: 'a', | ||
accessors: ['x'], | ||
filterOperations: () => true, | ||
supportsMoreColumns: false, | ||
dataTestSubj: 'lnsGroup', | ||
}, | ||
], | ||
}); | ||
|
||
const component = mountWithIntl(<LayerPanel {...getDefaultProps()} />); | ||
|
||
const group = component.find('DragDrop[data-test-subj="lnsGroup"]'); | ||
expect(group).toHaveLength(1); | ||
}); | ||
|
||
it('should render the group with a way to add a new column', () => { | ||
mockVisualization.getConfiguration.mockReturnValue({ | ||
groups: [ | ||
{ | ||
groupLabel: 'A', | ||
groupId: 'a', | ||
accessors: [], | ||
filterOperations: () => true, | ||
supportsMoreColumns: true, | ||
dataTestSubj: 'lnsGroup', | ||
}, | ||
], | ||
}); | ||
|
||
const component = mountWithIntl(<LayerPanel {...getDefaultProps()} />); | ||
|
||
const group = component.find('DragDrop[data-test-subj="lnsGroup"]'); | ||
expect(group).toHaveLength(1); | ||
}); | ||
|
||
it('should render the required warning when only one group is configured', () => { | ||
mockVisualization.getConfiguration.mockReturnValue({ | ||
groups: [ | ||
{ | ||
groupLabel: 'A', | ||
groupId: 'a', | ||
accessors: ['x'], | ||
filterOperations: () => true, | ||
supportsMoreColumns: false, | ||
dataTestSubj: 'lnsGroup', | ||
}, | ||
{ | ||
groupLabel: 'B', | ||
groupId: 'b', | ||
accessors: [], | ||
filterOperations: () => true, | ||
supportsMoreColumns: true, | ||
dataTestSubj: 'lnsGroup', | ||
required: true, | ||
}, | ||
], | ||
}); | ||
|
||
const component = mountWithIntl(<LayerPanel {...getDefaultProps()} />); | ||
|
||
const group = component | ||
.find(EuiFormRow) | ||
.findWhere((e) => e.prop('error') === 'Required dimension'); | ||
expect(group).toHaveLength(1); | ||
}); | ||
|
||
it('should render the datasource and visualization panels inside the dimension popover', () => { | ||
mockVisualization.getConfiguration.mockReturnValueOnce({ | ||
groups: [ | ||
{ | ||
groupLabel: 'A', | ||
groupId: 'a', | ||
accessors: ['newid'], | ||
filterOperations: () => true, | ||
supportsMoreColumns: false, | ||
dataTestSubj: 'lnsGroup', | ||
}, | ||
], | ||
}); | ||
mockVisualization.renderDimensionEditor = jest.fn(); | ||
|
||
const component = mountWithIntl(<LayerPanel {...getDefaultProps()} />); | ||
|
||
const group = component.find('DimensionPopover'); | ||
const panel = mount(group.prop('panel')); | ||
|
||
expect(panel.find('NativeRenderer')).toHaveLength(2); | ||
expect(mockDatasource.renderDimensionEditor).toHaveBeenCalledWith( | ||
expect.any(Element), | ||
expect.objectContaining({ | ||
columnId: 'newid', | ||
}) | ||
); | ||
expect(mockVisualization.renderDimensionEditor).toHaveBeenCalledWith( | ||
expect.any(Element), | ||
expect.objectContaining({ | ||
groupId: 'a', | ||
accessor: 'newid', | ||
}) | ||
); | ||
}); | ||
|
||
it('should keep the popover open when configuring a new dimension', () => { | ||
/** | ||
* The ID generation system for new dimensions has been messy before, so | ||
* this tests that the ID used in the first render is used to keep the popover | ||
* open in future renders | ||
*/ | ||
(generateId as jest.Mock).mockReturnValueOnce(`newid`); | ||
(generateId as jest.Mock).mockReturnValueOnce(`bad`); | ||
mockVisualization.getConfiguration.mockReturnValueOnce({ | ||
groups: [ | ||
{ | ||
groupLabel: 'A', | ||
groupId: 'a', | ||
accessors: [], | ||
filterOperations: () => true, | ||
supportsMoreColumns: true, | ||
dataTestSubj: 'lnsGroup', | ||
}, | ||
], | ||
}); | ||
// Normally the configuration would change in response to a state update, | ||
// but this test is updating it directly | ||
mockVisualization.getConfiguration.mockReturnValueOnce({ | ||
groups: [ | ||
{ | ||
groupLabel: 'A', | ||
groupId: 'a', | ||
accessors: ['newid'], | ||
filterOperations: () => true, | ||
supportsMoreColumns: false, | ||
dataTestSubj: 'lnsGroup', | ||
}, | ||
], | ||
}); | ||
|
||
const component = mountWithIntl(<LayerPanel {...getDefaultProps()} />); | ||
|
||
const group = component.find('DimensionPopover'); | ||
const triggerButton = mountWithIntl(group.prop('trigger')); | ||
act(() => { | ||
triggerButton.find('[data-test-subj="lns-empty-dimension"]').first().simulate('click'); | ||
}); | ||
component.update(); | ||
|
||
expect(component.find(EuiPopover).prop('isOpen')).toBe(true); | ||
}); | ||
}); | ||
}); |
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.
I don't understand this test. Could you explain? 🙏
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.
It's testing another one of the edge cases in rendering, where the known layers don't match. This tests that when rendering layer
first
without any information about that ID, it doesn't throw errors.