orgRoleSelect.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Panel, PanelBody, PanelHeader, PanelItem} from 'sentry/components/panels';
  4. import Radio from 'sentry/components/radio';
  5. import {t} from 'sentry/locale';
  6. import {OrgRole} from 'sentry/types';
  7. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  8. const Label = styled('label')`
  9. display: flex;
  10. flex: 1;
  11. align-items: center;
  12. margin-bottom: 0;
  13. `;
  14. type Props = {
  15. disabled: boolean;
  16. enforceAllowed: boolean;
  17. enforceRetired: boolean;
  18. roleList: OrgRole[];
  19. roleSelected: string;
  20. setSelected: (id: string) => void;
  21. };
  22. class OrganizationRoleSelect extends Component<Props> {
  23. render() {
  24. const {
  25. disabled,
  26. enforceRetired,
  27. enforceAllowed,
  28. roleList,
  29. roleSelected,
  30. setSelected,
  31. } = this.props;
  32. return (
  33. <Panel>
  34. <PanelHeader>{t('Organization Role')}</PanelHeader>
  35. <PanelBody>
  36. {roleList.map(role => {
  37. const {desc, name, id, allowed, isRetired: roleRetired} = role;
  38. const isRetired = enforceRetired && roleRetired;
  39. const isDisabled = disabled || isRetired || (enforceAllowed && !allowed);
  40. return (
  41. <PanelItem
  42. key={id}
  43. onClick={() => !isDisabled && setSelected(id)}
  44. css={!isDisabled ? {} : {color: 'grey', cursor: 'default'}}
  45. >
  46. <Label>
  47. <Radio id={id} value={name} checked={id === roleSelected} readOnly />
  48. <div style={{flex: 1, padding: '0 16px'}}>
  49. {name}
  50. <TextBlock noMargin>
  51. <div className="help-block">{desc}</div>
  52. </TextBlock>
  53. </div>
  54. </Label>
  55. </PanelItem>
  56. );
  57. })}
  58. </PanelBody>
  59. </Panel>
  60. );
  61. }
  62. }
  63. export default OrganizationRoleSelect;