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

SPT: Set template title in large preview #39831

Merged
merged 15 commits into from
Mar 4, 2020

Conversation

retrofox
Copy link
Contributor

@retrofox retrofox commented Mar 3, 2020

Changes proposed in this Pull Request

This PR improves how the template title is rendered into the preview. Now, it's a core/heading h1 block. What this PR proposes is to use the <PostTitle /> core editor component.

The only tricky part to deal is that this component gets the title from the post data. This is why we've created this PR in the core. In the meanwhile, however, we can go ahead in setting the template title using DOM manipulation. Once the core PR is ready 🤞, we can update and simplify the current approach.

Testing instructions

  1. Apply the patch
  2. Check how the title is rendered in the large preview box
  3. Compare with editor-canvas
  4. Test in different themes in order to detect format variations such as alignment, font-size, etc
  5. Compare with master branch

Mayhood

before
image

after
image

Screen Shot 2020-03-03 at 4 29 27 PM

Fixes #39805

retrofox added 4 commits March 3, 2020 11:39
It implements a hacky solution to propagate the template title to the <PostTitle /> component, since it isn't possible to do it in thr current implementation of the component. I've created a PR, but in the meanwhile we can take this patch in order to give a quick solution. We can iterate later once the code PR is ship? WordPress/gutenberg#20609
@matticbot
Copy link
Contributor

@retrofox retrofox requested a review from ajaykj March 3, 2020 15:24
@retrofox retrofox added the [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it label Mar 3, 2020
@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

@retrofox retrofox requested a review from a team March 3, 2020 19:30
@retrofox retrofox marked this pull request as ready for review March 3, 2020 19:30
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello retrofox! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D39778-code before merging this PR. Thank you!

Copy link
Contributor

@jeryj jeryj left a comment

Choose a reason for hiding this comment

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

Overall, this seems like a clever solution for being able to use the <PostTitle /> while waiting on an easier way to pass a string to the <PostTitle /> component 🙌

The only functional things I came across when testing in Chrome, Safari, and Firefox in multiple themes were:

  • There's extra spacing underneath of the preview title compared to master
    Previously, the title was within the preview blocks, which meant the margins between blocks were collapsed. This title is outside of that block list, so the margins don't collapse and there's extra space.

This branch:
Screen Shot 2020-03-03 at 3 14 55 PM

Master:
Screen Shot 2020-03-03 at 3 15 03 PM

  • Safari shows the preview title in a faded color. master shows it in black, as expected.

Faded About preview title

Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

Thanks for this PR. I haven't manually tested this yet. Noticed some minor points when reviewing the code which I'm happy to discuss and help clarify.

My principle concern here is that we're introducing a hack which breaks React's data flow model. As soon as we start reaching into the DOM and tinkering we're introducing the very side effects that React is designed to avoid. This could lead to unintended consequences especially given that we're relying on a Core component which is subject to change in it's DOM structure...etc. In some ways the DOM isn't part of the component's public API so it is subject to change without warning which could break this implementaiton.

That said, I fully appreciate that this change is being viewed as a temporary workaround. That's ok if it truly is temporary. However, I have concerns about landing this unless we are confident that:

  • the Core PR to set the title directly as a prop will be accepted - can we get a Core team member to provide some indication of this?
  • our team will have time allocated in a future Iteration to come back and remove this hack with the "proper" solution

Thanks for exploring this and doing such a thorough deep dive 👍

retrofox and others added 5 commits March 4, 2020 08:00
…emplates/page-template-modal/components/block-iframe-preview.js


Improve jsdoc. Props to @getdave :-)

Co-Authored-By: Dave Smith <[email protected]>
…emplates/page-template-modal/components/block-iframe-preview.js


Improve jsdoc. Props to @getdave

Co-Authored-By: Dave Smith <[email protected]>
…emplates/page-template-modal/styles/starter-page-templates-editor.scss


Set the CSS class name more targetted to the SPT scope.

Co-Authored-By: Dave Smith <[email protected]>
@retrofox retrofox removed the request for review from ajaykj March 4, 2020 12:26
@WunderBart WunderBart force-pushed the update/spt-template-title-in-large-preview branch from 57b43bd to 8e087e4 Compare March 4, 2020 12:40
@retrofox retrofox force-pushed the update/spt-template-title-in-large-preview branch from 8e087e4 to 437b03c Compare March 4, 2020 13:23
@retrofox
Copy link
Contributor Author

retrofox commented Mar 4, 2020

...That said, I fully appreciate that this change is being viewed as a temporary workaround.

Totally agree. This is something that we should try to achieve with Frame v2

@retrofox
Copy link
Contributor Author

retrofox commented Mar 4, 2020

our team will have time allocated in a future Iteration to come back and remove this hack with the "proper" solution

I don't think so in the short term. I'd like to continue with this in my 20% time, though.

Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

This is looking much better. Thanks for all the improvements 👍

One thing I'd suggest is that we create a Calypso Issue now in our backlog to track the task for updating to use the update Core component if your Core PR to allow for a placeholder title prop on the PostTitle component is accepted.


// Exists as a pass through component to simplify automatted testing of
// components which need to `BlockEditorProvider`. Setting up JSDom to handle
// and mock the entire Block Editor isn't useful and is difficult for testing.
// Therefore this component exists to simplify mocking out the Block Editor
// when under test conditions.
export default function( { blocks, settings, recomputeBlockListKey } ) {
/* eslint-disable wpcalypso/jsx-classname-namespace */
Copy link
Contributor

Choose a reason for hiding this comment

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

If we've updated to block-iframe-preview__template-title do we need the eslint disable? It's better to keep these kinds of warnings where possible as (despite the "noise") they are the first line of defence against bugs.

@retrofox
Copy link
Contributor Author

retrofox commented Mar 4, 2020

Safari shows the preview title in a faded color. master shows it in black, as expected.

Can we create a new for this one?

@retrofox retrofox merged commit dccfbd3 into master Mar 4, 2020
@retrofox retrofox deleted the update/spt-template-title-in-large-preview branch March 4, 2020 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Goal] Full Site Editing [Goal] Page Templates [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SPT: Tweak template title.
5 participants