Skip to content

Commit

Permalink
[Lens] fix suggestions api (allow not pass layerId to switch Visualiz…
Browse files Browse the repository at this point in the history
…ationType)
  • Loading branch information
mbondyra committed Oct 15, 2024
1 parent 63e116b commit 948b99e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4214,4 +4214,30 @@ describe('xy_visualization', () => {
`);
});
});
describe('switchVisualizationType', () => {
it('should switch all the layers to the new visualization type if layerId is not specified (AI assistant case)', () => {
const state = exampleState();
state.layers[1] = state.layers[0];
state.layers[1].layerId = 'second';
state.layers[2] = state.layers[0];
state.layers[2].layerId = 'third';
const newType = 'bar';
const newState = xyVisualization.switchVisualizationType!(newType, state);
expect((newState.layers[0] as XYDataLayerConfig).seriesType).toEqual(newType);
expect((newState.layers[1] as XYDataLayerConfig).seriesType).toEqual(newType);
expect((newState.layers[2] as XYDataLayerConfig).seriesType).toEqual(newType);
});
it('should switch only the second layer to the new visualization type if layerId is specified (chart switch case)', () => {
const state = exampleState();
state.layers[1] = { ...state.layers[0] };
state.layers[1].layerId = 'second';
state.layers[2] = { ...state.layers[0] };
state.layers[2].layerId = 'third';
const newType = 'bar';
const newState = xyVisualization.switchVisualizationType!(newType, state, 'first');
expect((newState.layers[0] as XYDataLayerConfig).seriesType).toEqual(newType);
expect((newState.layers[1] as XYDataLayerConfig).seriesType).toEqual('area');
expect((newState.layers[2] as XYDataLayerConfig).seriesType).toEqual('area');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,13 @@ export const getXyVisualization = ({
getDescription,

switchVisualizationType(seriesType: string, state: State, layerId?: string) {
const dataLayer = state.layers.find((l) => l.layerId === layerId);
const dataLayer = state.layers.find((l) => l.layerId === layerId) ?? state.layers[0];
if (dataLayer && !isDataLayer(dataLayer)) {
throw new Error('Cannot switch series type for non-data layer');
}
if (!dataLayer) {
return state;
}
// todo: test how they switch between percentage etc
const currentStackingType = stackingTypes.find(({ subtypes }) =>
subtypes.includes(dataLayer.seriesType)
);
Expand Down

0 comments on commit 948b99e

Please sign in to comment.