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] Fixes bug with removing layer with trendline #143723

Merged
merged 3 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,29 @@ describe('IndexPattern Data Source', () => {
},
});
});

it('should remove linked layers', () => {
const state = {
layers: {
first: {
indexPatternId: '1',
columnOrder: [],
columns: {},
},
second: {
indexPatternId: '2',
columnOrder: [],
columns: {},
linkToLayers: ['first'],
},
},
currentIndexPatternId: '1',
};
expect(FormBasedDatasource.removeLayer(state, 'first')).toEqual({
...state,
layers: {},
});
});
});

describe('#createEmptyLayer', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ export function getFormBasedDatasource({
const newLayers = { ...state.layers };
delete newLayers[layerId];

// delete layers linked to this layer
Object.keys(newLayers).forEach((id) => {
const linkedLayers = newLayers[id]?.linkToLayers;
if (linkedLayers && linkedLayers.includes(layerId)) {
delete newLayers[id];
}
});

return {
...state,
layers: newLayers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,16 @@ describe('metric visualization', () => {
`);
});

it('removes all accessors from a layer', () => {
const chk = visualization.removeLayer!(fullState, 'first');
expect(chk.metricAccessor).toBeUndefined();
expect(chk.trendlineLayerId).toBeUndefined();
expect(chk.trendlineLayerType).toBeUndefined();
expect(chk.trendlineMetricAccessor).toBeUndefined();
expect(chk.trendlineTimeAccessor).toBeUndefined();
expect(chk.trendlineBreakdownByAccessor).toBeUndefined();
});

it('appends a trendline layer', () => {
const newLayerId = 'new-layer-id';
const chk = visualization.appendLayer!(fullState, newLayerId, 'metricTrendline', '');
Expand All @@ -767,6 +777,7 @@ describe('metric visualization', () => {

it('removes trendline layer', () => {
const chk = visualization.removeLayer!(fullStateWTrend, fullStateWTrend.trendlineLayerId);
expect(chk.metricAccessor).toBe('metric-col-id');
expect(chk.trendlineLayerId).toBeUndefined();
expect(chk.trendlineLayerType).toBeUndefined();
expect(chk.trendlineMetricAccessor).toBeUndefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,10 @@ export const getMetricVisualization = ({
return { ...state, trendlineLayerId: layerId, trendlineLayerType: layerType };
},

removeLayer(state) {
removeLayer(state, layerId) {
const newState: MetricVisualizationState = {
...state,
...(state.layerId === layerId && { metricAccessor: undefined }),
trendlineLayerId: undefined,
trendlineLayerType: undefined,
trendlineMetricAccessor: undefined,
Expand Down