|
@@ -1,53 +1,36 @@
|
|
-import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
import React from 'react';
|
|
|
|
|
|
-import SentryTypes from 'app/sentryTypes';
|
|
|
|
import OrganizationAvatar from 'app/components/avatar/organizationAvatar';
|
|
import OrganizationAvatar from 'app/components/avatar/organizationAvatar';
|
|
import ProjectAvatar from 'app/components/avatar/projectAvatar';
|
|
import ProjectAvatar from 'app/components/avatar/projectAvatar';
|
|
import TeamAvatar from 'app/components/avatar/teamAvatar';
|
|
import TeamAvatar from 'app/components/avatar/teamAvatar';
|
|
import UserAvatar from 'app/components/avatar/userAvatar';
|
|
import UserAvatar from 'app/components/avatar/userAvatar';
|
|
import {Team, OrganizationSummary, AvatarProject} from 'app/types';
|
|
import {Team, OrganizationSummary, AvatarProject} from 'app/types';
|
|
|
|
|
|
-const BasicModelShape = PropTypes.shape({slug: PropTypes.string});
|
|
|
|
-
|
|
|
|
type Props = {
|
|
type Props = {
|
|
team?: Team;
|
|
team?: Team;
|
|
organization?: OrganizationSummary;
|
|
organization?: OrganizationSummary;
|
|
project?: AvatarProject;
|
|
project?: AvatarProject;
|
|
} & UserAvatar['props'];
|
|
} & UserAvatar['props'];
|
|
|
|
|
|
-class Avatar extends React.Component<Props> {
|
|
|
|
- static propTypes = {
|
|
|
|
- team: PropTypes.oneOfType([BasicModelShape, SentryTypes.Team]),
|
|
|
|
- organization: PropTypes.oneOfType([BasicModelShape, SentryTypes.Organization]),
|
|
|
|
- project: PropTypes.oneOfType([BasicModelShape, SentryTypes.Project]),
|
|
|
|
-
|
|
|
|
- ...UserAvatar.propTypes,
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- static defaultProps = {
|
|
|
|
- hasTooltip: false,
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- render() {
|
|
|
|
- const {user, team, project, organization, ...props} = this.props;
|
|
|
|
|
|
+const Avatar = React.forwardRef(function Avatar(
|
|
|
|
+ {hasTooltip = false, user, team, project, organization, ...props}: Props,
|
|
|
|
+ ref: React.Ref<HTMLSpanElement>
|
|
|
|
+) {
|
|
|
|
+ const commonProps = {hasTooltip, forwardedRef: ref, ...props};
|
|
|
|
|
|
- if (user) {
|
|
|
|
- return <UserAvatar user={user} {...props} />;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (team) {
|
|
|
|
- return <TeamAvatar team={team} {...props} />;
|
|
|
|
- }
|
|
|
|
|
|
+ if (user) {
|
|
|
|
+ return <UserAvatar user={user} {...commonProps} />;
|
|
|
|
+ }
|
|
|
|
|
|
- if (project) {
|
|
|
|
- return <ProjectAvatar project={project} {...props} />;
|
|
|
|
- }
|
|
|
|
|
|
+ if (team) {
|
|
|
|
+ return <TeamAvatar team={team} {...commonProps} />;
|
|
|
|
+ }
|
|
|
|
|
|
- return <OrganizationAvatar organization={organization} {...props} />;
|
|
|
|
|
|
+ if (project) {
|
|
|
|
+ return <ProjectAvatar project={project} {...commonProps} />;
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
|
|
-export default React.forwardRef<HTMLSpanElement, Props>((props, ref) => (
|
|
|
|
- <Avatar forwardedRef={ref} {...props} />
|
|
|
|
-));
|
|
|
|
|
|
+ return <OrganizationAvatar organization={organization} {...commonProps} />;
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+export default Avatar;
|