getAllSuggestions.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {
  2. PanelData,
  3. VisualizationSuggestion,
  4. VisualizationSuggestionsBuilder,
  5. PanelModel,
  6. VisualizationSuggestionScore,
  7. } from '@grafana/data';
  8. import { config } from '@grafana/runtime';
  9. import { importPanelPlugin } from 'app/features/plugins/importPanelPlugin';
  10. export const panelsToCheckFirst = [
  11. 'timeseries',
  12. 'barchart',
  13. 'gauge',
  14. 'stat',
  15. 'piechart',
  16. 'bargauge',
  17. 'table',
  18. 'state-timeline',
  19. 'status-history',
  20. 'logs',
  21. 'candlestick',
  22. ];
  23. export async function getAllSuggestions(data?: PanelData, panel?: PanelModel): Promise<VisualizationSuggestion[]> {
  24. const builder = new VisualizationSuggestionsBuilder(data, panel);
  25. for (const pluginId of panelsToCheckFirst) {
  26. const plugin = await importPanelPlugin(pluginId);
  27. const supplier = plugin.getSuggestionsSupplier();
  28. if (supplier) {
  29. supplier.getSuggestionsForData(builder);
  30. }
  31. }
  32. const list = builder.getList();
  33. if (builder.dataSummary.fieldCount === 0) {
  34. for (const plugin of Object.values(config.panels)) {
  35. if (!plugin.skipDataQuery || plugin.hideFromList) {
  36. continue;
  37. }
  38. list.push({
  39. name: plugin.name,
  40. pluginId: plugin.id,
  41. description: plugin.info.description,
  42. cardOptions: {
  43. imgSrc: plugin.info.logos.small,
  44. },
  45. });
  46. }
  47. }
  48. return list.sort((a, b) => {
  49. return (b.score ?? VisualizationSuggestionScore.OK) - (a.score ?? VisualizationSuggestionScore.OK);
  50. });
  51. }