DashboardsTable.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React, { FC } from 'react';
  2. import { Button, Icon } from '@grafana/ui';
  3. import { PluginDashboard } from '../../types';
  4. export interface Props {
  5. dashboards: PluginDashboard[];
  6. onImport: (dashboard: PluginDashboard, overwrite: boolean) => void;
  7. onRemove: (dashboard: PluginDashboard) => void;
  8. }
  9. const DashboardsTable: FC<Props> = ({ dashboards, onImport, onRemove }) => {
  10. function buttonText(dashboard: PluginDashboard) {
  11. return dashboard.revision !== dashboard.importedRevision ? 'Update' : 'Re-import';
  12. }
  13. return (
  14. <table className="filter-table">
  15. <tbody>
  16. {dashboards.map((dashboard, index) => {
  17. return (
  18. <tr key={`${dashboard.dashboardId}-${index}`}>
  19. <td className="width-1">
  20. <Icon name="apps" />
  21. </td>
  22. <td>
  23. {dashboard.imported ? (
  24. <a href={dashboard.importedUrl}>{dashboard.title}</a>
  25. ) : (
  26. <span>{dashboard.title}</span>
  27. )}
  28. </td>
  29. <td style={{ textAlign: 'right' }}>
  30. {!dashboard.imported ? (
  31. <Button variant="secondary" size="sm" onClick={() => onImport(dashboard, false)}>
  32. Import
  33. </Button>
  34. ) : (
  35. <Button variant="secondary" size="sm" onClick={() => onImport(dashboard, true)}>
  36. {buttonText(dashboard)}
  37. </Button>
  38. )}
  39. {dashboard.imported && (
  40. <Button icon="trash-alt" variant="destructive" size="sm" onClick={() => onRemove(dashboard)} />
  41. )}
  42. </td>
  43. </tr>
  44. );
  45. })}
  46. </tbody>
  47. </table>
  48. );
  49. };
  50. export default DashboardsTable;