From 94ce7676a52712e0e5116e36844f79e352c0eeea Mon Sep 17 00:00:00 2001 From: Matej Minar Date: Mon, 19 Oct 2020 12:49:53 +0200 Subject: [PATCH] ref(ts): Convert suggestedOwnerHovercard to typescript (#21407) --- ...ercard.jsx => suggestedOwnerHovercard.tsx} | 88 +++++++------------ 1 file changed, 34 insertions(+), 54 deletions(-) rename src/sentry/static/sentry/app/components/group/{suggestedOwnerHovercard.jsx => suggestedOwnerHovercard.tsx} (77%) diff --git a/src/sentry/static/sentry/app/components/group/suggestedOwnerHovercard.jsx b/src/sentry/static/sentry/app/components/group/suggestedOwnerHovercard.tsx similarity index 77% rename from src/sentry/static/sentry/app/components/group/suggestedOwnerHovercard.jsx rename to src/sentry/static/sentry/app/components/group/suggestedOwnerHovercard.tsx index 72c517abb93582..7b98d253260e70 100644 --- a/src/sentry/static/sentry/app/components/group/suggestedOwnerHovercard.jsx +++ b/src/sentry/static/sentry/app/components/group/suggestedOwnerHovercard.tsx @@ -1,8 +1,8 @@ -import PropTypes from 'prop-types'; import React from 'react'; import moment from 'moment'; import styled from '@emotion/styled'; +import {Actor, Commit} from 'app/types'; import {t, tct} from 'app/locale'; import {openInviteMembersModal} from 'app/actionCreators/modal'; import ActorAvatar from 'app/components/avatar/actorAvatar'; @@ -11,61 +11,41 @@ import Button from 'app/components/button'; import Hovercard from 'app/components/hovercard'; import {IconCommit, IconWarning} from 'app/icons'; import Link from 'app/components/links/link'; -import SentryTypes from 'app/sentryTypes'; import space from 'app/styles/space'; import theme from 'app/utils/theme'; +import {defined} from 'app/utils'; + +type Props = { + /** + * The suggested actor. + */ + actor: Actor; + /** + * The list of commits the actor is suggested for. May be left blank if the + * actor is not suggested for commits. + */ + commits?: Commit[]; + /** + * The list of ownership rules the actor is suggested for. May be left blank + * if the actor is not suggested based on ownership rules. + */ + rules?: any[] | null; +}; -class SuggestedOwnerHovercard extends React.Component { - static propTypes = { - /** - * The suggested actor. - */ - actor: PropTypes.oneOfType([ - // eslint-disable-next-line react/no-typos - SentryTypes.User, - // Sentry user which has *not* been expanded - PropTypes.shape({ - email: PropTypes.string.isRequired, - id: PropTypes.string.isRequired, - name: PropTypes.string.isRequired, - }), - // Unidentifier user (from commits) - PropTypes.shape({ - email: PropTypes.string.isRequired, - name: PropTypes.string.isRequired, - }), - // Sentry team - PropTypes.shape({ - id: PropTypes.string.isRequired, - name: PropTypes.string.isRequired, - }), - ]), - - /** - * The list of commits the actor is suggested for. May be left blank if the - * actor is not suggested for commits. - */ - commits: PropTypes.arrayOf( - PropTypes.shape({ - message: PropTypes.string.isRequired, - dateCreated: PropTypes.string.isRequired, - }) - ), - - /** - * The list of ownership rules the actor is suggested for. Maybe left blank - * if the actor is not suggested based on ownership rules. - */ - rules: PropTypes.arrayOf(PropTypes.array), - }; +type State = { + commitsExpanded: boolean; + rulesExpanded: boolean; +}; - state = { +class SuggestedOwnerHovercard extends React.Component { + state: State = { commitsExpanded: false, rulesExpanded: false, }; render() { const {actor, commits, rules, ...props} = this.props; + const {commitsExpanded, rulesExpanded} = this.state; return (
{commits - .slice(0, this.state.commitsExpanded ? commits.length : 3) + .slice(0, commitsExpanded ? commits.length : 3) .map(({message, dateCreated}, i) => ( @@ -119,21 +99,21 @@ class SuggestedOwnerHovercard extends React.Component { ))}
- {commits.length > 3 && !this.state.commitsExpanded ? ( + {commits.length > 3 && !commitsExpanded ? ( this.setState({commitsExpanded: true})} /> ) : null} )} - {rules !== undefined && ( + {defined(rules) && (
{t('Matching Ownership Rules')}
{rules - .slice(0, this.state.rulesExpanded ? rules.length : 3) + .slice(0, rulesExpanded ? rules.length : 3) .map(([type, matched], i) => ( @@ -141,7 +121,7 @@ class SuggestedOwnerHovercard extends React.Component { ))}
- {rules.length > 3 && !this.state.rulesExpanded ? ( + {rules.length > 3 && !rulesExpanded ? ( this.setState({rulesExpanded: true})} /> ) : null}
@@ -172,7 +152,7 @@ const CommitMessage = styled(({message = '', date, ...props}) => ( ))` color: ${p => p.theme.gray800}; - font-size: 11px; + font-size: ${p => p.theme.fontSizeExtraSmall}; margin-top: ${space(0.25)}; hyphens: auto; `; @@ -204,8 +184,8 @@ const RuleReasonItem = styled('code')` const OwnershipTag = styled(({tagType, ...props}) =>
{tagType}
)` background: ${p => tagColors[p.tagType.indexOf('tags') === -1 ? p.tagType : 'tag']}; - color: #fff; - font-size: 11px; + color: ${p => p.theme.white}; + font-size: ${p => p.theme.fontSizeExtraSmall}; padding: ${space(0.25)} ${space(0.5)}; margin: ${space(0.25)} ${space(0.5)} ${space(0.25)} 0; border-radius: 2px;