sentryAppAvatar.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import BaseAvatar from 'sentry/components/avatar/baseAvatar';
  2. import {IconGeneric} from 'sentry/icons';
  3. import {AvatarSentryApp} from 'sentry/types';
  4. type Props = {
  5. isColor?: boolean;
  6. isDefault?: boolean;
  7. sentryApp?: AvatarSentryApp;
  8. } & BaseAvatar['props'];
  9. const SentryAppAvatar = ({isColor = true, sentryApp, isDefault, ...props}: Props) => {
  10. const avatarDetails = sentryApp?.avatars?.find(({color}) => color === isColor);
  11. const defaultSentryAppAvatar = (
  12. <IconGeneric
  13. size={`${props.size}`}
  14. className={props.className}
  15. data-test-id="default-sentry-app-avatar"
  16. />
  17. );
  18. // Render the default if the prop is provided, there is no existing avatar, or it has been reverted to 'default'
  19. if (isDefault || !avatarDetails || avatarDetails.avatarType === 'default') {
  20. return defaultSentryAppAvatar;
  21. }
  22. return (
  23. <BaseAvatar
  24. {...props}
  25. type="upload"
  26. uploadPath="sentry-app-avatar"
  27. uploadId={avatarDetails?.avatarUuid}
  28. title={sentryApp?.name}
  29. backupAvatar={defaultSentryAppAvatar}
  30. />
  31. );
  32. };
  33. export default SentryAppAvatar;