getBadge.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import BaseBadge from 'sentry/components/idBadge/baseBadge';
  2. import MemberBadge from 'sentry/components/idBadge/memberBadge';
  3. import OrganizationBadge from 'sentry/components/idBadge/organizationBadge';
  4. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  5. import {TeamBadge} from 'sentry/components/idBadge/teamBadge';
  6. import UserBadge from 'sentry/components/idBadge/userBadge';
  7. import {Member, User} from 'sentry/types';
  8. type BaseBadgeProps = React.ComponentProps<typeof BaseBadge>;
  9. type DisplayName = BaseBadgeProps['displayName'];
  10. type Props = Omit<BaseBadgeProps, 'displayName'> & {
  11. displayName?: DisplayName;
  12. member?: Member;
  13. user?: User;
  14. };
  15. function getBadge({
  16. organization,
  17. team,
  18. project,
  19. user,
  20. member,
  21. ...props
  22. }: Props): React.ReactElement | null {
  23. if (organization) {
  24. return <OrganizationBadge organization={organization} {...props} />;
  25. }
  26. if (team) {
  27. return <TeamBadge team={team} {...props} />;
  28. }
  29. if (project) {
  30. return <ProjectBadge project={project} {...props} />;
  31. }
  32. if (user) {
  33. return <UserBadge user={user} {...props} />;
  34. }
  35. if (member) {
  36. return <MemberBadge member={member} {...props} />;
  37. }
  38. return null;
  39. }
  40. export default getBadge;