Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(avatars) Use avatarUrl in UI components #22

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fixtures/js-stubs/organization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function Organization(
avatar: {
avatarType: 'default',
avatarUuid: null,
avatarUrl: null,
},
codecovAccess: false,
dataScrubber: false,
Expand Down
31 changes: 7 additions & 24 deletions static/app/components/avatar/baseAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ const defaultProps: DefaultProps = {
* The type of avatar being rendered.
*/
type: 'letter_avatar',
/**
* Path to uploaded avatar (differs based on model type)
*/
uploadPath: 'avatar',
/**
* Should avatar be round instead of a square
*/
Expand All @@ -65,16 +61,6 @@ type DefaultProps = {
* The type of avatar being rendered.
*/
type?: Avatar['avatarType'];
/**
* Path to uploaded avatar (differs based on model type)
*/
uploadPath?:
| 'avatar'
| 'team-avatar'
| 'organization-avatar'
| 'project-avatar'
| 'sentry-app-avatar'
| 'doc-integration-avatar';
};

type BaseProps = DefaultProps & {
Expand Down Expand Up @@ -102,13 +88,9 @@ type BaseProps = DefaultProps & {
*/
tooltipOptions?: Omit<TooltipProps, 'children' | 'title'>;
/**
* The region domain that organization avatars are on
* Full URL to the uploaded avatar's image.
*/
uploadDomain?: string;
/**
* The uuid for the uploaded avatar.
*/
uploadId?: string | null | undefined;
uploadUrl?: string | null | undefined;
};

type Props = BaseProps;
Expand Down Expand Up @@ -145,11 +127,12 @@ class BaseAvatar extends Component<Props, State> {
}

buildUploadUrl() {
const {uploadDomain, uploadPath, uploadId} = this.props;
const {uploadUrl} = this.props;
if (!uploadUrl) {
return '';
}

return `${uploadDomain || ''}/${uploadPath || 'avatar'}/${uploadId}/?${qs.stringify({
s: DEFAULT_REMOTE_SIZE,
})}`;
return `${uploadUrl}?${qs.stringify({s: DEFAULT_REMOTE_SIZE})}`;
}

handleLoad = () => {
Expand Down
3 changes: 1 addition & 2 deletions static/app/components/avatar/docIntegrationAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ function DocIntegrationAvatar({docIntegration, ...props}: Props) {
<BaseAvatar
{...props}
type="upload"
uploadPath="doc-integration-avatar"
uploadId={docIntegration.avatar.avatarUuid}
uploadUrl={docIntegration.avatar.avatarUrl}
title={docIntegration.name}
/>
);
Expand Down
17 changes: 15 additions & 2 deletions static/app/components/avatar/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Avatar', function () {
const avatar: Avatar = {
avatarType: 'gravatar',
avatarUuid: '2d641b5d-8c74-44de-9cb6-fbd54701b35e',
avatarUrl: 'https://sentry.io/avatar/2d641b5d-8c74-44de-9cb6-fbd54701b35e/',
};

const user = {
Expand Down Expand Up @@ -159,6 +160,7 @@ describe('Avatar', function () {
avatar: {
avatarType: 'upload',
avatarUuid: 'abc123def',
avatarUrl: 'https://us.sentry.io/organization-avatar/abc123def/',
},
});

Expand Down Expand Up @@ -213,10 +215,16 @@ describe('Avatar', function () {
});

it('renders the correct SentryApp depending on its props', async function () {
const colorAvatar = {avatarUuid: 'abc', avatarType: 'upload' as const, color: true};
const colorAvatar = {
avatarUuid: 'abc',
avatarType: 'upload' as const,
avatarUrl: 'https://sentry.io/sentry-app-avatar/abc/',
color: true,
};
const simpleAvatar = {
avatarUuid: 'def',
avatarType: 'upload' as const,
avatarUrl: 'https://sentry.io/sentry-app-avatar/def/',
color: false,
};

Expand All @@ -243,7 +251,12 @@ describe('Avatar', function () {
});

it('renders the correct fallbacks for SentryAppAvatars', async function () {
const colorAvatar = {avatarUuid: 'abc', avatarType: 'upload' as const, color: true};
const colorAvatar = {
avatarUuid: 'abc',
avatarType: 'upload' as const,
avatarUrl: 'https://sentry.io/sentry-app-avatar/abc/',
color: true,
};
const sentryApp = SentryApp({avatars: []});

// No existing avatars
Expand Down
6 changes: 2 additions & 4 deletions static/app/components/avatar/organizationAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {explodeSlug} from 'sentry/utils';

type Props = {
organization?: OrganizationSummary;
} & Omit<BaseAvatar['props'], 'uploadPath' | 'uploadId'>;
} & BaseAvatar['props'];

function OrganizationAvatar({organization, ...props}: Props) {
if (!organization) {
Expand All @@ -17,9 +17,7 @@ function OrganizationAvatar({organization, ...props}: Props) {
<BaseAvatar
{...props}
type={(organization.avatar && organization.avatar.avatarType) || 'letter_avatar'}
uploadPath="organization-avatar"
uploadId={organization.avatar && organization.avatar.avatarUuid}
uploadDomain={organization.links?.regionUrl}
uploadUrl={organization.avatar && organization.avatar.avatarUrl}
letterId={slug}
tooltip={slug}
title={title}
Expand Down
5 changes: 1 addition & 4 deletions static/app/components/avatar/sentryAppAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ function SentryAppAvatar({isColor = true, sentryApp, isDefault, ...props}: Props
if (isDefault || !avatarDetails || avatarDetails.avatarType === 'default') {
return defaultSentryAppAvatar;
}
const {sentryUrl} = window.__initialData?.links ?? {};
return (
<BaseAvatar
{...props}
type="upload"
uploadPath="sentry-app-avatar"
uploadId={avatarDetails?.avatarUuid}
uploadDomain={sentryUrl}
uploadUrl={avatarDetails?.avatarUrl}
title={sentryApp?.name}
backupAvatar={defaultSentryAppAvatar}
/>
Expand Down
6 changes: 2 additions & 4 deletions static/app/components/avatar/teamAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import BaseAvatar from 'sentry/components/avatar/baseAvatar';
import type {Team} from 'sentry/types';
import {explodeSlug} from 'sentry/utils';

interface TeamAvatarProps extends Omit<BaseAvatar['props'], 'uploadPath' | 'uploadId'> {
type TeamAvatarProps = {
team: Team | null | undefined;
}
} & BaseAvatar['props'];

function TeamAvatar({team, tooltip: tooltipProp, ...props}: TeamAvatarProps) {
if (!team) {
Expand All @@ -19,8 +19,6 @@ function TeamAvatar({team, tooltip: tooltipProp, ...props}: TeamAvatarProps) {
<BaseAvatar
{...props}
type={(team.avatar && team.avatar.avatarType) || 'letter_avatar'}
uploadPath="team-avatar"
uploadId={team.avatar && team.avatar.avatarUuid}
letterId={slug}
tooltip={tooltip}
title={title}
Expand Down
9 changes: 3 additions & 6 deletions static/app/components/avatar/userAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,24 @@ function UserAvatar({

const avatarData = isActor(user)
? {
uploadId: '',
gravatarId: '',
letterId: user.name,
title: user.name,
uploadUrl: '',
}
: {
uploadId: user.avatar?.avatarUuid ?? '',
uploadUrl: user.avatar?.avatarUrl ?? '',
gravatarId: user.email?.toLowerCase(),
letterId: user.email || user.username || user.id || user.ip_address,
title: user.name || user.email || user.username || '',
};
const {sentryUrl} = window.__initialData?.links ?? {};

return (
<BaseAvatar
round
{...props}
type={type}
uploadPath="avatar"
uploadId={avatarData.uploadId}
uploadDomain={sentryUrl}
uploadUrl={avatarData.uploadUrl}
gravatarId={avatarData.gravatarId}
letterId={avatarData.letterId}
title={avatarData.title}
Expand Down
1 change: 1 addition & 0 deletions static/app/types/core.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {API_ACCESS_SCOPES} from 'sentry/constants';
export type Avatar = {
avatarType: 'letter_avatar' | 'upload' | 'gravatar' | 'background' | 'default';
avatarUuid: string | null;
avatarUrl?: string | null;
color?: boolean;
};

Expand Down