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

FSE: Most site building blocks need previews and placeholders #30029

Open
3 of 18 tasks
Tracked by #41241
jameskoster opened this issue Mar 19, 2021 · 19 comments
Open
3 of 18 tasks
Tracked by #41241

FSE: Most site building blocks need previews and placeholders #30029

jameskoster opened this issue Mar 19, 2021 · 19 comments
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") Needs Dev Ready for, and needs developer efforts [Type] Enhancement A suggestion for improvement.

Comments

@jameskoster
Copy link
Contributor

jameskoster commented Mar 19, 2021

Here's a figma file where we can work on this.

@jameskoster
Copy link
Contributor Author

jameskoster commented Mar 26, 2021

Some initial ideas for simplest text-based blocks:

Block Placeholder
Site Tagline The site description
Site Title The site title
Login/out Log in
Post Title The post title
Post Content The content of a post, page, or any other content-type. It may include a variety of different blocks like paragraphs, lists, image galleries, and more.
Post Author The post author
Post Comment The content of a comment.
Post Comments Count 1
Post Date [Gutenberg release date?]
Post Excerpt The excerpt of a post, page, or any other content-type.
Post Tags Tag
Term Description The description of a tag, category, or other custom taxonomy.
Archive Title The title of an archive like a category, tag, author, or date
Post Categories Category
Next post Next post
Previous post Previous post

@jameskoster jameskoster added the Needs Design Feedback Needs general design feedback. label Mar 26, 2021
@carolinan
Copy link
Contributor

I am wondering about this Login/out | Log in because in the editor we are always logged in, should it not be "Log out"?

@jameskoster
Copy link
Contributor Author

I was thinking about it from the hypothetical visitors perspective, who in most cases will be logged out. It's not a strong feeling though. "Log out" works too :)

@jameskoster
Copy link
Contributor Author

Post Title | The post title

I wonder what scope there is for these "post" block placeholders to be dynamic. While thinking about the template mosaic view for instance, it would be potentially confusing to see "The post title" in the page template.

If not dynamic, they perhaps need to be even more generic. Consider the singular template which can display posts and pages. What should the Post Title block placeholder display in that case? Maybe something simpler like "The title" would work better?

@jameskoster
Copy link
Contributor Author

Excluded some of the comment related blocks as these will need to be broken down in to smaller pieces (see #24101).

@jameskoster
Copy link
Contributor Author

Is there any reason not to use the WordPress logo for the Site Logo block preview (when no logo is set of course)?

Screenshot 2021-04-12 at 15 48 54

@jameskoster
Copy link
Contributor Author

I worked on designs for the text-based site blocks in figma. I removed the Post Comments Form, Query, and Template Part blocks from the OP for now as they are bit more complex and I suspect they will need dedicated issues to explore in detail.

Site Logo

Screenshot 2021-04-12 at 16 56 03


Site Title

Screenshot 2021-04-12 at 16 57 01


Site Tagline

Screenshot 2021-04-12 at 16 57 46


Login/out

Screenshot 2021-04-12 at 16 58 14


Next / Previous post

Screenshot 2021-04-12 at 16 58 32


Post Title

Screenshot 2021-04-12 at 16 58 45


Post Content

Screenshot 2021-04-12 at 16 59 02


Post Author

Screenshot 2021-04-12 at 16 59 19


Post Comments Count

Screenshot 2021-04-12 at 16 59 34


Post Date

Screenshot 2021-04-12 at 16 59 45


Post Excerpt

Screenshot 2021-04-12 at 16 59 57


Post Tags

Screenshot 2021-04-12 at 17 00 09


Post Categories

Screenshot 2021-04-12 at 17 00 21


Archive Title

Screenshot 2021-04-12 at 17 00 34


Term Description

Screenshot 2021-04-12 at 17 00 52


@jameskoster jameskoster added Needs Dev Ready for, and needs developer efforts and removed Needs Design Needs design efforts. labels Apr 12, 2021
@carolinan
Copy link
Contributor

Do we just add an empty example in index.js to these blocks, and adjust the width for some?

I can't figure out how to create an example as shown in the images.
For example, the site tagline shows the placeholder text from edit.js, and I don't think that text should be changed to "Just another WordPress site"

@jameskoster
Copy link
Contributor Author

We've recently updated the placeholders, so we might want to close this issue in favor of one that concentrates on the previews.

The Site Tagline block for example still doesn't have a preview:

Screenshot 2021-10-22 at 13 44 34

@carolinan
Copy link
Contributor

carolinan commented Oct 22, 2021

The comment I added above is all about that preview. So a new issue wont help me contribute towards making the preview look like in the image :).

Adding a width to block.json, or the empty example to index.js, displays the current tagline.
If there is no tagline it displays the placeholder text from edit.js which is "Write site tagline…".

@jameskoster
Copy link
Contributor Author

Ah sorry, I think I misread your comment.

Adding a width to block.json, or the empty example to index.js, displays the current tagline. If there is no tagline it displays the placeholder text from edit.js which is "Write site tagline…".

Is this definitely the behaviour we want, contextual previews? Given our current handling of placeholders the previews could end up being a bit lacklustre. Like the "Write site tagline..." example you shared. As another example, if a featured image isn't set you would end up seeing something like this:

Screenshot 2021-10-22 at 14 00 37

An alternative would be to hard code generic previews – which is how previews for regular blocks work. So when I hover Featured Image I would just see an image in the preview, regardless of whether one is set or not.

@carolinan
Copy link
Contributor

But how? :)
For example, this is the paragraph block. The post/site blocks do not have the "content" attribute.

	example: {
		attributes: {
			content: __(
				'In a village of La Mancha, the name of which I have no desire to call to mind, there lived not long since one of those gentlemen that keep a lance in the lance-rack, an old buckler, a lean hack, and a greyhound for coursing.'
			),
			style: {
				typography: {
					fontSize: 28,
				},
			},
			dropCap: true,
		},
	},

@carolinan
Copy link
Contributor

And I can't find any documentation for the "example" setting in block creation. Guess what shows up if I search for block.json example 😆

@jameskoster
Copy link
Contributor Author

But how? :)

Good question :D I'm sorry to say I don't know. Perhaps we need to enhance the example functionality in order to account for these data-driven blocks?

@carolinan
Copy link
Contributor

Yes we probably need to invent something new.

@talldan
Copy link
Contributor

talldan commented Jun 27, 2022

Yes we probably need to invent something new.

I stumbled across this issue. Unless this has been solved since your comment, I think we do need something new. There are probably quite a few different ways to solve this, but none of them that I could think of are ideal.

I think the third option I listed below would be my preferred solution. Any other options anyone can think of?

Option 1. Mock block context and entity data in the block definition

These blocks use block context to indicate which post they should read from. It could be possible to mock this data as part of the block definition:

example: {
    context: {
        postType: 'example',
        postId: '1',
    },
    entities: [
        {
            type: 'example',
            id: '1',
            featuredImage: 'https://wordpress.org/example-image.png'
        }
    ],
    attributes: { // ... },
    innerBlocks: [ // ... ],
}

Problems:

  • It looks easy, but this could be technically difficult to implement. It'll be difficult to control the context for inner blocks, because the preview is rendered as a single BlockList.
  • Bad developer experience

Option 2. Overriding values in the block edit

The simplest option could be to pass example data into the block edit component and use that to override the values of particular variables.

block.json

{
    "example": {
        "src": "https://wordpress.org/example-image.png"
    },
function PostFeaturedImageEdit( { attributes, example: { src: exampleSrc }, ... } ) {
    const isBlockPreview = useIsBlockPreview();
    let [ imageSrc ] = useEntityProp( // ... );
    
    if ( isBlockPreview ) {
        imageSrc = exampleSrc;
    }

    // ...
}

Problems:

  • This is pretty simple, but I don't think it's good practice to introduce extra logic to block rendering just for examples. I think it'll reduce code quality.

Option 3. Refactor blocks so that we can create BlockExample components

Blocks could have their presentation logic separated from their business logic. It'd then be easier to create a BlockExample component that renders the same thing as BlockEdit but with dummy data:
edit.js

function PostFeaturedImageEdit( { attributes, ... } ) {
    const [ imageSrc ] = useEntityProp( // ... );
   
    return <PostFeaturedImageEditView src={ imageSrc } />
}

example.js

function PostFeaturedImageExample() {
   return <PostFeaturedImageEditView src="https://wordpress.org/example-image.png" />
}

index.js

// A component can be declared as part of the example.
example: {
    component: PostFeaturedImageExample
    viewportWidth: 500
}

Problems:

  • Simple, but refactoring each block could be a lot of work
  • Could be open to abuse - e.g. rendering something in the preview that shouldn't be there. 🤷
  • This option would never show 'real' data when it's available.

@jameskoster
Copy link
Contributor Author

Since this issue was opened we've done quite a bit of work around improving the on-canvas representation of these blocks, accounting for context. For example the Featured Image block now displays a placeholder 'graphic' when appropriate.

So perhaps these block previews should just render the block itself (hopefully with the context passed to it). Is that an option?

@annezazu annezazu added the [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") label Jul 24, 2023
@jordesign jordesign added the [Type] Enhancement A suggestion for improvement. label Sep 8, 2023
@annezazu
Copy link
Contributor

👋🏼 Is this issue still relevant? If yes, can we update it? If not, can we close out?

@jameskoster
Copy link
Contributor Author

A lot of site building blocks still don't have previews.

So perhaps these block previews should just render the block itself (hopefully with the context passed to it). Is that an option?

This still feels like the path to explore.

@jameskoster jameskoster removed the Needs Design Feedback Needs general design feedback. label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") Needs Dev Ready for, and needs developer efforts [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

5 participants