Overview

from @balintbrews

Sending values for enum or examples of JS component props as integers/numbers using saves them as strings. The effect of this is that the component input form we generate can’t set an example/default value for integer/number props with enum. I didn’t test if this is an issue with the HTTP API of the config entity implementation itself.

This can actually be seen in \Drupal\Tests\experience_builder\Functional\XbConfigEntityHttpApiTest::testJavaScriptComponent

The prop is sent as

'integer' => [
          'type' => 'integer',
          'title' => 'Integer',
          'examples' => [23, 10, 2024],
        ],

but returned as

integer' => [
          'title' => 'Integer',
          'type' => 'integer',
          'examples' => ['23', '10', '2024'],
        ],

My guess would be that because the schema is define as

          examples:
            type: sequence
            label: 'Examples'
            sequence:
              type: string
          enum:
            requiredKey: false
            type: sequence
            sequence:
              type: string

where both are string the config system will case them as strings

Step debugging it seems this happens at save, $xb_config_entity->save();.

Proposed resolution

return these as the correct type

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

tedbow created an issue. See original summary.

tedbow’s picture

Issue summary: View changes
tedbow’s picture

Assigned: Unassigned » tedbow

tedbow’s picture

Assigned: tedbow » Unassigned
Status: Active » Needs work

got it started. add comment about needed test coverage. It seems like `\Drupal\experience_builder\Entity\JavaScriptComponent::normalizeForClientSide` is the right place but maybe we want to refactor that into another method.

Do we need to validate that only integers and numbers are sent in the request if that matches the type?

wim leers’s picture

Component: Internal HTTP API » Config management
Assigned: Unassigned » wim leers
Issue tags: +Configuration schema
Related issues: +#3499931: HTTP API for code component config entities, +#3499927: Config entity for storing code components

This can actually be seen in \Drupal\Tests\experience_builder\Functional\XbConfigEntityHttpApiTest::testJavaScriptComponent

Great catch!

Another missed defect in #3499931: HTTP API for code component config entities (actually even before that, in #3499927: Config entity for storing code components, but there it was less obvious than the literally incorrect example in the test that @tedbow quoted in the issue summary 👍).

Looking at your analysis so far, I wonder if this is actually a pure config schema problem 🤔

wim leers’s picture

Priority: Normal » Major

Yep, confirmed: this is a pure config schema problem. It's quite interesting, really: we need to describe in config schema how to specify a valid JSON Schema, for the subset of it that XB supports. 🤓🤯😄

Tests + fixes incoming.

wim leers’s picture

Title: js_component examples and enum do not respect the prop type » JavaScriptComponent config entities' `examples` and `enum` do not respect the prop's type
Assigned: wim leers » Unassigned
Status: Needs work » Needs review
Issue tags: +DX (Developer Experience), +data integrity
  1. Test coverage complete (functional + kernel), and it revealed quite a list of broken things: https://git.drupalcode.org/project/experience_builder/-/jobs/4484811
  2. One of the wildest things I've ever done: expressing the supported subset of JSON Schema in Drupal's Config Schema: https://git.drupalcode.org/project/experience_builder/-/merge_requests/7... 🤯 🤓 This automatically fixes the problem reported here, but also provides much more precise validation errors, and removes the need to perform manual typecasting.

The stricter validation this introduces even uncovered multiple test coverage bugs that @f.mazeikis and I missed in #3507929: Allow adding "image" props in the code component editor yesterday! 😱🥳

P.S.: This is what I was hoping/expecting to see on #3499927: Config entity for storing code components, but didn't ask for/block it on because it'd have delayed all of #3499919: [Meta] Plan for in-browser code components.

wim leers’s picture

Assigned: Unassigned » tedbow
Status: Needs review » Reviewed & tested by the community

CI agrees! (component-operations.cy.js fails on CI, but passes locally. It's been a known fairly frequent random failure for a while.)

I'd like @tedbow to do final sign-off given he started this MR and I took it in a very different direction. You don't need to review every detail — I am mostly curious whether you have concerns about the overall approach.

Also, I bet that @tedbow's #3509026: JavaScript code components slots' examples and description should be optional (which just landed) conflicts with this. About to merge in…

balintbrews’s picture

I also tested this, and the problem it caused is gone. I'll leave it up to you if this is ready to be merged.

tedbow’s picture

Assigned: tedbow » wim leers
Status: Reviewed & tested by the community » Needs work

a couple small things

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs work » Reviewed & tested by the community

All addressed 👍 Some nice catches, @tedbow — thanks!

@balintbrews Thanks for explicitly testing this indeed fixes the consequences in the UI! 🙏👍

  • wim leers committed c3f33038 on 0.x authored by tedbow
    Issue #3509037 by wim leers, tedbow, balintbrews: JavaScriptComponent...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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