Infrastructure low complexity frontendmobile
3
Dependencies
0
Dependents
0
Entities
0
Integrations

Description

BLoC state management unit for the period selection screen. Coordinates preset loading, custom range changes, record count fetching, and validation results, emitting a typed state stream consumed by the UI.

Feature: Bufdir Report Period Selection

period-selection-bloc

Summaries

The Period Selection BLoC orchestrates the entire period selection experience for coordinators preparing a Bufdir report. It translates user actions — choosing a preset date range or entering a custom period — into immediate feedback including how many activity records fall within that range and whether the period is valid for submission. This real-time guidance reduces coordinator errors before they reach the export stage, saving time and minimizing the risk of submitting an incorrect report to Bufdir. The smooth, responsive experience it enables builds coordinator confidence in the tool and reduces reliance on manual verification steps or support requests.

The Period Selection BLoC has three service dependencies — period-preset-service, period-record-count-service, and report-period-validator — all of which must be functional before this component can be fully integration-tested. Its complexity is rated low, but the event-driven BLoC pattern means test coverage must include all event types: preset selection, custom range changes, and confirmation. Pay particular attention to debounce behavior on custom range changes to avoid excessive record-count API calls during typing. The BLoC runs in both frontend and mobile execution contexts, so any platform-specific behavior in its dependencies must be accounted for.

Widget tests for the consuming UI should mock this BLoC's state stream rather than running live services.

Period Selection BLoC follows the flutter_bloc pattern, accepting events via the add(PeriodSelectionEvent) sink and emitting typed PeriodSelectionState instances on the state stream. Key event handlers: onPresetSelected triggers a preset lookup and record count fetch; onCustomRangeChanged should debounce (300–500ms) before triggering period-record-count-service to avoid flooding the API; onConfirmTapped invokes report-period-validator and emits either a validation error state or a confirmation-ready state. State transitions should be pure — derive state entirely from event data and service responses, avoid local mutable fields. Dispose all service subscriptions in the close() override.

The state stream is the single source of truth consumed by the UI widget; never let the UI call services directly.

Responsibilities

  • Load period presets on initialization
  • Handle preset and custom range selection events
  • Trigger record count queries and surface results to UI
  • Emit validation errors or confirmation-ready state

Interfaces

add(PeriodSelectionEvent event)
state (Stream<PeriodSelectionState>)
close()
onPresetSelected(SelectPresetEvent)
onCustomRangeChanged(CustomRangeChangedEvent)
onConfirmTapped(ConfirmPeriodEvent)

API Contract

View full contract →
REST /api/v1/period-selections 5 endpoints
GET /api/v1/period-selections List active period selection sessions for an organization
GET /api/v1/period-selections/:id Get the current state of a period selection session
POST /api/v1/period-selections Open a new period selection session for an organization
PUT /api/v1/period-selections/:id Dispatch an event to the BLoC session — maps to add(PeriodSelectionEvent) and onPresetSelected(SelectPresetEvent)
DELETE /api/v1/period-selections/:id Close and clean up a period selection session (maps to close())