Skip to content

Bugfix/metadata text#12

Open
wenga86 wants to merge 5 commits intocontentstack:masterfrom
shopsmart:bugfix/metadata-text
Open

Bugfix/metadata text#12
wenga86 wants to merge 5 commits intocontentstack:masterfrom
shopsmart:bugfix/metadata-text

Conversation

@wenga86
Copy link

@wenga86 wenga86 commented Mar 22, 2023

Problem

RTE JSON links may have more than one child within them. In cases such as these the text attribute should return all child text, not just the last child's value.

Solution

Collect all text nodes and stitch their values together

Real world Examples

{
    "uid": "27a303b40d2f4e85874c15bea3a906f5",
    "type": "reference",
    "attrs": {
        "display-type": "link",
        "type": "entry",
        "class-name": "embedded-entry redactor-component block-entry",
        "entry-uid": "blt513d896103aab8a4",
        "locale": "en-us",
        "content-type-uid": "product_listing",
        "target": "_self",
        "href": "/go/l/blt513d896103aab8a4"
    },
    "children": [
        {
            "text": ""
        },
        {
            "uid": "c3b9a54551464998a64c3b4f510f61e8",
            "type": "span",
            "attrs": {},
            "children": [
                {
                    "text": "L'Oreal Paris Telescopic Lift Washable Mascara"
                }
            ]
        },
        {
            "text": ""
        }
    ]
}

Expected

"L'Oreal Paris Telescopic Lift Washable Mascara"

Received

""
{
    "uid": "2643192bee9445ee9a84c637a9d8d185",
    "type": "reference",
    "attrs": {
        "href": "/go/l/bltb4a1874571d07893",
        "data-slate-node": "element",
        "data-slate-inline": "true",
        "display-type": "link",
        "type": "entry",
        "class-name": "embedded-entry redactor-component block-entry",
        "entry-uid": "bltb4a1874571d07893",
        "locale": "en-us",
        "content-type-uid": "product_listing",
        "target": "_self",
        "data-editor-type": "scrte",
        "class": "style-module_linkRef__c1tvp",
        "data-type": "link",
        "data-testid": "embed-hyperlink"
    },
    "children": [
        {
            "text": "L'Oreal Paris Telescopic Lift "
        },
        {
            "text": "Washable",
            "italic": true
        },
        {
            "text": " Mascara"
        }
    ]
}

Expected

"L'Oreal Paris Telescopic Lift Washable Mascara"

Received

" Mascara"

@wenga86 wenga86 requested a review from a team as a code owner March 22, 2023 02:14
@wenga86 wenga86 requested a review from a team March 22, 2023 02:14
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.

2 participants