Skip to content

Commit

Permalink
fix chart switching and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon committed Oct 21, 2022
1 parent 1be28b7 commit 1c7fd1b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,24 @@ describe('IndexPattern Data Source', () => {
describe('#removeLayer', () => {
it('should remove a layer', () => {
expect(TextBasedDatasource.removeLayer(baseState, 'a')).toEqual({
...baseState,
layers: {
a: {
columns: [],
allColumns: [
{
columnId: 'col1',
fieldName: 'Test 1',
meta: {
type: 'number',
removedLayerIds: ['a'],
newState: {
...baseState,
layers: {
a: {
columns: [],
allColumns: [
{
columnId: 'col1',
fieldName: 'Test 1',
meta: {
type: 'number',
},
},
},
],
query: { sql: 'SELECT * FROM foo' },
index: 'foo',
],
query: { sql: 'SELECT * FROM foo' },
index: 'foo',
},
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ describe('chart_switch', () => {

switchTo('visB', instance);
expect(datasourceMap.testDatasource.removeLayer).toHaveBeenCalledWith({}, 'a');
expect(datasourceMap.testDatasource.removeLayer).toHaveBeenCalledWith(undefined, 'b');
expect(datasourceMap.testDatasource.removeLayer).toHaveBeenCalledWith(undefined, 'c');
expect(datasourceMap.testDatasource.removeLayer).toHaveBeenCalledWith({}, 'b');
expect(datasourceMap.testDatasource.removeLayer).toHaveBeenCalledWith({}, 'c');
expect(visualizationMap.visB.getSuggestions).toHaveBeenCalledWith(
expect.objectContaining({
keptLayerIds: ['a'],
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/lens/public/mocks/datasource_mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function createMockDatasource(id: string): DatasourceMock {

return {
id: 'testDatasource',
clearLayer: jest.fn((state, _layerId) => state),
clearLayer: jest.fn((state, _layerId) => ({ newState: state, removedLayerIds: [] })),
getDatasourceSuggestionsForField: jest.fn((_state, _item, filterFn, _indexPatterns) => []),
getDatasourceSuggestionsForVisualizeField: jest.fn(
(_state, _indexpatternId, _fieldName, _indexPatterns) => []
Expand All @@ -44,7 +44,7 @@ export function createMockDatasource(id: string): DatasourceMock {
renderLayerPanel: jest.fn(),
toExpression: jest.fn((_frame, _state, _indexPatterns) => null),
insertLayer: jest.fn((_state, _newLayerId) => ({})),
removeLayer: jest.fn((_state, _layerId) => {}),
removeLayer: jest.fn((state, layerId) => ({ newState: state, removedLayerIds: [layerId] })),
cloneLayer: jest.fn((_state, _layerId, _newLayerId, getNewId) => {}),
removeColumn: jest.fn((props) => {}),
getLayers: jest.fn((_state) => []),
Expand Down
9 changes: 6 additions & 3 deletions x-pack/plugins/lens/public/state_management/lens_slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,9 +996,12 @@ export const makeLensReducer = (storeDeps: LensStoreDeps) => {
);
}) ?? [];
if (layerDatasourceId) {
state.datasourceStates[layerDatasourceId].state = datasourceMap[
layerDatasourceId
].removeLayer(current(state).datasourceStates[layerDatasourceId].state, layerId);
const { newState } = datasourceMap[layerDatasourceId].removeLayer(
current(state).datasourceStates[layerDatasourceId].state,
layerId
);
state.datasourceStates[layerDatasourceId].state = newState;
// TODO - call removeLayer for any extra (linked) layers removed by the datasource
}
});
},
Expand Down

0 comments on commit 1c7fd1b

Please sign in to comment.