DashboardsTable.tsx 1.8 KB

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