Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -72,6 +72,12 @@ jest.mock('../components/visualizations/visualization_builder_utils', () => ({
findRuleByIndex: jest.fn().mockReturnValue({
toExpression: jest.fn(),
}),
adaptLegacyData: jest.fn().mockReturnValue({ useThresholdColor: true }),
getColumnsByAxesMapping: jest.fn().mockReturnValue({
numericalColumns: [],
categoricalColumns: [],
dateColumns: [],
}),
}));

describe('ExploreEmbeddable', () => {
Expand Down Expand Up @@ -507,4 +513,31 @@ describe('ExploreEmbeddable', () => {
expect(embeddable.getOutput().error).toBeUndefined();
expect(embeddable.getOutput().loading).toBe(false);
});

test('should be able to adapt deprecated styles', async () => {
jest.spyOn(visualizationRegistry, 'findRuleByAxesMapping').mockReturnValueOnce({
id: 'test-rule',
name: 'Test Rule',
matches: jest.fn(),
chartTypes: [{ type: 'line', priority: 100, name: 'Line Chart', icon: '' }],
toSpec: jest.fn(),
});

const adaptLegacyDataSpy = jest.spyOn(
await import('../components/visualizations/visualization_builder_utils'),
'adaptLegacyData'
);

mockSavedExplore.visualization = JSON.stringify({
chartType: 'line',
axesMapping: { x: 'field1', y: 'field2' },
thresholdLines: [], // deprecated style
});
mockSavedExplore.uiState = JSON.stringify({ activeTab: 'visualization' });

// @ts-ignore
await embeddable.fetch();

expect(adaptLegacyDataSpy).toHaveBeenCalled();
});
});
14 changes: 12 additions & 2 deletions src/plugins/explore/public/embeddable/explore_embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ import {
StyleOptions,
} from '../components/visualizations/utils/use_visualization_types';
import { defaultPrepareQueryString } from '../application/utils/state_management/actions/query_actions';
import { convertStringsToMappings } from '../components/visualizations/visualization_builder_utils';
import {
adaptLegacyData,
convertStringsToMappings,
} from '../components/visualizations/visualization_builder_utils';
import { normalizeResultRows } from '../components/visualizations/utils/normalize_result_rows';
import { visualizationRegistry } from '../components/visualizations/visualization_registry';
import { getQueryWithSource } from '../application/utils/languages';
Expand Down Expand Up @@ -401,12 +404,19 @@ export class ExploreEmbeddable
};
this.searchProps.searchContext = searchContext;
const styleOptions = visualization.params;

const styles = adaptLegacyData({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we need to update searchProps.styleOptions as well?

Copy link
Contributor Author

@Qxisylolo Qxisylolo Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only table needs searchProps.styleOptions when rendering embeddable currently which doesn't need to adapt legacy data. but I will include this as table will use value mapping in the future and we may need to migrate some data. thanks!

type: selectedChartType,
styles: styleOptions,
axesMapping: visualization.axesMapping,
})?.styles;

const spec = matchedRule.toSpec(
visualizationData.transformedData,
numericalColumns,
categoricalColumns,
dateColumns,
styleOptions,
styles || styleOptions,
selectedChartType,
axesMapping
);
Expand Down
Loading