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

feat: Added cssClassName attribute to CoreGroup #328

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

colinmurphy
Copy link

@colinmurphy colinmurphy commented Dec 31, 2024

Overview

This adds the cssClassName for the CoreGroupAttributes as per issue reported here #327

Description

See above.

Related Issue(s):

#327

Testing

The following test checks that cssClassName is availble for the CoreGroupAttributes

Setup

If you update a page with the following HTML

<!-- wp:group {"tagName":"header","className":"test-group-class is-style-section-1","style":{"elements":{"link":{"color":{"text":"var:preset|color|accent-3"}}},"spacing":{"padding":{"top":"var:preset|spacing|20","bottom":"var:preset|spacing|20","left":"var:preset|spacing|20","right":"var:preset|spacing|20"},"margin":{"top":"var:preset|spacing|20","bottom":"var:preset|spacing|20"},"blockGap":"var:preset|spacing|20"},"dimensions":{"minHeight":"100px"},"border":{"radius":"1px","width":"4px"}},"backgroundColor":"base","textColor":"accent-3","borderColor":"accent-3","layout":{"type":"flex","flexWrap":"nowrap"}} -->
<header id="test-group-id" class="wp-block-group test-group-class is-style-section-1 has-border-color has-accent-3-border-color has-accent-3-color has-base-background-color has-text-color has-background has-link-color" style="border-width:4px;border-radius:1px;min-height:100px;margin-top:var(--wp--preset--spacing--20);margin-bottom:var(--wp--preset--spacing--20);padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--20);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--20)"><!-- wp:paragraph -->
<p>This is the left paragraph.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This is the right paragraph</p>
<!-- /wp:paragraph --></header>
<!-- /wp:group -->

<!-- wp:paragraph {"className":"example-class"} -->
<p class="example-class">This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like piña coladas. (And gettin' caught in the rain.)</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>...or something like this:</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>As a new WordPress user, you should go to <a href="https://alpha.multisite.local/wp-admin/">your dashboard</a> to delete this page and create new pages for your content. Have fun!</p>
<!-- /wp:paragraph -->

If you then run the following query in WPGraphQL IDE

fragment CoreGroupFragment on CoreGroup {
  attributes {
    align
    allowedBlocks
    backgroundColor
    borderColor
    className
    cssClassName
    fontFamily
    fontSize
    gradient
    layout
    lock
    metadata
    style
    tagName
    textColor
  }
}

query Page($id: ID!) {
  page(id: $id, idType: DATABASE_ID) {
    databaseId
    editorBlocks(flat:true) {
      apiVersion
      blockEditorCategoryName
      clientId
      cssClassNames
      innerBlocks {
        name
      }
      name
      parentClientId
      renderedHtml
      type
      ...CoreGroupFragment
    }
  }
}

Note: Add the following query variables (replacing your page/post id)

{
  "id": 2
}

You should get the following response

{
  "data": {
    "page": {
      "databaseId": 2,
      "editorBlocks": [
        {
          "apiVersion": 3,
          "blockEditorCategoryName": "design",
          "clientId": "67741a2965a9b",
          "cssClassNames": [
            "test-group-class",
            "is-style-default"
          ],
          "innerBlocks": [
            {
              "name": "core/paragraph"
            },
            {
              "name": "core/paragraph"
            }
          ],
          "name": "core/group",
          "parentClientId": null,
          "renderedHtml": "\n<header id=\"test-group-id\" class=\"wp-block-group test-group-class is-style-default is-content-justification-center is-layout-flex wp-container-core-group-is-layout-1 wp-block-group-is-layout-flex\">\n<p>This is the left paragraph.</p>\n\n\n\n<p>This is the right paragraph</p>\n</header>\n",
          "type": "CoreGroup",
          "attributes": {
            "align": null,
            "allowedBlocks": null,
            "backgroundColor": null,
            "borderColor": null,
            "className": "test-group-class is-style-default",
            "cssClassName": "wp-block-group test-group-class is-style-default is-content-justification-center is-layout-flex wp-container-core-group-is-layout-7 wp-block-group-is-layout-flex",
            "fontFamily": null,
            "fontSize": null,
            "gradient": null,
            "layout": "{\"type\":\"flex\",\"flexWrap\":\"wrap\",\"justifyContent\":\"center\"}",
            "lock": null,
            "metadata": null,
            "style": null,
            "tagName": "header",
            "textColor": null
          }
        },
        {
          "apiVersion": 3,
          "blockEditorCategoryName": "text",
          "clientId": "67741a2965a9f",
          "cssClassNames": null,
          "innerBlocks": [],
          "name": "core/paragraph",
          "parentClientId": "67741a2965a9b",
          "renderedHtml": "\n<p>This is the left paragraph.</p>\n",
          "type": "CoreParagraph"
        },
        {
          "apiVersion": 3,
          "blockEditorCategoryName": "text",
          "clientId": "67741a2965aa1",
          "cssClassNames": null,
          "innerBlocks": [],
          "name": "core/paragraph",
          "parentClientId": "67741a2965a9b",
          "renderedHtml": "\n<p>This is the right paragraph</p>\n",
          "type": "CoreParagraph"
        },
        {
          "apiVersion": 3,
          "blockEditorCategoryName": "text",
          "clientId": "67741a2965aa6",
          "cssClassNames": [
            "example-class"
          ],
          "innerBlocks": [],
          "name": "core/paragraph",
          "parentClientId": null,
          "renderedHtml": "\n<p class=\"example-class\">This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:</p>\n",
          "type": "CoreParagraph"
        }
      ]
    }
  }
}

Note that the cssClassName for the CoreGroup attribute node is wp-block-group test-group-class is-style-default is-content-justification-center is-layout-flex wp-container-core-group-is-layout-7 wp-block-group-is-layout-flex

Screenshots

Screenshot 2024-12-31 at 16 31 34

Copy link

changeset-bot bot commented Dec 31, 2024

🦋 Changeset detected

Latest commit: c0528c6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@wpengine/wp-graphql-content-blocks Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@colinmurphy colinmurphy changed the title Added CoreGroup block to add cssClassName to the CoreGroupAttributes Feat: Added cssClassName attribute to CoreGroup Dec 31, 2024
@colinmurphy colinmurphy changed the title Feat: Added cssClassName attribute to CoreGroup feat: Added cssClassName attribute to CoreGroup Dec 31, 2024
/**
* Test that the CoreGroup block is retrieved correctly.
*
* Covers the following attributes:
Copy link
Contributor

Choose a reason for hiding this comment

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

(this isn't a list of attributes.
Not saying you need one - we added it to track what Core*Attributes are actually being tested since this project doesn't have accurate codecov )

Copy link
Author

Choose a reason for hiding this comment

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

Thanks @justlevine

I will update the comment and that's good to know about the code coverage.

Also thanks for the code review 👍

@justlevine
Copy link
Contributor

justlevine commented Dec 31, 2024

Heads up I'm hoping to rip out this entire antipattern in rtCamp#31.

If we want to diverge from WP as a source of truth, we shouldn't have those fields masquerade as block.json attributes and this has been a consistent source of conflicts when upgrading wp versions.

Once a WPGraphQL Model is in place (so every new attribute isnt a perf drain due to render_block() ) this sort of handling will be moved to an Interface type.

@colinmurphy
Copy link
Author

Heads up I'm hoping to rip out this entire antipattern in rtCamp#31.

If we want to diverge from WP as a source of truth, we shouldn't have those fields masquerade as block.json attributes and this has been a consistent source of conflicts when upgrading wp versions.

Once a WPGraphQL Model is in place (so every new attribute isnt a perf drain due to render_block() ) this sort of handling will be moved to an Interface type.

Thanks @justlevine for the heads up and also the context around the upgrades.

I can definitely see how this might cause issues with upgrades. Let me know if you want me to do any testing for your branch once your ready 👍

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.

3 participants