Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👽 [#4693] Integrate Objects API prefill modal with backend #4799

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

stevenbal
Copy link
Contributor

@stevenbal stevenbal commented Oct 28, 2024

Closes #4693

Changes

  • Integrate Objects API prefill modal with backend

Checklist

Check off the items that are completed or not relevant.

  • Impact on features

    • Checked copying a form
    • Checked import/export of a form
    • Config checks in the configuration overview admin page
    • Problem detection in the admin email digest is handled
  • Release management

    • I have labelled the PR as "needs-backport" accordingly
  • I have updated the translations assets (you do NOT need to provide translations)

    • Ran ./bin/makemessages_js.sh
    • Ran ./bin/compilemessages_js.sh
  • Commit hygiene

    • Commit messages refer to the relevant Github issue
    • Commit messages explain the "why" of change, not the how

@stevenbal stevenbal marked this pull request as draft October 28, 2024 14:49
Copy link

codecov bot commented Oct 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.59%. Comparing base (4b73a1d) to head (4716f4b).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4799      +/-   ##
==========================================
+ Coverage   96.57%   96.59%   +0.02%     
==========================================
  Files         747      747              
  Lines       25400    25400              
  Branches     3355     3355              
==========================================
+ Hits        24529    24535       +6     
+ Misses        608      604       -4     
+ Partials      263      261       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stevenbal stevenbal force-pushed the feature/4693-product-prefill-modal-integration branch from c725d4c to 7436b8f Compare October 28, 2024 15:37
@stevenbal
Copy link
Contributor Author

@sergei-maertens I'm trying to fix the issue with the react-select menu being clipped, but I'm not sure how to fix it. I've tried setting a z-index, but that alone doesn't fix the issue. If I try using overflow: visible, I do see the full menu, but the rest of the modal breaks :/

current situation
image
with overflow
image

Any ideas on how this can be fixed? Changing the menuPlacement to bottom will likely cause the same issue in the future, if the list of choices gets long enough

@stevenbal stevenbal force-pushed the feature/4693-product-prefill-modal-integration branch 6 times, most recently from 49af4a9 to 175af2c Compare October 29, 2024 10:59
@stevenbal stevenbal marked this pull request as ready for review October 29, 2024 11:22
@stevenbal
Copy link
Contributor Author

@sergei-maertens I've made the placement bottom and set a maxMenuHeight for the selects used in the modal to avoid overflow issues (efb307d)

@stevenbal stevenbal marked this pull request as draft October 29, 2024 15:33
@stevenbal stevenbal force-pushed the feature/4693-product-prefill-modal-integration branch 3 times, most recently from 0b8256e to 5e646cc Compare November 4, 2024 08:35
@stevenbal stevenbal marked this pull request as ready for review November 4, 2024 08:43
@sergei-maertens sergei-maertens self-assigned this Nov 8, 2024
@sergei-maertens sergei-maertens force-pushed the feature/4693-product-prefill-modal-integration branch from 5e646cc to 33836d3 Compare November 12, 2024 10:15
Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed a couple more things when checking this out locally to look into the dropdown issue:

  • I'm missing the code structure from the registrations app a bit - now there's a single file with a number of components for the Objects API form, all in the variables/prefill folder. Perhaps building out a sub-structure like in registrations with a directory per plugin ID would be better to manage the code, and we can then split out the individual components.
  • When resetting the api group in the prefill form, the selected object type and version are not reset, only the variables mapping. This leads to hidden form state that is not accurately represented in the UI and is confusing at the least and dangerous at most.
  • The form field/button to copy the settings from a registration backend I haven't tested yet, but I found the UI controls to be in an odd place. I would expect that to be the first thing I see, visually separated from the rest of the fields since they also affect API group, object type and object type version, not just the variables mapping. And a paragraph with some explanation of what it actually does would go a long way for users to decide what they want to do to configure. Additionally, the 'copy' language should maybe be more along the lines of 'synchronize', since this would also be the mechanism to update the prefill config after the registration variables config/mapping is updated without having to manage everything manually afterwards
  • The help texts for fields now have the registration field help texts, those either need to be removed for the prefill plugin, or overridden with prefill-specific content. Now it's just confusing instead of making things more clear.

@@ -82,6 +82,7 @@ const SelectWithoutFormik = ({name, options, value, className, onChange, ...prop
classNamePrefix="admin-react-select"
styles={styles}
menuPlacement="auto"
menuPortalTarget={document.body}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is too simple as it breaks storybook, which renders in another DOM node and the within(canvasElement) queries break. Instead, we should probably set up a custom context that defaults to document.body, but which we can override in storybook to point it to the right node, similar to what we do with the modals.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we now have this modal context for storybook from @robinmolen, so we can apply the same pattern.

@sergei-maertens sergei-maertens marked this pull request as draft November 12, 2024 11:48
that allows the user to copy the configuration used by the Form's registration backend
* remove unnecessary prefill prefix from options in javascript code
* remove trailing comments
* use variable for computed name in VariableMapping
* add dropdown to select a registration backend instead of always picking first
* also copy variablesmapping when clicking copy button
* use setValues to set formik values at once, instead of multiple calls of setFieldValue
@sergei-maertens sergei-maertens force-pushed the feature/4693-product-prefill-modal-integration branch from 8e23cf3 to 4716f4b Compare November 18, 2024 13:32
@sergei-maertens
Copy link
Member

Rebased on master - I will now look at the state again and do a thorough review!

@sergei-maertens
Copy link
Member

I'm not happy yet with the "copy configuration" button and this is a tough nut to crack. After some discussion/debate with Joeri, we've settled on something like this:

  1. When you open the prefill modal, you get the current state (with dropdowns likely empty if this is the initial configuration:

    image

    • A link is injected next to the 'plugin' field. This will require some interesting changes which we can discuss tomorrow, since you currently can't provide additional children for the plugin field... We can add a tooltip here that describes how it works/what it does for better documentation.
    • The registration backend dropdown is not visible at all
  2. The user clicks the link to copy the settings - this makes the registration dropdown visible:

    image

  3. Clicking the link again just collapse the form row again

  4. Selecting a backend and then clicking the 'copy' button performs the copy as it is right now, but also automatically collapses the form row again at the end to declutter the UI again.

Please also set up the styling properly so that the link and button are nicely aligned.

Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should go through these remarks tomorrow :)

Let's get this PR wrapped up before we tackle the other one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we structure/organize this code a bit better? I noticed I was getting lost on what calls what. I'd like to see:

  • a directory src/openforms/js/components/admin/form_design/variables/prefill/ with...
  • subdirectories default, objects_api
  • AttributeField, IdentifierRoleField and DefaultFields go in default
  • ObjectsAPIFields goes in objects_api, and you can break up the component in multiple files - try to go for one file per component
  • Consider moving PLUGIN_COMPONENT_MAPPING to a constants.js or index.js instead of defining it in PrefillConfigurationForm (in the prefill directory)

This mimics the structure of registration frontend components more closely and makes it a bit easier to navigate imo.

className="button"
onClick={e => {
e.preventDefault();
const confirmed = window.confirm(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the useConfirm hook rework was merged, so you can use that now :)

@@ -104,7 +190,7 @@ const ObjectsAPIFields = ({errors}) => {
<ObjectsAPIGroup
apiGroupChoices={apiGroups}
onChangeCheck={async () => {
if (values.options.variablesMapping.length === 0) return true;
if (variablesMapping.length === 0) return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change resets the objecttype and object version too, so just checking for variable mappings is maybe too naive? Maybe better to warn as soon as an objecttype is selected

@@ -123,11 +211,11 @@ const ObjectsAPIFields = ({errors}) => {
}
>
<ObjectTypeSelect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the prefill configuration now shows the tooltips/help texts for the registration configuration, which is misleading

@@ -147,9 +237,11 @@ const ObjectsAPIFields = ({errors}) => {
<ObjectTypeVersionSelect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the prefill configuration now shows the tooltips/help texts for the registration configuration, which is misleading

Comment on lines +29 to +35
const defaults = {
objectsApiGroup: '',
objecttype: '',
objecttypeUuid: '',
objecttypeVersion: null,
variablesMapping: [],
},
errors,
}) => {
};
options = {...defaults, ...options};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be pushed down to ObjectsAPIFields and have it set the default values on initial render - you can get the initialValues from the Formik state. This generic component should not be polluted with plugin-specific options and we want to keep the relevant code co-located.

@@ -82,6 +82,7 @@ const SelectWithoutFormik = ({name, options, value, className, onChange, ...prop
classNamePrefix="admin-react-select"
styles={styles}
menuPlacement="auto"
menuPortalTarget={document.body}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we now have this modal context for storybook from @robinmolen, so we can apply the same pattern.

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.

Product prefill configuration modal: integrate with backend
3 participants