-
Notifications
You must be signed in to change notification settings - Fork 401
Hook up the details page to data #912
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1ea825f
Hook up the details page to data
kumar303 baf6aa0
switch comma to string
kumar303 979db83
whitelist the same description tags as olympia
kumar303 48e5123
localize 'by' in author list
kumar303 a64de88
move addHook into core/purify
kumar303 0bb3878
transform windows line breaks into br too
kumar303 9d47386
test that some tag attributes are stripped
kumar303 01664a9
fix localization of the author by-line
kumar303 3459d8d
correct some test descriptions
kumar303 5a1fcd4
fix missing quotes
kumar303 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,13 +1,39 @@ | ||
| import React from 'react'; | ||
| import React, { PropTypes } from 'react'; | ||
| import { compose } from 'redux'; | ||
| import { asyncConnect } from 'redux-async-connect'; | ||
| import { connect } from 'react-redux'; | ||
|
|
||
| import AddonDetail from 'amo/components/AddonDetail'; | ||
| import translate from 'core/i18n/translate'; | ||
| import { loadAddonIfNeeded } from 'core/utils'; | ||
|
|
||
| export class DetailPage extends React.Component { | ||
| static propTypes = { | ||
| addon: PropTypes.object, | ||
| } | ||
|
|
||
| export default class DetailPage extends React.Component { | ||
| render() { | ||
| return ( | ||
| <div> | ||
| <AddonDetail /> | ||
| <AddonDetail {...this.props} /> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| function mapStateToProps(state, ownProps) { | ||
| const { slug } = ownProps.params; | ||
| return { | ||
| addon: state.addons[slug], | ||
| slug, | ||
| }; | ||
| } | ||
|
|
||
| export default compose( | ||
| asyncConnect([{ | ||
| deferred: true, | ||
| promise: loadAddonIfNeeded, | ||
| }]), | ||
| connect(mapStateToProps), | ||
| translate({ withRef: true }), | ||
| )(DetailPage); | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,14 @@ | ||
| import createDOMPurify from 'dompurify'; | ||
| import universalWindow from 'core/window'; | ||
|
|
||
| export default createDOMPurify(universalWindow); | ||
| const purify = createDOMPurify(universalWindow); | ||
| export default purify; | ||
|
|
||
| purify.addHook('afterSanitizeAttributes', (node) => { | ||
| // Set all elements owning target to target=_blank | ||
| // and add rel="noreferrer". | ||
| if ('target' in node) { | ||
| node.setAttribute('target', '_blank'); | ||
| node.setAttribute('rel', 'noreferrer'); | ||
| } | ||
| }); |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| import camelCase from 'camelcase'; | ||
| import config from 'config'; | ||
|
|
||
| import { loadEntities } from 'core/actions'; | ||
| import { fetchAddon } from 'core/api'; | ||
| import log from 'core/logger'; | ||
| import purify from 'core/purify'; | ||
|
|
||
| export function gettext(str) { | ||
| return str; | ||
| } | ||
|
|
@@ -61,3 +66,39 @@ export function getClientApp(userAgentString) { | |
| export function isValidClientApp(value, { _config = config } = {}) { | ||
| return _config.get('validClientApplications').includes(value); | ||
| } | ||
|
|
||
| export function sanitizeHTML(text, allowTags = []) { | ||
|
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 know this was pre-existing, but |
||
| // TODO: Accept tags to allow and run through dom-purify. | ||
| return { | ||
| __html: purify.sanitize(text, { ALLOWED_TAGS: allowTags }), | ||
| }; | ||
| } | ||
|
|
||
| // Convert new lines to HTML breaks. | ||
| export function nl2br(text) { | ||
| return text.replace(/(?:\r\n|\r|\n)/g, '<br />'); | ||
| } | ||
|
|
||
| export function findAddon(state, slug) { | ||
| return state.addons[slug]; | ||
| } | ||
|
|
||
| // asyncConnect() helper for loading an add-on by slug. | ||
| // | ||
| // This accepts component properties and returns a promise | ||
| // that resolves when the requested add-on has been dispatched. | ||
| // If the add-on has already been fetched, the add-on value is returned. | ||
| // | ||
| export function loadAddonIfNeeded( | ||
| { store: { dispatch, getState }, params: { slug } } | ||
| ) { | ||
| const state = getState(); | ||
| const addon = findAddon(state, slug); | ||
| if (addon) { | ||
| log.info(`Found addon ${addon.id} in state`); | ||
| return addon; | ||
| } | ||
| log.info(`Fetching addon ${slug} from API`); | ||
| return fetchAddon({ slug, api: state.api }) | ||
| .then(({ entities }) => dispatch(loadEntities(entities))); | ||
| } | ||
This file contains hidden or 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 hidden or 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.
This is definitely nicer 👍