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

♻️ [#1068] -- Refactor formio integration #2388

Merged
merged 16 commits into from
Nov 25, 2022

Conversation

sergei-maertens
Copy link
Member

@sergei-maertens sergei-maertens commented Nov 23, 2022

Closes #1068

This refactors and restructures how we deal with formio components in the backend, tackling all the aspects now that our codebase is mature enough to see what is used and required.

So far, every aspect has had its own registry within the openforms.formio package, implementing functionality specific to that. However, it's becoming clear that those aspects also have interaction at some level (or will have this, see #2324), so the general direction is now to have ONE registry holding all the (known) formio component types as plugins, where every plugin can manage the relevant aspects.

This encourages composition and keeps the concerns together per component type rather than needing multiple files for a full picture of a single component type.

Aspects:

  • Formatters for renderers (properly displaying submitted values for human consumption)
  • Data normalization (from prefill endpoints that return data in unexpected ways)
  • On-the-fly component mutations for dynamic configurations - this is expected to be built out more in the future when we extend formio component configuration options more and more.
  • Handling custom types - sort of meta-component types that ultimately "compile" down to vanilla formio components, but depends on dynamic input data, possibly from external sources.
  • Check and update developer documentation!

@codecov-commenter
Copy link

codecov-commenter commented Nov 23, 2022

Codecov Report

Base: 93.53% // Head: 93.47% // Decreases project coverage by -0.05% ⚠️

Coverage data is based on head (ad4fd78) compared to base (c33d067).
Patch coverage: 92.99% of modified lines in pull request are covered.

❗ Current head ad4fd78 differs from pull request most recent head 1dc3088. Consider uploading reports for the commit 1dc3088 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2388      +/-   ##
==========================================
- Coverage   93.53%   93.47%   -0.06%     
==========================================
  Files         651      651              
  Lines       20750    20797      +47     
  Branches     1964     1964              
==========================================
+ Hits        19408    19440      +32     
- Misses       1024     1040      +16     
+ Partials      318      317       -1     
Impacted Files Coverage Δ
src/openforms/conf/base.py 92.95% <ø> (ø)
src/openforms/emails/confirmation_emails.py 94.28% <ø> (ø)
...forms/formio/components/np_family_members/admin.py 100.00% <ø> (ø)
...s/formio/components/np_family_members/constants.py 100.00% <ø> (ø)
...rmio/components/np_family_members/haal_centraal.py 100.00% <ø> (ø)
...orms/formio/components/np_family_members/models.py 100.00% <ø> (ø)
...rms/formio/components/np_family_members/stuf_bg.py 90.47% <ø> (ø)
src/openforms/formio/typing.py 100.00% <ø> (ø)
src/openforms/formio/formatters/service.py 71.42% <66.66%> (-28.58%) ⬇️
src/openforms/formio/registry.py 84.74% <84.74%> (ø)
... and 16 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@sergei-maertens sergei-maertens force-pushed the feature/1068-refactor-formio-integration branch 2 times, most recently from 64060e9 to 0b5e7ed Compare November 24, 2022 13:16
The public API now uses the new/single registry for formio components,
which also handles the formatting of values given to formio components.
This is now used by the component registry rather than implementing/
providing a formatter registry itself.
…port

This moves it up into the openforms.formio.service module rather than
in the formatters subpackage.
…stry

This deletes the dynamic config-specific registry, while mostly keeping
the public API intact.
…line

Instead of using a fixed pipeline, the concerns are now moved to the component level
that can opt-in to request-specific component rewriting.

This should also lead to slightly more optimized code execution since we're looping
over a caching datastructure rather than looping over the entire component tree
over and over again.
First step towards refactoring how custom fields are handled,
the request should not be needed as all required information
is/should be present on the submission instance.
…g approach

Now it's just another flavour of mutating an existing component on
the fly, with the added functionality of making some network calls to
retrieve the relevant data.

This essentially does away with the whole special treatment of custom
field types. The use case of adding one or more components and
rebuilding the component tree is removed, as there has not been any
demand for this.

We do keep in mind it may at some point be needed to inject components
at other locations in the tree or do more advanced operations, but
the current implementation does not sit in the way of that approach.

Additionally, this fixes the bug where only top-level npFamilyMembers
components could function correctly, which is now properly recursive
for nested components.
@sergei-maertens sergei-maertens force-pushed the feature/1068-refactor-formio-integration branch from 4242b88 to cd46627 Compare November 24, 2022 16:06
@sergei-maertens sergei-maertens force-pushed the feature/1068-refactor-formio-integration branch from cd46627 to 45b5a52 Compare November 24, 2022 16:07
@sergei-maertens sergei-maertens marked this pull request as ready for review November 24, 2022 17:36
The navtree was confusing and too nested, this structures the
docs more along the core/modules principles and keeps the topics
on a single page.
docs/developers/backend/core/formio.rst Outdated Show resolved Hide resolved
src/openforms/formio/formatters/formio.py Show resolved Hide resolved
@sergei-maertens sergei-maertens force-pushed the feature/1068-refactor-formio-integration branch from 536133b to 5b2629f Compare November 25, 2022 10:35
@sergei-maertens sergei-maertens merged commit 0dcd9bf into master Nov 25, 2022
@sergei-maertens sergei-maertens deleted the feature/1068-refactor-formio-integration branch November 25, 2022 10:38
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.

Refactor formio integration
3 participants