Skip to content

Commit 0d3fcd4

Browse files
authored
meta(propTypes): Relax requirements for badges (#13522)
Our proptypes for our main models (e.g. Org, Project, Team) require an `id` - Our badges/avatars can render without an `id` and just require a slug at the minimum. Change propTypes to allow a simple object with `slug`
1 parent 396dcf2 commit 0d3fcd4

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

src/sentry/static/sentry/app/components/avatar/index.jsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1+
import PropTypes from 'prop-types';
12
import React from 'react';
23

3-
import SentryTypes from 'app/sentryTypes';
4-
import TeamAvatar from 'app/components/avatar/teamAvatar';
54
import OrganizationAvatar from 'app/components/avatar/organizationAvatar';
65
import ProjectAvatar from 'app/components/avatar/projectAvatar';
6+
import SentryTypes from 'app/sentryTypes';
7+
import TeamAvatar from 'app/components/avatar/teamAvatar';
78
import UserAvatar from 'app/components/avatar/userAvatar';
89

10+
const BasicModelShape = PropTypes.shape({slug: PropTypes.string});
11+
912
class Avatar extends React.Component {
1013
static propTypes = {
11-
team: SentryTypes.Team,
12-
organization: SentryTypes.Organization,
13-
project: SentryTypes.Project,
14+
team: PropTypes.oneOfType([BasicModelShape, SentryTypes.Team]),
15+
organization: PropTypes.oneOfType([BasicModelShape, SentryTypes.Organization]),
16+
project: PropTypes.oneOfType([BasicModelShape, SentryTypes.Project]),
17+
1418
...UserAvatar.propTypes,
1519
};
1620

@@ -33,7 +37,6 @@ class Avatar extends React.Component {
3337
return <ProjectAvatar project={project} {...props} />;
3438
}
3539

36-
// Could support project too
3740
return <OrganizationAvatar organization={organization} {...props} />;
3841
}
3942
}

src/sentry/static/sentry/app/components/avatar/projectAvatar.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import PropTypes from 'prop-types';
12
import React from 'react';
23

34
import BaseAvatar from 'app/components/avatar/baseAvatar';
@@ -6,7 +7,10 @@ import SentryTypes from 'app/sentryTypes';
67

78
class ProjectAvatar extends React.Component {
89
static propTypes = {
9-
project: SentryTypes.Project.isRequired,
10+
project: PropTypes.oneOfType([
11+
PropTypes.shape({slug: PropTypes.string}),
12+
SentryTypes.Project,
13+
]).isRequired,
1014
...BaseAvatar.propTypes,
1115
};
1216

src/sentry/static/sentry/app/components/idBadge/baseBadge.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ import space from 'app/styles/space';
88
import overflowEllipsis from 'app/styles/overflowEllipsis';
99
import SentryTypes from 'app/sentryTypes';
1010

11+
const BasicModelShape = PropTypes.shape({slug: PropTypes.string});
12+
1113
class BaseBadge extends React.PureComponent {
1214
static propTypes = {
13-
team: SentryTypes.Team,
14-
organization: SentryTypes.Organization,
15-
project: SentryTypes.Project,
15+
team: PropTypes.oneOfType([BasicModelShape, SentryTypes.Team]),
16+
organization: PropTypes.oneOfType([BasicModelShape, SentryTypes.Organization]),
17+
project: PropTypes.oneOfType([BasicModelShape, SentryTypes.Project]),
18+
member: PropTypes.oneOfType([BasicModelShape, SentryTypes.Member]),
19+
user: PropTypes.oneOfType([BasicModelShape, SentryTypes.User]),
1620

1721
/**
1822
* Avatar size

src/sentry/static/sentry/app/components/idBadge/index.jsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import UserBadge from 'app/components/idBadge/userBadge';
77
import TeamBadge from 'app/components/idBadge/teamBadge';
88
import ProjectBadge from 'app/components/idBadge/projectBadge';
99
import OrganizationBadge from 'app/components/idBadge/organizationBadge';
10-
import SentryTypes from 'app/sentryTypes';
1110

1211
const COMPONENT_MAP = new Map([
1312
['organization', OrganizationBadge],
@@ -24,11 +23,6 @@ const COMPONENT_MAP = new Map([
2423
export default class IdBadge extends React.Component {
2524
static propTypes = {
2625
...BaseBadge.propTypes,
27-
team: SentryTypes.Team,
28-
project: SentryTypes.Project,
29-
organization: SentryTypes.Organization,
30-
member: SentryTypes.Member,
31-
user: SentryTypes.User,
3226
};
3327

3428
render() {

src/sentry/static/sentry/app/components/idBadge/projectBadge.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33

44
import BaseBadge from 'app/components/idBadge/baseBadge';
5-
import SentryTypes from 'app/sentryTypes';
65
import BadgeDisplayName from 'app/components/idBadge/badgeDisplayName';
76

87
export default class ProjectBadge extends React.PureComponent {
98
static propTypes = {
109
...BaseBadge.propTypes,
11-
project: SentryTypes.Project.isRequired,
10+
project: BaseBadge.propTypes.project.isRequired,
1211
avatarSize: PropTypes.number,
1312
/**
1413
* If true, will use default max-width, or specify one as a string

0 commit comments

Comments
 (0)