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

Refactor formio integration #1068

Closed
12 of 15 tasks
sergei-maertens opened this issue Dec 13, 2021 · 1 comment · Fixed by #2388
Closed
12 of 15 tasks

Refactor formio integration #1068

sergei-maertens opened this issue Dec 13, 2021 · 1 comment · Fixed by #2388
Assignees
Milestone

Comments

@sergei-maertens
Copy link
Member

sergei-maertens commented Dec 13, 2021

From #1099, #1059 and #1054 it's clear that we need to re-structure our code to manage (custom) formio types:

  • Hooking up special custom types with backend mutations
  • Formatting the values of vanilla and custom FormIO components

This ticket describes the technical design to resolve both mentioned issues.

Design principles

  • We provide first class support for FormIO
  • FormIO (or generally: vendor) specific integration code is contained in its own package (i.e. -> do not intertwine it with vendor-agnostic OF code)
  • Pluggable & testable

Tasks

  • Create a new top-level package openforms.formio
    • Subpackages custom_types and formatters
  • Set up the custom field registry
    • define the register in openforms.formio.custom_types.registry (move from openforms.forms.custom_field_types)
    • Ensure that the register inherits from our base register class to make things consistent
    • Define a custom base type inheriting from openforms.plugins.plugin.AbstractBasePlugin
    • A custom type can have two modes of operation:
      • Return value to append FormIO component schema(s)
      • Mutates given FormIO component schema
    • The handler must process components recursively (i.e.: use FormDefinition.iter_components(...), currently not the case
    • The handler also takes a submission object for context, instead of the request. The information possibly on the request should be persisted on the submission instead (such as authentication state).
    • Split up hooks into part with and without input data ('static' impact + data-dynamic impact)
  • Set up the formatters registry in openforms.formio.formatters.registry
    • A formatter takes two arguments: value and component, with component being the FormIO json schema
      • This has a big impact - the extra context of component is now not passed along and will lead to restructing in other places!
    • Define a module with vanilla Formio formatters openforms.formio.formatters.default
    • Define a default fallback formatter (could simply be str(value)), used for (custom) types without explicitly registered formatter, to avoid crashes
  • Consider marking formatters (or types?) as presentation only (vs. data) -> WYSYWIG, fieldsets, columns... (part of Labels of components hidden (direct or by logic) show up in summary #1451)
@sergei-maertens sergei-maertens added this to the Sprint #11 milestone Dec 13, 2021
@stevenbal stevenbal self-assigned this Dec 21, 2021
sergei-maertens added a commit that referenced this issue Nov 24, 2022
…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.
sergei-maertens added a commit that referenced this issue Nov 24, 2022
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.
sergei-maertens added a commit that referenced this issue Nov 24, 2022
…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 added a commit that referenced this issue Nov 24, 2022
The public API now uses the new/single registry for formio components,
which also handles the formatting of values given to formio components.
sergei-maertens added a commit that referenced this issue Nov 24, 2022
This is now used by the component registry rather than implementing/
providing a formatter registry itself.
sergei-maertens added a commit that referenced this issue Nov 24, 2022
…stry

This deletes the dynamic config-specific registry, while mostly keeping
the public API intact.
sergei-maertens added a commit that referenced this issue Nov 24, 2022
…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.
sergei-maertens added a commit that referenced this issue Nov 24, 2022
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.
sergei-maertens added a commit that referenced this issue Nov 24, 2022
…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 added a commit that referenced this issue Nov 24, 2022
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.
sergei-maertens added a commit that referenced this issue Nov 24, 2022
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.
sergei-maertens added a commit that referenced this issue Nov 25, 2022
…formio-integration

♻️ [#1068] -- Refactor formio integration
@sergei-maertens sergei-maertens moved this to Todo in Development Dec 8, 2022
@sergei-maertens sergei-maertens moved this from Todo to Done in Development Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants