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

Fix/1390 Make "title" a block #2714

Closed
wants to merge 2 commits into from

Conversation

tg-ephox
Copy link
Contributor

fixes #1390

This change moves the post title to a block.

Tests still need to be fixed however I wanted to check the approach is OK first.

Summary of changes:

  • added an attribute isFixed when registering a block which wont show the BlockMover and BlockRightMenu when the block is focused
  • when RESET_BLOCKS action is fired, a place holder block is always put before the other blocks for the post title
  • post title is updated same as before
  • post title is retrieved by changing getBlock selector
  • BlockMover labels had to be updated

Questions:

  • Is it ok to reference components from editor in a block? I have copied PostPermaLink at the moment but can remove this.
  • Do blocks need to have an editor.scss file? I didn't have this initially but then got no css on the page
  • Effect naming: I had to intercept the RESET_BLOCKS action in an effect to add the title block first. Should I use REQUEST_RESET_BLOCKS or similar or is that for an actual web request?

@tg-ephox tg-ephox self-assigned this Sep 11, 2017
@tg-ephox
Copy link
Contributor Author

hey @karmatosed @melchoyce @mtias can I pls get some feedback on this?

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Given the amount of special treatment we're putting toward post title specifically in these changes, I'm not sure treating post title as a block makes much sense.

I could see it being more reasonable if we added proper generic support for mapping between block values and post properties (like #2754) or generic support for locking blocks to specific locations within a post (title always shown first).

registerBlockType( 'core/post-title', {
title: __( 'Post Title' ),

keywords: [ __( 'title' ) ],
Copy link
Member

Choose a reason for hiding this comment

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

This would be redundant, given that searching "title" would also match the "Post Title" title property, unless it was localized significantly different between "title" and "Post Title".

},

save( { attributes } ) {
return <h1> { attributes.content } </h1>;
Copy link
Member

Choose a reason for hiding this comment

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

  • Even if we treat title as a block, I would expect its value should be saved as the post_title field of a post, not as an h1 within content
  • I don't think we need the space padding within the <h1>

* Internal Dependencies
*/
import './editor.scss';
import { isEditedPostNew, getEditedPostAttribute } from '../../../editor/selectors';
Copy link
Member

Choose a reason for hiding this comment

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

We don't want to be reaching out into the editor top-level directory. This could tie into #2473

@@ -0,0 +1,74 @@
/**
Copy link
Member

Choose a reason for hiding this comment

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

editor/post-permalink is redundant with this file and should be removed?


const PostTitleEdit = ( { title, focus, setFocus, onChange } ) => [
focus && <PostPermaLink />,
<Editable
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this needs to be editable, just a plain input (we don't need to / cannot support rich text).

style={ { textAlign: 'left' } }
formattingControls={ [] } /> ];

export default connect( null, dispatch => ( { onChange: title => {
Copy link
Member

Choose a reason for hiding this comment

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

This line is a bit difficult to understand given the many levels of function nesting and differing implicit return / explicit arrow function blocks it creates.

formattingControls={ [] } /> ];

export default connect( null, dispatch => ( { onChange: title => {
dispatch( editPost( { title: title[ 0 ] } ) );
Copy link
Member

Choose a reason for hiding this comment

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

What is the value of title here? If we were to consider PostTitleEdit the "presentational" component, I would think it's onChange callback should be called with the value we'd expect to be using, without any further manipulations like we're doing here.

@@ -273,4 +276,8 @@ export default {

return effects;
},
RESET_BLOCKS( action, store ) {
const blocks = [ createBlock( 'core/post-title' ) ].concat( action.blocks );
store.dispatch( { type: 'ACTUALLY_RESET_BLOCKS', blocks } );
Copy link
Member

Choose a reason for hiding this comment

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

If we need to better distinguish between effects triggered by SET_INITIAL_POST and what is considered in resetting blocks, I think we should either come up with better names (avoid "ACTUALLY_" prefix) or a different pattern for manipulating how post title is inserted into the block set. A standalone middleware which modifies action.blocks before dispatch occurs is one option.

@anna-harrison anna-harrison changed the title Fix/1390 clicking title then new block Fix/1390 Make "title" a block Oct 6, 2017
@anna-harrison
Copy link

Closing as new approach in #2948

@gziolo gziolo deleted the fix/1390-clicking-title-then-new-block branch October 16, 2017 06:48
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.

Bug when clicking on title block and then on new block
3 participants