roleSelectControl.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import styled from '@emotion/styled';
  2. import SelectControl, {
  3. ControlProps,
  4. } from 'sentry/components/forms/controls/selectControl';
  5. import {MemberRole} from 'sentry/types';
  6. type OptionType = {
  7. details: React.ReactNode;
  8. disabled: boolean;
  9. label: string;
  10. value: string;
  11. };
  12. type Props = Omit<ControlProps<OptionType>, 'onChange' | 'value'> & {
  13. disableUnallowed: boolean;
  14. roles: MemberRole[];
  15. /**
  16. * Narrower type than SelectControl because there is no empty value
  17. */
  18. onChange?: (value: OptionType) => void;
  19. value?: string | null;
  20. };
  21. function RoleSelectControl({roles, disableUnallowed, ...props}: Props) {
  22. return (
  23. <SelectControl
  24. options={roles?.map(
  25. (r: MemberRole) =>
  26. ({
  27. value: r.id,
  28. label: r.name,
  29. disabled: (disableUnallowed && !r.allowed) || r.isRetired,
  30. details: <Details>{r.desc}</Details>,
  31. } as OptionType)
  32. )}
  33. showDividers
  34. {...props}
  35. />
  36. );
  37. }
  38. export default RoleSelectControl;
  39. const Details = styled('span')`
  40. display: inline-block;
  41. width: 20rem;
  42. `;