AdminOrgsTable.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import React, { useState } from 'react';
  2. import { Button, ConfirmModal } from '@grafana/ui';
  3. import { contextSrv } from 'app/core/core';
  4. import { AccessControlAction, Organization } from 'app/types';
  5. interface Props {
  6. orgs: Organization[];
  7. onDelete: (orgId: number) => void;
  8. }
  9. export function AdminOrgsTable({ orgs, onDelete }: Props) {
  10. const canDeleteOrgs = contextSrv.hasPermission(AccessControlAction.OrgsDelete);
  11. const [deleteOrg, setDeleteOrg] = useState<Organization>();
  12. return (
  13. <table className="filter-table form-inline filter-table--hover">
  14. <thead>
  15. <tr>
  16. <th>ID</th>
  17. <th>Name</th>
  18. <th style={{ width: '1%' }}></th>
  19. </tr>
  20. </thead>
  21. <tbody>
  22. {orgs.map((org) => (
  23. <tr key={`${org.id}-${org.name}`}>
  24. <td className="link-td">
  25. <a href={`admin/orgs/edit/${org.id}`}>{org.id}</a>
  26. </td>
  27. <td className="link-td">
  28. <a href={`admin/orgs/edit/${org.id}`}>{org.name}</a>
  29. </td>
  30. <td className="text-right">
  31. <Button
  32. variant="destructive"
  33. size="sm"
  34. icon="times"
  35. onClick={() => setDeleteOrg(org)}
  36. aria-label="Delete org"
  37. disabled={!canDeleteOrgs}
  38. />
  39. </td>
  40. </tr>
  41. ))}
  42. </tbody>
  43. {deleteOrg && (
  44. <ConfirmModal
  45. isOpen
  46. icon="trash-alt"
  47. title="Delete"
  48. body={
  49. <div>
  50. Are you sure you want to delete &apos;{deleteOrg.name}&apos;?
  51. <br /> <small>All dashboards for this organization will be removed!</small>
  52. </div>
  53. }
  54. confirmText="Delete"
  55. onDismiss={() => setDeleteOrg(undefined)}
  56. onConfirm={() => {
  57. onDelete(deleteOrg.id);
  58. setDeleteOrg(undefined);
  59. }}
  60. />
  61. )}
  62. </table>
  63. );
  64. }