- Issue created by @balintbrews
- Merge request !420Draft: #3487484: Save page data form values in application state with support for undo/redo β (Open) created by Unnamed author
- πΊπΈUnited States bnjmnm Ann Arbor, MI
balintbrews β credited bnjmnm β .
- π³π±Netherlands balintbrews Amsterdam, NL
I discussed next steps with @bnjmnm on a call last week. We agreed on the followings:
- We will make use of
FormStateContext
implemented by@/components/form/components/Form
to provide the information of what form is being rendered: currently this will mean the component props form or page data form. InputBehaviors
can make use of this information and return different higher-order components (or the same with different props) to adjust the behaviors according to the form's needs.- We will not change how the Twig to JSX mapping is done, so reverting my previous commits,
twig-to-jsx-component-map.js
will stay unchanged. - All mapped components will be split into two (or more) components, where a component with its name prefixed with
Drupal
will render another component (or components) which are purely presentational. The Drupal-prefixed component will wrap the component(s) it renders inInputBehaviors
. This is what I already started in 1631cd12. The separation will help with our Storybook implementation, implementing designs in isolation etc.
Here is a high-level overview of what
InputBehavior
does today. Validation and store update are the two areas where we need to allow different logic for each form. They're currently implemented for component props. - We will make use of
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Just flagging that this might also need to update the preview API rtk mutation to also include the form data, and then we'll need corresponding updates to the auto-save controller on the backend.
I did see somewhere that we were talking about setting props on the root to cover the entity form data, so that would bypass any FE changes to the preview API and only require BE changes. - π³π±Netherlands balintbrews Amsterdam, NL
Good callout! It's out of scope for this issue, but I'm definitely keeping an eye on π Save metadata(page data) field with the entity revision Active to make saving easier β maybe quite soon.
- π³π±Netherlands balintbrews Amsterdam, NL
@jessebaker wisely suggested that I consider extracting a piece of this work into a separate issue, and it made a lot of sense to do so for #4.4 β¨ Save page data form values in application state with support for undo/redo Active : π Split form components into `Drupal`-prefixed behavioral wrappers and presentational components Needs work .
It's nice to wrap up that piece, and it will make the review of this issue much easier. π
- π³π±Netherlands balintbrews Amsterdam, NL
Draft code is up showing the idea:
InputBehaviors
wraps the input in one ofInputBehaviorsComponentPropsForm
orInputBehaviorsEntityForm
. (We can also add a fallback later.)- These wrappers both wrap the input in
InputBehaviorsCommon
which essentially does whatInputBehaviors
did before, but using the following callbacks it receives as props:commitFormState
;parseNewValue
;validateNewValue
β with an optionalsetInputMessages
argument.
This new approach already works and does everything it did before for the component props form.
Undo/redo isn't working yet for the page data form. I need a way to initially get the entire entity data, so I can put it in the Redux store all at once instead of saving each input one by one, which would pollute the history for undo/redo. I chatted about this with @larowlan, I'll return that data in the response of
\Drupal\experience_builder\Controller\ApiLayoutController
for now, and save it to the appropriate slice inonquerystarted
. - π³π±Netherlands balintbrews Amsterdam, NL
@bnjmnm is kind enough to take over for the rest of this week as I'll be mostly on holiday until early January.
Here is what's left:
- Reroll to incorporate changes from π Move form state into the global store Active ;
- Sending page data to backend;
- Test coverage;
- Code clean-up.
Follow-up issues opened:
- π [PP-1] Handle media image fields on page data form Postponed ;
- π [PP-1] Handle fields with multiple form control elements on the page data form Postponed .