actorAvatar.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {Component} from 'react';
  2. import * as Sentry from '@sentry/react';
  3. import TeamAvatar from 'sentry/components/avatar/teamAvatar';
  4. import UserAvatar from 'sentry/components/avatar/userAvatar';
  5. import LoadingIndicator from 'sentry/components/loadingIndicator';
  6. import Tooltip from 'sentry/components/tooltip';
  7. import MemberListStore from 'sentry/stores/memberListStore';
  8. import {Actor} from 'sentry/types';
  9. import Teams from 'sentry/utils/teams';
  10. type DefaultProps = {
  11. hasTooltip: boolean;
  12. size: number;
  13. };
  14. type Props = DefaultProps & {
  15. actor: Actor;
  16. className?: string;
  17. default?: string;
  18. gravatar?: boolean;
  19. onClick?: () => void;
  20. suggested?: boolean;
  21. title?: string;
  22. tooltip?: React.ReactNode;
  23. tooltipOptions?: Omit<React.ComponentProps<typeof Tooltip>, 'children' | 'title'>;
  24. };
  25. class ActorAvatar extends Component<Props> {
  26. static defaultProps: DefaultProps = {
  27. size: 24,
  28. hasTooltip: true,
  29. };
  30. render() {
  31. const {actor, ...props} = this.props;
  32. if (actor.type === 'user') {
  33. const user = actor.id ? MemberListStore.getById(actor.id) ?? actor : actor;
  34. return <UserAvatar user={user} {...props} />;
  35. }
  36. if (actor.type === 'team') {
  37. return (
  38. <Teams ids={[actor.id]}>
  39. {({initiallyLoaded, teams}) =>
  40. initiallyLoaded ? (
  41. <TeamAvatar team={teams[0]} {...props} />
  42. ) : (
  43. <LoadingIndicator mini />
  44. )
  45. }
  46. </Teams>
  47. );
  48. }
  49. Sentry.withScope(scope => {
  50. scope.setExtra('actor', actor);
  51. Sentry.captureException(new Error('Unknown avatar type'));
  52. });
  53. return null;
  54. }
  55. }
  56. export default ActorAvatar;