mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Suggestions: Prioritize preferred visualizations for suggestion list (#67326)
Prioritize preferred visualizations for suggestion list.
This commit is contained in:
@@ -338,6 +338,29 @@ scenario('Given default loki logs data', (ctx) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
scenario('Given a preferredVisualisationType', (ctx) => {
|
||||||
|
ctx.setData([
|
||||||
|
toDataFrame({
|
||||||
|
meta: {
|
||||||
|
preferredVisualisationType: 'table',
|
||||||
|
},
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'Trace Id',
|
||||||
|
type: FieldType.number,
|
||||||
|
values: [1, 2, 3],
|
||||||
|
config: {},
|
||||||
|
},
|
||||||
|
{ name: 'Trace Group', type: FieldType.string, values: ['traceGroup1', 'traceGroup2', 'traceGroup3'] },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
it('should return the preferred visualization first', () => {
|
||||||
|
expect(ctx.names()[0]).toEqual(SuggestionName.Table);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function repeatFrame(count: number, frame: DataFrame): DataFrame[] {
|
function repeatFrame(count: number, frame: DataFrame): DataFrame[] {
|
||||||
const frames: DataFrame[] = [];
|
const frames: DataFrame[] = [];
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
|
|||||||
@@ -54,6 +54,14 @@ export async function getAllSuggestions(data?: PanelData, panel?: PanelModel): P
|
|||||||
}
|
}
|
||||||
|
|
||||||
return list.sort((a, b) => {
|
return list.sort((a, b) => {
|
||||||
|
if (builder.dataSummary.preferredVisualisationType) {
|
||||||
|
if (a.pluginId === builder.dataSummary.preferredVisualisationType) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (b.pluginId === builder.dataSummary.preferredVisualisationType) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
return (b.score ?? VisualizationSuggestionScore.OK) - (a.score ?? VisualizationSuggestionScore.OK);
|
return (b.score ?? VisualizationSuggestionScore.OK) - (a.score ?? VisualizationSuggestionScore.OK);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user