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

Add function which checks if content of post is empty #2536

Closed
wants to merge 1 commit into from

Conversation

nitrajka
Copy link
Contributor

Fixes #1501.

I added a function which checks whether the content of a post is considered empty.
Another bug occurred. But that is probably related with #1240.

Steps to reproduce:

  1. go to the Gutenberg
  2. click on 'Write your story' -> doesn't save after 10 sec, which I currently fixed
  3. start typing something

I expect content to mark as dirty immediately and 'Save' button should be shown. But it happens after clicking next to the block.

All local tests ran OK.

@codecov
Copy link

codecov bot commented Aug 25, 2017

Codecov Report

Merging #2536 into master will decrease coverage by 2.98%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2536      +/-   ##
==========================================
- Coverage    30.1%   27.12%   -2.99%     
==========================================
  Files         174      159      -15     
  Lines        5288     4911     -377     
  Branches      907      818      -89     
==========================================
- Hits         1592     1332     -260     
+ Misses       3132     3036      -96     
+ Partials      564      543      -21
Impacted Files Coverage Δ
editor/selectors.js 96.35% <100%> (+0.02%) ⬆️
blocks/library/image/index.js 15% <0%> (-47.5%) ⬇️
blocks/library/separator/index.js 40% <0%> (-20%) ⬇️
blocks/library/code/index.js 42.85% <0%> (-14.29%) ⬇️
blocks/library/preformatted/index.js 40% <0%> (-10%) ⬇️
blocks/library/table/index.js 33.33% <0%> (-8.34%) ⬇️
components/tooltip/index.js 77.27% <0%> (-6.6%) ⬇️
components/drop-zone/index.js 0% <0%> (-5.89%) ⬇️
blocks/library/heading/index.js 23.8% <0%> (-4.77%) ⬇️
blocks/library/quote/index.js 13.88% <0%> (-2.78%) ⬇️
... and 49 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec49b3d...b86b88f. Read the comment docs.

@youknowriad
Copy link
Contributor

I don't know if I missing something here, but I expected the "publish" button to stay disabled when I click on the placeholder (creating a first empty text block).

In other words, I expected this

<!-- wp:core/paragraph -->
<p></p>
<!-- /wp:core/paragraph -->

to be considered as empty content

* @param {Object} state Global application state
* @return {Boolean} Whether it's considered empty
*/
export function isEmptyContent( state ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add some unit tests?

@@ -12,6 +12,9 @@ import { serialize, getBlockType } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url';

const REGEXP_EMPTY_CONTENT = /^<!--(.)*>(\s)*<p[^>]*>(&nbsp|\s|<br[^>]*>)*<\/p>(\s)(.)*-->$/mg;
Copy link
Member

@aduth aduth Aug 28, 2017

Choose a reason for hiding this comment

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

.* are prone to greediness, which results in issues like this:

https://regex101.com/r/64lOJ1/1

See: http://www.regular-expressions.info/repeat.html

@aduth
Copy link
Member

aduth commented Aug 28, 2017

We should also note the case of dynamic (server-rendered) blocks, which intentionally do not have any content in the post editor. Take the "Latest Posts" block for example, which saves itself as:

<!-- wp:core/latest-posts /-->

A post with this block should not be considered empty.

@nitrajka nitrajka closed this Sep 21, 2017
@gziolo gziolo deleted the fix/new-post-saved-as-dirty-1501 branch May 7, 2018 11:15
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.

Clicking the initial "Write your story" prompt marks a new post as dirty
3 participants