sentryAppAvatar.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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. function SentryAppAvatar({isColor = true, sentryApp, isDefault, ...props}: Props) {
  10. const avatarDetails = sentryApp?.avatars?.find(({color}) => color === isColor);
  11. const defaultSentryAppAvatar = (
  12. <IconGeneric
  13. legacySize={`${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. uploadUrl={avatarDetails?.avatarUrl}
  27. title={sentryApp?.name}
  28. backupAvatar={defaultSentryAppAvatar}
  29. />
  30. );
  31. }
  32. export default SentryAppAvatar;