ServiceAccountRoleRow.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { css, cx } from '@emotion/css';
  2. import React, { PureComponent } from 'react';
  3. import { UserRolePicker } from 'app/core/components/RolePicker/UserRolePicker';
  4. import { contextSrv } from 'app/core/core';
  5. import { AccessControlAction, OrgRole, Role, ServiceAccountDTO } from 'app/types';
  6. import { OrgRolePicker } from '../admin/OrgRolePicker';
  7. interface Props {
  8. label: string;
  9. serviceAccount: ServiceAccountDTO;
  10. onRoleChange: (role: OrgRole) => void;
  11. roleOptions: Role[];
  12. builtInRoles: Record<string, Role[]>;
  13. }
  14. export class ServiceAccountRoleRow extends PureComponent<Props> {
  15. render() {
  16. const { label, serviceAccount, roleOptions, builtInRoles, onRoleChange } = this.props;
  17. const canUpdateRole = contextSrv.hasPermissionInMetadata(AccessControlAction.ServiceAccountsWrite, serviceAccount);
  18. const rolePickerDisabled = !canUpdateRole;
  19. const labelClass = cx(
  20. 'width-16',
  21. css`
  22. font-weight: 500;
  23. `
  24. );
  25. const inputId = `${label}-input`;
  26. return (
  27. <tr>
  28. <td className={labelClass}>
  29. <label htmlFor={inputId}>{label}</label>
  30. </td>
  31. <td className="width-25" colSpan={2}>
  32. {contextSrv.licensedAccessControlEnabled() ? (
  33. <UserRolePicker
  34. userId={serviceAccount.id}
  35. orgId={serviceAccount.orgId}
  36. builtInRole={serviceAccount.role}
  37. onBuiltinRoleChange={onRoleChange}
  38. roleOptions={roleOptions}
  39. builtInRoles={builtInRoles}
  40. disabled={rolePickerDisabled}
  41. />
  42. ) : (
  43. <OrgRolePicker
  44. aria-label="Role"
  45. value={serviceAccount.role}
  46. disabled={!canUpdateRole}
  47. onChange={onRoleChange}
  48. />
  49. )}
  50. </td>
  51. <td></td>
  52. </tr>
  53. );
  54. }
  55. }