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

Disable the Preview button when post type isn't viewable #6232

Merged
merged 5 commits into from
Apr 18, 2018

Conversation

danielbachhuber
Copy link
Member

@danielbachhuber danielbachhuber commented Apr 18, 2018

Description

In the classic editor, the preview button is only available if is_post_type_viewable returns true. We are updating the logic to follow the same behavior.

Fixes #5749

Previously #5770 #6120

How Has This Been Tested?

Register a post type with publicly_queryable set to false.
E.g:

function create_product_type() {
	register_post_type( 'acme_product',
		array(
			'label'  => 'Product',
			'labels' => array(
				'name' => __( 'Products' ),
				'singular_name' => __( 'Product' )
			),
			'public' => true,
			'show_in_rest' => true,
			'publicly_queryable' => false,
		)
	);
}
add_action( 'init', 'create_product_type' );

Verify preview button is not available for posts of this Post Type.

image

image

@danielbachhuber
Copy link
Member Author

@pento There doesn't seem to be a good way to test a component using ifCondition. Specifically, I tried the following and didn't see what I expected:

it( 'should be null if the post type is not viewable', () => {
	const wrapper = shallow(
		<PostPreviewButton
			postId={ 1 }
			isSaveable
			isViewable={ false }
			link="https://wordpress.org/?p=1" />
	);
	expect( wrapper ).toBe( null );
} );

Is there a direction you can point me in, or should we punt on it for now?

@gziolo
Copy link
Member

gziolo commented Apr 18, 2018

@danielbachhuber, given that isViewable is coming from REST API and is never used inside the component because HOC bails out early when it is set to false, it won't work this way. In general, we don't test all those HOCs with unit tests. You could do it, but it's usually too much work to mock all dependencies which only slows us down when doing refactoring later. See also this section in our testing docs: https://github.com/WordPress/gutenberg/blob/master/docs/testing-overview.md#pain-points.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@youknowriad youknowriad merged commit d6d950a into master Apr 18, 2018
@youknowriad
Copy link
Contributor

Merged to include in the release.

@youknowriad youknowriad deleted the 5749-disable-preview-two branch April 18, 2018 08:32
nuzzio pushed a commit to nuzzio/gutenberg that referenced this pull request Apr 25, 2018
)

* Add tests for `viewable` REST API param

* Minor corrections to test and docs

* Disable the Preview button when post type isn't viewable

* Fix coding style issue

* Add e2e assertion for the preview button
@heldervilela
Copy link

Related to this topic.
In the WP 5.0 if the post type is 'publicly_queryable' => false the editor show the notice "Updating failed".

notice

Because of this error:

error

Let me know if more info is needed.

@danielbachhuber
Copy link
Member Author

@heldervilela Could you start a new issue for your bug, please? Having a new issue will help ensure the conversation isn't lost, and that your particular need is tracked through to resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants