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: Use post.utils for Status Testing #1712

Merged
merged 5 commits into from
Jan 11, 2016

Conversation

timmyc
Copy link
Contributor

@timmyc timmyc commented Dec 17, 2015

While working in post-editor.jsx today I noticed a few places where we are still manually testing post.status instead of leveraging lib/posts/utils. This branch is simply some trash pickup for the locations where the post status was being manually tested. Additionally it adds a new method for testing to see if a post's status is private and some tests for isPublished().

To Test

  • Open up a new post in the editor
  • Privately publish a post and ensure the proper messaging is displayed in the confirmation notice, and in Ground Control
  • Hard refresh the page to ensure the post was indeed published privately
  • Make an update to the privately published post, verify the messaging is correct
  • Create a new public post, follow the steps above to confirm messaging is correct

@timmyc timmyc added [Feature] Post/Page Editor The editor for editing posts and pages. [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Dec 17, 2015
@timmyc timmyc self-assigned this Dec 17, 2015
@dmsnell
Copy link
Member

dmsnell commented Jan 5, 2016

@timmyc I think this might need some updating following some work that went on with the Notices. They received some love recently.

Set post as private
Note this surprised me because although I hadn't published my post yet, I had to publish it in order to select private visibility. Perhaps this is simply how WordPress works, but I could not find a way to make it a private draft, or go back to a normal public draft after I had selected private.

screen shot 2016-01-04 at 9 45 50 pm

Notice says that the post was privately published.

Update private post

screen shot 2016-01-04 at 9 46 17 pm

Notice doesn't mention private blog - just that it was updated.

screen shot 2016-01-04 at 9 46 48 pm

It does also show a JavaScript error in the prop to the notice.

Publish a public post

screen shot 2016-01-04 at 9 47 31 pm

Update a public post

This was the same as for the private post, so I am not copying the screenshots here. The error message came back.

I think that if the notice code gets updated this will run smoothly.

@dmsnell dmsnell added [Status] Needs Author Reply and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jan 5, 2016
@timmyc timmyc force-pushed the update/editor/use-status-utils branch from 7e7237e to 7cb3cc1 Compare January 5, 2016 18:15
@timmyc
Copy link
Contributor Author

timmyc commented Jan 5, 2016

@dmsnell thanks for the review - I had forgotten about this PR over the holidays :)

Note this surprised me because although I hadn't published my post yet, I had to publish it in order to select private visibility. Perhaps this is simply how WordPress works

Indeed this is an odd flow, but it is how WordPress works. When a post status is set to private it is essentially published at that point. There are a few old PR's with discussion around this, and the current flow that I'd be happy to point you towards if you'd like to read up on that.

As for warning messages, in 7cb3cc1 I added textOnly to the translate calls, but still the props.text was being passed in as an Array instead of an object or a string which was resulting in the warning from components/notice. As such I added array to the list of valid prop types for text. This remedies the warning and the notices are showing properly still.

@timmyc timmyc added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Author Reply labels Jan 5, 2016
@dmsnell
Copy link
Member

dmsnell commented Jan 5, 2016

As for warning messages, in 7cb3cc1 I added textOnly to the translate calls, but still the props.text was being passed in as an Array instead of an object or a string which was resulting in the warning from components/notice. As such I added array to the list of valid prop types for text. This remedies the warning and the notices are showing properly still.

why are they being passed as an array and is it the right solution to just accept the arrays?

@timmyc
Copy link
Contributor Author

timmyc commented Jan 5, 2016

the output of this.translate is producing the array in this particular scenario. I thought that by adding in textOnly: true as an option to the translate call would prevent this from happening but I was wrong.

The text propType already allows an object so it seems fair to allow an array of strings or jsx elements too.

@dmsnell
Copy link
Member

dmsnell commented Jan 5, 2016

would you be willing to humor me and paste the output of one of those translate calls here? I'm simply not grasping what the array elements would be

@timmyc
Copy link
Contributor Author

timmyc commented Jan 5, 2016

Surely. So the array here was a result of publishing a post, console.loging this.state.notice.text in renderNotice. At this point, the text is the output of the this.translate call here and results in an array:

edit_post_ testingtimmy2_wordpress_com _wordpress_com

First and last elements are strings, in position 1 we have a react element for the site name / link.

@dmsnell
Copy link
Member

dmsnell commented Jan 6, 2016

thanks @timmyc that helps a bunch. I didn't realize it handled such translation strings like that. my previous thoughts were that it passed a React element.

there is one way I would recommend supporting our code here, though I admit the likelihood of messing up here is probably pretty slim. we should basically have either a single or an array of either text or React node

text: PropTypes.oneOfType( [
    PropTypes.oneOfType( [ PropTypes.string, PropTypes.node ] ),
    PropTypes.arrayOf( PropTypes.oneOfType( [ PropTypes.string, PropTypes.node ] ) )
] ).isRequired

so this should cover all our cases. I would be interested at least to learn if it passes all the tests and works in the code. the thing I like here is that it gives slightly more hinting to the developers what should be expected, whereas [string, object, array] covers just about every possible parameter

@dmsnell dmsnell added [Status] Needs Author Reply and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jan 6, 2016
@timmyc
Copy link
Contributor Author

timmyc commented Jan 6, 2016

@dmsnell updated in 4ea1a42

@timmyc timmyc added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Author Reply labels Jan 6, 2016
@dmsnell
Copy link
Member

dmsnell commented Jan 6, 2016

Thanks @timmyc - next ❓ are those textOnly properties helpful/useful/necessary?

@dmsnell dmsnell added [Status] Needs Author Reply and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jan 6, 2016
@timmyc
Copy link
Contributor Author

timmyc commented Jan 7, 2016

Backed out in e3c9268 - but did discover some places it is needed. I'll tackle that in a different branch though since this one has meandered a bit.

@timmyc timmyc added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jan 7, 2016
@nylen
Copy link
Contributor

nylen commented Jan 11, 2016

LGTM 👍

@nylen nylen added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jan 11, 2016
timmyc added a commit that referenced this pull request Jan 11, 2016
@timmyc timmyc merged commit a6ee94e into master Jan 11, 2016
@timmyc timmyc deleted the update/editor/use-status-utils branch January 11, 2016 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Post/Page Editor The editor for editing posts and pages.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants