MetaInspector.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { groupBy } from 'lodash';
  2. import React, { useMemo } from 'react';
  3. import { MetadataInspectorProps } from '@grafana/data';
  4. import { CloudWatchDatasource } from '../datasource';
  5. import { CloudWatchQuery, CloudWatchJsonData } from '../types';
  6. export type Props = MetadataInspectorProps<CloudWatchDatasource, CloudWatchQuery, CloudWatchJsonData>;
  7. export function MetaInspector({ data = [] }: Props) {
  8. const rows = useMemo(() => groupBy(data, 'refId'), [data]);
  9. return (
  10. <>
  11. <table className="filter-table form-inline">
  12. <thead>
  13. <tr>
  14. <th>RefId</th>
  15. <th>Metric Data Query ID</th>
  16. <th>Metric Data Query Expression</th>
  17. <th>Period</th>
  18. <th />
  19. </tr>
  20. </thead>
  21. {Object.entries(rows).map(([refId, frames], idx) => {
  22. if (!frames.length) {
  23. return null;
  24. }
  25. const frame = frames[0];
  26. const custom = frame.meta?.custom;
  27. if (!custom) {
  28. return null;
  29. }
  30. return (
  31. <tbody key={idx}>
  32. <tr>
  33. <td>{refId}</td>
  34. <td>{custom.id}</td>
  35. <td>{frame.meta?.executedQueryString}</td>
  36. <td>{custom.period}</td>
  37. </tr>
  38. </tbody>
  39. );
  40. })}
  41. </table>
  42. </>
  43. );
  44. }