orgRoleSelect.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 QuestionTooltip from 'sentry/components/questionTooltip';
  8. import Radio from 'sentry/components/radio';
  9. import {t} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. import {OrgRole} from 'sentry/types';
  12. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  13. const Label = styled('label')`
  14. display: flex;
  15. flex: 1;
  16. align-items: center;
  17. margin-bottom: 0;
  18. `;
  19. type Props = {
  20. disabled: boolean;
  21. enforceAllowed: boolean;
  22. enforceRetired: boolean;
  23. helpText: string | undefined;
  24. roleList: OrgRole[];
  25. roleSelected: string;
  26. setSelected: (id: string) => void;
  27. };
  28. class OrganizationRoleSelect extends Component<Props> {
  29. render() {
  30. const {
  31. disabled,
  32. enforceRetired,
  33. enforceAllowed,
  34. roleList,
  35. roleSelected,
  36. setSelected,
  37. helpText,
  38. } = this.props;
  39. return (
  40. <Panel>
  41. <StyledPanelHeader>
  42. <div>{t('Organization Role')}</div>
  43. {disabled && <QuestionTooltip size="sm" title={helpText} />}
  44. </StyledPanelHeader>
  45. <PanelBody>
  46. {roleList.map(role => {
  47. const {desc, name, id, allowed, isRetired: roleRetired} = role;
  48. const isRetired = enforceRetired && roleRetired;
  49. const isDisabled = disabled || isRetired || (enforceAllowed && !allowed);
  50. return (
  51. <PanelItem
  52. key={id}
  53. onClick={() => !isDisabled && setSelected(id)}
  54. css={!isDisabled ? {} : {color: 'grey', cursor: 'default'}}
  55. >
  56. <Label>
  57. <Radio id={id} value={name} checked={id === roleSelected} readOnly />
  58. <div style={{flex: 1, padding: '0 16px'}}>
  59. {name}
  60. <TextBlock noMargin>
  61. <div className="help-block">{desc}</div>
  62. </TextBlock>
  63. </div>
  64. </Label>
  65. </PanelItem>
  66. );
  67. })}
  68. </PanelBody>
  69. </Panel>
  70. );
  71. }
  72. }
  73. const StyledPanelHeader = styled(PanelHeader)`
  74. display: flex;
  75. gap: ${space(0.5)};
  76. justify-content: left;
  77. `;
  78. export default OrganizationRoleSelect;