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

Editor store: remove createUndoLevel and refreshPost actions #38585

Merged
merged 2 commits into from Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions docs/reference-guides/data/data-core-editor.md
Expand Up @@ -1043,12 +1043,9 @@ _Related_

### createUndoLevel

Returns an action object used in signalling that undo history record should
be created.
> **Deprecated** Since Gutenberg 13.0.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 Gutenberg 13.0.0.

Action for refreshing the current post.

### removeBlock

Expand Down
4 changes: 4 additions & 0 deletions packages/editor/CHANGELOG.md
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
38 changes: 15 additions & 23 deletions packages/editor/src/store/actions.js
Expand Up @@ -280,27 +280,16 @@ export function* savePost( options = {} ) {
}

/**
* Action generator for handling refreshing the current post.
* Action for refreshing the current post.
*
* @deprecated Since Gutenberg 13.0.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: '5.9',
alternative: 'Use the core entities store instead',
} );
yield controls.dispatch( STORE_NAME, 'resetPost', newPost );
return { type: 'DO_NOTHING' };
}

/**
Expand Down Expand Up @@ -404,13 +393,16 @@ 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 Gutenberg 13.0.0
*/
export function createUndoLevel() {
return { type: 'CREATE_UNDO_LEVEL' };
deprecated( "wp.data.dispatch( 'core/editor' ).createUndoLevel", {
since: '5.9',
alternative: 'Use the core entities store instead',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is GitHub missing a commit or something, I don't see the "version": "6.0"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, turns out I didn't really push the commit to the server 🙂 Please look again now.

} );
return { type: 'DO_NOTHING' };
}

/**
Expand Down
40 changes: 0 additions & 40 deletions packages/editor/src/store/test/actions.js
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