Data Layer medium complexity frontendmobile
0
Dependencies
3
Dependents
1
Entities
0
Integrations

Description

Provides data access for the preview feature, including fetching the aggregated report figures for the selected period and retrieving prior-period report data for the comparison diff view. Reads from Supabase and caches results locally to support fast re-renders and offline preview access after initial load.

Feature: Bufdir Report Preview

bufdir-preview-repository

Summaries

The Bufdir Preview Repository gives coordinators and administrators instant access to their aggregated reporting figures — including a side-by-side comparison with the prior reporting period — without requiring repeated server round-trips. By caching data locally after the first load, this component supports a smooth, responsive preview experience even in environments with intermittent connectivity, such as activity centers with unreliable internet access. The year-over-year comparison capability it enables is directly tied to organizational decision-making value: coordinators can spot unexpected drops or growth in activity figures before submitting, reducing the risk of submitting data that does not reflect operational reality. This directly protects the organization's standing with Bufdir and reduces the administrative cost of corrections.

The Bufdir Preview Repository has medium complexity and is a critical dependency for both the report preview screen and the field validation service, making it a high-priority deliverable in the reporting feature track. It spans two execution contexts — frontend and mobile — requiring coordination between web and mobile platform teams to ensure the caching and reactive stream implementations are consistent across platforms. The Supabase integration is the primary external dependency and should be validated early with a working proof-of-concept. Key risks include cache invalidation logic becoming stale when underlying aggregated data changes mid-session, and the behavior of `getPriorPeriodReportData` when no prior period exists for a new organization.

Both scenarios require explicit test coverage and defined UX handling. The `watchAggregatedData` reactive stream introduces complexity in testing and should be thoroughly covered with integration tests.

The Bufdir Preview Repository is a frontend and mobile data-access layer component that abstracts Supabase reads for the report preview feature. `getAggregatedReportData(organizationId, periodId)` fetches the flat aggregated figures for the current period, while `getPriorPeriodReportData(organizationId, currentPeriodId)` resolves the immediately preceding period and fetches its data for diff rendering. `watchAggregatedData(organizationId, periodId)` exposes a reactive stream (Observable or Stream, depending on platform) so the preview UI rebuilds automatically when data changes. Results are cached in local state keyed by `(organizationId, periodId)` to prevent redundant network calls during the same session; `invalidateCache(periodId)` is exposed for explicit invalidation after a report submission or data correction.

The component must handle the null case for prior-period data gracefully and should expose a loading and error state alongside data in its reactive streams.

Responsibilities

  • Fetch aggregated Bufdir report data for a given organization and period
  • Retrieve prior-period report data for year-over-year comparison
  • Cache fetched data in local state to avoid redundant network calls
  • Expose reactive streams so the UI rebuilds when data changes

Interfaces

getAggregatedReportData(organizationId, periodId)
getPriorPeriodReportData(organizationId, currentPeriodId)
watchAggregatedData(organizationId, periodId)
invalidateCache(periodId)
getReportMetadata(periodId)

Related Data Entities (1)

Data entities managed by this component

API Contract

View full contract →
REST /api/v1/aggregated-report-data 6 endpoints
GET /api/v1/aggregated-report-data
GET /api/v1/aggregated-report-data/:id
POST /api/v1/aggregated-report-data
PUT /api/v1/aggregated-report-data/:id
DELETE /api/v1/aggregated-report-data/:id
GET /api/v1/aggregated-report-data/watch