Overview

When adding components using the page builder agent, the response sent to the frontend is in the following format format

{
    "status": true,
    "operations": [
        {
            "operation": "ADD",
            "components": [
                {
                    "id": "sdc.starshot_demo.starshot-columns",
                    "nodePath": [
                        1,
                        0
                    ],
                    "fieldValues": {
                        "cols": "two",
                        "gap": "medium",
                        "alignment": "none"
                    }
                },
                {
                    "id": "sdc.starshot_demo.starshot-button",
                    "nodePath": [
                        1,
                        0,
                        0,
                        0
                    ],
                    "fieldValues": {
                        "text": "Read more",
                        "url": "https:\/\/example.com\/read-more-1",
                        "display": "primary"
                    }
                },
                {
                    "id": "sdc.starshot_demo.starshot-button",
                    "nodePath": [
                        1,
                        0,
                        1,
                        0
                    ],
                    "fieldValues": {
                        "text": "Read more",
                        "url": "https:\/\/example.com\/read-more-2",
                        "display": "primary"
                    }
                }
            ]
        }
    ],
}

The nodePath value was calculated for each component to be added, and then passed to addNewComponentToLayout to place it in the required position (e.g in a specific region, above or below another component, or inside a specific slot).

But now, after #3538576: Provide a way to programmatically add component with custom values + update values of an existing component got merged, it is no longer possible to pass the nodePath value to the function and therefore the component placement is broken

Proposed resolution

Just noticed that addNewComponentToLayout still supports adding a 'to' param in the payload. So, only this change has to be reverted

User interface changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

akhil babu created an issue. See original summary.

akhil babu’s picture

The nodePath value is critical to place each component at its intended position. For example, if only the content region is enabled and there are no components placed on a page, to add a component like sdc.example.two-column with two sdc.example.heading components in each slot, we could previously calculate the nodePath like this:

  • sdc.example.two-column → [0, 0]
  • first sdc.example.heading → [0, 0, 0, 0]
  • second sdc.example.heading → [0, 0, 1, 0]

Then, components could be added one by one using addNewComponentToLayout.

Similerly, if multiple regions are enabled, componets can be placed at the correct region by giving the proper nodePath.

Eg: if header, content and footer regions are available, then [0, 0] will add a component to the header, [1, 0] to the content and [2,0] to the footer

It would be great if we could bring back the ability to give nodePath directly in the method itself.

akhil babu’s picture

Issue tags: +AI Initiative
akhil babu’s picture

Assigned: Unassigned » akhil babu
akhil babu’s picture

akhil babu’s picture

Issue summary: View changes

Just noticed that addNewComponentToLayout still supports adding a 'to' param in the payload. So, only this change has to be reverted

akhil babu’s picture

Title: Option to provide the nodePath in addNewComponentToLayout » XB AI: Bring back the 'to' option in addNewComponentToLayout call in AiWizard.tsx

akhil babu’s picture

Assigned: akhil babu » Unassigned
Status: Active » Needs review

Minor change, Ready for review.

To test this, try any prompt that requires placing components in a specific region or slot, such as

Using page builder, Add a two column layout with 2 'Hello world' heading components in each columns.

Using page builder, Add a two column layout with 2 'Hello world' heading components in each columns, to the header region

Without this change, both headigs would get placed below the two column.

jessebaker made their first commit to this issue’s fork.

jessebaker’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.