Skip to content

Commit

Permalink
Editor store: remove createUndoLevel and refreshPost actions (#38585)
Browse files Browse the repository at this point in the history
* Editor store: remove createUndoLevel and refreshPost actions

* Correct deprecation versions
  • Loading branch information
jsnajdr authored Feb 8, 2022
1 parent 4e4e458 commit 96e3d2f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 69 deletions.
11 changes: 5 additions & 6 deletions docs/reference-guides/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1043,12 +1043,9 @@ _Related_

### createUndoLevel

Returns an action object used in signalling that undo history record should
be created.
> **Deprecated** Since WordPress 6.0
_Returns_

- `Object`: Action object.
Action that creates an undo history record.

### disablePublishSidebar

Expand Down Expand Up @@ -1221,7 +1218,9 @@ restore last popped state.

### refreshPost

Action generator for handling refreshing the current post.
> **Deprecated** Since WordPress 6.0.
Action for refreshing the current post.

### removeBlock

Expand Down
4 changes: 4 additions & 0 deletions packages/editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

- Removed unused `@wordpress/autop`, `@wordpress/blob` and `@wordpress/is-shallow-equal` dependencies ([#38388](https://github.com/WordPress/gutenberg/pull/38388)).

### Deprecations

- the `createUndoLevel` and `refreshPost` actions were marked as deprecated. They were already defunct and acting as noops.

## 12.1.0 (2022-01-27)

## 12.0.0 (2021-10-12)
Expand Down
40 changes: 17 additions & 23 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,27 +280,17 @@ export function* savePost( options = {} ) {
}

/**
* Action generator for handling refreshing the current post.
* Action for refreshing the current post.
*
* @deprecated Since WordPress 6.0.
*/
export function* refreshPost() {
const post = yield controls.select( STORE_NAME, 'getCurrentPost' );
const postTypeSlug = yield controls.select(
STORE_NAME,
'getCurrentPostType'
);
const postType = yield controls.resolveSelect(
coreStore,
'getPostType',
postTypeSlug
);
const newPost = yield apiFetch( {
// Timestamp arg allows caller to bypass browser caching, which is
// expected for this specific function.
path:
`/wp/v2/${ postType.rest_base }/${ post.id }` +
`?context=edit&_timestamp=${ Date.now() }`,
export function refreshPost() {
deprecated( "wp.data.dispatch( 'core/editor' ).refreshPost", {
since: '6.0',
version: '6.3',
alternative: 'Use the core entities store instead',
} );
yield controls.dispatch( STORE_NAME, 'resetPost', newPost );
return { type: 'DO_NOTHING' };
}

/**
Expand Down Expand Up @@ -404,13 +394,17 @@ export function* undo() {
}

/**
* Returns an action object used in signalling that undo history record should
* be created.
* Action that creates an undo history record.
*
* @return {Object} Action object.
* @deprecated Since WordPress 6.0
*/
export function createUndoLevel() {
return { type: 'CREATE_UNDO_LEVEL' };
deprecated( "wp.data.dispatch( 'core/editor' ).createUndoLevel", {
since: '6.0',
version: '6.3',
alternative: 'Use the core entities store instead',
} );
return { type: 'DO_NOTHING' };
}

/**
Expand Down
40 changes: 0 additions & 40 deletions packages/editor/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,46 +358,6 @@ describe( 'Post generator actions', () => {
} );
} );
} );
describe( 'refreshPost()', () => {
let fulfillment;
const currentPost = { id: 10, content: 'foo' };
const reset = () => ( fulfillment = actions.refreshPost() );
it( 'yields expected action for selecting the currentPost', () => {
reset();
const { value } = fulfillment.next();
expect( value ).toEqual(
controls.select( STORE_NAME, 'getCurrentPost' )
);
} );
it( 'yields expected action for selecting the current post type', () => {
const { value } = fulfillment.next( currentPost );
expect( value ).toEqual(
controls.select( STORE_NAME, 'getCurrentPostType' )
);
} );
it( 'yields expected action for selecting the post type object', () => {
const { value } = fulfillment.next( postTypeSlug );
expect( value ).toEqual(
controls.resolveSelect( 'core', 'getPostType', postTypeSlug )
);
} );
it( 'yields expected action for the api fetch call', () => {
const { value } = fulfillment.next( postType );
// since the timestamp is a computed value we can't do a direct comparison.
// so we'll just see if the path has most of the value.
expect( value.request.path ).toEqual(
expect.stringContaining(
`/wp/v2/${ postType.rest_base }/${ currentPost.id }?context=edit&_timestamp=`
)
);
} );
it( 'yields expected action for dispatching the reset of the post', () => {
const { value } = fulfillment.next( currentPost );
expect( value ).toEqual(
controls.dispatch( STORE_NAME, 'resetPost', currentPost )
);
} );
} );
} );

describe( 'Editor actions', () => {
Expand Down

0 comments on commit 96e3d2f

Please sign in to comment.