Skip to content

Commit

Permalink
Remove unused terms, taxonomies and categories code (#8250)
Browse files Browse the repository at this point in the history
* Deprecate receiveTerms

* Deprecate terms and taxonomies reducers

* Deprecate getCategories resolver

* Deprecate getCategories and getTerms selectors

* Deprecate isRequestingTerms and isRequestingCategories selectors

* Update docs

* Do not deprecate reducers, as they are not public API

* Use public API in deprecation messages

* Update docs

* Resolve conflicts in deprecations file

* Use 3.7.0 version

* Teach tests to understand deprecation warnings
  • Loading branch information
nosolosw authored and gziolo committed Aug 8, 2018
1 parent 5b81cbc commit ae2d929
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 74 deletions.
58 changes: 0 additions & 58 deletions docs/data/data-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,6 @@

## Selectors

### getTerms

Returns all the available terms for the given taxonomy.

*Parameters*

* state: Data state.
* taxonomy: Taxonomy name.

### getCategories

Returns all the available categories.

*Parameters*

* state: Data state.

*Returns*

Categories list.

### isRequestingTerms

Returns true if a request is in progress for terms data of a given taxonomy,
or false otherwise.

*Parameters*

* state: Data state.
* taxonomy: Taxonomy name.

*Returns*

Whether a request is in progress for taxonomy's terms.

### isRequestingCategories

Returns true if a request is in progress for categories data, or false
otherwise.

*Parameters*

* state: Data state.

*Returns*

Whether a request is in progress for categories.

### getAuthors

Returns all available authors.
Expand Down Expand Up @@ -118,16 +70,6 @@ Index data.

## Actions

### receiveTerms

Returns an action object used in signalling that terms have been received
for a given taxonomy.

*Parameters*

* taxonomy: Taxonomy name.
* terms: Terms received.

### receiveUserQuery

Returns an action object used in signalling that authors have been received.
Expand Down
5 changes: 5 additions & 0 deletions docs/reference/deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo
## 3.7.0

- `wp.components.withAPIData` has been removed. Please use the Core Data module or `wp.apiFetch` directly instead.
- `wp.data.dispatch("core").receiveTerms` has been deprecated. Please use `wp.data.dispatch("core").receiveEntityRecords` instead.
- `getCategories` resolvers has been deprecated. Please use `getEntityRecords` resolver instead.
- `wp.data.select("core").getTerms` has been deprecated. Please use `wp.data.select("core").getEntityRecords` instead.
- `wp.data.select("core").getCategories` has been deprecated. Please use `wp.data.select("core").getEntityRecords` instead.
- `wp.data.select("core").isRequestingTerms` has been deprecated. Please use `wp.data.select("core").getEntitiesByKind` instead.

## 3.6.0

Expand Down
23 changes: 7 additions & 16 deletions packages/core-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,24 @@ npm install @wordpress/core-data --save

## Example

Below is an example of a component which simply renders a list of categories:
Below is an example of a component which simply renders a list of authors:

```jsx
const { withSelect } = wp.data;

function MyCategoriesList( { categories, isRequesting } ) {
if ( isRequesting ) {
return 'Loading…';
}

function MyAuthorsList( { authors } ) {
return (
<ul>
{ categories.map( ( category ) => (
<li key={ category.id }>{ category.name }</li>
{ authors.map( ( author ) => (
<li key={ author.id }>{ author.name }</li>
) ) }
</ul>
);
}

MyCategoriesList = withSelect( ( select ) => {
const { getCategories, isRequestingCategories } = select( 'core' );

return {
categories: getCategories(),
isRequesting: isRequestingCategories(),
};
} );
MyAuthorsList = withSelect( ( select ) => ( {
authors: select( 'core' ).getAuthors(),
} ) );
```

## Actions
Expand Down
6 changes: 6 additions & 0 deletions packages/core-data/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { castArray } from 'lodash';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
Expand All @@ -21,6 +22,11 @@ import {
* @return {Object} Action object.
*/
export function receiveTerms( taxonomy, terms ) {
deprecated( 'wp.data.dispatch("core").receiveTerms', {
version: '3.7.0',
alternative: 'wp.data.dispatch("core").receiveEntityRecords',
plugin: 'Gutenberg',
} );
return {
type: 'RECEIVE_TERMS',
taxonomy,
Expand Down
6 changes: 6 additions & 0 deletions packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { find } from 'lodash';
*/
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
Expand All @@ -26,6 +27,11 @@ import { getKindEntities } from './entities';
* progress.
*/
export async function* getCategories() {
deprecated( 'getCategories resolver', {
version: '3.7.0',
alternative: 'getEntityRecords resolver',
plugin: 'Gutenberg',
} );
const categories = await apiFetch( { path: '/wp/v2/categories?per_page=-1' } );
yield receiveTerms( 'categories', categories );
}
Expand Down
21 changes: 21 additions & 0 deletions packages/core-data/src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { map, find, get, filter } from 'lodash';
* WordPress dependencies
*/
import { select } from '@wordpress/data';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
Expand Down Expand Up @@ -37,6 +38,11 @@ function isResolving( selectorName, ...args ) {
* @return {Array} Categories list.
*/
export function getTerms( state, taxonomy ) {
deprecated( 'wp.data.select("core").getTerms', {
version: '3.7.0',
alternative: 'wp.data.select("core").getEntityRecords',
plugin: 'Gutenberg',
} );
return state.terms[ taxonomy ];
}

Expand All @@ -48,6 +54,11 @@ export function getTerms( state, taxonomy ) {
* @return {Array} Categories list.
*/
export function getCategories( state ) {
deprecated( 'wp.data.select("core").getCategories', {
version: '3.7.0',
alternative: 'wp.data.select("core").getEntityRecords',
plugin: 'Gutenberg',
} );
return getTerms( state, 'categories' );
}

Expand All @@ -61,6 +72,11 @@ export function getCategories( state ) {
* @return {boolean} Whether a request is in progress for taxonomy's terms.
*/
export function isRequestingTerms( state, taxonomy ) {
deprecated( 'wp.data.select("core").isRequestingTerms', {
version: '3.7.0',
alternative: 'wp.data.select("core").getEntitiesByKind',
plugin: 'Gutenberg',
} );
return isResolving( 'getTerms', taxonomy );
}

Expand All @@ -73,6 +89,11 @@ export function isRequestingTerms( state, taxonomy ) {
* @return {boolean} Whether a request is in progress for categories.
*/
export function isRequestingCategories() {
deprecated( 'wp.data.select("core").isRequestingCategories', {
version: '3.7.0',
alternative: 'wp.data.select("core").getEntitiesByKind',
plugin: 'Gutenberg',
} );
return isResolving( 'getCategories' );
}

Expand Down
1 change: 1 addition & 0 deletions packages/core-data/src/test/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe( 'getCategories', () => {
const fulfillment = getCategories();
const received = ( await fulfillment.next() ).value;
expect( received ).toEqual( receiveTerms( 'categories', CATEGORIES ) );
expect( console ).toHaveWarnedWith( 'getCategories resolver is deprecated and will be removed from Gutenberg in 3.7.0. Please use getEntityRecords resolver instead.' );
} );
} );

Expand Down
2 changes: 2 additions & 0 deletions packages/core-data/src/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe( 'getTerms()', () => {
},
} );
expect( getTerms( state, 'categories' ) ).toEqual( [ { id: 1 } ] );
expect( console ).toHaveWarnedWith( 'wp.data.select("core").getTerms is deprecated and will be removed from Gutenberg in 3.7.0. Please use wp.data.select("core").getEntityRecords instead.' );
} );
} );

Expand All @@ -58,6 +59,7 @@ describe( 'isRequestingCategories()', () => {
it( 'returns false if never requested', () => {
const result = isRequestingCategories();
expect( result ).toBe( false );
expect( console ).toHaveWarnedWith( 'wp.data.select("core").isRequestingCategories is deprecated and will be removed from Gutenberg in 3.7.0. Please use wp.data.select("core").getEntitiesByKind instead.' );
} );

it( 'returns false if categories resolution finished', () => {
Expand Down

0 comments on commit ae2d929

Please sign in to comment.