Skip to content

meta(propTypes): Relax requirements for badges #13522

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

Merged
merged 1 commit into from
Jun 5, 2019
Merged
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
15 changes: 9 additions & 6 deletions src/sentry/static/sentry/app/components/avatar/index.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import PropTypes from 'prop-types';
import React from 'react';

import SentryTypes from 'app/sentryTypes';
import TeamAvatar from 'app/components/avatar/teamAvatar';
import OrganizationAvatar from 'app/components/avatar/organizationAvatar';
import ProjectAvatar from 'app/components/avatar/projectAvatar';
import SentryTypes from 'app/sentryTypes';
import TeamAvatar from 'app/components/avatar/teamAvatar';
import UserAvatar from 'app/components/avatar/userAvatar';

const BasicModelShape = PropTypes.shape({slug: PropTypes.string});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this worth having on sentryTypes? Perhaps as BasicAvatarShape?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not unless we have other components that accept these models progressively (e.g. slug -> full model)


class Avatar extends React.Component {
static propTypes = {
team: SentryTypes.Team,
organization: SentryTypes.Organization,
project: SentryTypes.Project,
team: PropTypes.oneOfType([BasicModelShape, SentryTypes.Team]),
organization: PropTypes.oneOfType([BasicModelShape, SentryTypes.Organization]),
project: PropTypes.oneOfType([BasicModelShape, SentryTypes.Project]),

...UserAvatar.propTypes,
};

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

// Could support project too
return <OrganizationAvatar organization={organization} {...props} />;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types';
import React from 'react';

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

class ProjectAvatar extends React.Component {
static propTypes = {
project: SentryTypes.Project.isRequired,
project: PropTypes.oneOfType([
PropTypes.shape({slug: PropTypes.string}),
SentryTypes.Project,
]).isRequired,
...BaseAvatar.propTypes,
};

Expand Down
10 changes: 7 additions & 3 deletions src/sentry/static/sentry/app/components/idBadge/baseBadge.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ import space from 'app/styles/space';
import overflowEllipsis from 'app/styles/overflowEllipsis';
import SentryTypes from 'app/sentryTypes';

const BasicModelShape = PropTypes.shape({slug: PropTypes.string});

class BaseBadge extends React.PureComponent {
static propTypes = {
team: SentryTypes.Team,
organization: SentryTypes.Organization,
project: SentryTypes.Project,
team: PropTypes.oneOfType([BasicModelShape, SentryTypes.Team]),
organization: PropTypes.oneOfType([BasicModelShape, SentryTypes.Organization]),
project: PropTypes.oneOfType([BasicModelShape, SentryTypes.Project]),
member: PropTypes.oneOfType([BasicModelShape, SentryTypes.Member]),
user: PropTypes.oneOfType([BasicModelShape, SentryTypes.User]),

/**
* Avatar size
Expand Down
6 changes: 0 additions & 6 deletions src/sentry/static/sentry/app/components/idBadge/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import UserBadge from 'app/components/idBadge/userBadge';
import TeamBadge from 'app/components/idBadge/teamBadge';
import ProjectBadge from 'app/components/idBadge/projectBadge';
import OrganizationBadge from 'app/components/idBadge/organizationBadge';
import SentryTypes from 'app/sentryTypes';

const COMPONENT_MAP = new Map([
['organization', OrganizationBadge],
Expand All @@ -24,11 +23,6 @@ const COMPONENT_MAP = new Map([
export default class IdBadge extends React.Component {
static propTypes = {
...BaseBadge.propTypes,
team: SentryTypes.Team,
project: SentryTypes.Project,
organization: SentryTypes.Organization,
member: SentryTypes.Member,
user: SentryTypes.User,
};

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import React from 'react';
import PropTypes from 'prop-types';

import BaseBadge from 'app/components/idBadge/baseBadge';
import SentryTypes from 'app/sentryTypes';
import BadgeDisplayName from 'app/components/idBadge/badgeDisplayName';

export default class ProjectBadge extends React.PureComponent {
static propTypes = {
...BaseBadge.propTypes,
project: SentryTypes.Project.isRequired,
project: BaseBadge.propTypes.project.isRequired,
avatarSize: PropTypes.number,
/**
* If true, will use default max-width, or specify one as a string
Expand Down