index.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {forwardRef} from 'react';
  2. import DocIntegrationAvatar from 'sentry/components/avatar/docIntegrationAvatar';
  3. import OrganizationAvatar from 'sentry/components/avatar/organizationAvatar';
  4. import ProjectAvatar from 'sentry/components/avatar/projectAvatar';
  5. import SentryAppAvatar from 'sentry/components/avatar/sentryAppAvatar';
  6. import TeamAvatar from 'sentry/components/avatar/teamAvatar';
  7. import UserAvatar from 'sentry/components/avatar/userAvatar';
  8. import {
  9. AvatarProject,
  10. AvatarSentryApp,
  11. DocIntegration,
  12. OrganizationSummary,
  13. Team,
  14. } from 'sentry/types';
  15. type Props = {
  16. docIntegration?: DocIntegration;
  17. /**
  18. * True if the Avatar is full color, rather than B&W (Used for SentryAppAvatar)
  19. */
  20. isColor?: boolean;
  21. /**
  22. * True if the rendered Avatar should be a static asset
  23. */
  24. isDefault?: boolean;
  25. organization?: OrganizationSummary;
  26. project?: AvatarProject;
  27. sentryApp?: AvatarSentryApp;
  28. team?: Team;
  29. } & React.ComponentProps<typeof UserAvatar>;
  30. const Avatar = forwardRef(function Avatar(
  31. {
  32. hasTooltip = false,
  33. user,
  34. team,
  35. project,
  36. organization,
  37. sentryApp,
  38. isColor = true,
  39. isDefault = false,
  40. docIntegration,
  41. ...props
  42. }: Props,
  43. ref: React.Ref<HTMLSpanElement>
  44. ) {
  45. const commonProps = {hasTooltip, forwardedRef: ref, ...props};
  46. if (user) {
  47. return <UserAvatar user={user} {...commonProps} />;
  48. }
  49. if (team) {
  50. return <TeamAvatar team={team} {...commonProps} />;
  51. }
  52. if (project) {
  53. return <ProjectAvatar project={project} {...commonProps} />;
  54. }
  55. if (sentryApp) {
  56. return (
  57. <SentryAppAvatar
  58. sentryApp={sentryApp}
  59. isColor={isColor}
  60. isDefault={isDefault}
  61. {...commonProps}
  62. />
  63. );
  64. }
  65. if (docIntegration) {
  66. return <DocIntegrationAvatar docIntegration={docIntegration} {...commonProps} />;
  67. }
  68. return <OrganizationAvatar organization={organization} {...commonProps} />;
  69. });
  70. export default Avatar;