Skip to content
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

State: Migrate lib/site-roles to Redux state #9249

Merged
merged 6 commits into from
Nov 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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