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

feat: support custom forms with plugins #346

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

kabaros
Copy link
Contributor

@kabaros kabaros commented Jul 3, 2023

This is a Proof of Concept for the idea of using plugins to host and run custom forms. It's not production-ready (nor recommended) but the PoC was built to serve as a basis for evaluating the plugin route when discussing alternatives for implementing custom forms.

The custom form plugin lives here: https://github.com/kabaros/dhis2-custom-form-plugin/blob/main/src/App.js.

To test the custom form plugin, run Aggregate the Data Entry app from this branch as usual (yarn install && yarn start), then checkout and run the custom form plugin with yarn install && yarn start then navigate to any existing custom form (i.e. TB Facility Reporting Form).

PoC conclusion

My recommendation after this PoC is to not go the plugin route at all. We should not make this route possible, because:

  1. it's unsafe if we want the users to be able to run any custom JavaScript (if we don't, then what we have already might be enough)
    • even if we don't allow random JS, it's potentially still unsafe
  2. it will make it even harder to get custom forms that could run on android one day
  3. it's a route that is deceivingly easy, so could lure people to build even more forms this way rather than custom apps for example, or explore the customisation already natively possible.
  4. it would still require developer effort to migrate the old forms (admittedly much less though), so we should channel that effort towards building something future-proof.

(I will write these notes in more details in a technical document about custom forms, but this is tldr; for the plugins usecase.)

Screenshots

Custom form running inside a plugin. It uses the styles from the custom form (the ugly yellow + form design) and it - dangerously - runs the JavaScript scripts defined in the form (in this case, to set the input background to green), and communicates data to/from the parent container (for context selection for example).

image

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.

1 participant