-
Notifications
You must be signed in to change notification settings - Fork 395
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
feat: Add a link to the stats dashboard for add-on owners #3203
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
/* @flow */ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { compose } from 'redux'; | ||
|
||
import Link from 'amo/components/Link'; | ||
import translate from 'core/i18n/translate'; | ||
import { isAddonAuthor } from 'core/utils'; | ||
import type { AddonType } from 'core/types/addons'; | ||
import LoadingText from 'ui/components/LoadingText'; | ||
import Rating from 'ui/components/Rating'; | ||
|
||
import 'amo/css/AddonMeta.scss'; | ||
|
||
|
||
type PropTypes = { | ||
addon: AddonType | null, | ||
i18n: Object, | ||
userId: number | null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure we have discussed this yet (at least not with me), but Flow users tend to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also I would go for strict typing if possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it's up to the design of the component. If it were |
||
} | ||
|
||
export class AddonMetaBase extends React.Component { | ||
static propTypes = { | ||
addon: PropTypes.object.isRequired, | ||
i18n: PropTypes.object.isRequired, | ||
} | ||
props: PropTypes; | ||
|
||
render() { | ||
const { addon, i18n } = this.props; | ||
const { addon, i18n, userId } = this.props; | ||
const averageRating = addon ? addon.ratings.average : null; | ||
const addonRatingCount = addon ? addon.ratings.count : null; | ||
|
||
|
@@ -49,7 +56,14 @@ export class AddonMetaBase extends React.Component { | |
<div className="AddonMeta-item AddonMeta-users"> | ||
<h3 className="visually-hidden">{i18n.gettext('Used by')}</h3> | ||
<p className="AddonMeta-text AddonMeta-user-count"> | ||
{userCount} | ||
{addon && isAddonAuthor({ addon, userId }) ? ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is probably no need for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, true! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Annoyingly, flow can't understand I won't access that property unless |
||
<Link | ||
href={`/addon/${addon.slug}/statistics/`} | ||
title={i18n.gettext('Click to view statistics')} | ||
> | ||
{userCount} | ||
</Link> | ||
) : userCount} | ||
</p> | ||
<p className="AddonMeta-text AddonMeta-review-count"> | ||
{reviewCount} | ||
|
@@ -66,6 +80,13 @@ export class AddonMetaBase extends React.Component { | |
} | ||
} | ||
|
||
export const mapStateToProps = (state: Object) => { | ||
return { | ||
userId: state.user.id, | ||
}; | ||
}; | ||
|
||
export default compose( | ||
translate({ withRef: true }), | ||
connect(mapStateToProps), | ||
translate(), | ||
)(AddonMetaBase); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,30 @@ | ||
/* @flow */ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { compose } from 'redux'; | ||
|
||
import Link from 'amo/components/Link'; | ||
import ReportAbuseButton from 'amo/components/ReportAbuseButton'; | ||
import translate from 'core/i18n/translate'; | ||
import { trimAndAddProtocolToUrl } from 'core/utils'; | ||
import type { AddonType } from 'core/types/addons'; | ||
import { isAddonAuthor, trimAndAddProtocolToUrl } from 'core/utils'; | ||
import Card from 'ui/components/Card'; | ||
import LoadingText from 'ui/components/LoadingText'; | ||
|
||
import './styles.scss'; | ||
|
||
|
||
type PropTypes = { | ||
addon: AddonType | null, | ||
i18n: Object, | ||
userId: number | null, | ||
} | ||
|
||
export class AddonMoreInfoBase extends React.Component { | ||
static propTypes = { | ||
addon: PropTypes.object.isRequired, | ||
i18n: PropTypes.object.isRequired, | ||
} | ||
props: PropTypes; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
|
||
listContent() { | ||
const { addon, i18n } = this.props; | ||
const { addon, i18n, userId } = this.props; | ||
|
||
if (!addon) { | ||
return this.renderDefinitions({ | ||
|
@@ -52,6 +57,14 @@ export class AddonMoreInfoBase extends React.Component { | |
return this.renderDefinitions({ | ||
homepage, | ||
supportUrl, | ||
statsLink: addon && isAddonAuthor({ addon, userId }) ? ( | ||
<Link | ||
className="AddonMoreInfo-stats-link" | ||
href={`/addon/${addon.slug}/statistics/`} | ||
> | ||
{i18n.gettext('Visit stats dashboard')} | ||
</Link> | ||
) : null, | ||
version: addon.current_version.version, | ||
versionLastUpdated: i18n.sprintf( | ||
// translators: This will output, in English: | ||
|
@@ -62,12 +75,12 @@ export class AddonMoreInfoBase extends React.Component { | |
} | ||
), | ||
versionLicenseLink: addon.current_version.license ? ( | ||
<a | ||
<Link | ||
className="AddonMoreInfo-license-link" | ||
href={addon.current_version.license.url} | ||
> | ||
{addon.current_version.license.name} | ||
</a> | ||
</Link> | ||
) : null, | ||
privacyPolicyLink: addon.has_privacy_policy ? ( | ||
<Link | ||
|
@@ -87,29 +100,30 @@ export class AddonMoreInfoBase extends React.Component { | |
) : null, | ||
addonId: addon.id, | ||
versionHistoryLink: ( | ||
<a | ||
<Link | ||
className="AddonMoreInfo-version-history-link" | ||
href={`/addon/${addon.slug}/versions/`} | ||
> | ||
{i18n.gettext('See all versions')} | ||
</a> | ||
</Link> | ||
), | ||
// Since current_beta_version is just an alias to the latest beta, | ||
// we can assume that no betas exist at all if it is null. | ||
betaVersionsLink: addon.current_beta_version ? ( | ||
<a | ||
<Link | ||
className="AddonMoreInfo-beta-versions-link" | ||
href={`/addon/${addon.slug}/versions/beta`} | ||
> | ||
{i18n.gettext('See all beta versions')} | ||
</a> | ||
</Link> | ||
) : null, | ||
}); | ||
} | ||
|
||
renderDefinitions({ | ||
homepage = null, | ||
supportUrl = null, | ||
statsLink = null, | ||
privacyPolicyLink = null, | ||
eulaLink = null, | ||
version, | ||
|
@@ -118,7 +132,7 @@ export class AddonMoreInfoBase extends React.Component { | |
versionHistoryLink, | ||
betaVersionsLink = null, | ||
addonId, | ||
}) { | ||
}: Object) { | ||
const { i18n } = this.props; | ||
return ( | ||
<dl className="AddonMoreInfo-contents"> | ||
|
@@ -171,6 +185,12 @@ export class AddonMoreInfoBase extends React.Component { | |
</dt> | ||
) : null} | ||
{betaVersionsLink ? <dd>{betaVersionsLink}</dd> : null} | ||
{statsLink ? ( | ||
<dt className="AddonMoreInfo-stats-title"> | ||
{i18n.gettext('Usage Statistics')} | ||
</dt> | ||
) : null} | ||
{statsLink ? <dd>{statsLink}</dd> : null} | ||
<dt | ||
className="AddonMoreInfo-database-id-title" | ||
title={i18n.gettext(`This ID is useful for debugging and | ||
|
@@ -201,6 +221,13 @@ export class AddonMoreInfoBase extends React.Component { | |
} | ||
} | ||
|
||
export const mapStateToProps = (state: Object) => { | ||
return { | ||
userId: state.user.id, | ||
}; | ||
}; | ||
|
||
export default compose( | ||
connect(mapStateToProps), | ||
translate(), | ||
)(AddonMoreInfoBase); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,6 @@ a:link { | |
@include font-medium(); | ||
|
||
color: $link-color; | ||
font-size: 14px; | ||
} | ||
|
||
em { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs
/* @flow */
if you're going to use it for prop types.