UserOrganizations.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { Trans } from '@lingui/macro';
  2. import React, { PureComponent } from 'react';
  3. import { selectors } from '@grafana/e2e-selectors';
  4. import { Button, LoadingPlaceholder } from '@grafana/ui';
  5. import { UserDTO, UserOrg } from 'app/types';
  6. export interface Props {
  7. user: UserDTO | null;
  8. orgs: UserOrg[];
  9. isLoading: boolean;
  10. setUserOrg: (org: UserOrg) => void;
  11. }
  12. export class UserOrganizations extends PureComponent<Props> {
  13. render() {
  14. const { isLoading, orgs, user } = this.props;
  15. if (isLoading) {
  16. return <LoadingPlaceholder text="Loading organizations..." />;
  17. }
  18. if (orgs.length === 0) {
  19. return null;
  20. }
  21. return (
  22. <div>
  23. <h3 className="page-sub-heading">
  24. <Trans id="user-orgs.title">Organizations</Trans>
  25. </h3>
  26. <div className="gf-form-group">
  27. <table className="filter-table form-inline" data-testid={selectors.components.UserProfile.orgsTable}>
  28. <thead>
  29. <tr>
  30. <th>
  31. <Trans id="user-orgs.name-column">Name</Trans>
  32. </th>
  33. <th>
  34. <Trans id="user-orgs.role-column">Role</Trans>
  35. </th>
  36. <th />
  37. </tr>
  38. </thead>
  39. <tbody>
  40. {orgs.map((org: UserOrg, index) => {
  41. return (
  42. <tr key={index}>
  43. <td>{org.name}</td>
  44. <td>{org.role}</td>
  45. <td className="text-right">
  46. {org.orgId === user?.orgId ? (
  47. <Button variant="secondary" size="sm" disabled>
  48. <Trans id="user-orgs.current-org-button">Current</Trans>
  49. </Button>
  50. ) : (
  51. <Button
  52. variant="secondary"
  53. size="sm"
  54. onClick={() => {
  55. this.props.setUserOrg(org);
  56. }}
  57. >
  58. <Trans id="user-orgs.select-org-button">Select organisation</Trans>
  59. </Button>
  60. )}
  61. </td>
  62. </tr>
  63. );
  64. })}
  65. </tbody>
  66. </table>
  67. </div>
  68. </div>
  69. );
  70. }
  71. }
  72. export default UserOrganizations;