PanelInspectActions.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React, { ComponentType } from 'react';
  2. import { PanelData } from '@grafana/data';
  3. import { PanelModel } from '../../state';
  4. export interface PanelInspectActionProps {
  5. panel: PanelModel;
  6. data?: PanelData;
  7. }
  8. export interface PanelInspectAction {
  9. title: string;
  10. description: string;
  11. component: ComponentType<PanelInspectActionProps>;
  12. }
  13. export interface PanelInspectActionSupplier {
  14. getActions: (panel: PanelModel) => PanelInspectAction[] | null;
  15. }
  16. // const dummySupplier: PanelInspectActionSupplier = {
  17. // getActions: (panel: PanelModel) => {
  18. // return [
  19. // {
  20. // title: 'Do something',
  21. // description: 'that thingy',
  22. // // eslint-disable-next-line react/display-name
  23. // component: ({ panel }) => {
  24. // return (
  25. // <div>
  26. // DO THING ONE. Panel: <pre>{JSON.stringify(panel.targets)}</pre>
  27. // </div>
  28. // );
  29. // },
  30. // },
  31. // {
  32. // title: 'Do something else',
  33. // description: 'another thing',
  34. // // eslint-disable-next-line react/display-name
  35. // component: ({ panel }) => {
  36. // return (
  37. // <div>
  38. // DO THING TWO. Panel: <pre>{JSON.stringify(panel.targets)}</pre>
  39. // </div>
  40. // );
  41. // },
  42. // },
  43. // ];
  44. // },
  45. // };
  46. // In Grafana 8.1, this can be improved and moved to `@grafana/runtime`
  47. // NOTE: This is an internal/experimental API/hack and will change!
  48. // (window as any).grafanaPanelInspectActionSupplier = dummySupplier;
  49. interface InspectActionsTabProps {
  50. panel: PanelModel;
  51. data?: PanelData;
  52. }
  53. export const InspectActionsTab: React.FC<InspectActionsTabProps> = ({ panel, data }) => {
  54. const supplier = (window as any).grafanaPanelInspectActionSupplier as PanelInspectActionSupplier;
  55. if (!supplier) {
  56. return <div>Missing actions</div>;
  57. }
  58. const actions = supplier.getActions(panel);
  59. if (!actions?.length) {
  60. return <div>No actions avaliable</div>;
  61. }
  62. return (
  63. <div>
  64. {actions.map((a, idx) => (
  65. <div key={idx}>
  66. <h2>{a.title}</h2>
  67. <span>{a.description}</span>
  68. <a.component panel={panel} data={data} />
  69. </div>
  70. ))}
  71. </div>
  72. );
  73. };