Skip to content

Add auto-refresh and manual sync for KoboToolbox changes #5

@langbart

Description

@langbart

Problem

When validation status is updated directly in KoboToolbox (outside the portal), the changes are not immediately reflected in the validation portal table. MongoDB is only updated when the R pipeline runs.

Current Behavior

  • Portal → MongoDB: ✅ Immediate update
  • Portal → KoboToolbox: ✅ Immediate update
  • KoboToolbox → MongoDB: ❌ Only updates when R pipeline runs (not real-time)
  • Table display: Shows MongoDB data only

Proposed Solution

Phase 1: Auto-refresh (Priority: High)

Add automatic table refresh every 60 seconds to catch:

  • Updates from other portal users
  • Changes made directly in KoboToolbox
  • Background R pipeline syncs

Implementation:

  • Add useEffect with interval timer in ValidationTable.tsx
  • Call refetch() every 60 seconds
  • Clean up interval on component unmount
  • Show subtle indicator when refreshing

Benefits:

  • Simple implementation
  • Covers 99% of use cases
  • No infrastructure changes needed
  • Handles concurrent users

Phase 2: Manual sync button (Priority: Medium)

Add "Sync from KoboToolbox" button for admin users to trigger on-demand sync.

Implementation:

  • Add admin-only button in ValidationTable
  • Create API endpoint: POST /api/admin/sync-from-kobo
  • Trigger existing R pipeline script
  • Show sync progress/status

Benefits:

  • Handles rare exceptional cases
  • Gives admins control
  • Reuses existing R pipeline logic

Phase 3 (Optional): WebSocket real-time updates

For future consideration if real-time updates become critical.

Acceptance Criteria

  • ValidationTable auto-refreshes every 60 seconds
  • Auto-refresh doesn't disrupt user's current selection/filters
  • Visual indicator shows when refresh is in progress
  • Manual sync button available for admin users
  • Manual sync triggers R pipeline and updates MongoDB
  • Sync status/progress is visible to user

Technical Notes

  • Auto-refresh interval should be configurable (env var or constant)
  • Consider pausing auto-refresh when user is actively editing
  • Ensure refresh doesn't reset table state (pagination, filters, sorting)

Related Files

  • src/components/ValidationTable/ValidationTable.tsx
  • src/api/api.ts (useFetchSubmissions hook)
  • api/admin/sync-from-kobo.js (new endpoint needed)

Implementation Estimate

  • Phase 1 (Auto-refresh): ~2-3 hours
  • Phase 2 (Manual sync): ~4-6 hours
  • Testing: ~2 hours

Alternative Considered

Webhooks from KoboToolbox: Rejected due to complexity and infrastructure requirements. The hybrid auto-refresh + manual sync approach is more practical for this use case.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions