Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Oct 16, 2025

feat: pass enrollment dates to form field plugins in widget profile

Summary

This PR enables form field plugins to access enrollment dates (enrolledAt and occurredAt) when editing tracked entities in the widget profile. Previously, these dates were only available in the registration page context, causing plugins that depend on them to break in the profile widget edit modal.

Implementation:

  • Uses enrollment data already fetched by the useLifecycle hook in the profile widget's DataEntry container
  • Creates a memoized pluginContext object with enrolledAt and occurredAt as read-only fields
  • Attempts to update these dates trigger console errors (soft enforcement of read-only behavior)
  • Threads pluginContext through the DataEntry component chain to reach form field plugins
  • Added proper PluginContext TypeScript type throughout the chain

Review & Testing Checklist for Human

  • Test with an actual form field plugin - This is the most critical item. Deploy to a test environment and verify that a plugin using enrolledAt/occurredAt can access these values when editing in the profile widget. I haven't tested with real plugins.
  • Verify date format - Confirm the dates from the enrollment object are in the correct format for plugins. The previous approach planned to use date converters, but this implementation passes dates directly from Redux state without conversion. Check if conversion is needed.
  • Verify enrollment data availability - Confirm the enrollment object from useLifecycle always has enrolledAt and occurredAt fields when editing in the profile widget context.
  • Test read-only enforcement - Verify that plugins attempting to update enrollment dates see console errors and that the soft enforcement approach is acceptable.

Notes

Recommended test plan:

  1. Set up a program with a form field plugin that uses enrolledAt or occurredAt from the plugin context
  2. Navigate to an enrollment dashboard
  3. Open the profile widget and click "Edit"
  4. Verify the plugin can read the enrollment dates correctly
  5. If the plugin attempts to update dates, verify console errors appear
  6. Compare behavior with the registration page to ensure consistency

Implementation details:

  • The enrollment data comes from the useLifecycle hook's context, which fetches it from Redux state (enrollmentDomain.enrollment)
  • This is a refactoring from the initial approach that created a separate hook to fetch enrollment dates
  • Query key pattern follows project conventions: ['WidgetProfile', 'pluginContext', enrollmentId] (though this is no longer used after refactoring)

Session details:

- Create useEnrollmentDatesForPlugin hook to fetch enrollment dates
- Pass enrollmentId through LayoutComponentConfig to WidgetProfile
- Build pluginContext with enrolledAt and occurredAt values
- Add console error for attempted date updates (read-only in profile)
- Pass pluginContext down through DataEntry component chain

Co-Authored-By: Eirik <[email protected]>
@devin-ai-integration devin-ai-integration bot requested a review from a team as a code owner October 16, 2025 12:12
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Contributor

@eirikhaugstulen eirikhaugstulen 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, Devin. Some minor comments.

devin-ai-integration bot and others added 2 commits October 16, 2025 12:31
- Import and use PluginContext type instead of any in DataEntryOutputProps
- Update query key from ['enrollmentDatesForPlugin'] to ['WidgetProfile', 'pluginContext']
- Aligns with project conventions for query key naming

Addresses review feedback on PR #4389

Co-Authored-By: Eirik <[email protected]>
- Deleted useEnrollmentDatesForPlugin hook
- Removed enrollmentId prop from WidgetProfile component chain
- Created pluginContext in DataEntry.container using enrollment data from context
- Memoized pluginContext with useMemo as requested

This simplifies the implementation by reusing existing enrollment data
already fetched by useLifecycle hook.

Co-Authored-By: Eirik <[email protected]>
@devin-ai-integration
Copy link
Contributor Author

Thanks for the context, Simona! I understand the trade-off here.

In this case, the PluginContext type import was necessary to properly type the pluginContext being passed through to the form field plugins. Since the goal was to maintain type safety while passing enrollment dates to plugins that already expect this type, it seemed like the most pragmatic approach.

If/when the widgets are extracted into a separate plugin, this import would indeed need to be addressed as part of that refactoring effort. Thanks for flagging it!

@sonarqubecloud
Copy link

@github-actions
Copy link

@henrikmv henrikmv merged commit f94a2b1 into master Oct 23, 2025
41 checks passed
@henrikmv henrikmv deleted the eh/feat/enrollment-dates-plugin-context branch October 23, 2025 15:34
dhis2-bot added a commit that referenced this pull request Oct 23, 2025
# [104.5.0](v104.4.0...v104.5.0) (2025-10-23)

### Features

* pass enrollment dates to form field plugins in widget profile ([#4389](#4389)) ([f94a2b1](f94a2b1))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 104.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants