-
Notifications
You must be signed in to change notification settings - Fork 2k
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: Replace the default auto-draft title of new Gutenberg posts. #27297
Conversation
client/gutenberg/editor/main.jsx
Outdated
@@ -53,13 +53,27 @@ class GutenbergEditor extends Component { | |||
} | |||
} | |||
|
|||
const addGutenbergDemoContent = post => { | |||
const title = { | |||
raw: 'Welcome to the Gutenberg Editor', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We likely need to localize this I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Automattic/calypso-sdk @Automattic/i18n any objections if we do the following?
import { translate } from 'i18n-calypso';
//...
const addGutenbergDemoContent = post => {
const title = {
raw: translate( 'Welcome to the Gutenberg Editor' ),
rendered: translate( 'Welcome to the Gutenberg Editor' ),
};
return {
...post,
title,
};
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested something like the following:
import { translate } from 'i18n-calypso';
//...
const demoTitleText = translate( 'Welcome to the Gutenberg Editor' );
const title = {
raw: demoTitleText,
rendered: demoTitleText,
};
Where a translation exists, it will render correctly.
In this instance we have translation, but you won't see translated output yet on /gutenberg/post/{site}
.
I've added the source path clients/gutenberg/editor/
to our views, so it should be picked up soon. I'll keep an 👁 on it. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, this will always live in Calypso, so I don't see any downsides of using Calypso's i18n.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, I meant to double-check it was translate
d at output, but no, it's not (which certainly makes sense). Will update.
client/gutenberg/editor/main.jsx
Outdated
} | ||
|
||
return null; | ||
const sitePostData = get( requestSitePost( siteId, postId ), 'data', null ); | ||
return sitePostData && 'auto-draft' === sitePostData.status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also wondering why an auto-draft is a requirement for Gutenberg init, but we can explore this in a core PR enhancement.
This tests as expected, but I'm unclear of the why. 🤔 Why would we want to force a title into the editor when the post has an Are there any chances that |
client/gutenberg/editor/main.jsx
Outdated
@@ -53,13 +53,27 @@ class GutenbergEditor extends Component { | |||
} | |||
} | |||
|
|||
const addGutenbergDemoContent = post => { | |||
const title = { | |||
raw: 'Welcome to the Gutenberg Editor', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it going to be clear to users at this point what "Gutenberg" brand is? Should we instead roll it out as:
Welcome to the new editor
...PR might not be the right place for this discussion, though! Good to check on wording, is what I'm saying. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One other thing, could we maybe decorate content using a query param like ?demo
to start? Without this, I think we'll want to blank out the title set here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it going to be clear to users at this point what "Gutenberg" brand is?
I do see value in it being the same as wp-admin
, particularly if users find themselves back and forth for any reason. But yes, definitely a valid bigger question for the core project 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To load, Gutenberg requires a valid post (p7jreA-1N0-p2), so if we're creating a new post, that comes in the form of an auto-draft (and auto-drafts have a default title of "Auto Draft"). Something more useful to the user would be better (and this PR lines that up with the default content for the Gutenberg demo in
Not sure what you mean, but the first time the auto-draft is, erm, auto-saved, its status will go from |
client/gutenberg/editor/main.jsx
Outdated
|
||
return { | ||
...post, | ||
title, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested it, but I have a feeling that this won't work, notably at the point that we actually save. Since what we're feeding here is instructing Gutenberg to what the saved value of the post is, Gutenberg is not aware that the title has been modified and thus will not include it in the save payload. Since it won't be included in the save payload, it won't be updated server-side and thus the existing title (presumably "Auto Draft") will remain.
This is what the overridePost
prop of the Editor
component (and argument of initializeEditor
) is meant to represent:
This is also subject to refactoring in WordPress/gutenberg#9403, both in form of renaming this to initialEdits
and, in doing so, not expecting values to be passed in shape of object with raw
/ rendered
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did verify that it saves properly, but I'm not sure if that's a good or bad thing to what you expected 🙃
I didn't know about overridePost
though, so I'll dig into that too as an option (even if we need to tighten up after a refactor). Thanks!
See also https://github.com/WordPress/gutenberg/blob/45bc8e4991d408bca8e87cba868e0872f742230b/lib/client-assets.php#L1346 where it looks like we probably eventually pass this encoded json to the overridePost field on init. |
@kwight thanks for the explanation! Another question: what if we passed |
@Copons Oh! I get what you mean – I've been ignoring the placeholder aspect of it, sorry was confused 🙃 |
1f61699
to
f226d94
Compare
client/gutenberg/editor/main.jsx
Outdated
bodyPlaceholder: translate( 'Write your story' ), | ||
}; | ||
|
||
const isAutoDraft = () => post && 'auto-draft' === post.status; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor note, but we can also move this logic to mapStateToProps:
const mapStateToProps = ( state, { siteId, postId, uniqueDraftKey } ) => {
const draftPostId = get( getHttpData( uniqueDraftKey ), 'data.ID', null );
const post = getPost( siteId, postId || draftPostId );
const isAutodraft = get( post, 'status', null );
const overridePost = isAutodraft ? { title: '' } : null;
return {
siteSlug: getSiteSlug( state, siteId ),
post,
overridePost,
};
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, I really was looking at this too much 🙃 Yes, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kwight ✨ This works great. I left an optional note, but free free to
f226d94
to
a55ebe6
Compare
If we receive an auto-draft on opening the Gutenberg editor, replace its default "Auto Draft" title with that of the
wp-admin
: "Add title". This should also allow easily adding the demo content when required as a follow-up PR.Fixes #27162 .
Testing
https://calypso.localhost:3000/gutenberg/post
, and select a site.