orgRoleSelect.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import {
  4. Panel,
  5. PanelAlert,
  6. PanelBody,
  7. PanelHeader,
  8. PanelItem,
  9. } from 'sentry/components/panels';
  10. import Radio from 'sentry/components/radio';
  11. import {t, tct} from 'sentry/locale';
  12. import {OrgRole} from 'sentry/types';
  13. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  14. const Label = styled('label')`
  15. display: flex;
  16. flex: 1;
  17. align-items: center;
  18. margin-bottom: 0;
  19. `;
  20. type Props = {
  21. disabled: boolean;
  22. enforceAllowed: boolean;
  23. enforceIdpRoleRestricted: boolean;
  24. enforceRetired: boolean;
  25. isCurrentUser: boolean;
  26. roleList: OrgRole[];
  27. roleSelected: string;
  28. setSelected: (id: string) => void;
  29. };
  30. class OrganizationRoleSelect extends Component<Props> {
  31. render() {
  32. const {
  33. disabled,
  34. enforceRetired,
  35. enforceAllowed,
  36. isCurrentUser,
  37. roleList,
  38. enforceIdpRoleRestricted,
  39. roleSelected,
  40. setSelected,
  41. } = this.props;
  42. return (
  43. <Panel>
  44. <PanelHeader>
  45. <div>{t('Organization Role')}</div>
  46. </PanelHeader>
  47. {enforceIdpRoleRestricted && (
  48. <PanelAlert>
  49. {tct(
  50. "[person] organization-level role is managed through your organization's identity provider.",
  51. {person: isCurrentUser ? 'Your' : "This member's"}
  52. )}
  53. </PanelAlert>
  54. )}
  55. <PanelBody>
  56. {roleList.map(role => {
  57. const {desc, name, id, allowed, isRetired: roleRetired} = role;
  58. const isRetired = enforceRetired && roleRetired;
  59. const isDisabled =
  60. disabled ||
  61. isRetired ||
  62. (enforceAllowed && !allowed) ||
  63. enforceIdpRoleRestricted;
  64. return (
  65. <PanelItem
  66. key={id}
  67. onClick={() => !isDisabled && setSelected(id)}
  68. css={!isDisabled ? {} : {color: 'grey', cursor: 'default'}}
  69. >
  70. <Label>
  71. <Radio id={id} value={name} checked={id === roleSelected} readOnly />
  72. <div style={{flex: 1, padding: '0 16px'}}>
  73. {name}
  74. <TextBlock noMargin>
  75. <div className="help-block">{desc}</div>
  76. </TextBlock>
  77. </div>
  78. </Label>
  79. </PanelItem>
  80. );
  81. })}
  82. </PanelBody>
  83. </Panel>
  84. );
  85. }
  86. }
  87. export default OrganizationRoleSelect;