-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Plugins: Add QueryJetpackPlugins query component #8275
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
83d87c4
Plugins: Add QueryJetpackPlugins query component
tyxla b69c6b4
Jetpack Plugins: Use site IDs instead of site objects to fetch plugins
tyxla 432063e
Jetpack Plugins: Rename installed plugins test describe calls
tyxla 01568f7
Jetpack Plugins: Hide promise errors from installed plugin tests
tyxla 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 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,19 @@ | ||
Query Jetpack Plugins | ||
================= | ||
|
||
`<QueryJetpackPlugins />` is a React component used in managing network requests for Jetpack plugins. | ||
|
||
## Usage | ||
|
||
Render the component, passing `siteIds`. It does not accept any children, nor does it render any elements to the page. You can use it adjacent to other sibling components which make use of the fetched data made available through the global application state. | ||
|
||
## Props | ||
|
||
### `siteIds` | ||
|
||
<table> | ||
<tr><th>Type</th><td>Array</td></tr> | ||
<tr><th>Required</th><td>Yes</td></tr> | ||
</table> | ||
|
||
The array of site IDs for which Jetpack plugins should be requested. |
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,52 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { Component, PropTypes } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { isEqual } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { fetchPlugins } from 'state/plugins/installed/actions'; | ||
import { isRequestingForSites } from 'state/plugins/installed/selectors'; | ||
|
||
class QueryJetpackPlugins extends Component { | ||
componentWillMount() { | ||
if ( this.props.siteIds && ! this.props.isRequestingForSites ) { | ||
this.props.fetchPlugins( this.props.siteIds ); | ||
} | ||
} | ||
|
||
componentWillReceiveProps( nextProps ) { | ||
if ( isEqual( nextProps.siteIds, this.props.siteIds ) ) { | ||
return; | ||
} | ||
this.refresh( nextProps.isRequestingForSites, nextProps.siteIds ); | ||
} | ||
|
||
refresh( isRequesting, siteIds ) { | ||
if ( ! isRequesting ) { | ||
this.props.fetchPlugins( siteIds ); | ||
} | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
QueryJetpackPlugins.propTypes = { | ||
siteIds: PropTypes.array.isRequired, | ||
isRequestingForSites: PropTypes.bool, | ||
fetchPlugins: PropTypes.func | ||
}; | ||
|
||
export default connect( | ||
( state, props ) => { | ||
return { | ||
isRequestingForSites: isRequestingForSites( state, props.siteIds ), | ||
}; | ||
}, | ||
{ fetchPlugins } | ||
)( QueryJetpackPlugins ); |
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
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.
Let's ask a native english speaker about it, but shouldn't it be "isRequestingSites", without the 'for' ?
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.
isRequestingForSites
makes sense to me because we're checking if it's requesting plugins for sites, but I can see it either way. English ¯_(ツ)_/¯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.
ok, yeah, that makes sense ... "isRequestingForSites" sounds ok if you think about it like that .
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.
I agree with @ryelle on this one - we're requesting the plugins for the given sites, so naming makes sense.