Skip to content

fix: update cht-form to not fail when loading a form using extension-… #9840

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

Merged
merged 9 commits into from
Mar 26, 2025

Conversation

jkuester
Copy link
Contributor

@jkuester jkuester commented Mar 14, 2025

Description

Closes #9844

  • Adds support for injecting extension-lib functions into cht-form
  • Fixes runtime errors in cht-form by mocking out the language service
  • Updates cht-form "cancel" logic to work properly with new behavior (presumably caused by the recent Angular uplift) where the web component framework de-bounces multiple calls to set a web component property with the same value.
    • As a part of this, I re-worked the integration test logic a bit to allow multiple forms to be submitted in the same test without actually reloading the page for each form. This should help ensure the cancel logic continues working as desired in the future.

Code review checklist

  • UI/UX backwards compatible: Test it works for the new design (enabled by default). And test it works in the old design, enable can_view_old_navigation permission to see the old design. Test it has appropriate design for RTL languages.
  • Readable: Concise, well named, follows the style guide, documented if necessary.
  • Documented: Configuration and user documentation on cht-docs
  • Tested: Unit and/or e2e where appropriate
  • Internationalised: All user facing text
  • Backwards compatible: Works with existing data and configuration or includes a migration. Any breaking changes documented in the release notes.

Compose URLs

If Build CI hasn't passed, these may 404:

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

@jkuester jkuester requested a review from dianabarsan March 18, 2025 03:23
@jkuester jkuester marked this pull request as ready for review March 18, 2025 03:25
Copy link
Member

@dianabarsan dianabarsan left a comment

Choose a reason for hiding this comment

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

Great work! i think I have one question inline.

// @ts-expect-error it does exist
component.formModel = undefined;
// @ts-expect-error it does exist
component.contactSummary = undefined;
Copy link
Member

Choose a reason for hiding this comment

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

I have a PR that adds an additional field to formContext. This link between form-context AND the cht-form sems very loose. I wouldn't know I had to reset this new field if I had not read this code.

Is it possible to somehow iterate over the possible properties of the formContext interface, to get their names, and reset their corresponding value in this component instead of hardcoding them here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a PR that adds an additional field to formContext. This link between form-context AND the cht-form sems very loose.

To be clear, these fields that we need to reset here are the @input fields defined above for this component instance. They are not directly related to the EnketoFormContext from the enketo.service. Particularly if the fields are optional, you should not need to make any changes here in cht-form unless you explicitly wanted to be able to inject that data (and in that case you would need to add a new @input above and then clear it out down here).

Copy link
Member

Choose a reason for hiding this comment

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

ah, I see.
This new field would be required to be testable, as it's going to contain the contact summary of the logged in user.

Copy link
Member

Choose a reason for hiding this comment

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

Is there any way we could connect the cht-form with the EnketoFormContext interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In theory I think we could make EnketoFormContext an interface and then include an implementation here in cht-form. Then, when the interface changes, the cht-form build should break if its data model is not updated with the new interface changes. I do kind of like this idea! 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I have updated EnektoFormContext so that webapp and cht-form have separate implementations. This seems to work out well since tsc will require them to be in-sync. Additionally, each implementation can be extended with properties/methods needed that are specific to webapp/cht-form. Let me know what you think!

Copy link
Member

Choose a reason for hiding this comment

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

If something forces the two types to be synced, I'm happy!

Copy link
Member

@dianabarsan dianabarsan left a comment

Choose a reason for hiding this comment

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

Approving to unblock, since all questions have been addressed!
Thanks @jkuester !

@jkuester jkuester requested a review from dianabarsan March 24, 2025 23:20
Copy link
Member

@dianabarsan dianabarsan left a comment

Choose a reason for hiding this comment

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

Sweeeeeet!

@@ -351,3 +352,40 @@ export class FormService {
}
}

export class WebappEnketoFormContext implements EnketoFormContext {
Copy link
Member

Choose a reason for hiding this comment

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

Nice moving this to forms service instead of enketo service! I was very tempted to do the same thing in a PR of mine, but it was too much an unrelated change. Thanks for making this switch!

// @ts-expect-error it does exist
component.formModel = undefined;
// @ts-expect-error it does exist
component.contactSummary = undefined;
Copy link
Member

Choose a reason for hiding this comment

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

If something forces the two types to be synced, I'm happy!

@jkuester jkuester merged commit e73d2e3 into master Mar 26, 2025
46 checks passed
@jkuester jkuester deleted the cht-form_extension-libs branch March 26, 2025 21:14
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.

Add support for cht-form for using extension-libs in forms
2 participants