-
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
Report add-on abuse UI #3202
Merged
Merged
Report add-on abuse UI #3202
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
import classNames from 'classnames'; | ||
import { oneLine } from 'common-tags'; | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import Textarea from 'react-textarea-autosize'; | ||
import { compose } from 'redux'; | ||
|
||
import { withErrorHandler } from 'core/errorHandler'; | ||
import type { ErrorHandlerType } from 'core/errorHandler'; | ||
import translate from 'core/i18n/translate'; | ||
import log from 'core/logger'; | ||
import { | ||
disableAbuseButtonUI, | ||
enableAbuseButtonUI, | ||
hideAddonAbuseReportUI, | ||
sendAddonAbuseReport, | ||
showAddonAbuseReportUI, | ||
} from 'core/reducers/abuse'; | ||
import { sanitizeHTML } from 'core/utils'; | ||
import Button from 'ui/components/Button'; | ||
|
||
import './styles.scss'; | ||
|
||
|
||
type PropTypes = { | ||
abuseReport: {| | ||
message: string, | ||
reporter: Object | null, | ||
|}, | ||
addon: Object | null, | ||
dispatch: Function, | ||
errorHandler: ErrorHandlerType, | ||
loading: bool, | ||
i18n: Object, | ||
}; | ||
|
||
export class ReportAbuseButtonBase extends React.Component { | ||
dismissReportUI = (event) => { | ||
event.preventDefault(); | ||
|
||
const { addon, dispatch, loading } = this.props; | ||
|
||
if (loading) { | ||
log.debug( | ||
"Ignoring dismiss click because we're submitting the abuse report"); | ||
return; | ||
} | ||
|
||
dispatch(hideAddonAbuseReportUI({ addon })); | ||
} | ||
|
||
sendReport = (event) => { | ||
event.preventDefault(); | ||
|
||
// The button isn't clickable if there is no content, but just in case: | ||
// we verify there's a message to send. | ||
if (!this.textarea.value.length) { | ||
log.debug(oneLine`User managed to click submit button while textarea | ||
was empty. Ignoring this onClick/sendReport event.`); | ||
return; | ||
} | ||
|
||
const { addon, dispatch, errorHandler } = this.props; | ||
|
||
dispatch(sendAddonAbuseReport({ | ||
addonSlug: addon.slug, | ||
errorHandlerId: errorHandler.id, | ||
message: this.textarea.value, | ||
})); | ||
} | ||
|
||
showReportUI = (event) => { | ||
event.preventDefault(); | ||
|
||
const { addon, dispatch } = this.props; | ||
|
||
dispatch(showAddonAbuseReportUI({ addon })); | ||
this.textarea.focus(); | ||
} | ||
|
||
textareaChange = () => { | ||
const { abuseReport, addon, dispatch } = this.props; | ||
|
||
// Don't dispatch the UI update if the button is already visible. | ||
// We also test for `value.trim()` so the user can't submit an | ||
// empty report full of spaces. | ||
if (this.textarea.value.trim().length && !abuseReport.buttonEnabled) { | ||
dispatch(enableAbuseButtonUI({ addon })); | ||
} else if (!this.textarea.value.trim().length) { | ||
dispatch(disableAbuseButtonUI({ addon })); | ||
} | ||
} | ||
|
||
props: PropTypes; | ||
|
||
render() { | ||
const { abuseReport, addon, i18n, loading } = this.props; | ||
|
||
if (!addon) { | ||
return null; | ||
} | ||
|
||
if (abuseReport && abuseReport.message) { | ||
return ( | ||
<div className="ReportAbuseButton ReportAbuseButton--report-sent"> | ||
<h3 className="ReportAbuseButton-header"> | ||
{i18n.gettext('You reported this add-on for abuse')} | ||
</h3> | ||
|
||
<p className="ReportAbuseButton-first-paragraph"> | ||
{i18n.gettext( | ||
`We have received your report. Thanks for letting us know about | ||
your concerns with this add-on.` | ||
)} | ||
</p> | ||
|
||
<p> | ||
{i18n.gettext( | ||
`We can't respond to every abuse report but we'll look into | ||
this issue.` | ||
)} | ||
</p> | ||
</div> | ||
); | ||
} | ||
|
||
const sendButtonIsDisabled = loading || !abuseReport.buttonEnabled; | ||
|
||
const prefaceText = i18n.sprintf(i18n.gettext( | ||
`If you think this add-on violates | ||
%(linkTagStart)sMozilla's add-on policies%(linkTagEnd)s or has | ||
security or privacy issues, please report these issues to Mozilla using | ||
this form.` | ||
), { | ||
linkTagStart: '<a href="https://developer.mozilla.org/en-US/Add-ons/AMO/Policy">', | ||
linkTagEnd: '</a>', | ||
}); | ||
|
||
/* eslint-disable react/no-danger */ | ||
return ( | ||
<div | ||
className={classNames('ReportAbuseButton', { | ||
'ReportAbuseButton--is-expanded': abuseReport.uiVisible, | ||
})} | ||
> | ||
<div className="ReportAbuseButton--preview"> | ||
<Button | ||
className="ReportAbuseButton-show-more Button--report" | ||
onClick={this.showReportUI} | ||
> | ||
{i18n.gettext('Report this add-on for abuse')} | ||
</Button> | ||
</div> | ||
|
||
<div className="ReportAbuseButton--expanded"> | ||
<h3 className="ReportAbuseButton-header"> | ||
{i18n.gettext('Report this add-on for abuse')} | ||
</h3> | ||
|
||
<p | ||
className="ReportAbuseButton-first-paragraph" | ||
dangerouslySetInnerHTML={sanitizeHTML(prefaceText, ['a'])} | ||
/> | ||
|
||
<p>{i18n.gettext( | ||
`Please don't use this form to report bugs or request add-on | ||
features; this report will be sent to Mozilla and not to the | ||
add-on developer.` | ||
)}</p> | ||
<Textarea | ||
className="ReportAbuseButton-textarea" | ||
disabled={loading} | ||
inputRef={(ref) => { this.textarea = ref; }} | ||
onChange={this.textareaChange} | ||
placeholder={i18n.gettext( | ||
'Explain how this add-on is violating our policies.' | ||
)} | ||
/> | ||
|
||
<div className="ReportAbuseButton-buttons"> | ||
<a | ||
className={classNames('ReportAbuseButton-dismiss-report', { | ||
'ReportAbuseButton-dismiss-report--disabled': loading, | ||
})} | ||
href="#cancel" | ||
onClick={this.dismissReportUI} | ||
> | ||
{i18n.gettext('Dismiss')} | ||
</a> | ||
<Button | ||
className="ReportAbuseButton-send-report Button--report Button--small" | ||
disabled={sendButtonIsDisabled} | ||
onClick={this.sendReport} | ||
> | ||
{loading ? | ||
i18n.gettext('Sending abuse report') : | ||
i18n.gettext('Send abuse report')} | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
/* eslint-enable react/no-danger */ | ||
} | ||
} | ||
|
||
export const mapStateToProps = (state, ownProps) => { | ||
const addon = ownProps.addon; | ||
|
||
return { | ||
abuseReport: addon && state.abuse.bySlug[addon.slug] ? | ||
state.abuse.bySlug[addon.slug] : {}, | ||
loading: state.abuse.loading, | ||
}; | ||
}; | ||
|
||
export default compose( | ||
connect(mapStateToProps), | ||
translate(), | ||
withErrorHandler({ name: 'ReportAbuseButton' }), | ||
)(ReportAbuseButtonBase); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
@import "~ui/css/vars"; | ||
|
||
.ReportAbuseButton { | ||
margin: 10px auto; | ||
} | ||
|
||
.ReportAbuseButton-header { | ||
margin-bottom: 0; | ||
} | ||
|
||
.ReportAbuseButton-first-paragraph { | ||
margin-top: 6px; | ||
} | ||
|
||
.ReportAbuseButton--preview { | ||
display: block; | ||
|
||
.ReportAbuseButton--is-expanded & { | ||
display: none; | ||
} | ||
} | ||
|
||
.ReportAbuseButton--expanded { | ||
display: none; | ||
|
||
.ReportAbuseButton--is-expanded & { | ||
display: block; | ||
} | ||
} | ||
|
||
.ReportAbuseButton-show-more { | ||
width: 100%; | ||
} | ||
|
||
.ReportAbuseButton-textarea { | ||
font-size: $font-size-m-smaller; | ||
line-height: 1.4; | ||
margin: 5px auto; | ||
// This is the height of two lines of text. Often the placeholder text | ||
// will span two lines–because this element will grow/shrink based on | ||
// the contents of the text inside it, we set a minimum height so it | ||
// won't shrink when the two-line placeholder is replaced with a single | ||
// character when the user starts typing. | ||
min-height: 51px; | ||
padding: 5px; | ||
resize: none; | ||
width: 100%; | ||
} | ||
|
||
.ReportAbuseButton-buttons { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
|
||
.ReportAbuseButton-dismiss-report { | ||
align-self: center; | ||
} | ||
|
||
.ReportAbuseButton-dismiss-report--disabled:link { | ||
color: $neutral-base-color; | ||
cursor: not-allowed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
no need for
oneLine
tag here? (same comment applies 7 lines above)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.
Yeah, I think I've mentioned it but it's easy to forget and very confusing: for
i18n
calls specifically our i18n tools deal with multiline template strings and automaticallyoneLine
them. If we do it manually there are weird bugs (see #2059).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.
Ah snap. Forgot it, again.