Skip to content

Commit

Permalink
Merge pull request #9249 from Automattic/update/redixify-site-roles
Browse files Browse the repository at this point in the history
State: Migrate lib/site-roles to Redux state
  • Loading branch information
tyxla authored Nov 14, 2016
2 parents 5279fde + 5e32301 commit 324337f
Show file tree
Hide file tree
Showing 20 changed files with 772 additions and 452 deletions.
38 changes: 38 additions & 0 deletions client/components/data/query-site-roles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Query Site Roles
================

`<QuerySiteRoles />` is a React component used in managing network requests for site roles.

## Usage

Render the component, passing `siteId`. 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.

```jsx
import React from 'react';
import QuerySiteRoles from 'components/data/query-site-roles';
import MySiteRolesListItem from './list-item';

export default function MySiteRolesList( { siteRoles } ) {
return (
<div>
<QuerySiteRoles siteId={ 12345678 } />
{ siteRoles.map( ( role ) => {
return (
<MySiteRolesListItem role={ role } />
);
} }
</div>
);
}
```
## Props
### `siteId`
<table>
<tr><th>Type</th><td>Number</td></tr>
<tr><th>Required</th><td>Yes</td></tr>
</table>
The site ID for which site roles should be requested.
50 changes: 50 additions & 0 deletions client/components/data/query-site-roles/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* External dependencies
*/
import { Component, PropTypes } from 'react';
import { connect } from 'react-redux';

/**
* Internal dependencies
*/
import { isRequestingSiteRoles } from 'state/site-roles/selectors';
import { requestSiteRoles } from 'state/site-roles/actions';

class QuerySiteRoles extends Component {
static propTypes = {
siteId: PropTypes.number.isRequired,
requestingSiteRoles: PropTypes.bool,
requestSiteRoles: PropTypes.func
};

componentWillMount() {
this.request( this.props );
}

componentWillReceiveProps( nextProps ) {
if ( this.props.siteId !== nextProps.siteId ) {
this.request( nextProps );
}
}

request( props ) {
if ( props.requestingSiteRoles ) {
return;
}

props.requestSiteRoles( props.siteId );
}

render() {
return null;
}
}

export default connect(
( state, ownProps ) => {
return {
requestingSiteRoles: isRequestingSiteRoles( state, ownProps.siteId )
};
},
{ requestSiteRoles }
)( QuerySiteRoles );
4 changes: 0 additions & 4 deletions client/lib/site-roles/README.md

This file was deleted.

33 changes: 0 additions & 33 deletions client/lib/site-roles/actions.js

This file was deleted.

68 changes: 0 additions & 68 deletions client/lib/site-roles/store.js

This file was deleted.

128 changes: 0 additions & 128 deletions client/lib/site-roles/test/fixtures/roles.js

This file was deleted.

31 changes: 0 additions & 31 deletions client/lib/site-roles/test/fixtures/site.js

This file was deleted.

11 changes: 0 additions & 11 deletions client/lib/site-roles/test/mocks/lib/actions.js

This file was deleted.

Loading

0 comments on commit 324337f

Please sign in to comment.