suggestions.ts 914 B

123456789101112131415161718192021222324252627282930313233
  1. import { VisualizationSuggestionsBuilder, VisualizationSuggestionScore } from '@grafana/data';
  2. import { SuggestionName } from 'app/types/suggestions';
  3. import { Options } from './types';
  4. export class LogsPanelSuggestionsSupplier {
  5. getSuggestionsForData(builder: VisualizationSuggestionsBuilder) {
  6. const list = builder.getListAppender<Options, {}>({
  7. name: '',
  8. pluginId: 'logs',
  9. options: {},
  10. fieldConfig: {
  11. defaults: {
  12. custom: {},
  13. },
  14. overrides: [],
  15. },
  16. });
  17. const { dataSummary: ds } = builder;
  18. // Require a string & time field
  19. if (!ds.hasData || !ds.hasTimeField || !ds.hasStringField) {
  20. return;
  21. }
  22. if (ds.preferredVisualisationType === 'logs') {
  23. list.append({ name: SuggestionName.Logs, score: VisualizationSuggestionScore.Best });
  24. } else {
  25. list.append({ name: SuggestionName.Logs });
  26. }
  27. }
  28. }