HTTP API: update /xb-component/{component_id} to list possible prop sources for current entity context

Created on 20 June 2024, 5 months ago
Updated 12 September 2024, 2 months ago

Problem/Motivation

βœ… Unblocked by ✨ Allow specifying default props values when opting an SDC in for XB Fixed .
βœ… Unblocked on ✨ Allow specifying default props values when opting an SDC in for XB Fixed .
βœ… Un-soft-blocked by #3455898-4: Connect client & server, with zero changes to client (UI): rough working endpoints that mimic the UI's mocks β†’ , which may be fixed either there by @jessebaker or in a follow-up issue.
βœ… Unblocked by πŸ“Œ Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings Fixed .

The UI currently assumes all SDC props have static values (which is why πŸ“Œ Connect client & server, with zero changes to client (UI): rough working endpoints that mimic the UI's mocks Needs review 's logic is even transforming SDC props populated by DynamicPropSources to static values for the client/UI, because that is what the client currently expects).

The HTTP API should race ahead of the UI, to empower the UI to surface multiple choices to the end user β€” choices that the FieldForComponentSuggester service can already generate:

This SHOULD also update the Open API spec if πŸ“Œ Create an Open API spec for the current mock HTTP responses Fixed landed before this is done.

Steps to reproduce

(See how in the /node/1/edit UI, the component instance with fake UUID dynamic-static-card2df uses a DynamicPropSource for the text SDC prop. Then see how in the UI, that is presented as a static value, i.e. as a StaticPropSource.)

Proposed resolution

  1. Make /xb-component/… return not just {id: …, name: …, metadata: …} for every component, but {id: …, name: …, metadata: …, prop_source_choices: …}
  2. For the purpose of this issue (and sufficient for 0.1.0), this can be hardcoded to FieldForComponentSuggester::suggest($component_id, EntityDataDefinition::create('node', 'article');
  3. The adapters key that ::suggest() returns MUST be removed: out of scope for 0.1.0
  4. The types key MUST be omitted, in favor of the sole choice computed by πŸ“Œ Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings Fixed .
  5. The instances key MUST be passed through as-is.
  6. This must come with explicit Functional test coverage. Look at \Drupal\Tests\experience_builder\Kernel\FieldForComponentSuggesterTest + \Drupal\Tests\experience_builder\Functional\EndToEndDemoIntegrationTest for inspiration.

Remaining tasks

All points above.

User interface changes

None β€” this is about leaping ahead of the UI, to allow it to offer the user a choice.

API changes

New API/endpoint to talk to.

Data model changes

None.

πŸ“Œ Task
Status

Fixed

Component

Page builder

Created by

πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @wim leers
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    The FE of this is handled in πŸ“Œ Make store API paths/uris configurable via environment variables (and eventually drupalSettings) Needs work it shows (in comments) the extension points. I knew we'd need this at some point so took the time to document it there.

  • Assigned to wim leers
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    I need to update this issue β€” many things have changed since this was created.

  • Issue was unassigned.
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    All originally identified blockers are in. But πŸ“Œ Support complex SDC prop shapes: introduce (Storable)PropShape to compute field type storage settings Fixed changes things.

    Issue summary fully updated πŸ‘

  • Status changed to Active 4 months ago
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • Assigned to bnjmnm
  • πŸ‡ΊπŸ‡ΈUnited States bnjmnm Ann Arbor, MI
  • Issue was unassigned.
  • Status changed to Needs review 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States bnjmnm Ann Arbor, MI
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Thank you, @bnjmnm, for getting this going! πŸ€©πŸ™

    This looks stellar. Zero remarks on the code. Looks like the details I write >2 months ago were sufficient? πŸ€“

    The exact shape of the response is irrelevant at this time β€” because the very purpose of this issue is to just leap ahead of the UI and at least allow some experimentation to happen on the front end when the necessary designs for this eventually arrive.

    But I am surprised the new test does not fail because πŸ“Œ Create an Open API spec for the current mock HTTP responses Fixed introduced an OpenAPI spec that covers this route too. In that OpenAPI spec, /xb-components has this schema:

                    type: object
                    minProperties: 1
                    # @see \Drupal\Core\Plugin\Component::$machineName
                    patternProperties:
                      '^\\[a-zA-Z0-9_-]:[a-zA-Z0-9_-]$':
                        $ref: '#/components/schemas/Component'
    

    and that $ref does list additionalProperties: false, which this test should be triggering? πŸ€”

    Now, I know that I literally just wrote:

    The exact shape of the response is irrelevant at this time […]

    … but I'd expect we'd need to update openapi.yml somewhat like this as a very MVP way to capture this in the OpenAPI spec:

    diff --git a/openapi.yml b/openapi.yml
    index a29efe50..4160b691 100644
    --- a/openapi.yml
    +++ b/openapi.yml
    @@ -180,6 +180,10 @@ components:
                     type: [string, integer, number, boolean, object]
             default_markup:
               type: string
    +        # @todo Refine when designs for choosing a PropSource arrive.
    +        # @see https://www.drupal.org/project/experience_builder/issues/3455975
    +        prop_source_choices:
    +          type: object
           additionalProperties: false
         Layout:
           title: layout
    
  • Status changed to Needs work 3 months ago
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Still missing here: an update to openapi.yml. The fact that this is currently passing tests is indicative of the openapi.yml file not being validated correctly by ApiResponseValidator, because additionalProperties: false in $ref: '#/components/schemas/Component' should result in a validation error 😬

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Ugh, looks like thephpleague/openapi-psr7-validator does not really support patternProperties, because the only mention of it is in a comment, and the same goes for devizzent/cebe-php-openapi which it relies upon?! 😱🀯

    😭

    Time to call it a day.

  • First commit to issue fork.
  • Assigned to wim leers
  • Status changed to Needs review 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

    @Wim Leers see my MR comments. let me know what you think the `x-xb-validation` using the OpenAPI extension naming to check this. If you are good with approach assign it back to me and I will finish it up

  • Assigned to tedbow
  • Status changed to Needs work 3 months ago
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    +1 for this direction. Details on the MR. Glad you've found a way forward! πŸ‘

  • Assigned to wim leers
  • Status changed to Needs review 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

    @Wim Leers see my MR comments

  • Assigned to tedbow
  • Status changed to Needs work 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

    Actually I still need to look at test failures

  • Issue was unassigned.
  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

    Unassigning myself. I am not sure the Cypress test is failing. I have the tests running locally but I can't figure it out. Thought maybe it was `ApiResponseValidator` but I commented that out and the test is still failing

  • πŸ‡³πŸ‡±Netherlands balintbrews Amsterdam, NL

    ✨ Implement simplified zoom interface Fixed significantly rewrites those end-to-end tests and introduces hardening for the tests to avoid trying to access elements in the iframe before their events are initialized. It's close to being merged, so I recommend that we wait until it lands, and see how the failing tests behave with those changes.

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Thanks, @balintbrews!

  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

    @balintbrews thanks!

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Turns out it's not ✨ Implement simplified zoom interface Fixed that will fix that, but πŸ› Unnecessary wait() use in e2e tests causing failures Active .

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • Status changed to Postponed 3 months ago
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • Status changed to Needs work 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States bnjmnm Ann Arbor, MI

    There's a remaining test failing because it is failing to find an iframe where data-test-xb-content-initialized is TRUE and I discovered why by adding console.log() calls next to where data-test-xb-content-initialized is switched to false and true.

    The two final logs - both which change the attribute to FALSE (without the expected switch to TRUE) - only happen in this MR.

    I can see how this might happen since the switch to FALSE will occur any time the useEffect is triggered by a change to dispatch, height, handleDragAdd, handleDragEnd, handleDragStart, layout, model, components, but the switch to TRUE only happens when the onload callback is invoked. It seems like there are plenty of opportunities for one of the 8 useEffect dependencies to change and change data-test-xb-content-initialized to FALSE without onload firing to change it to TRUE.

    If those extra renders of the iframe are unnecessary, perhaps they should be addressed in this issue. If it is expected and acceptable, then we need a different way to mark something as initialized.

    WITH THIS MR OPEN YOU CAN CONFIRM THIS BY... going to the XB UI and look at the iframe html - you'll see the data-test-xb-content-initialized within moments of the UI loading.

  • πŸ‡ΊπŸ‡ΈUnited States bnjmnm Ann Arbor, MI

    Further debugging shows that this MR is not creating any new changes that trigger the iFrame attribute update changes. Instead, it is changing the order that they change, and components is changing after layout and model.

    A change to component triggers the useEffect that sets data-test-xb-content-initialized to false, but unlike layout/model it does not result in the iframe loading anything new, so the onload that would set data-test-xb-content-initialized to TRUE is not invoked.

  • Status changed to Needs review 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States bnjmnm Ann Arbor, MI

    Based on the extensive debugging it looks like this can be addressed by changing a few lines so components (a list of the available components) is no longer a dependency of the iframe-impacting useEffect or the updateData useCallback. Neither of these should need to update if the components list changes.

    While it's true that updateData requires components to have initialized for it to properly add a component to the layout, this doesn't need to be enforced as a callback dependency because the UI doesn't offer that option until it is ready anyways.

    I think this solution is sound but it would be good to get another FE person to look it over to ensure this isn't going to break something elsewhere.

  • πŸ‡³πŸ‡±Netherlands balintbrews Amsterdam, NL

    Truly great investigation, and I agree with the solution! I love how this ended up being an actual problem β€” unnecessary rerenders β€” our test uncovered.

  • Status changed to RTBC 3 months ago
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    πŸ‘ @bnjmnm! Agreed with @balintbrews 😊

  • Pipeline finished with Skipped
    3 months ago
    #268366
  • Pipeline finished with Skipped
    3 months ago
    #268374
  • Status changed to Fixed 3 months ago
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

    Somehow the removal of patternProperties got remove from this MR will open up a follow-up

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

Production build 0.71.5 2024