PanelHeaderNotices.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import React, { FC, useCallback } from 'react';
  2. import { DataFrame, QueryResultMetaNotice } from '@grafana/data';
  3. import { locationService } from '@grafana/runtime';
  4. import { PanelHeaderNotice } from './PanelHeaderNotice';
  5. interface Props {
  6. panelId: number;
  7. frames: DataFrame[];
  8. }
  9. export const PanelHeaderNotices: FC<Props> = ({ frames, panelId }) => {
  10. const openInspect = useCallback(
  11. (e: React.SyntheticEvent, tab: string) => {
  12. e.stopPropagation();
  13. locationService.partial({ inspect: panelId, inspectTab: tab });
  14. },
  15. [panelId]
  16. );
  17. // dedupe on severity
  18. const notices: Record<string, QueryResultMetaNotice> = {};
  19. for (const frame of frames) {
  20. if (!frame.meta || !frame.meta.notices) {
  21. continue;
  22. }
  23. for (const notice of frame.meta.notices) {
  24. notices[notice.severity] = notice;
  25. }
  26. }
  27. return (
  28. <>
  29. {Object.values(notices).map((notice) => (
  30. <PanelHeaderNotice notice={notice} onClick={openInspect} key={notice.severity} />
  31. ))}
  32. </>
  33. );
  34. };