orgRoleSelect.tsx 2.1 KB

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