Overview

#3478299: Implement basic auto-save is implemented autoaving the UI data so you could reload the browser and have your current work in XB even without an entity save

This issue will make an actual entity save

Proposed resolution

Create a new route to save the entity and create "Publish" button on the client

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

The current merge requests uses the preview API call same as #3478299: Implement basic auto-save

it currently does not work with components with a "name" property and it does not for images.

tedbow’s picture

Now I have images working. It is just a POC so just assumes we are using media entities and the src always matches a file which then matches and a media entity

tedbow’s picture

Title: AutoSave Entity Revision POC » Add Entity Revision save via Publish button

Changing this issue to do that actual save via "Publish" as that is the first functionality we need to add.

#3478299: Implement basic auto-save was committed for auto-save to the tempstore

tedbow’s picture

Assigned: tedbow » Unassigned
Priority: Normal » Major
Issue summary: View changes
Status: Active » Needs review

I think this is ready for review.

This is no longer a POC so changing the Priority

tedbow’s picture

Assigned: Unassigned » longwave

wim leers made their first commit to this issue’s fork.

wim leers’s picture

Assigned: longwave » tedbow
Status: Needs review » Needs work

Very much on the right track, but I think in the current state it'll be hard to evolve.

I left a bunch of suggestions that IMHO make this more approachable, and make it easier to iterate on in the future.

WDYT, @tedbow?

tedbow’s picture

Assigned: tedbow » wim leers

re #12 see MR comments

Also I removed the changes under /UI where I had added the button because there were merge conflicts. I just copied that JS from another issue. I think this issue could go in without any UI changes because we have the functional test. It is not ideal because we don't have a way make sure the test client data is correct but I think to be practical it is fine, we can then create a client-side follow-up issue to use the new endpoiont

tedbow’s picture

Status: Needs work » Needs review
Related issues: +#3487381: Create exception class for invalid data from client

I think the e2e failure was random🤞🏻

I talked with @f.mazeikis about this. He is working on #3479643: Introduce a `Pattern` config entity( I think that is the correct issue). He said he could use some of this work in the new trait. I think maybe also \Drupal\experience_builder\Controller\ApiSaveController::clientModelToServerProps the functions it calls. So probably in his issue that could all be moved to the new trait(it is only needed in the controller in this issue)

So I think it would be good to this issue in and do #3487381: Create exception class for invalid data from client in a follow-up. Could create other follow-ups if @wim leers sees the need

tedbow’s picture

tedbow credited f.mazeikis.

tedbow’s picture

wim leers’s picture

Assigned: wim leers » tedbow
Status: Needs review » Needs work

A thorough review round 🏓

I think there's some crucial bits that are too rough to get merged here:

  1. supports only POST but does not restrict the route to that and appears to support updating an entity. Suggested fixes on MR: rename route + controller to be about saving entity revisions, not entities, then it all makes sense.
  2. the validation error response is way too unstructured, even after having incorporated @longwave's feedback. This will make surfacing validation errors on the client side unnecessarily cumbersome. All the right pieces exist already. I pointed to them in my MR comments.
  3. The helper methods were constructing various kinds of undocumented arrays of doom. This is implied by your comment at https://git.drupalcode.org/project/experience_builder/-/merge_requests/3.... I pushed a handful of commits that improve that.
tedbow’s picture

There are now phpunit (next major) tests failing. But the fail the same way for me on 0.x locally after I pulled the latest 11.x changes. That last 0.x ci passed so maybe it is something in Core 11.x.. Will rerun 0.x

tedbow’s picture

Assigned: tedbow » wim leers
Status: Needs work » Needs review
wim leers’s picture

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

Sorry for frustrating you, @tedbow 😬 🙈

Given this is introducing a HTTP API route that accepts arbitrary inputs, we IMHO should not defer precise validation error messages for the UI to follow-up issues: this issue IMHO SHOULD provide the necessary infrastructure to enable folks working on the XB UI to work on validation errors at the same time as they work on saving — because they go hand-in-hand. Validation was already handled … but it was lacking the precision needed for the XB UI to provide a good UX.

@tedbow is right that this resulted in some scope creep. But that's only because I tried to accelerate getting this MR to the point where I am comfortable with it landing (thanks to it being sufficiently complete/not having many follow-ups). Ideally, the changes to ValidComponentTreeConstraintValidator would have happened in a blocking issue/MR (commits https://git.drupalcode.org/project/experience_builder/-/merge_requests/3... + https://git.drupalcode.org/project/experience_builder/-/merge_requests/3...), but for the sake of speed/minimizing overhead, I am personally fine with the scope creep 😇

In particular these two MR threads:

tedbow’s picture

Status: Reviewed & tested by the community » Needs review

I think I need to review the changes @wim leers made then I will put back to RTBC

tedbow’s picture

Assigned: tedbow » wim leers
Status: Needs review » Needs work

Needs work for the 2 failing tests cases I added, @wim leers maybe you think we shouldn't cover the new cases because we can somewhat trust the client but I thought I would at least point them out.

Setting to needs work to either make the tests pass or remove the test cases.
@wim leers I assigned to the issue to you to review those not necessarily fix those.

I guess it is also needs review for my long comment here https://git.drupalcode.org/project/experience_builder/-/merge_requests/3... 😬
but like I said there maybe I just need to sleep on it to see the wisdom of the changes @wim leers made, I definitely been convinced before 😉. So i guess I am not asking for any changes right now unless @wim leers is blow away by arguments there(which I am not expecting). I just wrote out what I was thinking and will see if I feel the same tomorrow.

@wim leers ultimately you are the tech lead so if are already confident on the changes you made and don't buy my argument that it is more complicated and harder to understand then I have reviewed them I am fine with them technically, so I won't block or hold up commit on those. I would rather get this issue and move on to other issues.

Other than that I think the only outstanding problem is the failing test cases and if those are fixed or removed I think this issue is ready to be committed.

tedbow’s picture

Title: Add Entity Revision save via Publish button » Add Entity Update controller

renaming because no longer have the button.

It was in the MR previously but i remove because I kept having merge conflicts under `/ui`

If we want to could add that back.

wim leers’s picture

Assigned: wim leers » tedbow
Issue summary: View changes
Status: Needs work » Needs review

👏

The two failing test cases are excellent additions! 👍 🙏

Correct me if I'm wrong: AFAICT those new test cases would also have failed before I started making significant changes, right? 🤔

Asymmetric validation of layout/tree vs model/props.

I did already spot the validation asymmetry: model is validated, but tree is not. That was a concern, but I didn't want to hold this back any longer because I believed the infrastructure now had the right shape.

So if I was right, I should be able to:

  1. quickly fix the remaining two failures
  2. AND reuse all of the existing validation infrastructure

Solution

Thankfully, that is the case:

  1. https://git.drupalcode.org/project/experience_builder/-/merge_requests/3... introduces the same pattern for ::clientLayoutToServerTree() as I already added for ::clientModelToServerProps()fixes add a failing test case for missing component
  2. 👆 that did NOT fix add failing test case for missing props — because in HEAD, it's been impossible to send such an invalid value, since this MR introduces the potential for arbitrary inputs, as I described on the MR yesterday: https://git.drupalcode.org/project/experience_builder/-/merge_requests/3.... That's why HEAD has \Drupal\experience_builder\Plugin\DataType\ComponentPropsValues::getComponentPropsSources() throwing an exception when tree + props (in the client-side data model: layout + model) are out of sync.
  3. That simply was due to one missing catch in ValidComponentTreeConstraintValidator that I just added in https://git.drupalcode.org/project/experience_builder/-/merge_requests/3...— which was written by yours truly to validate that tree+props together are valid 😊

Conclusion

Overall, thanks to your two new failing test cases, the point I was making during my reviews has actually been confirmed 😅: any API interactions MUST maximally reuse the existing validation constraints.

Put differently: if any gaps are found in the validation, then we MUST NOT write additional logic for the one code path we're working on in an MR, but instead we MUST update the validation constraint validator itself, to ensure it runs always. That is how we achieve consistency across the entire codebase, and how the same concepts are treated the same everywhere, making the codebase easier to reason about.

wim leers’s picture

Issue summary: View changes

Oops, wrote my comment in the IS field 🤣🙈

wim leers’s picture

tedbow’s picture

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

I think this is ready.

wim leers’s picture

Title: Add Entity Update controller » Add Entity Update controller

but I like the changes we use more of the validation logic we already have.

— @tedbow at https://git.drupalcode.org/project/experience_builder/-/merge_requests/3...

Whew! 😮‍💨

Per #30, merging! But apparently this needs to pull in origin/0.x first, so did that, eagerly awaiting test results 🤓

  • wim leers committed 7c2d2269 on 0.x authored by tedbow
    Issue #3478565 by tedbow, wim leers, longwave, traviscarden, larowlan, f...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Merged!

Next step: reroll #3487773, because this MR moved some code that that MR was going to remove — see #3487773-7: Get component name from components list not from the component's model. Un-RTBC'd that prioritize this (more complex) MR.

Status: Fixed » Closed (fixed)

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