actorAvatar.tsx 1.5 KB

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