AnalyticsStatsTab.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React from 'react';
  2. import AutoSizer from 'react-virtualized-auto-sizer';
  3. import { FieldType } from '@grafana/data';
  4. import { Themeable2, withTheme2 } from '@grafana/ui';
  5. import { DashboardModel } from 'app/features/dashboard/state';
  6. import { DashboardDailySummaryDTO } from '../api';
  7. import { AnalyticsTab } from './AnalyticsTab';
  8. export interface Props extends Themeable2 {
  9. dashboard: DashboardModel;
  10. dailySummaries: DashboardDailySummaryDTO[];
  11. }
  12. class AnalyticsStatsTab extends AnalyticsTab<Props> {
  13. render() {
  14. const { dailySummaries, theme } = this.props;
  15. if (dailySummaries && dailySummaries.length > 0) {
  16. const timeRange = this.buildTimeRange();
  17. return (
  18. <AutoSizer disableHeight>
  19. {({ width }) => {
  20. if (width === 0) {
  21. return null;
  22. }
  23. return (
  24. <main style={{ width }}>
  25. {this.renderChart({
  26. title: 'Daily query count',
  27. valueField: 'queries',
  28. fieldType: FieldType.number,
  29. width,
  30. timeRange,
  31. color: '',
  32. showBars: true,
  33. showLines: false,
  34. })}
  35. {this.renderChart({
  36. title: 'Errors last 30 days',
  37. valueField: 'errors',
  38. fieldType: FieldType.number,
  39. width,
  40. timeRange,
  41. color: theme.colors.error.border,
  42. showBars: false,
  43. showLines: true,
  44. })}
  45. </main>
  46. );
  47. }}
  48. </AutoSizer>
  49. );
  50. }
  51. return <span>No data.</span>;
  52. }
  53. }
  54. export default withTheme2(AnalyticsStatsTab);